1 line
18 KiB
JavaScript
1 line
18 KiB
JavaScript
|
function wpo_parse_json(s){if("object"==typeof s)return s;try{var e=JSON.parse(s);return e}catch(o){console.log("WPO: Exception when trying to parse JSON (1) - will attempt to fix/re-parse"),console.log(s)}var i=s.indexOf("{"),a=s.lastIndexOf("}");if(i>-1&&a>-1){var n=s.slice(i,a+1);try{var t=JSON.parse(n);return t}catch(o){console.log("WPO: Exception when trying to parse JSON (2) - will attempt to fix/re-parse based upon bracket counting");for(var m=i,_=0,r="",u=!1;(_>0||m==i)&&m<=a;){var c=s.charAt(m);u||"{"!=c?u||"}"!=c?'"'==c&&"\\"!=r&&(u=!u):_--:_++,r=c,m++}console.log("Started at cursor="+i+", ended at cursor="+m+" with result following:"),console.log(s.substring(i,m));try{var t=JSON.parse(s.substring(i,m));return t}catch(o){throw o}}}throw"WPO: could not parse the JSON"}jQuery(function(s){WP_Optimize_Smush=WP_Optimize_Smush()});var WP_Optimize_Smush=function(){function s(){var s=0==U('input[type="checkbox"]:checked',z).length;K.prop("disabled",s),M.prop("disabled",s)}function e(s,o){if(H){var i=U("#smush-information-modal-cancel-btn .smush-information");I("mark_all_as_uncompressed",{restore_backup:s?1:0,delete_only_backups_meta:o?1:0},function(o){if(H)return o.hasOwnProperty("error")?(x(U("#smush-information-modal"),U.unblockUI),U("#smush-information-modal .smush-information").text(o.error),void a()):void(o.completed?(x(U("#smush-information-modal"),U.unblockUI),U("#smush-information-modal .smush-information").text(o.message),a()):(i.text(o.message),e(s)))})}}function o(){U(this).toggleClass("opened"),U(this).hasClass("opened")?U(this).text(wposmush.less):U(this).text(wposmush.more)}function a(e){var e="undefined"==typeof e||e,o={use_cache:e};P.html("..."),j.hide(),w(!0),I("get_ui_update",o,function(e){O(e,u),f(),w(!1),s()})}function n(){U("#wpo_smush_images_grid input:checked").each(function(){image={attachment_id:U(this).val(),blog_id:U(this).data("blog")},F.push(image)}),data={optimization_id:"smush",selected_images:F,smush_options:{compression_server:U("input[name='compression_server']:checked").val(),image_quality:U("#image_quality").val(),lossy_compression:U("#smush-lossy-compression").is(":checked"),back_up_original:U("#smush-backup-original").is(":checked"),preserve_exif:U("#smush-preserve-exif").is(":checked")}},c(),I("process_bulk_smush",data)}function t(){if(U("#wp-optimize-wrap").length){U("#wpo_smush_images_save_options_spinner").show().delay(3e3).fadeOut(),U("#enable_custom_compression").is(":checked")?(image_quality=U("#custom_compression_slider").val(),lossy_compression=image_quality<100):(image_quality=U("#enable_lossy_compression").is(":checked")?90:100,lossy_compression=image_quality<100);var s={compression_server:U("input[name='compression_server']:checked").val(),image_quality:image_quality,lossy_compression:lossy_compression,back_up_original:U("#smush-backup-original").is(":checked"),back_up_delete_after:U("#smush-backup-delete").is(":checked"),back_up_delete_after_days:U("#smush-backup-delete-days").val(),preserve_exif:U("#smush-preserve-exif").is(":checked"),autosmush:U("#smush-automatically").is(":checked"),show_smush_metabox:U("#smush-show-metabox").is(":checked"),webp_conversion:U("#enable_webp_conversion").is(":checked")};I("update_smush_options",s,function(s){U("#wpo_smush_images_save_options_spinner").hide(),s.hasOwnProperty("saved")&&s.saved?(U("#wpo_smush_images_save_options_done").show().delay(3e3).fadeOut(),S.hide()):(U("#wpo_smush_images_save_options_fail").show().delay(3e3).fadeOut(),S.show())})}}function m(){Z=!0,X++,seconds=X%60+""<10?"0"+X%60:X%60,minutes=parseInt(X/60)+""<10?"0"+parseInt(X/60):parseInt(X/60),U("#smush_stats_timer").text(minutes+":"+seconds),_(X)}function _(s){0==s%3&&r(),0==s%60&&I("process_pending_images",{},function(s){O(s,l)})}function r(s){data={update_ui:!0,use_cache:!1},I("get_ui_update",data,function(s){O(s,l)})}function u(s){if(z.html(""),s&&s.hasOwnProperty("unsmushed_images")){s.unsmushed_images,s.pending_tasks;0==s.unsmushed_images.length&&0==s.pending_tasks&&z.text(wposmush.all_images_compressed).wrapInner("<div class='wpo-fieldgroup'> </div>"),
|