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

1 line
1.8 KiB
JavaScript

!function(u){var i=wp.customize,o=function(t,e,i){var o;return function(){var n=arguments;i=i||this,clearTimeout(o),o=setTimeout(function(){o=null,t.apply(i,n)},e)}};i.Preview=i.Messenger.extend({initialize:function(n,t){var e=this;i.Messenger.prototype.initialize.call(this,n,t),this.body=u(document.body),this.body.on("click.preview","a",function(n){n.preventDefault(),e.send("scroll",0),e.send("url",u(this).prop("href"))}),this.body.on("submit.preview","form",function(n){n.preventDefault()}),this.window=u(window),this.window.on("scroll.preview",o(function(){e.send("scroll",e.window.scrollTop())},200)),this.bind("scroll",function(n){e.window.scrollTop(n)})}}),u(function(){var n,e;i.settings=window._wpCustomizeSettings,i.settings&&((e=new i.Preview({url:window.location.href,channel:i.settings.channel})).bind("settings",function(n){u.each(n,function(n,t){i.has(n)?i(n).set(t):i.create(n,t)})}),e.trigger("settings",i.settings.values),e.bind("setting",function(n){var t;n=n.slice(),(t=i(n.shift()))&&t.set.apply(t,n)}),e.bind("sync",function(n){u.each(n,function(n,t){e.trigger(n,t)}),e.send("synced")}),e.bind("active",function(){i.settings.nonce&&e.send("nonce",i.settings.nonce)}),e.send("ready"),n=u.map(["color","image","position_x","repeat","attachment"],function(n){return"background_"+n}),i.when.apply(i,n).done(function(t,e,i,o,s){var c=u(document.body),r=u("head"),a=u("#custom-background-css"),n=function(){var n="";c.toggleClass("custom-background",!(!t()&&!e())),t()&&(n+="background-color: "+t()+";"),e()&&(n+='background-image: url("'+e()+'");',n+="background-position: top "+i()+";",n+="background-repeat: "+o()+";",n+="background-attachment: "+s()+";"),a.remove(),a=u('<style type="text/css" id="custom-background-css">body.custom-background { '+n+" }</style>").appendTo(r)};u.each(arguments,function(){this.bind(n)})}))})}((wp,jQuery));