diff --git a/wp-admin/js/customize-controls.js b/wp-admin/js/customize-controls.js
index ede6a867ea..22b3975e9d 100644
--- a/wp-admin/js/customize-controls.js
+++ b/wp-admin/js/customize-controls.js
@@ -37,6 +37,7 @@
this.id = id;
this.selector = '#customize-control-' + id.replace( /\]/g, '' ).replace( /\[/g, '-' );
this.container = $( this.selector );
+ this.active = new api.Value( this.params.active );
settings = $.map( this.params.settings, function( value ) {
return value;
@@ -79,10 +80,30 @@
element.set( setting() );
});
});
+
+ control.active.bind( function ( active ) {
+ control.toggle( active );
+ } );
+ control.toggle( control.active() );
},
ready: function() {},
+ /**
+ * Callback for change to the control's active state.
+ *
+ * Override function for custom behavior for the control being active/inactive.
+ *
+ * @param {Boolean} active
+ */
+ toggle: function ( active ) {
+ if ( active ) {
+ this.container.slideDown();
+ } else {
+ this.container.slideUp();
+ }
+ },
+
dropdownInit: function() {
var control = this,
statuses = this.container.find('.dropdown-status'),
@@ -563,6 +584,26 @@
this.bind( 'ready', this._ready );
+ this.bind( 'ready', function ( data ) {
+ if ( ! data || ! data.activeControls ) {
+ return;
+ }
+
+ // Any controls not even registered on the previewed URL are not active either
+ api.control.each( function ( control ) {
+ if ( typeof data.activeControls[ control.id ] === 'undefined' ) {
+ data.activeControls[ control.id ] = false;
+ }
+ } );
+
+ $.each( data.activeControls, function ( id, active ) {
+ var control = api.control( id );
+ if ( control ) {
+ control.active( active );
+ }
+ } );
+ } );
+
this.request = $.ajax( this.previewUrl(), {
type: 'POST',
data: this.query,
diff --git a/wp-admin/js/customize-controls.min.js b/wp-admin/js/customize-controls.min.js
index 7275474d49..126a23e57d 100644
--- a/wp-admin/js/customize-controls.min.js
+++ b/wp-admin/js/customize-controls.min.js
@@ -1 +1 @@
-!function(a,b){var c=wp.customize;c.Setting=c.Value.extend({initialize:function(a,b,d){c.Value.prototype.initialize.call(this,b,d),this.id=a,this.transport=this.transport||"refresh",this.bind(this.preview)},preview:function(){switch(this.transport){case"refresh":return this.previewer.refresh();case"postMessage":return this.previewer.send("setting",[this.id,this()])}}}),c.Control=c.Class.extend({initialize:function(a,d){var e,f,g,h=this;this.params={},b.extend(this,d||{}),this.id=a,this.selector="#customize-control-"+a.replace(/\]/g,"").replace(/\[/g,"-"),this.container=b(this.selector),g=b.map(this.params.settings,function(a){return a}),c.apply(c,g.concat(function(){var a;h.settings={};for(a in h.params.settings)h.settings[a]=c(h.params.settings[a]);h.setting=h.settings["default"]||null,h.ready()})),h.elements=[],e=this.container.find("[data-customize-setting-link]"),f={},e.each(function(){var a,d=b(this);if(d.is(":radio")){if(a=d.prop("name"),f[a])return;f[a]=!0,d=e.filter('[name="'+a+'"]')}c(d.data("customizeSettingLink"),function(a){var b=new c.Element(d);h.elements.push(b),b.sync(a),b.set(a())})})},ready:function(){},dropdownInit:function(){var a=this,b=this.container.find(".dropdown-status"),c=this.params,d=!1,e=function(a){"string"==typeof a&&c.statuses&&c.statuses[a]?b.html(c.statuses[a]).show():b.hide()};this.container.on("click keydown",".dropdown",function(b){("keydown"!==b.type||13===b.which)&&(b.preventDefault(),d||a.container.toggleClass("open"),a.container.hasClass("open")&&a.container.parent().parent().find("li.library-selected").focus(),d=!0,setTimeout(function(){d=!1},400))}),this.setting.bind(e),e(this.setting())}}),c.ColorControl=c.Control.extend({ready:function(){var a=this,b=this.container.find(".color-picker-hex");b.val(a.setting()).wpColorPicker({change:function(){a.setting.set(b.wpColorPicker("color"))},clear:function(){a.setting.set(!1)}})}}),c.UploadControl=c.Control.extend({ready:function(){var a=this;this.params.removed=this.params.removed||"",this.success=b.proxy(this.success,this),this.uploader=b.extend({container:this.container,browser:this.container.find(".upload"),dropzone:this.container.find(".upload-dropzone"),success:this.success,plupload:{},params:{}},this.uploader||{}),a.params.extensions&&(a.uploader.plupload.filters=[{title:c.l10n.allowedFiles,extensions:a.params.extensions}]),a.params.context&&(a.uploader.params["post_data[context]"]=this.params.context),c.settings.theme.stylesheet&&(a.uploader.params["post_data[theme]"]=c.settings.theme.stylesheet),this.uploader=new wp.Uploader(this.uploader),this.remover=this.container.find(".remove"),this.remover.on("click keydown",function(b){("keydown"!==b.type||13===b.which)&&(a.setting.set(a.params.removed),b.preventDefault())}),this.removerVisibility=b.proxy(this.removerVisibility,this),this.setting.bind(this.removerVisibility),this.removerVisibility(this.setting.get())},success:function(a){this.setting.set(a.get("url"))},removerVisibility:function(a){this.remover.toggle(a!=this.params.removed)}}),c.ImageControl=c.UploadControl.extend({ready:function(){var a,d=this;this.uploader={init:function(){var a,b;this.supports.dragdrop||(a=d.container.find(".upload-fallback"),b=a.children().detach(),this.browser.detach().empty().append(b),a.append(this.browser).show())}},c.UploadControl.prototype.ready.call(this),this.thumbnail=this.container.find(".preview-thumbnail img"),this.thumbnailSrc=b.proxy(this.thumbnailSrc,this),this.setting.bind(this.thumbnailSrc),this.library=this.container.find(".library"),this.tabs={},a=this.library.find(".library-content"),this.library.children("ul").children("li").each(function(){var c=b(this),e=c.data("customizeTab"),f=a.filter('[data-customize-tab="'+e+'"]');d.tabs[e]={both:c.add(f),link:c,panel:f}}),this.library.children("ul").on("click keydown","li",function(a){if("keydown"!==a.type||13===a.which){var c=b(this).data("customizeTab"),e=d.tabs[c];a.preventDefault(),e.link.hasClass("library-selected")||(d.selected.both.removeClass("library-selected"),d.selected=e,d.selected.both.addClass("library-selected"))}}),this.library.on("click keydown","a",function(a){if("keydown"!==a.type||13===a.which){var c=b(this).data("customizeImageValue");c&&(d.setting.set(c),a.preventDefault())}}),this.tabs.uploaded&&(this.tabs.uploaded.target=this.library.find(".uploaded-target"),this.tabs.uploaded.panel.find(".thumbnail").length||this.tabs.uploaded.both.addClass("hidden")),a.each(function(){var a=d.tabs[b(this).data("customizeTab")];return a.link.hasClass("hidden")?void 0:(d.selected=a,a.both.addClass("library-selected"),!1)}),this.dropdownInit()},success:function(a){c.UploadControl.prototype.success.call(this,a),this.tabs.uploaded&&this.tabs.uploaded.target.length&&(this.tabs.uploaded.both.removeClass("hidden"),a.element=b('').data("customizeImageValue",a.get("url")).append('').appendTo(this.tabs.uploaded.target))},thumbnailSrc:function(a){/^(https?:)?\/\//.test(a)?this.thumbnail.prop("src",a).show():this.thumbnail.hide()}}),c.HeaderControl=c.Control.extend({ready:function(){this.btnRemove=b("#customize-control-header_image .actions .remove"),this.btnNew=b("#customize-control-header_image .actions .new"),_.bindAll(this,"openMedia","removeImage"),this.btnNew.on("click",this.openMedia),this.btnRemove.on("click",this.removeImage),c.HeaderTool.currentHeader=new c.HeaderTool.ImageModel,new c.HeaderTool.CurrentView({model:c.HeaderTool.currentHeader,el:".current .container"}),new c.HeaderTool.ChoiceListView({collection:c.HeaderTool.UploadsList=new c.HeaderTool.ChoiceList,el:".choices .uploaded .list"}),new c.HeaderTool.ChoiceListView({collection:c.HeaderTool.DefaultsList=new c.HeaderTool.DefaultsList,el:".choices .default .list"}),c.HeaderTool.combinedList=c.HeaderTool.CombinedList=new c.HeaderTool.CombinedList([c.HeaderTool.UploadsList,c.HeaderTool.DefaultsList])},calculateImageSelectOptions:function(a,b){var d,e,f,g,h,i,j=parseInt(_wpCustomizeHeader.data.width,10),k=parseInt(_wpCustomizeHeader.data.height,10),l=!!parseInt(_wpCustomizeHeader.data["flex-width"],10),m=!!parseInt(_wpCustomizeHeader.data["flex-height"],10);return h=a.get("width"),g=a.get("height"),this.headerImage=new c.HeaderTool.ImageModel,this.headerImage.set({themeWidth:j,themeHeight:k,themeFlexWidth:l,themeFlexHeight:m,imageWidth:h,imageHeight:g}),b.set("canSkipCrop",!this.headerImage.shouldBeCropped()),d=j/k,e=h,f=g,e/f>d?(k=f,j=k*d):(j=e,k=j/d),i={handles:!0,keys:!0,instance:!0,persistent:!0,imageWidth:h,imageHeight:g,x1:0,y1:0,x2:j,y2:k},m===!1&&l===!1&&(i.aspectRatio=j+":"+k),m===!1&&(i.maxHeight=k),l===!1&&(i.maxWidth=j),i},openMedia:function(a){var b=_wpMediaViewsL10n;a.preventDefault(),this.frame=wp.media({button:{text:b.selectAndCrop,close:!1},states:[new wp.media.controller.Library({title:b.chooseImage,library:wp.media.query({type:"image"}),multiple:!1,priority:20,suggestedWidth:_wpCustomizeHeader.data.width,suggestedHeight:_wpCustomizeHeader.data.height}),new wp.media.controller.Cropper({imgSelectOptions:this.calculateImageSelectOptions})]}),this.frame.on("select",this.onSelect,this),this.frame.on("cropped",this.onCropped,this),this.frame.on("skippedcrop",this.onSkippedCrop,this),this.frame.open()},onSelect:function(){this.frame.setState("cropper")},onCropped:function(a){var b=a.post_content,c=a.attachment_id,d=a.width,e=a.height;this.setImageFromURL(b,c,d,e)},onSkippedCrop:function(a){var b=a.get("url"),c=a.get("width"),d=a.get("height");this.setImageFromURL(b,a.id,c,d)},setImageFromURL:function(a,b,d,e){var f,g={};g.url=a,g.thumbnail_url=a,g.timestamp=_.now(),b&&(g.attachment_id=b),d&&(g.width=d),e&&(g.height=e),f=new c.HeaderTool.ImageModel({header:g,choice:a.split("/").pop()}),c.HeaderTool.UploadsList.add(f),c.HeaderTool.currentHeader.set(f.toJSON()),f.save(),f.importImage()},removeImage:function(){c.HeaderTool.currentHeader.trigger("hide"),c.HeaderTool.CombinedList.trigger("control:removeImage")}}),c.defaultConstructor=c.Setting,c.control=new c.Values({defaultConstructor:c.Control}),c.PreviewFrame=c.Messenger.extend({sensitivity:2e3,initialize:function(a,d){var e=b.Deferred();e.promise(this),this.container=a.container,this.signature=a.signature,b.extend(a,{channel:c.PreviewFrame.uuid()}),c.Messenger.prototype.initialize.call(this,a,d),this.add("previewUrl",a.previewUrl),this.query=b.extend(a.query||{},{customize_messenger_channel:this.channel()}),this.run(e)},run:function(a){var c=this,d=!1,e=!1;this._ready&&this.unbind("ready",this._ready),this._ready=function(){e=!0,d&&a.resolveWith(c)},this.bind("ready",this._ready),this.request=b.ajax(this.previewUrl(),{type:"POST",data:this.query,xhrFields:{withCredentials:!0}}),this.request.fail(function(){a.rejectWith(c,["request failure"])}),this.request.done(function(f){var g,h=c.request.getResponseHeader("Location"),i=c.signature;return h&&h!=c.previewUrl()?void a.rejectWith(c,["redirect",h]):"0"===f?void c.login(a):"-1"===f?void a.rejectWith(c,["cheatin"]):(g=f.lastIndexOf(i),-1===g||g")?void a.rejectWith(c,["unsigned"]):(f=f.slice(0,g)+f.slice(g+i.length),c.iframe=b("").appendTo(c.container),c.iframe.one("load",function(){d=!0,e?a.resolveWith(c):setTimeout(function(){a.rejectWith(c,["ready timeout"])},c.sensitivity)}),c.targetWindow(c.iframe[0].contentWindow),c.targetWindow().document.open(),c.targetWindow().document.write(f),void c.targetWindow().document.close()))})},login:function(a){var d,e=this;return d=function(){a.rejectWith(e,["logged out"])},this.triedLogin?d():void b.get(c.settings.url.ajax,{action:"logged-in"}).fail(d).done(function(c){var f;"1"!==c&&d(),f=b('').hide(),f.appendTo(e.container),f.load(function(){e.triedLogin=!0,f.remove(),e.run(a)})})},destroy:function(){c.Messenger.prototype.destroy.call(this),this.request.abort(),this.iframe&&this.iframe.remove(),delete this.request,delete this.iframe,delete this.targetWindow}}),function(){var a=0;c.PreviewFrame.uuid=function(){return"preview-"+a++}}(),c.Previewer=c.Messenger.extend({refreshBuffer:250,initialize:function(a,d){var e=this,f=/^https?/;b.extend(this,d||{}),this.refresh=function(a){var b,c=a.refresh,d=function(){b=null,c.call(a)};return function(){if("number"!=typeof b){if(!a.loading)return d();a.abort()}clearTimeout(b),b=setTimeout(d,a.refreshBuffer)}}(this),this.container=c.ensure(a.container),this.allowedUrls=a.allowedUrls,this.signature=a.signature,a.url=window.location.href,c.Messenger.prototype.initialize.call(this,a),this.add("scheme",this.origin()).link(this.origin).setter(function(a){var b=a.match(f);return b?b[0]:""}),this.add("previewUrl",a.previewUrl).setter(function(a){var c;return/\/wp-admin(\/|$)/.test(a.replace(/[#?].*$/,""))?null:(b.each([a.replace(f,e.scheme()),a],function(a,d){return b.each(e.allowedUrls,function(a,b){var e;return b=b.replace(/\/+$/,""),e=d.replace(b,""),0===d.indexOf(b)&&/^([/#?]|$)/.test(e)?(c=d,!1):void 0}),c?!1:void 0}),c?c:null)}),this.previewUrl.bind(this.refresh),this.scroll=0,this.bind("scroll",function(a){this.scroll=a}),this.bind("url",this.previewUrl)},query:function(){},abort:function(){this.loading&&(this.loading.destroy(),delete this.loading)},refresh:function(){var a=this;this.abort(),this.loading=new c.PreviewFrame({url:this.url(),previewUrl:this.previewUrl(),query:this.query()||{},container:this.container,signature:this.signature}),this.loading.done(function(){this.bind("synced",function(){a.preview&&a.preview.destroy(),a.preview=this,delete a.loading,a.targetWindow(this.targetWindow()),a.channel(this.channel()),a.send("active")}),this.send("sync",{scroll:a.scroll,settings:c.get()})}),this.loading.fail(function(b,c){"redirect"===b&&c&&a.previewUrl(c),"logged out"===b&&(a.preview&&(a.preview.destroy(),delete a.preview),a.login().done(a.refresh)),"cheatin"===b&&a.cheatin()})},login:function(){var a,d,e,f=this;return this._login?this._login:(a=b.Deferred(),this._login=a.promise(),d=new c.Messenger({channel:"login",url:c.settings.url.login}),e=b('').appendTo(this.container),d.targetWindow(e[0].contentWindow),d.bind("login",function(){e.remove(),d.destroy(),delete f._login,a.resolve()}),this._login)},cheatin:function(){b(document.body).empty().addClass("cheatin").append(""+c.l10n.cheatin+"
")}}),c.controlConstructor={color:c.ColorControl,upload:c.UploadControl,image:c.ImageControl,header:c.HeaderControl},b(function(){if(c.settings=window._wpCustomizeSettings,c.l10n=window._wpCustomizeControlsL10n,c.settings){if(!b.support.postMessage||!b.support.cors&&c.settings.isCrossDomain)return window.location=c.settings.url.fallback;var a,d,e=b(document.body),f=e.children(".wp-full-overlay"),g=b("#customize-info .theme-name.site-title"),h=b(".customize-controls-close"),i=b("#save");b("#customize-controls").on("keydown",function(a){var c=13===a.which,d=b(a.target);c&&(d.is("input:not([type=button])")||d.is("select"))&&a.preventDefault()}),c.previewer=new c.Previewer({container:"#customize-preview",form:"#customize-controls",previewUrl:c.settings.url.preview,allowedUrls:c.settings.url.allowed,signature:"WP_CUSTOMIZER_SIGNATURE"},{nonce:c.settings.nonce,query:function(){return{wp_customize:"on",theme:c.settings.theme.stylesheet,customized:JSON.stringify(c.get()),nonce:this.nonce.preview}},save:function(){var a,d,f=this,g=b.extend(this.query(),{action:"customize_save",nonce:this.nonce.save}),h=c.state("processing");e.addClass("saving"),d=function(){var a=b.post(c.settings.url.ajax,g);c.trigger("save",a),a.always(function(){e.removeClass("saving")}),a.done(function(a){return"0"===a?(f.preview.iframe.hide(),void f.login().done(function(){f.save(),f.preview.iframe.show()})):"-1"===a?void f.cheatin():void c.trigger("saved")})},0===h()?d():(a=function(){0===h()&&(c.state.unbind("change",a),d())},c.state.bind("change",a))}}),c.previewer.bind("nonce",function(a){b.extend(this.nonce,a)}),b.each(c.settings.settings,function(a,b){c.create(a,a,b.value,{transport:b.transport,previewer:c.previewer})}),b.each(c.settings.controls,function(a,b){var d,e=c.controlConstructor[b.type]||c.Control;d=c.control.add(a,new e(a,{params:b,previewer:c.previewer}))}),c.previewer.previewUrl()?c.previewer.refresh():c.previewer.previewUrl(c.settings.url.home),function(){var a=new c.Values,b=a.create("saved"),d=a.create("activated"),e=a.create("processing");a.bind("change",function(){d()?b()?(i.val(c.l10n.saved).prop("disabled",!0),h.find(".screen-reader-text").text(c.l10n.close)):(i.val(c.l10n.save).prop("disabled",!1),h.find(".screen-reader-text").text(c.l10n.cancel)):(i.val(c.l10n.activate).prop("disabled",!1),h.find(".screen-reader-text").text(c.l10n.cancel))}),b(!0),d(c.settings.theme.active),e(0),c.bind("change",function(){a("saved").set(!1)}),c.bind("saved",function(){a("saved").set(!0),a("activated").set(!0)}),d.bind(function(a){a&&c.trigger("activated")}),c.state=a}(),i.click(function(a){c.previewer.save(),a.preventDefault()}).keydown(function(a){9!==a.which&&(13===a.which&&c.previewer.save(),a.preventDefault())}),h.keydown(function(a){9!==a.which&&(13===a.which&&this.click(),a.preventDefault())}),b(".upload-dropzone a.upload").keydown(function(a){13===a.which&&this.click()}),b(".collapse-sidebar").on("click keydown",function(a){("keydown"!==a.type||13===a.which)&&(f.toggleClass("collapsed").toggleClass("expanded"),a.preventDefault())}),g.length&&b("#customize-control-blogname input").on("input",function(){g.text(this.value)}),a=new c.Messenger({url:c.settings.url.parent,channel:"loader"}),a.bind("back",function(){h.on("click.customize-controls-close",function(b){b.preventDefault(),a.send("close")})}),b(window).on("beforeunload",function(){return c.state("saved")()?void 0:c.l10n.saveAlert}),b.each(["saved","change"],function(b,d){c.bind(d,function(){a.send(d)})}),c.bind("activated",function(){a.targetWindow()?a.send("activated",c.settings.url.activated):c.settings.url.activated&&(window.location=c.settings.url.activated)}),a.send("ready"),b.each({background_image:{controls:["background_repeat","background_position_x","background_attachment"],callback:function(a){return!!a}},show_on_front:{controls:["page_on_front","page_for_posts"],callback:function(a){return"page"===a}},header_textcolor:{controls:["header_textcolor"],callback:function(a){return"blank"!==a}}},function(a,d){c(a,function(a){b.each(d.controls,function(b,e){c.control(e,function(b){var c=function(a){b.container.toggle(d.callback(a))};c(a.get()),a.bind(c)})})})}),c.control("display_header_text",function(a){var b="";a.elements[0].unsync(c("header_textcolor")),a.element=new c.Element(a.container.find("input")),a.element.set("blank"!==a.setting()),a.element.bind(function(d){d||(b=c("header_textcolor").get()),a.setting.set(d?b:"blank")}),a.setting.bind(function(b){a.element.set("blank"!==b)})}),c.trigger("ready"),d=h,d.focus(),setTimeout(function(){d.focus()},200)}})}(wp,jQuery);
\ No newline at end of file
+!function(a,b){var c=wp.customize;c.Setting=c.Value.extend({initialize:function(a,b,d){c.Value.prototype.initialize.call(this,b,d),this.id=a,this.transport=this.transport||"refresh",this.bind(this.preview)},preview:function(){switch(this.transport){case"refresh":return this.previewer.refresh();case"postMessage":return this.previewer.send("setting",[this.id,this()])}}}),c.Control=c.Class.extend({initialize:function(a,d){var e,f,g,h=this;this.params={},b.extend(this,d||{}),this.id=a,this.selector="#customize-control-"+a.replace(/\]/g,"").replace(/\[/g,"-"),this.container=b(this.selector),this.active=new c.Value(this.params.active),g=b.map(this.params.settings,function(a){return a}),c.apply(c,g.concat(function(){var a;h.settings={};for(a in h.params.settings)h.settings[a]=c(h.params.settings[a]);h.setting=h.settings["default"]||null,h.ready()})),h.elements=[],e=this.container.find("[data-customize-setting-link]"),f={},e.each(function(){var a,d=b(this);if(d.is(":radio")){if(a=d.prop("name"),f[a])return;f[a]=!0,d=e.filter('[name="'+a+'"]')}c(d.data("customizeSettingLink"),function(a){var b=new c.Element(d);h.elements.push(b),b.sync(a),b.set(a())})}),h.active.bind(function(a){h.toggle(a)}),h.toggle(h.active())},ready:function(){},toggle:function(a){a?this.container.slideDown():this.container.slideUp()},dropdownInit:function(){var a=this,b=this.container.find(".dropdown-status"),c=this.params,d=!1,e=function(a){"string"==typeof a&&c.statuses&&c.statuses[a]?b.html(c.statuses[a]).show():b.hide()};this.container.on("click keydown",".dropdown",function(b){("keydown"!==b.type||13===b.which)&&(b.preventDefault(),d||a.container.toggleClass("open"),a.container.hasClass("open")&&a.container.parent().parent().find("li.library-selected").focus(),d=!0,setTimeout(function(){d=!1},400))}),this.setting.bind(e),e(this.setting())}}),c.ColorControl=c.Control.extend({ready:function(){var a=this,b=this.container.find(".color-picker-hex");b.val(a.setting()).wpColorPicker({change:function(){a.setting.set(b.wpColorPicker("color"))},clear:function(){a.setting.set(!1)}})}}),c.UploadControl=c.Control.extend({ready:function(){var a=this;this.params.removed=this.params.removed||"",this.success=b.proxy(this.success,this),this.uploader=b.extend({container:this.container,browser:this.container.find(".upload"),dropzone:this.container.find(".upload-dropzone"),success:this.success,plupload:{},params:{}},this.uploader||{}),a.params.extensions&&(a.uploader.plupload.filters=[{title:c.l10n.allowedFiles,extensions:a.params.extensions}]),a.params.context&&(a.uploader.params["post_data[context]"]=this.params.context),c.settings.theme.stylesheet&&(a.uploader.params["post_data[theme]"]=c.settings.theme.stylesheet),this.uploader=new wp.Uploader(this.uploader),this.remover=this.container.find(".remove"),this.remover.on("click keydown",function(b){("keydown"!==b.type||13===b.which)&&(a.setting.set(a.params.removed),b.preventDefault())}),this.removerVisibility=b.proxy(this.removerVisibility,this),this.setting.bind(this.removerVisibility),this.removerVisibility(this.setting.get())},success:function(a){this.setting.set(a.get("url"))},removerVisibility:function(a){this.remover.toggle(a!=this.params.removed)}}),c.ImageControl=c.UploadControl.extend({ready:function(){var a,d=this;this.uploader={init:function(){var a,b;this.supports.dragdrop||(a=d.container.find(".upload-fallback"),b=a.children().detach(),this.browser.detach().empty().append(b),a.append(this.browser).show())}},c.UploadControl.prototype.ready.call(this),this.thumbnail=this.container.find(".preview-thumbnail img"),this.thumbnailSrc=b.proxy(this.thumbnailSrc,this),this.setting.bind(this.thumbnailSrc),this.library=this.container.find(".library"),this.tabs={},a=this.library.find(".library-content"),this.library.children("ul").children("li").each(function(){var c=b(this),e=c.data("customizeTab"),f=a.filter('[data-customize-tab="'+e+'"]');d.tabs[e]={both:c.add(f),link:c,panel:f}}),this.library.children("ul").on("click keydown","li",function(a){if("keydown"!==a.type||13===a.which){var c=b(this).data("customizeTab"),e=d.tabs[c];a.preventDefault(),e.link.hasClass("library-selected")||(d.selected.both.removeClass("library-selected"),d.selected=e,d.selected.both.addClass("library-selected"))}}),this.library.on("click keydown","a",function(a){if("keydown"!==a.type||13===a.which){var c=b(this).data("customizeImageValue");c&&(d.setting.set(c),a.preventDefault())}}),this.tabs.uploaded&&(this.tabs.uploaded.target=this.library.find(".uploaded-target"),this.tabs.uploaded.panel.find(".thumbnail").length||this.tabs.uploaded.both.addClass("hidden")),a.each(function(){var a=d.tabs[b(this).data("customizeTab")];return a.link.hasClass("hidden")?void 0:(d.selected=a,a.both.addClass("library-selected"),!1)}),this.dropdownInit()},success:function(a){c.UploadControl.prototype.success.call(this,a),this.tabs.uploaded&&this.tabs.uploaded.target.length&&(this.tabs.uploaded.both.removeClass("hidden"),a.element=b('').data("customizeImageValue",a.get("url")).append('').appendTo(this.tabs.uploaded.target))},thumbnailSrc:function(a){/^(https?:)?\/\//.test(a)?this.thumbnail.prop("src",a).show():this.thumbnail.hide()}}),c.HeaderControl=c.Control.extend({ready:function(){this.btnRemove=b("#customize-control-header_image .actions .remove"),this.btnNew=b("#customize-control-header_image .actions .new"),_.bindAll(this,"openMedia","removeImage"),this.btnNew.on("click",this.openMedia),this.btnRemove.on("click",this.removeImage),c.HeaderTool.currentHeader=new c.HeaderTool.ImageModel,new c.HeaderTool.CurrentView({model:c.HeaderTool.currentHeader,el:".current .container"}),new c.HeaderTool.ChoiceListView({collection:c.HeaderTool.UploadsList=new c.HeaderTool.ChoiceList,el:".choices .uploaded .list"}),new c.HeaderTool.ChoiceListView({collection:c.HeaderTool.DefaultsList=new c.HeaderTool.DefaultsList,el:".choices .default .list"}),c.HeaderTool.combinedList=c.HeaderTool.CombinedList=new c.HeaderTool.CombinedList([c.HeaderTool.UploadsList,c.HeaderTool.DefaultsList])},calculateImageSelectOptions:function(a,b){var d,e,f,g,h,i,j=parseInt(_wpCustomizeHeader.data.width,10),k=parseInt(_wpCustomizeHeader.data.height,10),l=!!parseInt(_wpCustomizeHeader.data["flex-width"],10),m=!!parseInt(_wpCustomizeHeader.data["flex-height"],10);return h=a.get("width"),g=a.get("height"),this.headerImage=new c.HeaderTool.ImageModel,this.headerImage.set({themeWidth:j,themeHeight:k,themeFlexWidth:l,themeFlexHeight:m,imageWidth:h,imageHeight:g}),b.set("canSkipCrop",!this.headerImage.shouldBeCropped()),d=j/k,e=h,f=g,e/f>d?(k=f,j=k*d):(j=e,k=j/d),i={handles:!0,keys:!0,instance:!0,persistent:!0,imageWidth:h,imageHeight:g,x1:0,y1:0,x2:j,y2:k},m===!1&&l===!1&&(i.aspectRatio=j+":"+k),m===!1&&(i.maxHeight=k),l===!1&&(i.maxWidth=j),i},openMedia:function(a){var b=_wpMediaViewsL10n;a.preventDefault(),this.frame=wp.media({button:{text:b.selectAndCrop,close:!1},states:[new wp.media.controller.Library({title:b.chooseImage,library:wp.media.query({type:"image"}),multiple:!1,priority:20,suggestedWidth:_wpCustomizeHeader.data.width,suggestedHeight:_wpCustomizeHeader.data.height}),new wp.media.controller.Cropper({imgSelectOptions:this.calculateImageSelectOptions})]}),this.frame.on("select",this.onSelect,this),this.frame.on("cropped",this.onCropped,this),this.frame.on("skippedcrop",this.onSkippedCrop,this),this.frame.open()},onSelect:function(){this.frame.setState("cropper")},onCropped:function(a){var b=a.post_content,c=a.attachment_id,d=a.width,e=a.height;this.setImageFromURL(b,c,d,e)},onSkippedCrop:function(a){var b=a.get("url"),c=a.get("width"),d=a.get("height");this.setImageFromURL(b,a.id,c,d)},setImageFromURL:function(a,b,d,e){var f,g={};g.url=a,g.thumbnail_url=a,g.timestamp=_.now(),b&&(g.attachment_id=b),d&&(g.width=d),e&&(g.height=e),f=new c.HeaderTool.ImageModel({header:g,choice:a.split("/").pop()}),c.HeaderTool.UploadsList.add(f),c.HeaderTool.currentHeader.set(f.toJSON()),f.save(),f.importImage()},removeImage:function(){c.HeaderTool.currentHeader.trigger("hide"),c.HeaderTool.CombinedList.trigger("control:removeImage")}}),c.defaultConstructor=c.Setting,c.control=new c.Values({defaultConstructor:c.Control}),c.PreviewFrame=c.Messenger.extend({sensitivity:2e3,initialize:function(a,d){var e=b.Deferred();e.promise(this),this.container=a.container,this.signature=a.signature,b.extend(a,{channel:c.PreviewFrame.uuid()}),c.Messenger.prototype.initialize.call(this,a,d),this.add("previewUrl",a.previewUrl),this.query=b.extend(a.query||{},{customize_messenger_channel:this.channel()}),this.run(e)},run:function(a){var d=this,e=!1,f=!1;this._ready&&this.unbind("ready",this._ready),this._ready=function(){f=!0,e&&a.resolveWith(d)},this.bind("ready",this._ready),this.bind("ready",function(a){a&&a.activeControls&&(c.control.each(function(b){"undefined"==typeof a.activeControls[b.id]&&(a.activeControls[b.id]=!1)}),b.each(a.activeControls,function(a,b){var d=c.control(a);d&&d.active(b)}))}),this.request=b.ajax(this.previewUrl(),{type:"POST",data:this.query,xhrFields:{withCredentials:!0}}),this.request.fail(function(){a.rejectWith(d,["request failure"])}),this.request.done(function(c){var g,h=d.request.getResponseHeader("Location"),i=d.signature;return h&&h!=d.previewUrl()?void a.rejectWith(d,["redirect",h]):"0"===c?void d.login(a):"-1"===c?void a.rejectWith(d,["cheatin"]):(g=c.lastIndexOf(i),-1===g||g")?void a.rejectWith(d,["unsigned"]):(c=c.slice(0,g)+c.slice(g+i.length),d.iframe=b("").appendTo(d.container),d.iframe.one("load",function(){e=!0,f?a.resolveWith(d):setTimeout(function(){a.rejectWith(d,["ready timeout"])},d.sensitivity)}),d.targetWindow(d.iframe[0].contentWindow),d.targetWindow().document.open(),d.targetWindow().document.write(c),void d.targetWindow().document.close()))})},login:function(a){var d,e=this;return d=function(){a.rejectWith(e,["logged out"])},this.triedLogin?d():void b.get(c.settings.url.ajax,{action:"logged-in"}).fail(d).done(function(c){var f;"1"!==c&&d(),f=b('').hide(),f.appendTo(e.container),f.load(function(){e.triedLogin=!0,f.remove(),e.run(a)})})},destroy:function(){c.Messenger.prototype.destroy.call(this),this.request.abort(),this.iframe&&this.iframe.remove(),delete this.request,delete this.iframe,delete this.targetWindow}}),function(){var a=0;c.PreviewFrame.uuid=function(){return"preview-"+a++}}(),c.Previewer=c.Messenger.extend({refreshBuffer:250,initialize:function(a,d){var e=this,f=/^https?/;b.extend(this,d||{}),this.refresh=function(a){var b,c=a.refresh,d=function(){b=null,c.call(a)};return function(){if("number"!=typeof b){if(!a.loading)return d();a.abort()}clearTimeout(b),b=setTimeout(d,a.refreshBuffer)}}(this),this.container=c.ensure(a.container),this.allowedUrls=a.allowedUrls,this.signature=a.signature,a.url=window.location.href,c.Messenger.prototype.initialize.call(this,a),this.add("scheme",this.origin()).link(this.origin).setter(function(a){var b=a.match(f);return b?b[0]:""}),this.add("previewUrl",a.previewUrl).setter(function(a){var c;return/\/wp-admin(\/|$)/.test(a.replace(/[#?].*$/,""))?null:(b.each([a.replace(f,e.scheme()),a],function(a,d){return b.each(e.allowedUrls,function(a,b){var e;return b=b.replace(/\/+$/,""),e=d.replace(b,""),0===d.indexOf(b)&&/^([/#?]|$)/.test(e)?(c=d,!1):void 0}),c?!1:void 0}),c?c:null)}),this.previewUrl.bind(this.refresh),this.scroll=0,this.bind("scroll",function(a){this.scroll=a}),this.bind("url",this.previewUrl)},query:function(){},abort:function(){this.loading&&(this.loading.destroy(),delete this.loading)},refresh:function(){var a=this;this.abort(),this.loading=new c.PreviewFrame({url:this.url(),previewUrl:this.previewUrl(),query:this.query()||{},container:this.container,signature:this.signature}),this.loading.done(function(){this.bind("synced",function(){a.preview&&a.preview.destroy(),a.preview=this,delete a.loading,a.targetWindow(this.targetWindow()),a.channel(this.channel()),a.send("active")}),this.send("sync",{scroll:a.scroll,settings:c.get()})}),this.loading.fail(function(b,c){"redirect"===b&&c&&a.previewUrl(c),"logged out"===b&&(a.preview&&(a.preview.destroy(),delete a.preview),a.login().done(a.refresh)),"cheatin"===b&&a.cheatin()})},login:function(){var a,d,e,f=this;return this._login?this._login:(a=b.Deferred(),this._login=a.promise(),d=new c.Messenger({channel:"login",url:c.settings.url.login}),e=b('').appendTo(this.container),d.targetWindow(e[0].contentWindow),d.bind("login",function(){e.remove(),d.destroy(),delete f._login,a.resolve()}),this._login)},cheatin:function(){b(document.body).empty().addClass("cheatin").append(""+c.l10n.cheatin+"
")}}),c.controlConstructor={color:c.ColorControl,upload:c.UploadControl,image:c.ImageControl,header:c.HeaderControl},b(function(){if(c.settings=window._wpCustomizeSettings,c.l10n=window._wpCustomizeControlsL10n,c.settings){if(!b.support.postMessage||!b.support.cors&&c.settings.isCrossDomain)return window.location=c.settings.url.fallback;var a,d,e=b(document.body),f=e.children(".wp-full-overlay"),g=b("#customize-info .theme-name.site-title"),h=b(".customize-controls-close"),i=b("#save");b("#customize-controls").on("keydown",function(a){var c=13===a.which,d=b(a.target);c&&(d.is("input:not([type=button])")||d.is("select"))&&a.preventDefault()}),c.previewer=new c.Previewer({container:"#customize-preview",form:"#customize-controls",previewUrl:c.settings.url.preview,allowedUrls:c.settings.url.allowed,signature:"WP_CUSTOMIZER_SIGNATURE"},{nonce:c.settings.nonce,query:function(){return{wp_customize:"on",theme:c.settings.theme.stylesheet,customized:JSON.stringify(c.get()),nonce:this.nonce.preview}},save:function(){var a,d,f=this,g=b.extend(this.query(),{action:"customize_save",nonce:this.nonce.save}),h=c.state("processing");e.addClass("saving"),d=function(){var a=b.post(c.settings.url.ajax,g);c.trigger("save",a),a.always(function(){e.removeClass("saving")}),a.done(function(a){return"0"===a?(f.preview.iframe.hide(),void f.login().done(function(){f.save(),f.preview.iframe.show()})):"-1"===a?void f.cheatin():void c.trigger("saved")})},0===h()?d():(a=function(){0===h()&&(c.state.unbind("change",a),d())},c.state.bind("change",a))}}),c.previewer.bind("nonce",function(a){b.extend(this.nonce,a)}),b.each(c.settings.settings,function(a,b){c.create(a,a,b.value,{transport:b.transport,previewer:c.previewer})}),b.each(c.settings.controls,function(a,b){var d,e=c.controlConstructor[b.type]||c.Control;d=c.control.add(a,new e(a,{params:b,previewer:c.previewer}))}),c.previewer.previewUrl()?c.previewer.refresh():c.previewer.previewUrl(c.settings.url.home),function(){var a=new c.Values,b=a.create("saved"),d=a.create("activated"),e=a.create("processing");a.bind("change",function(){d()?b()?(i.val(c.l10n.saved).prop("disabled",!0),h.find(".screen-reader-text").text(c.l10n.close)):(i.val(c.l10n.save).prop("disabled",!1),h.find(".screen-reader-text").text(c.l10n.cancel)):(i.val(c.l10n.activate).prop("disabled",!1),h.find(".screen-reader-text").text(c.l10n.cancel))}),b(!0),d(c.settings.theme.active),e(0),c.bind("change",function(){a("saved").set(!1)}),c.bind("saved",function(){a("saved").set(!0),a("activated").set(!0)}),d.bind(function(a){a&&c.trigger("activated")}),c.state=a}(),i.click(function(a){c.previewer.save(),a.preventDefault()}).keydown(function(a){9!==a.which&&(13===a.which&&c.previewer.save(),a.preventDefault())}),h.keydown(function(a){9!==a.which&&(13===a.which&&this.click(),a.preventDefault())}),b(".upload-dropzone a.upload").keydown(function(a){13===a.which&&this.click()}),b(".collapse-sidebar").on("click keydown",function(a){("keydown"!==a.type||13===a.which)&&(f.toggleClass("collapsed").toggleClass("expanded"),a.preventDefault())}),g.length&&b("#customize-control-blogname input").on("input",function(){g.text(this.value)}),a=new c.Messenger({url:c.settings.url.parent,channel:"loader"}),a.bind("back",function(){h.on("click.customize-controls-close",function(b){b.preventDefault(),a.send("close")})}),b(window).on("beforeunload",function(){return c.state("saved")()?void 0:c.l10n.saveAlert}),b.each(["saved","change"],function(b,d){c.bind(d,function(){a.send(d)})}),c.bind("activated",function(){a.targetWindow()?a.send("activated",c.settings.url.activated):c.settings.url.activated&&(window.location=c.settings.url.activated)}),a.send("ready"),b.each({background_image:{controls:["background_repeat","background_position_x","background_attachment"],callback:function(a){return!!a}},show_on_front:{controls:["page_on_front","page_for_posts"],callback:function(a){return"page"===a}},header_textcolor:{controls:["header_textcolor"],callback:function(a){return"blank"!==a}}},function(a,d){c(a,function(a){b.each(d.controls,function(b,e){c.control(e,function(b){var c=function(a){b.container.toggle(d.callback(a))};c(a.get()),a.bind(c)})})})}),c.control("display_header_text",function(a){var b="";a.elements[0].unsync(c("header_textcolor")),a.element=new c.Element(a.container.find("input")),a.element.set("blank"!==a.setting()),a.element.bind(function(d){d||(b=c("header_textcolor").get()),a.setting.set(d?b:"blank")}),a.setting.bind(function(b){a.element.set("blank"!==b)})}),c.trigger("ready"),d=h,d.focus(),setTimeout(function(){d.focus()},200)}})}(wp,jQuery);
\ No newline at end of file
diff --git a/wp-admin/js/customize-widgets.js b/wp-admin/js/customize-widgets.js
index 3ba7df8919..51aec941a2 100644
--- a/wp-admin/js/customize-widgets.js
+++ b/wp-admin/js/customize-widgets.js
@@ -751,13 +751,6 @@
}
} );
- // Update widget control to indicate whether it is currently rendered
- api.previewer.bind( 'rendered-widgets', function( renderedWidgets ) {
- var isRendered = !! renderedWidgets[self.params.widget_id];
-
- self.container.toggleClass( 'widget-rendered', isRendered );
- } );
-
formSyncHandler = api.Widgets.formSyncHandlers[ this.params.widget_id_base ];
if ( formSyncHandler ) {
$( document ).on( 'widget-synced', function( e, widget ) {
@@ -768,6 +761,17 @@
}
},
+ /**
+ * Update widget control to indicate whether it is currently rendered.
+ *
+ * Overrides api.Control.toggle()
+ *
+ * @param {Boolean} active
+ */
+ toggle: function ( active ) {
+ this.container.toggleClass( 'widget-rendered', active );
+ },
+
/**
* Set up event handlers for widget removal
*/
@@ -1418,32 +1422,38 @@
} );
// Update the model with whether or not the sidebar is rendered
- api.previewer.bind( 'rendered-sidebars', function( renderedSidebars ) {
- var isRendered = !! renderedSidebars[self.params.sidebar_id];
-
- registeredSidebar.set( 'is_rendered', isRendered );
+ self.active.bind( function ( active ) {
+ registeredSidebar.set( 'is_rendered', active );
} );
+ },
- // Show the sidebar section when it becomes visible
- registeredSidebar.on( 'change:is_rendered', function( ) {
- var sectionSelector = '#accordion-section-sidebar-widgets-' + this.get( 'id' ), $section;
+ /**
+ * Show the sidebar section when it becomes visible.
+ *
+ * Overrides api.Control.toggle()
+ *
+ * @param {Boolean} active
+ */
+ toggle: function ( active ) {
+ var $section, sectionSelector;
- $section = $( sectionSelector );
- if ( this.get( 'is_rendered' ) ) {
- $section.stop().slideDown( function() {
- $( this ).css( 'height', 'auto' ); // so that the .accordion-section-content won't overflow
- } );
+ sectionSelector = '#accordion-section-sidebar-widgets-' + this.params.sidebar_id;
+ $section = $( sectionSelector );
- } else {
- // Make sure that hidden sections get closed first
- if ( $section.hasClass( 'open' ) ) {
- // it would be nice if accordionSwitch() in accordion.js was public
- $section.find( '.accordion-section-title' ).trigger( 'click' );
- }
+ if ( active ) {
+ $section.stop().slideDown( function() {
+ $( this ).css( 'height', 'auto' ); // so that the .accordion-section-content won't overflow
+ } );
- $section.stop().slideUp();
+ } else {
+ // Make sure that hidden sections get closed first
+ if ( $section.hasClass( 'open' ) ) {
+ // it would be nice if accordionSwitch() in accordion.js was public
+ $section.find( '.accordion-section-title' ).trigger( 'click' );
}
- } );
+
+ $section.stop().slideUp();
+ }
},
/**
diff --git a/wp-admin/js/customize-widgets.min.js b/wp-admin/js/customize-widgets.min.js
index a1de10760e..29e5f4cdc0 100644
--- a/wp-admin/js/customize-widgets.min.js
+++ b/wp-admin/js/customize-widgets.min.js
@@ -1 +1 @@
-!function(a,b){function c(a){var b,c={number:null,id_base:null};return b=a.match(/^(.+)-(\d+)$/),b?(c.id_base=b[1],c.number=parseInt(b[2],10)):c.id_base=a,c}function d(a){var b,d=c(a);return b="widget_"+d.id_base,d.number&&(b+="["+d.number+"]"),b}if(a&&a.customize){var e,f=a.customize;f.Widgets=f.Widgets||{},f.Widgets.data=_wpCustomizeWidgetsSettings||{},e=f.Widgets.data.l10n,delete f.Widgets.data.l10n,f.Widgets.WidgetModel=Backbone.Model.extend({id:null,temp_id:null,classname:null,control_tpl:null,description:null,is_disabled:null,is_multi:null,multi_number:null,name:null,id_base:null,transport:"refresh",params:[],width:null,height:null,search_matched:!0}),f.Widgets.WidgetCollection=Backbone.Collection.extend({model:f.Widgets.WidgetModel,doSearch:function(a){this.terms!==a&&(this.terms=a,this.terms.length>0&&this.search(this.terms),""===this.terms&&this.each(function(a){a.set("search_matched",!0)}))},search:function(a){var b,c;a=a.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"),a=a.replace(/ /g,")(?=.*"),b=new RegExp("^(?=.*"+a+").+","i"),this.each(function(a){c=[a.get("name"),a.get("id"),a.get("description")].join(" "),a.set("search_matched",b.test(c))})}}),f.Widgets.availableWidgets=new f.Widgets.WidgetCollection(f.Widgets.data.availableWidgets),f.Widgets.SidebarModel=Backbone.Model.extend({after_title:null,after_widget:null,before_title:null,before_widget:null,"class":null,description:null,id:null,name:null,is_rendered:!1}),f.Widgets.SidebarCollection=Backbone.Collection.extend({model:f.Widgets.SidebarModel}),f.Widgets.registeredSidebars=new f.Widgets.SidebarCollection(f.Widgets.data.registeredSidebars),f.Widgets.AvailableWidgetsPanelView=a.Backbone.View.extend({el:"#available-widgets",events:{"input #widgets-search":"search","keyup #widgets-search":"search","change #widgets-search":"search","search #widgets-search":"search","focus .widget-tpl":"focus","click .widget-tpl":"_submit","keypress .widget-tpl":"_submit",keydown:"keyboardAccessible"},selected:null,currentSidebarControl:null,$search:null,initialize:function(){var a=this;this.$search=b("#widgets-search"),_.bindAll(this,"close"),this.listenTo(this.collection,"change",this.updateList),this.updateList(),b("#customize-controls").on("click keydown",function(c){var d=b(c.target).is(".add-new-widget, .add-new-widget *");b("body").hasClass("adding-widget")&&!d&&a.close()}),f.previewer.bind("url",this.close)},search:function(a){var b;this.collection.doSearch(a.target.value),this.selected&&!this.selected.is(":visible")&&(this.selected.removeClass("selected"),this.selected=null),this.selected&&!a.target.value&&(this.selected.removeClass("selected"),this.selected=null),!this.selected&&a.target.value&&(b=this.$el.find("> .widget-tpl:visible:first"),b.length&&this.select(b))},updateList:function(){this.collection.each(function(a){var c=b("#widget-tpl-"+a.id);c.toggle(a.get("search_matched")&&!a.get("is_disabled")),a.get("is_disabled")&&c.is(this.selected)&&(this.selected=null)})},select:function(a){this.selected=b(a),this.selected.siblings(".widget-tpl").removeClass("selected"),this.selected.addClass("selected")},focus:function(a){this.select(b(a.currentTarget))},_submit:function(a){("keypress"!==a.type||13===a.which||32===a.which)&&this.submit(b(a.currentTarget))},submit:function(a){var c,d;a||(a=this.selected),a&&this.currentSidebarControl&&(this.select(a),c=b(this.selected).data("widget-id"),d=this.collection.findWhere({id:c}),d&&(this.currentSidebarControl.addWidget(d.get("id_base")),this.close()))},open:function(a){this.currentSidebarControl=a,_(this.currentSidebarControl.getWidgetFormControls()).each(function(a){a.params.is_wide&&a.collapseForm()}),b("body").addClass("adding-widget"),this.$el.find(".selected").removeClass("selected"),this.collection.doSearch(""),this.$search.focus()},close:function(a){a=a||{},a.returnFocus&&this.currentSidebarControl&&this.currentSidebarControl.container.find(".add-new-widget").focus(),this.currentSidebarControl=null,this.selected=null,b("body").removeClass("adding-widget"),this.$search.val("")},keyboardAccessible:function(a){var c=13===a.which,d=27===a.which,e=40===a.which,f=38===a.which,g=null,h=this.$el.find("> .widget-tpl:visible:first"),i=this.$el.find("> .widget-tpl:visible:last"),j=b(a.target).is(this.$search);return e||f?(e?j?g=h:this.selected&&0!==this.selected.nextAll(".widget-tpl:visible").length&&(g=this.selected.nextAll(".widget-tpl:visible:first")):f&&(j?g=i:this.selected&&0!==this.selected.prevAll(".widget-tpl:visible").length&&(g=this.selected.prevAll(".widget-tpl:visible:first"))),this.select(g),void(g?g.focus():this.$search.focus())):void((!c||this.$search.val())&&(c?this.submit():d&&this.close({returnFocus:!0})))}}),f.Widgets.formSyncHandlers={rss:function(a,c,d){var e=c.find(".widget-error:first"),f=b(""+d+"
").find(".widget-error:first");e.length&&f.length?e.replaceWith(f):e.length?e.remove():f.length&&c.find(".widget-content:first").prepend(f)}},f.Widgets.WidgetControl=f.Control.extend({ready:function(){this._setupModel(),this._setupWideWidget(),this._setupControlToggle(),this._setupWidgetTitle(),this._setupReorderUI(),this._setupHighlightEffects(),this._setupUpdateUI(),this._setupRemoveUI()},_setupModel:function(){var a,b=this;f.Widgets.savedWidgetIds=f.Widgets.savedWidgetIds||[],a=function(){f.Widgets.savedWidgetIds[b.params.widget_id]=!0},f.bind("ready",a),f.bind("saved",a),this._updateCount=0,this.isWidgetUpdating=!1,this.liveUpdateMode=!0,this.setting.bind(function(a,c){_(c).isEqual(a)||b.isWidgetUpdating||b.updateWidget({instance:a})})},_setupWideWidget:function(){var a,c,d,e,g,h=this;this.params.is_wide&&(a=this.container.find(".widget-inside"),c=a.find("> .form"),d=b(".wp-full-overlay-sidebar-content:first"),this.container.addClass("wide-widget-control"),this.container.find(".widget-content:first").css({"max-width":this.params.width,"min-height":this.params.height}),g=function(){var d,e=h.container.offset().top,f=b(window).height(),g=c.outerHeight();a.css("max-height",f),d=Math.max(0,Math.min(Math.max(e,0),f-g)),a.css("top",d)},e=b("#customize-theme-controls"),this.container.on("expand",function(){g(),d.on("scroll",g),b(window).on("resize",g),e.on("expanded collapsed",g)}),this.container.on("collapsed",function(){d.off("scroll",g),b(window).off("resize",g),e.off("expanded collapsed",g)}),f.each(function(a){0===a.id.indexOf("sidebars_widgets[")&&a.bind(function(){h.container.hasClass("expanded")&&g()})}))},_setupControlToggle:function(){var a,b=this;this.container.find(".widget-top").on("click",function(a){a.preventDefault();var c=b.getSidebarWidgetsControl();c.isReordering||b.toggleForm()}),a=this.container.find(".widget-control-close"),a.on("click",function(a){a.preventDefault(),b.collapseForm(),b.container.find(".widget-top .widget-action:first").focus()})},_setupWidgetTitle:function(){var a,b=this;a=function(){var a=b.setting().title,c=b.container.find(".in-widget-title");c.text(a?": "+a:"")},this.setting.bind(a),a()},_setupReorderUI:function(){var a,c,d,e,g=this;a=function(a){a.siblings(".selected").removeClass("selected"),a.addClass("selected");var b=a.data("id")===g.params.sidebar_id;g.container.find(".move-widget-btn").prop("disabled",b)},this.container.find(".widget-title-action").after(b(f.Widgets.data.tpl.widgetReorderNav)),c=b(_.template(f.Widgets.data.tpl.moveWidgetArea,{sidebars:_(f.Widgets.registeredSidebars.toArray()).pluck("attributes")})),this.container.find(".widget-top").after(c),e=function(){var d,e=c.find("li");d=e.filter(function(){return b(this).data("id")===g.params.sidebar_id}),e.each(function(){var c,e,g=b(this);c=g.data("id"),e=f.Widgets.registeredSidebars.get(c),g.toggle(e.get("is_rendered")),g.hasClass("selected")&&!e.get("is_rendered")&&a(d)})},e(),f.Widgets.registeredSidebars.on("change:is_rendered",e),d=this.container.find(".widget-reorder-nav"),d.find(".move-widget, .move-widget-down, .move-widget-up").on("click keypress",function(a){if("keypress"!==a.type||13===a.which||32===a.which)if(b(this).focus(),b(this).is(".move-widget"))g.toggleWidgetMoveArea();else{var c=b(this).is(".move-widget-down"),d=b(this).is(".move-widget-up"),e=g.getWidgetSidebarPosition();if(d&&0===e||c&&e===g.getSidebarWidgetsControl().setting().length-1)return;d?g.moveUp():g.moveDown(),b(this).focus()}}),this.container.find(".widget-area-select").on("click keypress","li",function(c){("keypress"!==event.type||13===event.which||32===event.which)&&(c.preventDefault(),a(b(this)))}),this.container.find(".move-widget-btn").click(function(){g.getSidebarWidgetsControl().toggleReordering(!1);var a,b,c,d,e,h=g.params.sidebar_id,i=g.container.find(".widget-area-select li.selected").data("id");a=f("sidebars_widgets["+h+"]"),b=f("sidebars_widgets["+i+"]"),c=Array.prototype.slice.call(a()),d=Array.prototype.slice.call(b()),e=g.getWidgetSidebarPosition(),c.splice(e,1),d.push(g.params.widget_id),a(c),b(d),g.focus()})},_setupHighlightEffects:function(){var a=this;this.container.on("mouseenter click",function(){a.setting.previewer.send("highlight-widget",a.params.widget_id)}),this.setting.bind(function(){a.setting.previewer.send("highlight-widget",a.params.widget_id)})},_setupUpdateUI:function(){var a,c,d,g,h,i=this;a=this.container.find(".widget:first"),c=a.find(".widget-content:first"),d=this.container.find(".widget-control-save"),d.val(e.saveBtnLabel),d.attr("title",e.saveBtnTooltip),d.removeClass("button-primary").addClass("button-secondary"),d.on("click",function(a){a.preventDefault(),i.updateWidget({disable_form:!0})}),g=_.debounce(function(){i.updateWidget()},250),c.on("keydown","input",function(a){13===a.which&&(a.preventDefault(),i.updateWidget({ignoreActiveElement:!0}))}),c.on("change input propertychange",":input",function(a){i.liveUpdateMode&&("change"===a.type?i.updateWidget():this.checkValidity&&this.checkValidity()&&g())}),this.setting.previewer.channel.bind("synced",function(){i.container.removeClass("previewer-loading")}),f.previewer.bind("widget-updated",function(a){a===i.params.widget_id&&i.container.removeClass("previewer-loading")}),f.previewer.bind("rendered-widgets",function(a){var b=!!a[i.params.widget_id];i.container.toggleClass("widget-rendered",b)}),h=f.Widgets.formSyncHandlers[this.params.widget_id_base],h&&b(document).on("widget-synced",function(b,c){a.is(c)&&h.apply(document,arguments)})},_setupRemoveUI:function(){var a,b,c=this;a=this.container.find("a.widget-control-remove"),a.on("click",function(a){a.preventDefault();var b;b=c.container.next().is(".customize-control-widget_form")?c.container.next().find(".widget-action:first"):c.container.prev().is(".customize-control-widget_form")?c.container.prev().find(".widget-action:first"):c.container.next(".customize-control-sidebar_widgets").find(".add-new-widget:first"),c.container.slideUp(function(){var a,d,e=f.Widgets.getSidebarWidgetControlContainingWidget(c.params.widget_id);e&&(a=e.setting().slice(),d=_.indexOf(a,c.params.widget_id),-1!==d&&(a.splice(d,1),e.setting(a),b.focus()))})}),b=function(){a.text(e.removeBtnLabel),a.attr("title",e.removeBtnTooltip)},this.params.is_new?f.bind("saved",b):b()},_getInputs:function(a){return b(a).find(":input[name]")},_getInputsSignature:function(a){var c=_(a).map(function(a){var c,d=b(a);return c=d.is(":checkbox, :radio")?[d.attr("id"),d.attr("name"),d.prop("value")]:[d.attr("id"),d.attr("name")],c.join(",")});return c.join(";")},_getInputStatePropertyName:function(a){var c=b(a);return c.is(":radio, :checkbox")?"checked":"value"},getSidebarWidgetsControl:function(){var a,b;return a="sidebars_widgets["+this.params.sidebar_id+"]",(b=f.control(a))?b:void 0},updateWidget:function(c){var d,g,h,i,j,k,l,m,n,o,p,q=this;c=b.extend({instance:null,complete:null,ignoreActiveElement:!1},c),d=c.instance,g=c.complete,this._updateCount+=1,j=this._updateCount,h=this.container.find(".widget:first"),i=h.find(".widget-content:first"),i.find(".widget-error").remove(),this.container.addClass("widget-form-loading"),this.container.addClass("previewer-loading"),n=f.state("processing"),n(n()+1),this.liveUpdateMode||this.container.addClass("widget-form-disabled"),k={},k.action="update-widget",k.wp_customize="on",k.nonce=f.Widgets.data.nonce,k.theme=f.settings.theme.stylesheet,l=b.param(k),m=this._getInputs(i),m.each(function(){var a=b(this),c=q._getInputStatePropertyName(this);a.data("state"+j,a.prop(c))}),l+=d?"&"+b.param({sanitized_widget_setting:JSON.stringify(d)}):"&"+m.serialize(),l+="&"+i.find("~ :input").serialize(),o=b.post(a.ajax.settings.url,l),o.done(function(a){var d,k,l,n,o=!1;return"0"===a?(f.previewer.preview.iframe.hide(),void f.previewer.login().done(function(){q.updateWidget(c),f.previewer.preview.iframe.show()})):"-1"===a?void f.previewer.cheatin():void(a.success?(k=b(""+a.data.form+"
"),l=q._getInputs(k),n=q._getInputsSignature(m)===q._getInputsSignature(l),n&&!q.liveUpdateMode&&(q.liveUpdateMode=!0,q.container.removeClass("widget-form-disabled"),q.container.find('input[name="savewidget"]').hide()),n&&q.liveUpdateMode?(m.each(function(a){var d,e,f,g=b(this),h=b(l[a]),i=q._getInputStatePropertyName(this);d=g.data("state"+j),e=h.prop(i),g.data("sanitized",e),f=d!==e&&(c.ignoreActiveElement||!g.is(document.activeElement)),f&&g.prop(i,e)}),b(document).trigger("widget-synced",[h,a.data.form])):q.liveUpdateMode?(q.liveUpdateMode=!1,q.container.find('input[name="savewidget"]').show(),o=!0):(i.html(a.data.form),q.container.removeClass("widget-form-disabled"),b(document).trigger("widget-updated",[h])),p=!o&&!_(q.setting()).isEqual(a.data.instance),p?(q.isWidgetUpdating=!0,q.setting(a.data.instance),q.isWidgetUpdating=!1):q.container.removeClass("previewer-loading"),g&&g.call(q,null,{noChange:!p,ajaxFinished:!0})):(d=e.error,a.data&&a.data.message&&(d=a.data.message),g?g.call(q,d):i.prepend(''+d+"
")))}),o.fail(function(a,b){g&&g.call(q,b)}),o.always(function(){q.container.removeClass("widget-form-loading"),m.each(function(){b(this).removeData("state"+j)}),n(n()-1)})},expandControlSection:function(){var a=this.container.closest(".accordion-section");a.hasClass("open")||a.find(".accordion-section-title:first").trigger("click")},expandForm:function(){this.toggleForm(!0)},collapseForm:function(){this.toggleForm(!1)},toggleForm:function(a){var b,c,d,e=this;b=this.container.find("div.widget:first"),c=b.find(".widget-inside:first"),"undefined"==typeof a&&(a=!c.is(":visible")),c.is(":visible")!==a&&(a?(f.control.each(function(a){e.params.type===a.params.type&&e!==a&&a.collapseForm()}),d=function(){e.container.removeClass("expanding"),e.container.addClass("expanded"),e.container.trigger("expanded")},e.params.is_wide?c.fadeIn("fast",d):c.slideDown("fast",d),e.container.trigger("expand"),e.container.addClass("expanding")):(d=function(){e.container.removeClass("collapsing"),e.container.removeClass("expanded"),e.container.trigger("collapsed")},e.container.trigger("collapse"),e.container.addClass("collapsing"),e.params.is_wide?c.fadeOut("fast",d):c.slideUp("fast",function(){b.css({width:"",margin:""}),d()})))},focus:function(){this.expandControlSection(),this.expandForm(),this.container.find(".widget-content :focusable:first").focus()},getWidgetSidebarPosition:function(){var a,b;return a=this.getSidebarWidgetsControl().setting(),b=_.indexOf(a,this.params.widget_id),-1!==b?b:void 0},moveUp:function(){this._moveWidgetByOne(-1)},moveDown:function(){this._moveWidgetByOne(1)},_moveWidgetByOne:function(a){var b,c,d,e;b=this.getWidgetSidebarPosition(),c=this.getSidebarWidgetsControl().setting,d=Array.prototype.slice.call(c()),e=d[b+a],d[b+a]=this.params.widget_id,d[b]=e,c(d)},toggleWidgetMoveArea:function(a){var c,d=this;c=this.container.find(".move-widget-area"),"undefined"==typeof a&&(a=!c.hasClass("active")),a&&(c.find(".selected").removeClass("selected"),c.find("li").filter(function(){return b(this).data("id")===d.params.sidebar_id}).addClass("selected"),this.container.find(".move-widget-btn").prop("disabled",!0)),c.toggleClass("active",a)},highlightSectionAndControl:function(){var a;a=this.container.is(":hidden")?this.container.closest(".control-section"):this.container,b(".highlighted").removeClass("highlighted"),a.addClass("highlighted"),setTimeout(function(){a.removeClass("highlighted")},500)}}),f.Widgets.SidebarControl=f.Control.extend({ready:function(){this.$controlSection=this.container.closest(".control-section"),this.$sectionContent=this.container.closest(".accordion-section-content"),this._setupModel(),this._setupSortable(),this._setupAddition(),this._applyCardinalOrderClassNames()},_setupModel:function(){var a=this,d=f.Widgets.registeredSidebars.get(this.params.sidebar_id);this.setting.bind(function(d,e){var g,h,i,j;j=_(e).difference(d),d=_(d).filter(function(a){var b=c(a);return!!f.Widgets.availableWidgets.findWhere({id_base:b.id_base})}),g=_(d).map(function(b){var c=f.Widgets.getWidgetFormControlForWidget(b);return c||(c=a.addWidget(b)),c}),g.sort(function(a,b){var c=_.indexOf(d,a.params.widget_id),e=_.indexOf(d,b.params.widget_id);return c===e?0:e>c?-1:1}),i=_(g).map(function(a){return a.container[0]}),h=a.$sectionContent.find(".customize-control-sidebar_widgets"),h.before(i),a._applyCardinalOrderClassNames(),_(g).each(function(b){b.params.sidebar_id=a.params.sidebar_id}),_(j).each(function(d){setTimeout(function(){var e,g,h,i,j,k=!1;f.each(function(b){if(b.id!==a.setting.id&&0===b.id.indexOf("sidebars_widgets[")&&"sidebars_widgets[wp_inactive_widgets]"!==b.id){var c,e=b();c=_.indexOf(e,d),-1!==c&&(k=!0)}}),k||(e=f.Widgets.getWidgetFormControlForWidget(d),g=e&&b.contains(document,e.container[0])&&!b.contains(a.$sectionContent[0],e.container[0]),e&&!g&&(f.control.remove(e.id),e.container.remove()),f.Widgets.savedWidgetIds[d]&&(h=f.value("sidebars_widgets[wp_inactive_widgets]")().slice(),h.push(d),f.value("sidebars_widgets[wp_inactive_widgets]")(_(h).unique())),i=c(d).id_base,j=f.Widgets.availableWidgets.findWhere({id_base:i}),j&&!j.get("is_multi")&&j.set("is_disabled",!1))})})}),f.previewer.bind("rendered-sidebars",function(b){var c=!!b[a.params.sidebar_id];d.set("is_rendered",c)}),d.on("change:is_rendered",function(){var a,c="#accordion-section-sidebar-widgets-"+this.get("id");a=b(c),this.get("is_rendered")?a.stop().slideDown(function(){b(this).css("height","auto")}):(a.hasClass("open")&&a.find(".accordion-section-title").trigger("click"),a.stop().slideUp())})},_setupSortable:function(){var a=this;this.isReordering=!1,this.$sectionContent.sortable({items:"> .customize-control-widget_form",handle:".widget-top",axis:"y",connectWith:".accordion-section-content:has(.customize-control-sidebar_widgets)",update:function(){var c,d=a.$sectionContent.sortable("toArray");c=b.map(d,function(a){return b("#"+a).find(":input[name=widget-id]").val()}),a.setting(c)}}),this.$controlSection.find(".accordion-section-title").droppable({accept:".customize-control-widget_form",over:function(){a.$controlSection.hasClass("open")||(a.$controlSection.addClass("open"),a.$sectionContent.toggle(!1).slideToggle(150,function(){a.$sectionContent.sortable("refreshPositions")}))}}),this.container.find(".reorder-toggle").on("click keydown",function(b){("keydown"!==b.type||13===b.which||32===b.which)&&a.toggleReordering(!a.isReordering)})},_setupAddition:function(){var a=this;this.container.find(".add-new-widget").on("click keydown",function(c){("keydown"!==c.type||13===c.which||32===c.which)&&(a.$sectionContent.hasClass("reordering")||(b("body").hasClass("adding-widget")?f.Widgets.availableWidgetsPanel.close():f.Widgets.availableWidgetsPanel.open(a)))})},_applyCardinalOrderClassNames:function(){this.$sectionContent.find(".customize-control-widget_form").removeClass("first-widget").removeClass("last-widget").find(".move-widget-down, .move-widget-up").prop("tabIndex",0),this.$sectionContent.find(".customize-control-widget_form:first").addClass("first-widget").find(".move-widget-up").prop("tabIndex",-1),this.$sectionContent.find(".customize-control-widget_form:last").addClass("last-widget").find(".move-widget-down").prop("tabIndex",-1)},toggleReordering:function(a){a=Boolean(a),a!==this.$sectionContent.hasClass("reordering")&&(this.isReordering=a,this.$sectionContent.toggleClass("reordering",a),a&&_(this.getWidgetFormControls()).each(function(a){a.collapseForm()}))},getWidgetFormControls:function(){var a;return a=_(this.setting()).map(function(a){var b=d(a),c=f.control(b);if(c)return c})},addWidget:function(a){var d,e,g,h,i,j,k,l,m,n=this,o="widget_form",p=c(a),q=p.number,r=p.id_base,s=f.Widgets.availableWidgets.findWhere({id_base:r});return s?q&&!s.get("is_multi")?!1:(s.get("is_multi")&&!q&&(s.set("multi_number",s.get("multi_number")+1),q=s.get("multi_number")),d=b.trim(b("#widget-tpl-"+s.get("id")).html()),s.get("is_multi")?d=d.replace(/<[^<>]+>/g,function(a){return a.replace(/__i__|%i%/g,q)}):s.set("is_disabled",!0),e=b(d),g=b("").addClass("customize-control").addClass("customize-control-"+o).append(e),g.find("> .widget-icon").remove(),s.get("is_multi")&&(g.find('input[name="widget_number"]').val(q),g.find('input[name="multi_number"]').val(q)),a=g.find('[name="widget-id"]').val(),g.hide(),i="widget_"+s.get("id_base"),s.get("is_multi")&&(i+="["+q+"]"),g.attr("id","customize-control-"+i.replace(/\]/g,"").replace(/\[/g,"-")),this.container.after(g),j=f.has(i),j||(m={transport:"refresh",previewer:this.setting.previewer},f.create(i,i,{},m)),h=f.controlConstructor[o],k=new h(i,{params:{settings:{"default":i},sidebar_id:n.params.sidebar_id,widget_id:a,widget_id_base:s.get("id_base"),type:o,is_new:!j,width:s.get("width"),height:s.get("height"),is_wide:s.get("is_wide")},previewer:n.setting.previewer}),f.control.add(i,k),f.each(function(b){if(b.id!==n.setting.id&&0===b.id.indexOf("sidebars_widgets[")){var c=b().slice(),d=_.indexOf(c,a);-1!==d&&(c.splice(d),b(c))}}),l=this.setting().slice(),-1===_.indexOf(l,a)&&(l.push(a),this.setting(l)),g.slideDown(function(){j?(k.expandForm(),k.updateWidget({instance:k.setting(),complete:function(a){if(a)throw a;k.focus()}})):k.focus()}),b(document).trigger("widget-added",[e]),k):!1}}),b.extend(f.controlConstructor,{widget_form:f.Widgets.WidgetControl,sidebar_widgets:f.Widgets.SidebarControl}),f.bind("ready",function(){f.Widgets.availableWidgetsPanel=new f.Widgets.AvailableWidgetsPanelView({collection:f.Widgets.availableWidgets}),f.previewer.bind("highlight-widget-control",f.Widgets.highlightWidgetFormControl),f.previewer.bind("focus-widget-control",f.Widgets.focusWidgetFormControl)}),f.Widgets.highlightWidgetFormControl=function(a){var b=f.Widgets.getWidgetFormControlForWidget(a);b&&b.highlightSectionAndControl()},f.Widgets.focusWidgetFormControl=function(a){var b=f.Widgets.getWidgetFormControlForWidget(a);b&&b.focus()},f.Widgets.getSidebarWidgetControlContainingWidget=function(a){var b=null;return f.control.each(function(c){"sidebar_widgets"===c.params.type&&-1!==_.indexOf(c.setting(),a)&&(b=c)}),b},f.Widgets.getWidgetFormControlForWidget=function(a){var b=null;return f.control.each(function(c){"widget_form"===c.params.type&&c.params.widget_id===a&&(b=c)}),b}}}(window.wp,jQuery);
\ No newline at end of file
+!function(a,b){function c(a){var b,c={number:null,id_base:null};return b=a.match(/^(.+)-(\d+)$/),b?(c.id_base=b[1],c.number=parseInt(b[2],10)):c.id_base=a,c}function d(a){var b,d=c(a);return b="widget_"+d.id_base,d.number&&(b+="["+d.number+"]"),b}if(a&&a.customize){var e,f=a.customize;f.Widgets=f.Widgets||{},f.Widgets.data=_wpCustomizeWidgetsSettings||{},e=f.Widgets.data.l10n,delete f.Widgets.data.l10n,f.Widgets.WidgetModel=Backbone.Model.extend({id:null,temp_id:null,classname:null,control_tpl:null,description:null,is_disabled:null,is_multi:null,multi_number:null,name:null,id_base:null,transport:"refresh",params:[],width:null,height:null,search_matched:!0}),f.Widgets.WidgetCollection=Backbone.Collection.extend({model:f.Widgets.WidgetModel,doSearch:function(a){this.terms!==a&&(this.terms=a,this.terms.length>0&&this.search(this.terms),""===this.terms&&this.each(function(a){a.set("search_matched",!0)}))},search:function(a){var b,c;a=a.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"),a=a.replace(/ /g,")(?=.*"),b=new RegExp("^(?=.*"+a+").+","i"),this.each(function(a){c=[a.get("name"),a.get("id"),a.get("description")].join(" "),a.set("search_matched",b.test(c))})}}),f.Widgets.availableWidgets=new f.Widgets.WidgetCollection(f.Widgets.data.availableWidgets),f.Widgets.SidebarModel=Backbone.Model.extend({after_title:null,after_widget:null,before_title:null,before_widget:null,"class":null,description:null,id:null,name:null,is_rendered:!1}),f.Widgets.SidebarCollection=Backbone.Collection.extend({model:f.Widgets.SidebarModel}),f.Widgets.registeredSidebars=new f.Widgets.SidebarCollection(f.Widgets.data.registeredSidebars),f.Widgets.AvailableWidgetsPanelView=a.Backbone.View.extend({el:"#available-widgets",events:{"input #widgets-search":"search","keyup #widgets-search":"search","change #widgets-search":"search","search #widgets-search":"search","focus .widget-tpl":"focus","click .widget-tpl":"_submit","keypress .widget-tpl":"_submit",keydown:"keyboardAccessible"},selected:null,currentSidebarControl:null,$search:null,initialize:function(){var a=this;this.$search=b("#widgets-search"),_.bindAll(this,"close"),this.listenTo(this.collection,"change",this.updateList),this.updateList(),b("#customize-controls").on("click keydown",function(c){var d=b(c.target).is(".add-new-widget, .add-new-widget *");b("body").hasClass("adding-widget")&&!d&&a.close()}),f.previewer.bind("url",this.close)},search:function(a){var b;this.collection.doSearch(a.target.value),this.selected&&!this.selected.is(":visible")&&(this.selected.removeClass("selected"),this.selected=null),this.selected&&!a.target.value&&(this.selected.removeClass("selected"),this.selected=null),!this.selected&&a.target.value&&(b=this.$el.find("> .widget-tpl:visible:first"),b.length&&this.select(b))},updateList:function(){this.collection.each(function(a){var c=b("#widget-tpl-"+a.id);c.toggle(a.get("search_matched")&&!a.get("is_disabled")),a.get("is_disabled")&&c.is(this.selected)&&(this.selected=null)})},select:function(a){this.selected=b(a),this.selected.siblings(".widget-tpl").removeClass("selected"),this.selected.addClass("selected")},focus:function(a){this.select(b(a.currentTarget))},_submit:function(a){("keypress"!==a.type||13===a.which||32===a.which)&&this.submit(b(a.currentTarget))},submit:function(a){var c,d;a||(a=this.selected),a&&this.currentSidebarControl&&(this.select(a),c=b(this.selected).data("widget-id"),d=this.collection.findWhere({id:c}),d&&(this.currentSidebarControl.addWidget(d.get("id_base")),this.close()))},open:function(a){this.currentSidebarControl=a,_(this.currentSidebarControl.getWidgetFormControls()).each(function(a){a.params.is_wide&&a.collapseForm()}),b("body").addClass("adding-widget"),this.$el.find(".selected").removeClass("selected"),this.collection.doSearch(""),this.$search.focus()},close:function(a){a=a||{},a.returnFocus&&this.currentSidebarControl&&this.currentSidebarControl.container.find(".add-new-widget").focus(),this.currentSidebarControl=null,this.selected=null,b("body").removeClass("adding-widget"),this.$search.val("")},keyboardAccessible:function(a){var c=13===a.which,d=27===a.which,e=40===a.which,f=38===a.which,g=null,h=this.$el.find("> .widget-tpl:visible:first"),i=this.$el.find("> .widget-tpl:visible:last"),j=b(a.target).is(this.$search);return e||f?(e?j?g=h:this.selected&&0!==this.selected.nextAll(".widget-tpl:visible").length&&(g=this.selected.nextAll(".widget-tpl:visible:first")):f&&(j?g=i:this.selected&&0!==this.selected.prevAll(".widget-tpl:visible").length&&(g=this.selected.prevAll(".widget-tpl:visible:first"))),this.select(g),void(g?g.focus():this.$search.focus())):void((!c||this.$search.val())&&(c?this.submit():d&&this.close({returnFocus:!0})))}}),f.Widgets.formSyncHandlers={rss:function(a,c,d){var e=c.find(".widget-error:first"),f=b(""+d+"
").find(".widget-error:first");e.length&&f.length?e.replaceWith(f):e.length?e.remove():f.length&&c.find(".widget-content:first").prepend(f)}},f.Widgets.WidgetControl=f.Control.extend({ready:function(){this._setupModel(),this._setupWideWidget(),this._setupControlToggle(),this._setupWidgetTitle(),this._setupReorderUI(),this._setupHighlightEffects(),this._setupUpdateUI(),this._setupRemoveUI()},_setupModel:function(){var a,b=this;f.Widgets.savedWidgetIds=f.Widgets.savedWidgetIds||[],a=function(){f.Widgets.savedWidgetIds[b.params.widget_id]=!0},f.bind("ready",a),f.bind("saved",a),this._updateCount=0,this.isWidgetUpdating=!1,this.liveUpdateMode=!0,this.setting.bind(function(a,c){_(c).isEqual(a)||b.isWidgetUpdating||b.updateWidget({instance:a})})},_setupWideWidget:function(){var a,c,d,e,g,h=this;this.params.is_wide&&(a=this.container.find(".widget-inside"),c=a.find("> .form"),d=b(".wp-full-overlay-sidebar-content:first"),this.container.addClass("wide-widget-control"),this.container.find(".widget-content:first").css({"max-width":this.params.width,"min-height":this.params.height}),g=function(){var d,e=h.container.offset().top,f=b(window).height(),g=c.outerHeight();a.css("max-height",f),d=Math.max(0,Math.min(Math.max(e,0),f-g)),a.css("top",d)},e=b("#customize-theme-controls"),this.container.on("expand",function(){g(),d.on("scroll",g),b(window).on("resize",g),e.on("expanded collapsed",g)}),this.container.on("collapsed",function(){d.off("scroll",g),b(window).off("resize",g),e.off("expanded collapsed",g)}),f.each(function(a){0===a.id.indexOf("sidebars_widgets[")&&a.bind(function(){h.container.hasClass("expanded")&&g()})}))},_setupControlToggle:function(){var a,b=this;this.container.find(".widget-top").on("click",function(a){a.preventDefault();var c=b.getSidebarWidgetsControl();c.isReordering||b.toggleForm()}),a=this.container.find(".widget-control-close"),a.on("click",function(a){a.preventDefault(),b.collapseForm(),b.container.find(".widget-top .widget-action:first").focus()})},_setupWidgetTitle:function(){var a,b=this;a=function(){var a=b.setting().title,c=b.container.find(".in-widget-title");c.text(a?": "+a:"")},this.setting.bind(a),a()},_setupReorderUI:function(){var a,c,d,e,g=this;a=function(a){a.siblings(".selected").removeClass("selected"),a.addClass("selected");var b=a.data("id")===g.params.sidebar_id;g.container.find(".move-widget-btn").prop("disabled",b)},this.container.find(".widget-title-action").after(b(f.Widgets.data.tpl.widgetReorderNav)),c=b(_.template(f.Widgets.data.tpl.moveWidgetArea,{sidebars:_(f.Widgets.registeredSidebars.toArray()).pluck("attributes")})),this.container.find(".widget-top").after(c),e=function(){var d,e=c.find("li");d=e.filter(function(){return b(this).data("id")===g.params.sidebar_id}),e.each(function(){var c,e,g=b(this);c=g.data("id"),e=f.Widgets.registeredSidebars.get(c),g.toggle(e.get("is_rendered")),g.hasClass("selected")&&!e.get("is_rendered")&&a(d)})},e(),f.Widgets.registeredSidebars.on("change:is_rendered",e),d=this.container.find(".widget-reorder-nav"),d.find(".move-widget, .move-widget-down, .move-widget-up").on("click keypress",function(a){if("keypress"!==a.type||13===a.which||32===a.which)if(b(this).focus(),b(this).is(".move-widget"))g.toggleWidgetMoveArea();else{var c=b(this).is(".move-widget-down"),d=b(this).is(".move-widget-up"),e=g.getWidgetSidebarPosition();if(d&&0===e||c&&e===g.getSidebarWidgetsControl().setting().length-1)return;d?g.moveUp():g.moveDown(),b(this).focus()}}),this.container.find(".widget-area-select").on("click keypress","li",function(c){("keypress"!==event.type||13===event.which||32===event.which)&&(c.preventDefault(),a(b(this)))}),this.container.find(".move-widget-btn").click(function(){g.getSidebarWidgetsControl().toggleReordering(!1);var a,b,c,d,e,h=g.params.sidebar_id,i=g.container.find(".widget-area-select li.selected").data("id");a=f("sidebars_widgets["+h+"]"),b=f("sidebars_widgets["+i+"]"),c=Array.prototype.slice.call(a()),d=Array.prototype.slice.call(b()),e=g.getWidgetSidebarPosition(),c.splice(e,1),d.push(g.params.widget_id),a(c),b(d),g.focus()})},_setupHighlightEffects:function(){var a=this;this.container.on("mouseenter click",function(){a.setting.previewer.send("highlight-widget",a.params.widget_id)}),this.setting.bind(function(){a.setting.previewer.send("highlight-widget",a.params.widget_id)})},_setupUpdateUI:function(){var a,c,d,g,h,i=this;a=this.container.find(".widget:first"),c=a.find(".widget-content:first"),d=this.container.find(".widget-control-save"),d.val(e.saveBtnLabel),d.attr("title",e.saveBtnTooltip),d.removeClass("button-primary").addClass("button-secondary"),d.on("click",function(a){a.preventDefault(),i.updateWidget({disable_form:!0})}),g=_.debounce(function(){i.updateWidget()},250),c.on("keydown","input",function(a){13===a.which&&(a.preventDefault(),i.updateWidget({ignoreActiveElement:!0}))}),c.on("change input propertychange",":input",function(a){i.liveUpdateMode&&("change"===a.type?i.updateWidget():this.checkValidity&&this.checkValidity()&&g())}),this.setting.previewer.channel.bind("synced",function(){i.container.removeClass("previewer-loading")}),f.previewer.bind("widget-updated",function(a){a===i.params.widget_id&&i.container.removeClass("previewer-loading")}),h=f.Widgets.formSyncHandlers[this.params.widget_id_base],h&&b(document).on("widget-synced",function(b,c){a.is(c)&&h.apply(document,arguments)})},toggle:function(a){this.container.toggleClass("widget-rendered",a)},_setupRemoveUI:function(){var a,b,c=this;a=this.container.find("a.widget-control-remove"),a.on("click",function(a){a.preventDefault();var b;b=c.container.next().is(".customize-control-widget_form")?c.container.next().find(".widget-action:first"):c.container.prev().is(".customize-control-widget_form")?c.container.prev().find(".widget-action:first"):c.container.next(".customize-control-sidebar_widgets").find(".add-new-widget:first"),c.container.slideUp(function(){var a,d,e=f.Widgets.getSidebarWidgetControlContainingWidget(c.params.widget_id);e&&(a=e.setting().slice(),d=_.indexOf(a,c.params.widget_id),-1!==d&&(a.splice(d,1),e.setting(a),b.focus()))})}),b=function(){a.text(e.removeBtnLabel),a.attr("title",e.removeBtnTooltip)},this.params.is_new?f.bind("saved",b):b()},_getInputs:function(a){return b(a).find(":input[name]")},_getInputsSignature:function(a){var c=_(a).map(function(a){var c,d=b(a);return c=d.is(":checkbox, :radio")?[d.attr("id"),d.attr("name"),d.prop("value")]:[d.attr("id"),d.attr("name")],c.join(",")});return c.join(";")},_getInputStatePropertyName:function(a){var c=b(a);return c.is(":radio, :checkbox")?"checked":"value"},getSidebarWidgetsControl:function(){var a,b;return a="sidebars_widgets["+this.params.sidebar_id+"]",(b=f.control(a))?b:void 0},updateWidget:function(c){var d,g,h,i,j,k,l,m,n,o,p,q=this;c=b.extend({instance:null,complete:null,ignoreActiveElement:!1},c),d=c.instance,g=c.complete,this._updateCount+=1,j=this._updateCount,h=this.container.find(".widget:first"),i=h.find(".widget-content:first"),i.find(".widget-error").remove(),this.container.addClass("widget-form-loading"),this.container.addClass("previewer-loading"),n=f.state("processing"),n(n()+1),this.liveUpdateMode||this.container.addClass("widget-form-disabled"),k={},k.action="update-widget",k.wp_customize="on",k.nonce=f.Widgets.data.nonce,k.theme=f.settings.theme.stylesheet,l=b.param(k),m=this._getInputs(i),m.each(function(){var a=b(this),c=q._getInputStatePropertyName(this);a.data("state"+j,a.prop(c))}),l+=d?"&"+b.param({sanitized_widget_setting:JSON.stringify(d)}):"&"+m.serialize(),l+="&"+i.find("~ :input").serialize(),o=b.post(a.ajax.settings.url,l),o.done(function(a){var d,k,l,n,o=!1;return"0"===a?(f.previewer.preview.iframe.hide(),void f.previewer.login().done(function(){q.updateWidget(c),f.previewer.preview.iframe.show()})):"-1"===a?void f.previewer.cheatin():void(a.success?(k=b(""+a.data.form+"
"),l=q._getInputs(k),n=q._getInputsSignature(m)===q._getInputsSignature(l),n&&!q.liveUpdateMode&&(q.liveUpdateMode=!0,q.container.removeClass("widget-form-disabled"),q.container.find('input[name="savewidget"]').hide()),n&&q.liveUpdateMode?(m.each(function(a){var d,e,f,g=b(this),h=b(l[a]),i=q._getInputStatePropertyName(this);d=g.data("state"+j),e=h.prop(i),g.data("sanitized",e),f=d!==e&&(c.ignoreActiveElement||!g.is(document.activeElement)),f&&g.prop(i,e)}),b(document).trigger("widget-synced",[h,a.data.form])):q.liveUpdateMode?(q.liveUpdateMode=!1,q.container.find('input[name="savewidget"]').show(),o=!0):(i.html(a.data.form),q.container.removeClass("widget-form-disabled"),b(document).trigger("widget-updated",[h])),p=!o&&!_(q.setting()).isEqual(a.data.instance),p?(q.isWidgetUpdating=!0,q.setting(a.data.instance),q.isWidgetUpdating=!1):q.container.removeClass("previewer-loading"),g&&g.call(q,null,{noChange:!p,ajaxFinished:!0})):(d=e.error,a.data&&a.data.message&&(d=a.data.message),g?g.call(q,d):i.prepend(''+d+"
")))}),o.fail(function(a,b){g&&g.call(q,b)}),o.always(function(){q.container.removeClass("widget-form-loading"),m.each(function(){b(this).removeData("state"+j)}),n(n()-1)})},expandControlSection:function(){var a=this.container.closest(".accordion-section");a.hasClass("open")||a.find(".accordion-section-title:first").trigger("click")},expandForm:function(){this.toggleForm(!0)},collapseForm:function(){this.toggleForm(!1)},toggleForm:function(a){var b,c,d,e=this;b=this.container.find("div.widget:first"),c=b.find(".widget-inside:first"),"undefined"==typeof a&&(a=!c.is(":visible")),c.is(":visible")!==a&&(a?(f.control.each(function(a){e.params.type===a.params.type&&e!==a&&a.collapseForm()}),d=function(){e.container.removeClass("expanding"),e.container.addClass("expanded"),e.container.trigger("expanded")},e.params.is_wide?c.fadeIn("fast",d):c.slideDown("fast",d),e.container.trigger("expand"),e.container.addClass("expanding")):(d=function(){e.container.removeClass("collapsing"),e.container.removeClass("expanded"),e.container.trigger("collapsed")},e.container.trigger("collapse"),e.container.addClass("collapsing"),e.params.is_wide?c.fadeOut("fast",d):c.slideUp("fast",function(){b.css({width:"",margin:""}),d()})))},focus:function(){this.expandControlSection(),this.expandForm(),this.container.find(".widget-content :focusable:first").focus()},getWidgetSidebarPosition:function(){var a,b;return a=this.getSidebarWidgetsControl().setting(),b=_.indexOf(a,this.params.widget_id),-1!==b?b:void 0},moveUp:function(){this._moveWidgetByOne(-1)},moveDown:function(){this._moveWidgetByOne(1)},_moveWidgetByOne:function(a){var b,c,d,e;b=this.getWidgetSidebarPosition(),c=this.getSidebarWidgetsControl().setting,d=Array.prototype.slice.call(c()),e=d[b+a],d[b+a]=this.params.widget_id,d[b]=e,c(d)},toggleWidgetMoveArea:function(a){var c,d=this;c=this.container.find(".move-widget-area"),"undefined"==typeof a&&(a=!c.hasClass("active")),a&&(c.find(".selected").removeClass("selected"),c.find("li").filter(function(){return b(this).data("id")===d.params.sidebar_id}).addClass("selected"),this.container.find(".move-widget-btn").prop("disabled",!0)),c.toggleClass("active",a)},highlightSectionAndControl:function(){var a;a=this.container.is(":hidden")?this.container.closest(".control-section"):this.container,b(".highlighted").removeClass("highlighted"),a.addClass("highlighted"),setTimeout(function(){a.removeClass("highlighted")},500)}}),f.Widgets.SidebarControl=f.Control.extend({ready:function(){this.$controlSection=this.container.closest(".control-section"),this.$sectionContent=this.container.closest(".accordion-section-content"),this._setupModel(),this._setupSortable(),this._setupAddition(),this._applyCardinalOrderClassNames()},_setupModel:function(){var a=this,d=f.Widgets.registeredSidebars.get(this.params.sidebar_id);this.setting.bind(function(d,e){var g,h,i,j;j=_(e).difference(d),d=_(d).filter(function(a){var b=c(a);return!!f.Widgets.availableWidgets.findWhere({id_base:b.id_base})}),g=_(d).map(function(b){var c=f.Widgets.getWidgetFormControlForWidget(b);return c||(c=a.addWidget(b)),c}),g.sort(function(a,b){var c=_.indexOf(d,a.params.widget_id),e=_.indexOf(d,b.params.widget_id);return c===e?0:e>c?-1:1}),i=_(g).map(function(a){return a.container[0]}),h=a.$sectionContent.find(".customize-control-sidebar_widgets"),h.before(i),a._applyCardinalOrderClassNames(),_(g).each(function(b){b.params.sidebar_id=a.params.sidebar_id}),_(j).each(function(d){setTimeout(function(){var e,g,h,i,j,k=!1;f.each(function(b){if(b.id!==a.setting.id&&0===b.id.indexOf("sidebars_widgets[")&&"sidebars_widgets[wp_inactive_widgets]"!==b.id){var c,e=b();c=_.indexOf(e,d),-1!==c&&(k=!0)}}),k||(e=f.Widgets.getWidgetFormControlForWidget(d),g=e&&b.contains(document,e.container[0])&&!b.contains(a.$sectionContent[0],e.container[0]),e&&!g&&(f.control.remove(e.id),e.container.remove()),f.Widgets.savedWidgetIds[d]&&(h=f.value("sidebars_widgets[wp_inactive_widgets]")().slice(),h.push(d),f.value("sidebars_widgets[wp_inactive_widgets]")(_(h).unique())),i=c(d).id_base,j=f.Widgets.availableWidgets.findWhere({id_base:i}),j&&!j.get("is_multi")&&j.set("is_disabled",!1))})})}),a.active.bind(function(a){d.set("is_rendered",a)})},toggle:function(a){var c,d;d="#accordion-section-sidebar-widgets-"+this.params.sidebar_id,c=b(d),a?c.stop().slideDown(function(){b(this).css("height","auto")}):(c.hasClass("open")&&c.find(".accordion-section-title").trigger("click"),c.stop().slideUp())},_setupSortable:function(){var a=this;this.isReordering=!1,this.$sectionContent.sortable({items:"> .customize-control-widget_form",handle:".widget-top",axis:"y",connectWith:".accordion-section-content:has(.customize-control-sidebar_widgets)",update:function(){var c,d=a.$sectionContent.sortable("toArray");c=b.map(d,function(a){return b("#"+a).find(":input[name=widget-id]").val()}),a.setting(c)}}),this.$controlSection.find(".accordion-section-title").droppable({accept:".customize-control-widget_form",over:function(){a.$controlSection.hasClass("open")||(a.$controlSection.addClass("open"),a.$sectionContent.toggle(!1).slideToggle(150,function(){a.$sectionContent.sortable("refreshPositions")}))}}),this.container.find(".reorder-toggle").on("click keydown",function(b){("keydown"!==b.type||13===b.which||32===b.which)&&a.toggleReordering(!a.isReordering)})},_setupAddition:function(){var a=this;this.container.find(".add-new-widget").on("click keydown",function(c){("keydown"!==c.type||13===c.which||32===c.which)&&(a.$sectionContent.hasClass("reordering")||(b("body").hasClass("adding-widget")?f.Widgets.availableWidgetsPanel.close():f.Widgets.availableWidgetsPanel.open(a)))})},_applyCardinalOrderClassNames:function(){this.$sectionContent.find(".customize-control-widget_form").removeClass("first-widget").removeClass("last-widget").find(".move-widget-down, .move-widget-up").prop("tabIndex",0),this.$sectionContent.find(".customize-control-widget_form:first").addClass("first-widget").find(".move-widget-up").prop("tabIndex",-1),this.$sectionContent.find(".customize-control-widget_form:last").addClass("last-widget").find(".move-widget-down").prop("tabIndex",-1)},toggleReordering:function(a){a=Boolean(a),a!==this.$sectionContent.hasClass("reordering")&&(this.isReordering=a,this.$sectionContent.toggleClass("reordering",a),a&&_(this.getWidgetFormControls()).each(function(a){a.collapseForm()}))},getWidgetFormControls:function(){var a;return a=_(this.setting()).map(function(a){var b=d(a),c=f.control(b);if(c)return c})},addWidget:function(a){var d,e,g,h,i,j,k,l,m,n=this,o="widget_form",p=c(a),q=p.number,r=p.id_base,s=f.Widgets.availableWidgets.findWhere({id_base:r});return s?q&&!s.get("is_multi")?!1:(s.get("is_multi")&&!q&&(s.set("multi_number",s.get("multi_number")+1),q=s.get("multi_number")),d=b.trim(b("#widget-tpl-"+s.get("id")).html()),s.get("is_multi")?d=d.replace(/<[^<>]+>/g,function(a){return a.replace(/__i__|%i%/g,q)}):s.set("is_disabled",!0),e=b(d),g=b("").addClass("customize-control").addClass("customize-control-"+o).append(e),g.find("> .widget-icon").remove(),s.get("is_multi")&&(g.find('input[name="widget_number"]').val(q),g.find('input[name="multi_number"]').val(q)),a=g.find('[name="widget-id"]').val(),g.hide(),i="widget_"+s.get("id_base"),s.get("is_multi")&&(i+="["+q+"]"),g.attr("id","customize-control-"+i.replace(/\]/g,"").replace(/\[/g,"-")),this.container.after(g),j=f.has(i),j||(m={transport:"refresh",previewer:this.setting.previewer},f.create(i,i,{},m)),h=f.controlConstructor[o],k=new h(i,{params:{settings:{"default":i},sidebar_id:n.params.sidebar_id,widget_id:a,widget_id_base:s.get("id_base"),type:o,is_new:!j,width:s.get("width"),height:s.get("height"),is_wide:s.get("is_wide")},previewer:n.setting.previewer}),f.control.add(i,k),f.each(function(b){if(b.id!==n.setting.id&&0===b.id.indexOf("sidebars_widgets[")){var c=b().slice(),d=_.indexOf(c,a);-1!==d&&(c.splice(d),b(c))}}),l=this.setting().slice(),-1===_.indexOf(l,a)&&(l.push(a),this.setting(l)),g.slideDown(function(){j?(k.expandForm(),k.updateWidget({instance:k.setting(),complete:function(a){if(a)throw a;k.focus()}})):k.focus()}),b(document).trigger("widget-added",[e]),k):!1}}),b.extend(f.controlConstructor,{widget_form:f.Widgets.WidgetControl,sidebar_widgets:f.Widgets.SidebarControl}),f.bind("ready",function(){f.Widgets.availableWidgetsPanel=new f.Widgets.AvailableWidgetsPanelView({collection:f.Widgets.availableWidgets}),f.previewer.bind("highlight-widget-control",f.Widgets.highlightWidgetFormControl),f.previewer.bind("focus-widget-control",f.Widgets.focusWidgetFormControl)}),f.Widgets.highlightWidgetFormControl=function(a){var b=f.Widgets.getWidgetFormControlForWidget(a);b&&b.highlightSectionAndControl()},f.Widgets.focusWidgetFormControl=function(a){var b=f.Widgets.getWidgetFormControlForWidget(a);b&&b.focus()},f.Widgets.getSidebarWidgetControlContainingWidget=function(a){var b=null;return f.control.each(function(c){"sidebar_widgets"===c.params.type&&-1!==_.indexOf(c.setting(),a)&&(b=c)}),b},f.Widgets.getWidgetFormControlForWidget=function(a){var b=null;return f.control.each(function(c){"widget_form"===c.params.type&&c.params.widget_id===a&&(b=c)}),b}}}(window.wp,jQuery);
\ No newline at end of file
diff --git a/wp-includes/class-wp-customize-control.php b/wp-includes/class-wp-customize-control.php
index 48c3791611..a1748e74a2 100644
--- a/wp-includes/class-wp-customize-control.php
+++ b/wp-includes/class-wp-customize-control.php
@@ -85,6 +85,19 @@ class WP_Customize_Control {
*/
public $type = 'text';
+ /**
+ * Callback
+ *
+ * @since 4.0.0
+ *
+ * @access public
+ * @see WP_Customize_Control::active()
+ * @var callable Callback is called with one argument, the instance of
+ * WP_Customize_Control, and returns bool to indicate whether
+ * the control is active (such as it relates to the URL
+ * currently being previewed).
+ */
+ public $active_callback = '';
/**
* Constructor.
@@ -102,16 +115,21 @@ class WP_Customize_Control {
public function __construct( $manager, $id, $args = array() ) {
$keys = array_keys( get_object_vars( $this ) );
foreach ( $keys as $key ) {
- if ( isset( $args[ $key ] ) )
+ if ( isset( $args[ $key ] ) ) {
$this->$key = $args[ $key ];
+ }
}
$this->manager = $manager;
$this->id = $id;
+ if ( empty( $this->active_callback ) ) {
+ $this->active_callback = array( $this, 'active_callback' );
+ }
// Process settings.
- if ( empty( $this->settings ) )
+ if ( empty( $this->settings ) ) {
$this->settings = $id;
+ }
$settings = array();
if ( is_array( $this->settings ) ) {
@@ -132,6 +150,41 @@ class WP_Customize_Control {
*/
public function enqueue() {}
+ /**
+ * Check whether control is active to current customizer preview.
+ *
+ * @since 4.0.0
+ *
+ * @return bool
+ */
+ public final function active() {
+ $control = $this;
+ $active = call_user_func( $this->active_callback, $this );
+
+ /**
+ * Filter response of WP_Customize_Control::active().
+ *
+ * @since 4.0.0
+ *
+ * @param bool $active
+ * @param WP_Customize_Control $control
+ */
+ $active = apply_filters( 'customize_control_active', $active, $control );
+
+ return $active;
+ }
+
+ /**
+ * Default callback used when invoking WP_Customize_Control::active().
+ *
+ * Subclasses can override this with their specific logic, or they may
+ * provide an 'active_callback' argument to the constructor.
+ *
+ * @return bool
+ */
+ public function active_callback() {
+ return true;
+ }
/**
* Fetch a setting's value.
@@ -143,8 +196,9 @@ class WP_Customize_Control {
* @return mixed The requested setting's value, if the setting exists.
*/
public final function value( $setting_key = 'default' ) {
- if ( isset( $this->settings[ $setting_key ] ) )
+ if ( isset( $this->settings[ $setting_key ] ) ) {
return $this->settings[ $setting_key ]->value();
+ }
}
/**
@@ -159,6 +213,7 @@ class WP_Customize_Control {
}
$this->json['type'] = $this->type;
+ $this->json['active'] = $this->active();
}
/**
@@ -256,7 +311,7 @@ class WP_Customize_Control {
echo $this->get_link( $setting_key );
}
- /**
+ /**
* Render the custom attributes for the control's input element.
*
* @since 4.0.0
@@ -995,6 +1050,13 @@ class WP_Widget_Area_Customize_Control extends WP_Customize_Control {
manager->widgets->is_sidebar_rendered( $this->sidebar_id );
+ }
}
/**
@@ -1035,5 +1097,12 @@ class WP_Widget_Form_Customize_Control extends WP_Customize_Control {
$args = wp_list_widget_controls_dynamic_sidebar( array( 0 => $args, 1 => $widget['params'][0] ) );
echo $this->manager->widgets->get_widget_control( $args );
}
+
+ /**
+ * @return bool
+ */
+ function active_callback() {
+ return $this->manager->widgets->is_widget_rendered( $this->widget_id );
+ }
}
diff --git a/wp-includes/class-wp-customize-manager.php b/wp-includes/class-wp-customize-manager.php
index bdd79bab66..4929d150ab 100644
--- a/wp-includes/class-wp-customize-manager.php
+++ b/wp-includes/class-wp-customize-manager.php
@@ -475,7 +475,8 @@ final class WP_Customize_Manager {
public function customize_preview_settings() {
$settings = array(
'values' => array(),
- 'channel' => esc_js( $_POST['customize_messenger_channel'] ),
+ 'channel' => wp_unslash( $_POST['customize_messenger_channel'] ),
+ 'activeControls' => array(),
);
if ( 2 == $this->nonce_tick ) {
@@ -488,6 +489,9 @@ final class WP_Customize_Manager {
foreach ( $this->settings as $id => $setting ) {
$settings['values'][ $id ] = $setting->js_value();
}
+ foreach ( $this->controls as $id => $control ) {
+ $settings['activeControls'][ $id ] = $control->active();
+ }
?>