WordPress/wp-includes/js/customize-preview.min.js

1 line
2.8 KiB
JavaScript

!function(d){var o=wp.customize,t=function(n,t,i){var o;return function(){var e=arguments;i=i||this,clearTimeout(o),o=setTimeout(function(){o=null,n.apply(i,e)},t)}};o.Preview=o.Messenger.extend({initialize:function(e,n){var i=this;o.Messenger.prototype.initialize.call(this,e,n),this.body=d(document.body),this.body.on("click.preview","a",function(e){var n=d(this),t="#"===n.attr("href").substr(0,1);e.preventDefault(),t&&"#"!==n.attr("href")&&d(n.attr("href")).each(function(){this.scrollIntoView()}),e.shiftKey||t||(i.send("scroll",0),i.send("url",n.prop("href")))}),this.body.on("submit.preview","form",function(e){e.preventDefault()}),this.window=d(window),this.window.on("scroll.preview",t(function(){i.send("scroll",i.window.scrollTop())},200)),this.bind("scroll",function(e){i.window.scrollTop(e)})}}),d(function(){var e,n;o.settings=window._wpCustomizeSettings,o.settings&&(o.preview=new o.Preview({url:window.location.href,channel:o.settings.channel}),n=function(e,n,t){var i=o(e);i?i.set(n):(t=t||!1,i=o.create(e,n,{id:e}),t&&(i._dirty=!0))},o.preview.bind("settings",function(e){d.each(e,n)}),o.preview.trigger("settings",o.settings.values),d.each(o.settings._dirty,function(e,n){n=o(n);n&&(n._dirty=!0)}),o.preview.bind("setting",function(e){n.apply(null,e.concat(!0))}),o.preview.bind("sync",function(e){d.each(e,function(e,n){o.preview.trigger(e,n)}),o.preview.send("synced")}),o.preview.bind("active",function(){o.preview.send("nonce",o.settings.nonce),o.preview.send("documentTitle",document.title)}),o.preview.bind("saved",function(e){o.trigger("saved",e)}),o.bind("saved",function(){o.each(function(e){e._dirty=!1})}),o.preview.bind("nonce-refresh",function(e){d.extend(o.settings.nonce,e)}),o.preview.send("ready",{activePanels:o.settings.activePanels,activeSections:o.settings.activeSections,activeControls:o.settings.activeControls,settingValidities:o.settings.settingValidities}),o.preview.bind("loading-initiated",function(){d("body").addClass("wp-customizer-unloading")}),o.preview.bind("loading-failed",function(){d("body").removeClass("wp-customizer-unloading")}),e=d.map(["color","image","position_x","repeat","attachment"],function(e){return"background_"+e}),o.when.apply(o,e).done(function(n,t,i,o,s){var c=d(document.body),r=d("head"),a=d("#custom-background-css"),e=function(){var e="";c.toggleClass("custom-background",!(!n()&&!t())),n()&&(e+="background-color: "+n()+";"),t()&&(e+='background-image: url("'+t()+'");',e+="background-position: top "+i()+";",e+="background-repeat: "+o()+";",e+="background-attachment: "+s()+";"),a.remove(),a=d('<style type="text/css" id="custom-background-css">body.custom-background { '+e+" }</style>").appendTo(r)};d.each(arguments,function(){this.bind(e)})}),o("custom_logo",function(e){d("body").toggleClass("wp-custom-logo",!!e.get()),e.bind(function(e){d("body").toggleClass("wp-custom-logo",!!e)})}),o.trigger("preview-ready"))})}((wp,jQuery));