1 line
1.9 KiB
JavaScript
1 line
1.9 KiB
JavaScript
!function(u){var o=wp.customize,i=function(t,e,o){var i;return function(){var n=arguments;o=o||this,clearTimeout(i),i=setTimeout(function(){i=null,t.apply(o,n)},e)}};o.Preview=o.Messenger.extend({initialize:function(n,t){var e=this;o.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",i(function(){e.send("scroll",e.window.scrollTop())},200)),this.bind("scroll",function(n){e.window.scrollTop(n)})}}),u(function(){var n,e;o.settings=window._wpCustomizeSettings,o.settings&&((e=new o.Preview({url:window.location.href,channel:o.settings.channel})).bind("settings",function(n){u.each(n,function(n,t){o.has(n)?o(n).set(t):o.create(n,t)})}),e.trigger("settings",o.settings.values),e.bind("setting",function(n){var t;n=n.slice(),(t=o(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(){o.settings.nonce&&e.send("nonce",o.settings.nonce)}),e.send("ready"),n=u.map(["color","image","position_x","repeat","attachment"],function(n){return"background_"+n}),o.when.apply(o,n).done(function(t,e,o,i,s){var n,c=u(document.body),r=u("head"),a=u("#custom-background-css");c.hasClass("custom-background")&&!a.length||(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 "+o()+";",n+="background-repeat: "+i()+";",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)); |