1 line
9.8 KiB
JavaScript
1 line
9.8 KiB
JavaScript
!function(t){var e=window.wp_optimize||{},i=e.send_command,n=wpoptimize.refresh_frequency||3e4;if(!i)return void console.error("WP-Optimize Minify: wp_optimize.send_command is required.");var s={};s.init=function(){function e(t){return t.data("url")}function n(e){var i=t("#exclude_js"),n=i.val();n+=e+"\n",i.val(n)}function s(e){var i=t("#exclude_css"),n=i.val();n+=e+"\n",i.val(n)}function a(e){var i=e.data("url"),n=t("#async_js"),s=n.val();s+=i+"\n",n.val(s),c("js"),p(e)}function o(e){var i=e.data("url"),n=t("#async_css"),s=n.val();s+=i+"\n",n.val(s),c("css"),p(e)}function c(e){t("#wp-optimize-nav-tab-wpo_minify-"+e+"-contents form").data("need_saving",!0)}function p(e){e.closest(".wpo_min_log").prev().removeClass("hidden").addClass("updated").slideDown(),e.text(wpoptimize.added_to_list),e.removeClass("exclude"),e.parent().addClass("disable-list-item"),e.replaceWith(t("<span>"+e.text()+"</span>"))}function l(e){t('input[name="enable_defer_js"]').each(function(e,i){t(i).closest("fieldset").removeClass("selected").find(".defer-js-settings").slideUp("fast")}),t('input[name="enable_defer_js"]:checked').closest("fieldset").addClass("selected").find(".defer-js-settings").slideDown("fast")}function d(){h||(h=setInterval(function(){r()},5e3))}function r(){i("get_minify_preload_status",null,function(t){t.done?(_.val(wpoptimize.run_now),_.data("running",!1),clearInterval(h),h=null):(_.val(wpoptimize.cancel),_.data("running",!0)),m.text(t.message),u(t)})}function u(e){t("#wpo_min_cache_size").text(e.size),t("#wpo_min_cache_total_size").text(e.total_size)}var f=this;this.enabled=!1,t(document).on("wp-optimize/minify/toggle-status",function(e,i){i.hasOwnProperty("enabled")&&(t('[data-whichpage="wpo_minify"]').toggleClass("is-enabled",i.enabled),f.enabled=i.enabled,f.enabled&&f.getFiles())}),t(".purge_minify_cache").on("click",function(e){e.preventDefault(),t.blockUI(),i("purge_minify_cache",null,function(t){f.updateFilesLists(t.files),f.updateStats(t.files)}).always(function(){t.unblockUI()})}),t(".purge_all_minify_cache").on("click",function(){t.blockUI(),i("purge_all_minify_cache",null,function(t){f.updateFilesLists(t.files),f.updateStats(t.files)}).always(function(){t.unblockUI()})}),t(".minify_increment_cache").on("click",function(){t.blockUI(),i("minify_increment_cache",null,function(t){t.hasOwnProperty("files")&&(f.updateFilesLists(t.files),f.updateStats(t.files))}).always(function(){t.unblockUI()})}),t("#wp-optimize-nav-tab-wpo_minify-status-contents form :input, #wp-optimize-nav-tab-wpo_minify-js-contents form :input, #wp-optimize-nav-tab-wpo_minify-css-contents form :input, #wp-optimize-nav-tab-wpo_minify-font-contents form :input, #wp-optimize-nav-tab-wpo_minify-settings-contents form :input, #wp-optimize-nav-tab-wpo_minify-advanced-contents form :input").on("change",function(){t(this).closest("form").data("need_saving",!0)}),t("input[type=checkbox].wpo-save-setting").on("change",function(e){var n=t(this),s=n.prop("checked"),a=n.prop("name"),o={};o[a]=s,t.blockUI(),i("save_minify_settings",o,function(t){t.success?(n.trigger("wp-optimize/minify/saved_setting"),t.hasOwnProperty("files")&&(f.updateFilesLists(t.files),f.updateStats(t.files))):console.log("Settings not saved",o)}).always(function(){t.unblockUI()})}),t("#wpo_min_enable_minify").on("wp-optimize/minify/saved_setting",function(){this.enabled=t(this).prop("checked"),t(document).trigger("wp-optimize/minify/toggle-status",{enabled:this.enabled})}),t("#wpo_min_enable_minify").on("wp-optimize/minify/saved_setting",function(){t(this).closest(".wpo_section").toggleClass("wpo-feature-is-disabled",!t(this).is(":checked"))}),t("#wpo_min_enable_minify_css, #wpo_min_enable_minify_js").on("wp-optimize/minify/saved_setting",function(){t('#wp-optimize-nav-tab-wrapper__wpo_minify a[data-tab="'+t(this).data("tabname")+'"] span.disabled').toggleClass("hidden",t(this).is(":checked"))}).each(function(){t('#wp-optimize-nav-tab-wrapper__wpo_minify a[data-tab="'+t(this).data("tabname")+'"] span.disabled').toggleClass("hidden",t(this).is(":checked"))}),t("#wpo_min_enable_minify_debug").on("wp-optimize/minify/saved_setting",function(){t.blockUI({message:"<h1>"+wpoptimize.page_refresh+"</h1>"}),location.href=t("#wp-optimize-nav-tab-wpo_minify-advanced").prop("href")}),t("#wpo_min_edit_default_exclutions").on("wp-optimize/minify/saved_setting",function(){t(".wpo-minify-default-exclusions").toggleClass("hidden",!t(this).prop("checked"))}),t(".wp-optimize-save-minify-settings").on("click",function(e){function n(e){var i=t(e).serializeArray().reduce(s,{});return t(e).find('input[type="checkbox"]').each(function(e){var n=t(this).prop("name");if(n.includes("[]")){if(!t(this).is(":checked"))return;var s=n.replace("[]","");i[s]||(i[s]=[]),i[s].push(t(this).val())}else i[n]=t(this).is(":checked")?"true":"false"}),i}function s(t,e){return e.name.includes("[]")?t:(t[e.name]=e.value,t)}e.preventDefault();var a=t(this),o=a.next(),c=o.next();o.show(),t.blockUI();var p={},l=t('[data-whichpage="wpo_minify"] .wp-optimize-nav-tab-contents form');l.each(function(){var e=t(this);!0===e.data("need_saving")&&(p=Object.assign(p,n(e)),e.data("need_saving",!1))}),i("save_minify_settings",p,function(e){e.hasOwnProperty("error")?(console.log(e.error),t(".wpo-error__enabling-cache").removeClass("wpo_hidden").find("p").text(e.error.message)):t(".wpo-error__enabling-cache").addClass("wpo_hidden").find("p").text(""),e.hasOwnProperty("files")&&(f.updateFilesLists(e.files),f.updateStats(e.files)),o.hide(),c.show(),setTimeout(function(){c.fadeOut("slow",function(){c.hide()})},5e3)}).always(function(){t.unblockUI()})}),t(".wp-optimize-minify-status-information-notice").on("click",".notice-dismiss",function(t){t.preventDefault(),i("hide_minify_notice")}),t("#wpo_min_jsprocessed, #wpo_min_cssprocessed").on("click",".log",function(e){e.preventDefault(),t(this).nextAll(".wpo_min_log").slideToggle("fast")}),t("#wpo_min_jsprocessed").on("click",".exclude",function(i){i.preventDefault();var s=t(this),a=e(s);n(a),c("js"),p(s)}),t("#wpo_min_cssprocessed").on("click",".exclude",function(i){i.preventDefault();var n=t(this),a=e(n);s(a),c("css"),p(n)}),t("#wpo_min_jsprocessed").on("click",".defer",function(e){e.preventDefault(),a(t(this))}),t("#wpo_min_cssprocessed").on("click",".async",function(e){e.preventDefault(),o(t(this))}),t("#wp-optimize-minify-advanced").on("click",".save-exclusions",function(e){e.preventDefault(),t(".wp-optimize-save-minify-settings").first().trigger("click")}),this.enabled=t("#wpo_min_enable_minify").prop("checked"),t(document).trigger("wp-optimize/minify/toggle-status",{enabled:this.enabled}),this.enabled||t('#wp-optimize-nav-tab-wrapper__wpo_minify a[data-tab="status"]').is(".nav-tab-active")||t('#wp-optimize-nav-tab-wrapper__wpo_minify a[data-tab="status"]').trigger("click"),t('input[name="enable_defer_js"]').on("change",l),l();var _=t("#wp_optimize_run_minify_preload"),m=t("#wp_optimize_preload_minify_status"),h=null;return _.on("click",function(){var e=t(this),n=e.data("running"),s=m.text();e.prop("disabled",!0),n?(e.data("running",!1),clearInterval(h),h=null,i("cancel_minify_preload",null,function(t){t&&t.hasOwnProperty("message")&&m.text(t.message)}).always(function(){e.val(wpoptimize.run_now),e.prop("disabled",!1)})):(m.text(wpoptimize.starting_preload),e.data("running",!0),i("run_minify_preload",null,null,!0,{timeout:3e3}).always(function(t){try{var i=wpo_parse_json(t)}catch(n){}if(i&&i.error){var a=wpoptimize.error_unexpected_response;return"function"!=typeof i.error?a=i.error:i.status&&(a=i.status+": "+i.statusText),alert(a),m.text(s),e.prop("disabled",!1),void e.data("running",!1)}m.text(wpoptimize.loading_urls),e.val(wpoptimize.cancel),e.prop("disabled",!1),d()}))}),_.data("running")&&d(),this},s.getFiles=function(){if(this.enabled){var t={stamp:(new Date).getTime()};i("get_minify_cached_files",t,function(t){s.updateFilesLists(t),s.updateStats(t)}),n&&setTimeout(s.getFiles.bind(this),n)}},s.updateFilesLists=function(e){var i=[];e.js.length>0&&t(e.js).each(function(){i.push(this.uid),0==t("#"+this.uid).length&&t("#wpo_min_jsprocessed ul.processed").append('\t\t\t\t\t<li id="'+this.uid+'">\t\t\t\t\t\t<span class="filename"><a href="'+this.file_url+'" target="_blank">'+this.filename+"</a> ("+this.fsize+')</span>\t\t\t\t\t\t<a href="#" class="log">'+wpoptimize.toggle_info+'</a>\t\t\t\t\t\t<div class="hidden save_notice">\t\t\t\t\t\t\t<p>'+wpoptimize.added_notice+'</p>\t\t\t\t\t\t\t<p><button class="button button-primary save-exclusions">'+wpoptimize.save_notice+'</button></p>\t\t\t\t\t\t</div>\t\t\t\t\t\t<div class="hidden wpo_min_log">'+this.log+"</div>\t\t\t\t\t</li>\t\t\t\t")}),t("#wpo_min_jsprocessed ul.processed .no-files-yet").toggle(!e.js.length),e.css.length>0&&t(e.css).each(function(){i.push(this.uid),0==t("#"+this.uid).length&&t("#wpo_min_cssprocessed ul.processed").append('\t\t\t\t\t<li id="'+this.uid+'">\t\t\t\t\t\t<span class="filename"><a href="'+this.file_url+'" target="_blank">'+this.filename+"</a> ("+this.fsize+')</span>\t\t\t\t\t\t<a href="#" class="log">'+wpoptimize.toggle_info+'</a>\t\t\t\t\t\t<div class="hidden save_notice">\t\t\t\t\t\t\t<p>'+wpoptimize.added_to_list+'</p>\t\t\t\t\t\t\t<p><button class="button button-primary save-exclusions">'+wpoptimize.save_notice+'</button></p>\t\t\t\t\t\t</div>\t\t\t\t\t\t<div class="hidden wpo_min_log">'+this.log+"</div>\t\t\t\t\t</li>\t\t\t\t")}),t("#wpo_min_cssprocessed ul.processed .no-files-yet").toggle(!e.css.length),t("#wpo_min_jsprocessed ul.processed > li, #wpo_min_cssprocessed ul.processed > li").each(function(){-1==jQuery.inArray(t(this).attr("id"),i)&&(t(this).is(".no-files-yet")||t(this).remove())})},s.updateStats=function(e){e.cachesize.length>0&&(t("#wpo_min_cache_size").html(this.enabled?e.cachesize:wpoptimize.no_minified_assets),t("#wpo_min_cache_total_size").html(this.enabled?e.total_cache_size:wpoptimize.no_minified_assets),t("#wpo_min_cache_time").html(this.enabled?e.cacheTime:"-"),t("#wpo_min_cache_path").html(e.cachePath))},e.minify=s}(jQuery); |