diff --git a/wp-admin/customize.php b/wp-admin/customize.php index 1d795980f7..50ee0ad111 100644 --- a/wp-admin/customize.php +++ b/wp-admin/customize.php @@ -53,8 +53,6 @@ do_action( 'customize_controls_init' ); wp_enqueue_script( 'customize-controls' ); wp_enqueue_style( 'customize-controls' ); -wp_enqueue_script( 'accordion' ); - /** * Enqueue Customizer control scripts. * @@ -130,7 +128,7 @@ do_action( 'customize_controls_print_scripts' ); ?>
"+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(){var a={};return c.each(function(b,c){b._dirty&&(a[c]=b())}),{wp_customize:"on",theme:c.settings.theme.stylesheet,customized:JSON.stringify(a),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():(c.each(function(a){a._dirty=!1}),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,d,e,f,g,h=wp.customize;h.Setting=h.Value.extend({initialize:function(a,b,c){h.Value.prototype.initialize.call(this,b,c),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=function(a,c){b.each(c,function(b,c){a[c].bind(function(b,c){a.parent&&b!==c&&a.parent.trigger("change",a)})})},e=function(a){var b,c,d;b=this,a=a||{},d=function(){b.container.find(":focusable:first").focus(),b.container[0].scrollIntoView(!0)},a.completeCallback?(c=a.completeCallback,a.completeCallback=function(){d(),c()}):a.completeCallback=d,b.expand?b.expand(a):a.completeCallback()},f=function(a){return"keydown"===a.type&&13!==a.which},g=function(a,c){var d=a.length===c.length&&-1===_.map(_.zip(a,c),function(a){return b(a[0]).is(a[1])}).indexOf(!1);return d},d=h.Class.extend({defaultActiveArguments:{duration:"fast"},defaultExpandedArguments:{duration:"fast"},initialize:function(a,d){var e=this;e.id=a,e.params={},b.extend(e,d||{}),e.container=b(e.params.content),e.deferred={ready:new b.Deferred},e.priority=new h.Value,e.active=new h.Value,e.activeArgumentsQueue=[],e.expanded=new h.Value,e.expandedArgumentsQueue=[],e.active.bind(function(a){var c=e.activeArgumentsQueue.shift();c=b.extend({},e.defaultActiveArguments,c),a=a&&e.isContextuallyActive(),e.onChangeActive(a,c)}),e.expanded.bind(function(a){var c=e.expandedArgumentsQueue.shift();c=b.extend({},e.defaultExpandedArguments,c),e.onChangeExpanded(a,c)}),e.attachEvents(),c(e,["priority","active"]),e.priority.set(isNaN(e.params.priority)?100:e.params.priority),e.active.set(e.params.active),e.expanded.set(!1)},ready:function(){},_children:function(a,b){var c=this,d=[];return h[b].each(function(b){b[a].get()===c.id&&d.push(b)}),d.sort(function(a,b){return a.priority()-b.priority()}),d},isContextuallyActive:function(){throw new Error("Must override with subclass.")},onChangeActive:function(a,b){var c="resolved"===h.previewer.deferred.active.state()?b.duration:0;a?this.container.stop(!0,!0).slideDown(c,b.completeCallback):this.container.stop(!0,!0).slideUp(c,b.completeCallback)},_toggleActive:function(a,b){var c=this;return b=b||{},a&&this.active.get()||!a&&!this.active.get()?(b.unchanged=!0,c.onChangeActive(c.active.get(),b),!1):(b.unchanged=!1,this.activeArgumentsQueue.push(b),this.active.set(a),!0)},activate:function(a){return this._toggleActive(!0,a)},deactivate:function(a){return this._toggleActive(!1,a)},onChangeExpanded:function(){throw new Error("Must override with subclass.")},_toggleExpanded:function(a,b){var c=this;return b=b||{},a&&this.expanded.get()||!a&&!this.expanded.get()?(b.unchanged=!0,c.onChangeExpanded(c.expanded.get(),b),!1):(b.unchanged=!1,this.expandedArgumentsQueue.push(b),this.expanded.set(a),!0)},expand:function(a){return this._toggleExpanded(!0,a)},collapse:function(a){return this._toggleExpanded(!1,a)},focus:e}),h.Section=d.extend({initialize:function(a,e){var f=this;d.prototype.initialize.call(f,a,e),f.id=a,f.panel=new h.Value,f.panel.bind(function(a){b(f.container).toggleClass("control-subsection",!!a)}),f.panel.set(f.params.panel||""),c(f,["panel"]),f.embed(),f.deferred.ready.done(function(){f.ready()})},embed:function(){var a,c=this;a=function(a){var d;a?h.panel(a,function(a){a.deferred.ready.done(function(){d=a.container.find("ul:first"),c.container.parent().is(d)||d.append(c.container),c.deferred.ready.resolve()})}):(d=b("#customize-theme-controls").children("ul"),c.container.parent().is(d)||d.append(c.container),c.deferred.ready.resolve())},c.panel.bind(a),a(c.panel.get())},attachEvents:function(){var a=this;a.container.find(".accordion-section-title").on("click keydown",function(b){f(b)||(b.preventDefault(),a.expanded()?a.collapse():a.expand())})},isContextuallyActive:function(){var a=this,b=a.controls(),c=0;return _(b).each(function(a){a.active()&&(c+=1)}),0!==c},controls:function(){return this._children("section","control")},onChangeExpanded:function(a,b){var c,d=this,e=d.container.find(".accordion-section-content");a?(c=b.unchanged?b.completeCallback:function(){e.stop().slideDown(b.duration,b.completeCallback),d.container.addClass("open")},b.allowMultiple||h.section.each(function(a){a!==d&&a.collapse({duration:b.duration})}),d.panel()?h.panel(d.panel()).expand({duration:b.duration,completeCallback:c}):c()):(d.container.removeClass("open"),e.slideUp(b.duration,b.completeCallback))}}),h.Panel=d.extend({initialize:function(a,b){var c=this;d.prototype.initialize.call(c,a,b),c.embed(),c.deferred.ready.done(function(){c.ready()})},embed:function(){var a=this,c=b("#customize-theme-controls > ul");a.container.parent().is(c)||c.append(a.container),a.deferred.ready.resolve()},attachEvents:function(){var a,b=this;b.container.find(".accordion-section-title").on("click keydown",function(a){f(a)||(a.preventDefault(),b.expanded()||b.expand())}),a=b.container.find(".panel-meta:first"),a.find("> .accordion-section-title").on("click keydown",function(c){if(!f(c)&&(c.preventDefault(),!a.hasClass("cannot-expand"))){var d=a.find(".accordion-section-content:first");a.hasClass("open")?(a.toggleClass("open"),d.slideUp(b.defaultExpandedArguments.duration)):(d.slideDown(b.defaultExpandedArguments.duration),a.toggleClass("open"))}})},sections:function(){return this._children("panel","section")},isContextuallyActive:function(){var a=this,b=a.sections(),c=0;return _(b).each(function(a){a.active()&&a.isContextuallyActive()&&(c+=1)}),0!==c},onChangeExpanded:function(a,b){if(b.unchanged)return void(b.completeCallback&&b.completeCallback());var c,d,e=this,f=e.container.closest(".accordion-section"),g=f.closest(".wp-full-overlay"),i=f.closest(".accordion-container"),j=i.find(".open"),k=g.find("#customize-theme-controls > ul > .accordion-section > .accordion-section-title").add("#customize-info > .accordion-section-title"),l=g.find(".control-panel-back"),m=f.find(".accordion-section-title").first(),n=f.find(".control-panel-content");a?(h.section.each(function(a){a.panel()||a.collapse({duration:0})}),h.panel.each(function(a){e!==a&&a.collapse({duration:0})}),n.show(0,function(){c=n.offset().top,d=i.scrollTop(),n.css("margin-top",45-c-d),f.addClass("current-panel"),g.addClass("in-sub-panel"),i.scrollTop(0),b.completeCallback&&b.completeCallback()}),k.attr("tabindex","-1"),l.attr("tabindex","0"),l.focus()):(j.removeClass("open"),f.removeClass("current-panel"),g.removeClass("in-sub-panel"),n.delay(180).hide(0,function(){n.css("margin-top","inherit"),b.completeCallback&&b.completeCallback()}),k.attr("tabindex","0"),l.attr("tabindex","-1"),m.focus(),i.scrollTop(0))}}),h.Control=h.Class.extend({defaultActiveArguments:{duration:"fast"},initialize:function(a,d){var e,f,g,i=this;i.params={},b.extend(i,d||{}),i.id=a,i.selector="#customize-control-"+a.replace(/\]/g,"").replace(/\[/g,"-"),i.templateSelector="customize-control-"+i.params.type+"-content",i.container=b(i.params.content?i.params.content:i.selector),i.deferred={ready:new b.Deferred},i.section=new h.Value,i.priority=new h.Value,i.active=new h.Value,i.activeArgumentsQueue=[],i.elements=[],e=i.container.find("[data-customize-setting-link]"),f={},e.each(function(){var a,c=b(this);if(c.is(":radio")){if(a=c.prop("name"),f[a])return;f[a]=!0,c=e.filter('[name="'+a+'"]')}h(c.data("customizeSettingLink"),function(a){var b=new h.Element(c);i.elements.push(b),b.sync(a),b.set(a())})}),i.active.bind(function(a){var c=i.activeArgumentsQueue.shift();c=b.extend({},i.defaultActiveArguments,c),i.onChangeActive(a,c)}),i.section.set(i.params.section),i.priority.set(isNaN(i.params.priority)?10:i.params.priority),i.active.set(i.params.active),c(i,["section","priority","active"]),g=b.map(i.params.settings,function(a){return a}),h.apply(h,g.concat(function(){var a;i.settings={};for(a in i.params.settings)i.settings[a]=h(i.params.settings[a]);i.setting=i.settings["default"]||null,i.embed()})),i.deferred.ready.done(function(){i.ready()})},embed:function(){var a,b=this;a=function(a){var c;a&&h.section(a,function(a){a.deferred.ready.done(function(){c=a.container.find("ul:first"),b.container.parent().is(c)||(c.append(b.container),b.renderContent()),b.deferred.ready.resolve()})})},b.section.bind(a),a(b.section.get())},ready:function(){},expand:function(a){h.section(this.section()).expand(a)},focus:e,onChangeActive:function(a,b){a?this.container.slideDown(b.duration,b.completeCallback):this.container.slideUp(b.duration,b.completeCallback)},toggle:function(a){return this.onChangeActive(a,this.defaultActiveArguments)},activate:d.prototype.activate,deactivate:d.prototype.deactivate,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){f(b)||(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())},renderContent:function(){var a,c=this;0!==b("#tmpl-"+c.templateSelector).length&&(a=wp.template(c.templateSelector),a&&c.container&&c.container.append(a(c.params)))}}),h.ColorControl=h.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)}})}}),h.UploadControl=h.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:h.l10n.allowedFiles,extensions:a.params.extensions}]),a.params.context&&(a.uploader.params["post_data[context]"]=this.params.context),h.settings.theme.stylesheet&&(a.uploader.params["post_data[theme]"]=h.settings.theme.stylesheet),this.uploader=new wp.Uploader(this.uploader),this.remover=this.container.find(".remove"),this.remover.on("click keydown",function(b){f(b)||(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)}}),h.ImageControl=h.UploadControl.extend({ready:function(){var a,c=this;this.uploader={init:function(){var a,b;this.supports.dragdrop||(a=c.container.find(".upload-fallback"),b=a.children().detach(),this.browser.detach().empty().append(b),a.append(this.browser).show())}},h.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 d=b(this),e=d.data("customizeTab"),f=a.filter('[data-customize-tab="'+e+'"]');c.tabs[e]={both:d.add(f),link:d,panel:f}}),this.library.children("ul").on("click keydown","li",function(a){if(!f(a)){var d=b(this).data("customizeTab"),e=c.tabs[d];a.preventDefault(),e.link.hasClass("library-selected")||(c.selected.both.removeClass("library-selected"),c.selected=e,c.selected.both.addClass("library-selected"))}}),this.library.on("click keydown","a",function(a){if(!f(a)){var d=b(this).data("customizeImageValue");d&&(c.setting.set(d),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=c.tabs[b(this).data("customizeTab")];return a.link.hasClass("hidden")?void 0:(c.selected=a,a.both.addClass("library-selected"),!1)}),this.dropdownInit()},success:function(a){h.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('"+h.l10n.cheatin+"
")}}),h.controlConstructor={color:h.ColorControl,upload:h.UploadControl,image:h.ImageControl,header:h.HeaderControl},h.panelConstructor={},h.sectionConstructor={},b(function(){if(h.settings=window._wpCustomizeSettings,h.l10n=window._wpCustomizeControlsL10n,h.settings){if(!b.support.postMessage||!b.support.cors&&h.settings.isCrossDomain)return window.location=h.settings.url.fallback;var a,c,d=b(document.body),e=d.children(".wp-full-overlay"),i=b("#customize-info .theme-name.site-title"),j=b(".customize-controls-close"),k=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()}),b("#customize-info").find("> .accordion-section-title").on("click keydown",function(a){if(!f(a)){a.preventDefault();var c=b(this).parent(),d=c.find(".accordion-section-content:first");c.hasClass("cannot-expand")||(c.hasClass("open")?(c.toggleClass("open"),d.slideUp(h.Panel.prototype.defaultExpandedArguments.duration)):(d.slideDown(h.Panel.prototype.defaultExpandedArguments.duration),c.toggleClass("open")))}}),h.previewer=new h.Previewer({container:"#customize-preview",form:"#customize-controls",previewUrl:h.settings.url.preview,allowedUrls:h.settings.url.allowed,signature:"WP_CUSTOMIZER_SIGNATURE"},{nonce:h.settings.nonce,query:function(){var a={};return h.each(function(b,c){b._dirty&&(a[c]=b())}),{wp_customize:"on",theme:h.settings.theme.stylesheet,customized:JSON.stringify(a),nonce:this.nonce.preview}},save:function(){var a,c,e=this,f=b.extend(this.query(),{action:"customize_save",nonce:this.nonce.save}),g=h.state("processing");d.addClass("saving"),c=function(){var a=b.post(h.settings.url.ajax,f);h.trigger("save",a),a.always(function(){d.removeClass("saving")}),a.done(function(a){return"0"===a?(e.preview.iframe.hide(),void e.login().done(function(){e.save(),e.preview.iframe.show()})):"-1"===a?void e.cheatin():(h.each(function(a){a._dirty=!1}),void h.trigger("saved"))})},0===g()?c():(a=function(){0===g()&&(h.state.unbind("change",a),c())},h.state.bind("change",a))}}),h.previewer.bind("nonce",function(a){b.extend(this.nonce,a)}),b.each(h.settings.settings,function(a,b){h.create(a,a,b.value,{transport:b.transport,previewer:h.previewer})}),b.each(h.settings.panels,function(a,b){var c,d=h.panelConstructor[b.type]||h.Panel;c=new d(a,{params:b}),h.panel.add(a,c)}),b.each(h.settings.sections,function(a,b){var c,d=h.sectionConstructor[b.type]||h.Section;c=new d(a,{params:b}),h.section.add(a,c)}),b.each(h.settings.controls,function(a,b){var c,d=h.controlConstructor[b.type]||h.Control;c=new d(a,{params:b,previewer:h.previewer}),h.control.add(a,c)}),_.each(["panel","section","control"],function(a){var b,c=h.settings.autofocus[a];c&&h[a](c)&&(b=h[a](c),b.deferred.ready.done(function(){h.previewer.deferred.active.done(function(){b.focus()})}))}),h.reflowPaneContents=_.bind(function(){var a,c,d,e=[],f=!1;document.activeElement&&(c=b(document.activeElement)),h.panel.each(function(b){var c=b.sections(),d=_.pluck(c,"container");e.push(b),a=b.container.find("ul:first"),g(d,a.children("[id]"))||(_(c).each(function(b){a.append(b.container)}),f=!0)}),h.section.each(function(b){var c=b.controls(),d=_.pluck(c,"container");b.panel()||e.push(b),a=b.container.find("ul:first"),g(d,a.children("[id]"))||(_(c).each(function(b){a.append(b.container)}),f=!0)}),e.sort(function(a,b){return a.priority()-b.priority()}),d=_.pluck(e,"container"),a=b("#customize-theme-controls").children("ul"),g(d,a.children())||(_(e).each(function(b){a.append(b.container)}),f=!0),h.panel.each(function(a){var b=a.active();a.active.callbacks.fireWith(a.active,[b,b])}),h.section.each(function(a){var b=a.active();a.active.callbacks.fireWith(a.active,[b,b])}),f&&c&&c.focus()},h),h.bind("ready",h.reflowPaneContents),h.reflowPaneContents=_.debounce(h.reflowPaneContents,100),b([h.panel,h.section,h.control]).each(function(a,b){b.bind("add",h.reflowPaneContents),b.bind("change",h.reflowPaneContents),b.bind("remove",h.reflowPaneContents)}),h.previewer.previewUrl()?h.previewer.refresh():h.previewer.previewUrl(h.settings.url.home),function(){var a=new h.Values,b=a.create("saved"),c=a.create("activated"),d=a.create("processing");a.bind("change",function(){c()?b()?(k.val(h.l10n.saved).prop("disabled",!0),j.find(".screen-reader-text").text(h.l10n.close)):(k.val(h.l10n.save).prop("disabled",!1),j.find(".screen-reader-text").text(h.l10n.cancel)):(k.val(h.l10n.activate).prop("disabled",!1),j.find(".screen-reader-text").text(h.l10n.cancel))}),b(!0),c(h.settings.theme.active),d(0),h.bind("change",function(){a("saved").set(!1)}),h.bind("saved",function(){a("saved").set(!0),a("activated").set(!0)}),c.bind(function(a){a&&h.trigger("activated")}),h.state=a}(),k.click(function(a){h.previewer.save(),a.preventDefault()}).keydown(function(a){9!==a.which&&(13===a.which&&h.previewer.save(),a.preventDefault())}),b("#customize-header-actions").on("click keydown",".control-panel-back",function(a){f(a)||(a.preventDefault(),h.panel.each(function(a){a.collapse()}))}),j.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){f(a)||(e.toggleClass("collapsed").toggleClass("expanded"),a.preventDefault())}),i.length&&b("#customize-control-blogname input").on("input",function(){i.text(this.value)}),a=new h.Messenger({url:h.settings.url.parent,channel:"loader"}),a.bind("back",function(){j.on("click.customize-controls-close",function(b){b.preventDefault(),a.send("close")})}),b(window).on("beforeunload",function(){return h.state("saved")()?void 0:h.l10n.saveAlert}),b.each(["saved","change"],function(b,c){h.bind(c,function(){a.send(c)})}),h.bind("activated",function(){a.targetWindow()?a.send("activated",h.settings.url.activated):h.settings.url.activated&&(window.location=h.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,c){h(a,function(a){b.each(c.controls,function(b,d){h.control(d,function(b){var d=function(a){b.container.toggle(c.callback(a))};d(a.get()),a.bind(d)})})})}),h.control("display_header_text",function(a){var b="";a.elements[0].unsync(h("header_textcolor")),a.element=new h.Element(a.container.find("input")),a.element.set("blank"!==a.setting()),a.element.bind(function(c){c||(b=h("header_textcolor").get()),a.setting.set(c?b:"blank")}),a.setting.bind(function(b){a.element.set("blank"!==b)})}),h.trigger("ready"),c=j,c.focus(),setTimeout(function(){c.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 6be9a0807a..8112f3e093 100644 --- a/wp-admin/js/customize-widgets.js +++ b/wp-admin/js/customize-widgets.js @@ -404,6 +404,23 @@ * @augments wp.customize.Control */ api.Widgets.WidgetControl = api.Control.extend({ + defaultExpandedArguments: { + duration: 'fast' + }, + + initialize: function ( id, options ) { + var control = this; + api.Control.prototype.initialize.call( control, id, options ); + control.expanded = new api.Value(); + control.expandedArgumentsQueue = []; + control.expanded.bind( function ( expanded ) { + var args = control.expandedArgumentsQueue.shift(); + args = $.extend( {}, control.defaultExpandedArguments, args ); + control.onChangeExpanded( expanded, args ); + }); + control.expanded.set( false ); + }, + /** * Set up the control */ @@ -529,13 +546,13 @@ if ( sidebarWidgetsControl.isReordering ) { return; } - self.toggleForm(); + self.expanded( ! self.expanded() ); } ); $closeBtn = this.container.find( '.widget-control-close' ); $closeBtn.on( 'click', function( e ) { e.preventDefault(); - self.collapseForm(); + self.collapse(); self.container.find( '.widget-top .widget-action:first' ).focus(); // keyboard accessibility } ); }, @@ -777,9 +794,14 @@ * Overrides api.Control.toggle() * * @param {Boolean} active + * @param {Object} args */ - toggle: function ( active ) { + onChangeActive: function ( active, args ) { + // Note: there is a second 'args' parameter being passed, merged on top of this.defaultActiveArguments this.container.toggleClass( 'widget-rendered', active ); + if ( args.completeCallback ) { + args.completeCallback(); + } }, /** @@ -1101,51 +1123,90 @@ * Expand the accordion section containing a control */ expandControlSection: function() { - var $section = this.container.closest( '.accordion-section' ); - - if ( ! $section.hasClass( 'open' ) ) { - $section.find( '.accordion-section-title:first' ).trigger( 'click' ); - } + api.Control.prototype.expand.call( this ); }, + /** + * @param {Boolean} expanded + * @param {Object} [params] + * @returns {Boolean} false if state already applied + */ + _toggleExpanded: api.Section.prototype._toggleExpanded, + + /** + * @param {Object} [params] + * @returns {Boolean} false if already expanded + */ + expand: api.Section.prototype.expand, + /** * Expand the widget form control + * + * @deprecated alias of expand() */ expandForm: function() { - this.toggleForm( true ); + this.expand(); }, + /** + * @param {Object} [params] + * @returns {Boolean} false if already collapsed + */ + collapse: api.Section.prototype.collapse, + /** * Collapse the widget form control + * + * @deprecated alias of expand() */ collapseForm: function() { - this.toggleForm( false ); + this.collapse(); }, /** * Expand or collapse the widget control * + * @deprecated this is poor naming, and it is better to directly set control.expanded( showOrHide ) + * * @param {boolean|undefined} [showOrHide] If not supplied, will be inverse of current visibility */ toggleForm: function( showOrHide ) { - var self = this, $widget, $inside, complete; - - $widget = this.container.find( 'div.widget:first' ); - $inside = $widget.find( '.widget-inside:first' ); if ( typeof showOrHide === 'undefined' ) { - showOrHide = ! $inside.is( ':visible' ); + showOrHide = ! this.expanded(); } + this.expanded( showOrHide ); + }, - // Already expanded or collapsed, so noop - if ( $inside.is( ':visible' ) === showOrHide ) { + /** + * Respond to change in the expanded state. + * + * @param {Boolean} expanded + * @param {Object} args merged on top of this.defaultActiveArguments + */ + onChangeExpanded: function ( expanded, args ) { + var self = this, $widget, $inside, complete, prevComplete; + + // If the expanded state is unchanged only manipulate container expanded states + if ( args.unchanged ) { + if ( expanded ) { + api.Control.prototype.expand.call( self, { + completeCallback: args.completeCallback + }); + } return; } - if ( showOrHide ) { + $widget = this.container.find( 'div.widget:first' ); + $inside = $widget.find( '.widget-inside:first' ); + + if ( expanded ) { + + self.expandControlSection(); + // Close all other widget controls before expanding this one api.control.each( function( otherControl ) { if ( self.params.type === otherControl.params.type && self !== otherControl ) { - otherControl.collapseForm(); + otherControl.collapse(); } } ); @@ -1154,29 +1215,44 @@ self.container.addClass( 'expanded' ); self.container.trigger( 'expanded' ); }; + if ( args.completeCallback ) { + prevComplete = complete; + complete = function () { + prevComplete(); + args.completeCallback(); + }; + } if ( self.params.is_wide ) { - $inside.fadeIn( 'fast', complete ); + $inside.fadeIn( args.duration, complete ); } else { - $inside.slideDown( 'fast', complete ); + $inside.slideDown( args.duration, complete ); } self.container.trigger( 'expand' ); self.container.addClass( 'expanding' ); } else { + complete = function() { self.container.removeClass( 'collapsing' ); self.container.removeClass( 'expanded' ); self.container.trigger( 'collapsed' ); }; + if ( args.completeCallback ) { + prevComplete = complete; + complete = function () { + prevComplete(); + args.completeCallback(); + }; + } self.container.trigger( 'collapse' ); self.container.addClass( 'collapsing' ); if ( self.params.is_wide ) { - $inside.fadeOut( 'fast', complete ); + $inside.fadeOut( args.duration, complete ); } else { - $inside.slideUp( 'fast', function() { + $inside.slideUp( args.duration, function() { $widget.css( { width:'', margin:'' } ); complete(); } ); @@ -1184,16 +1260,6 @@ } }, - /** - * Expand the containing sidebar section, expand the form, and focus on - * the first input in the control - */ - focus: function() { - this.expandControlSection(); - this.expandForm(); - this.container.find( '.widget-content :focusable:first' ).focus(); - }, - /** * Get the position (index) of the widget in the containing sidebar * @@ -1304,6 +1370,7 @@ * @augments wp.customize.Control */ api.Widgets.SidebarControl = api.Control.extend({ + /** * Set up the control */ @@ -1325,7 +1392,7 @@ registeredSidebar = api.Widgets.registeredSidebars.get( this.params.sidebar_id ); this.setting.bind( function( newWidgetIds, oldWidgetIds ) { - var widgetFormControls, $sidebarWidgetsAddControl, finalControlContainers, removedWidgetIds; + var widgetFormControls, removedWidgetIds, priority; removedWidgetIds = _( oldWidgetIds ).difference( newWidgetIds ); @@ -1350,21 +1417,16 @@ widgetFormControls.sort( function( a, b ) { var aIndex = _.indexOf( newWidgetIds, a.params.widget_id ), bIndex = _.indexOf( newWidgetIds, b.params.widget_id ); + return aIndex - bIndex; + }); - if ( aIndex === bIndex ) { - return 0; - } - - return aIndex < bIndex ? -1 : 1; - } ); - - // Append the controls to put them in the right order - finalControlContainers = _( widgetFormControls ).map( function( widgetFormControls ) { - return widgetFormControls.container[0]; - } ); - - $sidebarWidgetsAddControl = self.$sectionContent.find( '.customize-control-sidebar_widgets' ); - $sidebarWidgetsAddControl.before( finalControlContainers ); + priority = 0; + _( widgetFormControls ).each( function ( control ) { + control.priority( priority ); + control.section( self.section() ); + priority += 1; + }); + self.priority( priority ); // Make sure sidebar control remains at end // Re-sort widget form controls (including widgets form other sidebars newly moved here) self._applyCardinalOrderClassNames(); @@ -1434,36 +1496,9 @@ // Update the model with whether or not the sidebar is rendered self.active.bind( function ( active ) { registeredSidebar.set( 'is_rendered', active ); + api.section( self.section.get() ).active( active ); } ); - }, - - /** - * Show the sidebar section when it becomes visible. - * - * Overrides api.Control.toggle() - * - * @param {Boolean} active - */ - toggle: function ( active ) { - var $section, sectionSelector; - - sectionSelector = '#accordion-section-sidebar-widgets-' + this.params.sidebar_id; - $section = $( sectionSelector ); - - if ( active ) { - $section.stop().slideDown( function() { - $( this ).css( 'height', 'auto' ); // so that the .accordion-section-content won't overflow - } ); - - } 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(); - } + api.section( self.section.get() ).active( self.active() ); }, /** @@ -1500,12 +1535,18 @@ this.$controlSection.find( '.accordion-section-title' ).droppable({ accept: '.customize-control-widget_form', over: function() { - if ( ! self.$controlSection.hasClass( 'open' ) ) { - self.$controlSection.addClass( 'open' ); - self.$sectionContent.toggle( false ).slideToggle( 150, function() { - self.$sectionContent.sortable( 'refreshPositions' ); - } ); - } + var section = api.section( self.section.get() ); + section.expand({ + allowMultiple: true, // Prevent the section being dragged from to be collapsed + completeCallback: function () { + // @todo It is not clear when refreshPositions should be called on which sections, or if it is even needed + api.section.each( function ( otherSection ) { + if ( otherSection.container.find( '.customize-control-sidebar_widgets' ).length ) { + otherSection.container.find( '.accordion-section-content:first' ).sortable( 'refreshPositions' ); + } + } ); + } + }); } }); @@ -1548,16 +1589,30 @@ * Add classes to the widget_form controls to assist with styling */ _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 ); + var widgetControls = []; + _.each( this.setting(), function ( widgetId ) { + var widgetControl = api.Widgets.getWidgetFormControlForWidget( widgetId ); + if ( widgetControl ) { + widgetControls.push( widgetControl ); + } + }); - this.$sectionContent.find( '.customize-control-widget_form:first' ) + if ( ! widgetControls.length ) { + return; + } + + $( widgetControls ).each( function () { + $( this.container ) + .removeClass( 'first-widget' ) + .removeClass( 'last-widget' ) + .find( '.move-widget-down, .move-widget-up' ).prop( 'tabIndex', 0 ); + }); + + _.first( widgetControls ).container .addClass( 'first-widget' ) .find( '.move-widget-up' ).prop( 'tabIndex', -1 ); - this.$sectionContent.find( '.customize-control-widget_form:last' ) + _.last( widgetControls ).container .addClass( 'last-widget' ) .find( '.move-widget-down' ).prop( 'tabIndex', -1 ); }, @@ -1571,6 +1626,8 @@ * Enable/disable the reordering UI * * @param {Boolean} showOrHide to enable/disable reordering + * + * @todo We should have a reordering state instead and rename this to onChangeReordering */ toggleReordering: function( showOrHide ) { showOrHide = Boolean( showOrHide ); @@ -1584,7 +1641,7 @@ if ( showOrHide ) { _( this.getWidgetFormControls() ).each( function( formControl ) { - formControl.collapseForm(); + formControl.collapse(); } ); this.$sectionContent.find( '.first-widget .move-widget' ).focus(); @@ -1619,7 +1676,7 @@ * @returns {object|false} widget_form control instance, or false on error */ addWidget: function( widgetId ) { - var self = this, controlHtml, $widget, controlType = 'widget_form', $control, controlConstructor, + var self = this, controlHtml, $widget, controlType = 'widget_form', controlContainer, controlConstructor, parsedWidgetId = parseWidgetId( widgetId ), widgetNumber = parsedWidgetId.number, widgetIdBase = parsedWidgetId.id_base, @@ -1651,30 +1708,28 @@ $widget = $( controlHtml ); - $control = $( '' ) + controlContainer = $( '' ) .addClass( 'customize-control' ) .addClass( 'customize-control-' + controlType ) .append( $widget ); // Remove icon which is visible inside the panel - $control.find( '> .widget-icon' ).remove(); + controlContainer.find( '> .widget-icon' ).remove(); if ( widget.get( 'is_multi' ) ) { - $control.find( 'input[name="widget_number"]' ).val( widgetNumber ); - $control.find( 'input[name="multi_number"]' ).val( widgetNumber ); + controlContainer.find( 'input[name="widget_number"]' ).val( widgetNumber ); + controlContainer.find( 'input[name="multi_number"]' ).val( widgetNumber ); } - widgetId = $control.find( '[name="widget-id"]' ).val(); + widgetId = controlContainer.find( '[name="widget-id"]' ).val(); - $control.hide(); // to be slid-down below + controlContainer.hide(); // to be slid-down below settingId = 'widget_' + widget.get( 'id_base' ); if ( widget.get( 'is_multi' ) ) { settingId += '[' + widgetNumber + ']'; } - $control.attr( 'id', 'customize-control-' + settingId.replace( /\]/g, '' ).replace( /\[/g, '-' ) ); - - this.container.after( $control ); + controlContainer.attr( 'id', 'customize-control-' + settingId.replace( /\]/g, '' ).replace( /\[/g, '-' ) ); // Only create setting if it doesn't already exist (if we're adding a pre-existing inactive widget) isExistingWidget = api.has( settingId ); @@ -1692,6 +1747,7 @@ settings: { 'default': settingId }, + content: controlContainer, sidebar_id: self.params.sidebar_id, widget_id: widgetId, widget_id_base: widget.get( 'id_base' ), @@ -1731,9 +1787,9 @@ this.setting( sidebarWidgets ); } - $control.slideDown( function() { + controlContainer.slideDown( function() { if ( isExistingWidget ) { - widgetFormControl.expandForm(); + widgetFormControl.expand(); widgetFormControl.updateWidget( { instance: widgetFormControl.setting(), complete: function( error ) { diff --git a/wp-admin/js/customize-widgets.min.js b/wp-admin/js/customize-widgets.min.js index ea5e8a4ecb..166cdc9610 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=9===a.which,h=a.shiftKey,i=null,j=this.$el.find("> .widget-tpl:visible:first"),k=this.$el.find("> .widget-tpl:visible:last"),l=b(a.target).is(this.$search),m=b(a.target).is(".widget-tpl:visible:last");return e||f?(e?l?i=j:this.selected&&0!==this.selected.nextAll(".widget-tpl:visible").length&&(i=this.selected.nextAll(".widget-tpl:visible:first")):f&&(l?i=k:this.selected&&0!==this.selected.prevAll(".widget-tpl:visible").length&&(i=this.selected.prevAll(".widget-tpl:visible:first"))),this.select(i),void(i?i.focus():this.$search.focus())):void((!c||this.$search.val())&&(c?this.submit():d&&this.close({returnFocus:!0}),g&&(h&&l||!h&&m)&&(this.currentSidebarControl.container.find(".add-new-widget").focus(),a.preventDefault())))}}),f.Widgets.formSyncHandlers={rss:function(a,c,d){var e=c.find(".widget-error:first"),f=b("'+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()}),this.$sectionContent.find(".first-widget .move-widget").focus(),this.$sectionContent.find(".add-new-widget").prop("tabIndex",-1)):this.$sectionContent.find(".add-new-widget").prop("tabIndex",0))},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=9===a.which,h=a.shiftKey,i=null,j=this.$el.find("> .widget-tpl:visible:first"),k=this.$el.find("> .widget-tpl:visible:last"),l=b(a.target).is(this.$search),m=b(a.target).is(".widget-tpl:visible:last");return e||f?(e?l?i=j:this.selected&&0!==this.selected.nextAll(".widget-tpl:visible").length&&(i=this.selected.nextAll(".widget-tpl:visible:first")):f&&(l?i=k:this.selected&&0!==this.selected.prevAll(".widget-tpl:visible").length&&(i=this.selected.prevAll(".widget-tpl:visible:first"))),this.select(i),void(i?i.focus():this.$search.focus())):void((!c||this.$search.val())&&(c?this.submit():d&&this.close({returnFocus:!0}),g&&(h&&l||!h&&m)&&(this.currentSidebarControl.container.find(".add-new-widget").focus(),a.preventDefault())))}}),f.Widgets.formSyncHandlers={rss:function(a,c,d){var e=c.find(".widget-error:first"),f=b("'+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(){f.Control.prototype.expand.call(this)},_toggleExpanded:f.Section.prototype._toggleExpanded,expand:f.Section.prototype.expand,expandForm:function(){this.expand()},collapse:f.Section.prototype.collapse,collapseForm:function(){this.collapse()},toggleForm:function(a){"undefined"==typeof a&&(a=!this.expanded()),this.expanded(a)},onChangeExpanded:function(a,b){var c,d,e,g,h=this;return b.unchanged?void(a&&f.Control.prototype.expand.call(h,{completeCallback:b.completeCallback})):(c=this.container.find("div.widget:first"),d=c.find(".widget-inside:first"),void(a?(h.expandControlSection(),f.control.each(function(a){h.params.type===a.params.type&&h!==a&&a.collapse()}),e=function(){h.container.removeClass("expanding"),h.container.addClass("expanded"),h.container.trigger("expanded")},b.completeCallback&&(g=e,e=function(){g(),b.completeCallback()}),h.params.is_wide?d.fadeIn(b.duration,e):d.slideDown(b.duration,e),h.container.trigger("expand"),h.container.addClass("expanding")):(e=function(){h.container.removeClass("collapsing"),h.container.removeClass("expanded"),h.container.trigger("collapsed")},b.completeCallback&&(g=e,e=function(){g(),b.completeCallback()}),h.container.trigger("collapse"),h.container.addClass("collapsing"),h.params.is_wide?d.fadeOut(b.duration,e):d.slideUp(b.duration,function(){c.css({width:"",margin:""}),e()}))))},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;h=_(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}),i=0,_(g).each(function(b){b.priority(i),b.section(a.section()),i+=1}),a.priority(i),a._applyCardinalOrderClassNames(),_(g).each(function(b){b.params.sidebar_id=a.params.sidebar_id}),_(h).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(b){d.set("is_rendered",b),f.section(a.section.get()).active(b)}),f.section(a.section.get()).active(a.active())},_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(){var b=f.section(a.section.get());b.expand({allowMultiple:!0,completeCallback:function(){f.section.each(function(a){a.container.find(".customize-control-sidebar_widgets").length&&a.container.find(".accordion-section-content:first").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(){var a=[];_.each(this.setting(),function(b){var c=f.Widgets.getWidgetFormControlForWidget(b);c&&a.push(c)}),a.length&&(b(a).each(function(){b(this.container).removeClass("first-widget").removeClass("last-widget").find(".move-widget-down, .move-widget-up").prop("tabIndex",0)}),_.first(a).container.addClass("first-widget").find(".move-widget-up").prop("tabIndex",-1),_.last(a).container.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.collapse()}),this.$sectionContent.find(".first-widget .move-widget").focus(),this.$sectionContent.find(".add-new-widget").prop("tabIndex",-1)):this.$sectionContent.find(".add-new-widget").prop("tabIndex",0))},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,"-")),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},content:g,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.expand(),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 a790b71115..dcebb0f8a2 100644 --- a/wp-includes/class-wp-customize-control.php +++ b/wp-includes/class-wp-customize-control.php @@ -74,6 +74,7 @@ class WP_Customize_Control { public $input_attrs = array(); /** + * @deprecated It is better to just call the json() method * @access public * @var array */ @@ -218,9 +219,24 @@ class WP_Customize_Control { } $this->json['type'] = $this->type; + $this->json['priority'] = $this->priority; + $this->json['active'] = $this->active(); + $this->json['section'] = $this->section; + $this->json['content'] = $this->get_content(); $this->json['label'] = $this->label; $this->json['description'] = $this->description; - $this->json['active'] = $this->active(); + } + + /** + * Get the data to export to the client via JSON. + * + * @since 4.1.0 + * + * @return array + */ + public function json() { + $this->to_json(); + return $this->json; } /** @@ -243,6 +259,21 @@ class WP_Customize_Control { return true; } + /** + * Get the control's content for insertion into the Customizer pane. + * + * @since 4.1.0 + * + * @return string + */ + public final function get_content() { + ob_start(); + $this->maybe_render(); + $template = trim( ob_get_contents() ); + ob_end_clean(); + return $template; + } + /** * Check capabilities and render the control. * @@ -1073,6 +1104,7 @@ class WP_Customize_Header_Image_Control extends WP_Customize_Image_Control { /** * Widget Area Customize Control Class * + * @since 3.9.0 */ class WP_Widget_Area_Customize_Control extends WP_Customize_Control { public $type = 'sidebar_widgets'; @@ -1114,6 +1146,8 @@ class WP_Widget_Area_Customize_Control extends WP_Customize_Control { /** * Widget Form Customize Control Class + * + * @since 3.9.0 */ class WP_Widget_Form_Customize_Control extends WP_Customize_Control { public $type = 'widget_form'; diff --git a/wp-includes/class-wp-customize-manager.php b/wp-includes/class-wp-customize-manager.php index bcbf127888..4d4e73eda1 100644 --- a/wp-includes/class-wp-customize-manager.php +++ b/wp-includes/class-wp-customize-manager.php @@ -498,6 +498,8 @@ final class WP_Customize_Manager { $settings = array( 'values' => array(), 'channel' => wp_unslash( $_POST['customize_messenger_channel'] ), + 'activePanels' => array(), + 'activeSections' => array(), 'activeControls' => array(), ); @@ -511,6 +513,12 @@ final class WP_Customize_Manager { foreach ( $this->settings as $id => $setting ) { $settings['values'][ $id ] = $setting->js_value(); } + foreach ( $this->panels as $id => $panel ) { + $settings['activePanels'][ $id ] = $panel->active(); + } + foreach ( $this->sections as $id => $section ) { + $settings['activeSections'][ $id ] = $section->active(); + } foreach ( $this->controls as $id => $control ) { $settings['activeControls'][ $id ] = $control->active(); } @@ -911,11 +919,11 @@ final class WP_Customize_Manager { if ( ! $section->panel ) { // Top-level section. - $sections[] = $section; + $sections[ $section->id ] = $section; } else { // This section belongs to a panel. if ( isset( $this->panels [ $section->panel ] ) ) { - $this->panels[ $section->panel ]->sections[] = $section; + $this->panels[ $section->panel ]->sections[ $section->id ] = $section; } } } @@ -932,8 +940,8 @@ final class WP_Customize_Manager { continue; } - usort( $panel->sections, array( $this, '_cmp_priority' ) ); - $panels[] = $panel; + uasort( $panel->sections, array( $this, '_cmp_priority' ) ); + $panels[ $panel->id ] = $panel; } $this->panels = $panels; diff --git a/wp-includes/class-wp-customize-panel.php b/wp-includes/class-wp-customize-panel.php index f289cb7ff0..201c4b914f 100644 --- a/wp-includes/class-wp-customize-panel.php +++ b/wp-includes/class-wp-customize-panel.php @@ -82,6 +82,28 @@ class WP_Customize_Panel { */ public $sections; + /** + * @since 4.1.0 + * @access public + * @var string + */ + public $type; + + /** + * Callback. + * + * @since 4.1.0 + * @access public + * + * @see WP_Customize_Section::active() + * + * @var callable Callback is called with one argument, the instance of + * WP_Customize_Section, and returns bool to indicate whether + * the section is active (such as it relates to the URL + * currently being previewed). + */ + public $active_callback = ''; + /** * Constructor. * @@ -103,12 +125,69 @@ class WP_Customize_Panel { $this->manager = $manager; $this->id = $id; + if ( empty( $this->active_callback ) ) { + $this->active_callback = array( $this, 'active_callback' ); + } $this->sections = array(); // Users cannot customize the $sections array. return $this; } + /** + * Check whether panel is active to current Customizer preview. + * + * @since 4.1.0 + * @access public + * + * @return bool Whether the panel is active to the current preview. + */ + public final function active() { + $panel = $this; + $active = call_user_func( $this->active_callback, $this ); + + /** + * Filter response of WP_Customize_Panel::active(). + * + * @since 4.1.0 + * + * @param bool $active Whether the Customizer panel is active. + * @param WP_Customize_Panel $panel WP_Customize_Panel instance. + */ + $active = apply_filters( 'customize_panel_active', $active, $panel ); + + return $active; + } + + /** + * Default callback used when invoking WP_Customize_Panel::active(). + * + * Subclasses can override this with their specific logic, or they may + * provide an 'active_callback' argument to the constructor. + * + * @since 4.1.0 + * @access public + * + * @return bool Always true. + */ + public function active_callback() { + return true; + } + + /** + * Gather the parameters passed to client JavaScript via JSON. + * + * @since 4.1.0 + * + * @return array The array to be exported to the client as JSON + */ + public function json() { + $array = wp_array_slice_assoc( (array) $this, array( 'title', 'description', 'priority', 'type' ) ); + $array['content'] = $this->get_content(); + $array['active'] = $this->active(); + return $array; + } + /** * Checks required user capabilities and whether the theme has the * feature support required by the panel. @@ -129,6 +208,21 @@ class WP_Customize_Panel { return true; } + /** + * Get the panel's content template for insertion into the Customizer pane. + * + * @since 4.1.0 + * + * @return string + */ + public final function get_content() { + ob_start(); + $this->maybe_render(); + $template = trim( ob_get_contents() ); + ob_end_clean(); + return $template; + } + /** * Check capabilities and render the panel. * @@ -189,7 +283,7 @@ class WP_Customize_Panel { */ protected function render_content() { ?> -description; ?>
description; ?>
+