2014-03-18 11:21:15 -04:00
|
|
|
var WidgetCustomizer=function(a){"use strict";function b(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 c(a){var c,d=b(a);return c="widget_"+d.id_base,d.number&&(c+="["+d.number+"]"),c}var d,e,f,g,h,i=wp.customize,j={update_widget_ajax_action:null,update_widget_nonce_value:null,update_widget_nonce_post_key:null,i18n:{save_btn_label:"",save_btn_tooltip:"",remove_btn_label:"",remove_btn_tooltip:""},available_widgets:[],registered_widgets:[],active_sidebar_control:null,previewer:null,saved_widget_ids:{},registered_sidebars:[],tpl:{move_widget_area:"",widget_reorder_nav:""}};return a.extend(j,WidgetCustomizer_exports),"undefined"==typeof window.ajaxurl&&(window.ajaxurl=wp.ajax.settings.url),a("#customize-theme-controls").closest("div:not([id])").attr("id","widgets-right"),d=j.Widget=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}),e=j.WidgetCollection=Backbone.Collection.extend({model:d}),j.available_widgets=new e(j.available_widgets),f=j.Sidebar=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}),g=j.SidebarCollection=Backbone.Collection.extend({model:f}),j.registered_sidebars=new g(j.registered_sidebars),j.init=function(){this.showFirstSidebarIfRequested(),this.availableWidgetsPanel.setup()},wp.customize.bind("ready",function(){j.init()}),j.showFirstSidebarIfRequested=function(){if(/widget-customizer=open/.test(location.search)){var b=function(){j.registered_sidebars.off("change:is_rendered",b);var c,d=j.registered_sidebars.find(function(a){return a.get("is_rendered")});d&&(c=a("#accordion-section-sidebar-widgets-"+d.get("id")),c.hasClass("open")||c.find(".accordion-section-title").trigger("click"),c[0].scrollIntoView())};b=_.debounce(b,100),j.registered_sidebars.on("change:is_rendered",b)}},i.controlConstructor.sidebar_widgets=i.Control.extend({ready:function(){var a=this;a.control_section=a.container.closest(".control-section"),a.section_content=a.container.closest(".accordion-section-content"),a._setupModel(),a._setupSortable(),a._setupAddition(),a._applyCardinalOrderClassNames()},_setupModel:function(){var c=this,d=j.registered_sidebars.get(c.params.sidebar_id);c.setting.bind(function(d,e){var f,g,h,i=_(e).difference(d);d=_(d).filter(function(a){var c=b(a);return!!j.available_widgets.findWhere({id_base:c.id_base})}),f=_(d).map(function(a){var b=j.getWidgetFormControlForWidget(a);return b||(b=c.addWidget(a)),b}),f.sort(function(a,b){var c=d.indexOf(a.params.widget_id),e=d.indexOf(b.params.widget_id);return c===e?0:e>c?-1:1}),g=c.section_content.find(".customize-control-sidebar_widgets"),h=_(f).map(function(a){return a.container[0]}),g.before(h),c._applyCardinalOrderClassNames(),_(f).each(function(a){a.params.sidebar_id=c.params.sidebar_id}),_(i).each(function(d){setTimeout(function(){var e,f,g,h,i,k=!1;wp.customize.each(function(a){if(a.id!==c.setting.id&&0===a.id.indexOf("sidebars_widgets[")&&"sidebars_widgets[wp_inactive_widgets]"!==a.id){var b,e=a();b=e.indexOf(d),-1!==b&&(k=!0)}}),k||(e=j.getWidgetFormControlForWidget(d),f=e&&a.contains(document,e.container[0])&&!a.contains(c.section_content[0],e.container[0]),e&&!f&&(wp.customize.control.remove(e.id),e.container.remove()),j.saved_widget_ids[d]&&(g=wp.customize.value("sidebars_widgets[wp_inactive_widgets]")().slice(),g.push(d),wp.customize.value("sidebars_widgets[wp_inactive_widgets]")(_(g).unique())),h=b(d).id_base,i=j.available_widgets.findWhere({id_base:h}),i&&!i.get("is_multi")&&i.set("is_disabled",!1))})})}),j.previewer.bind("rendered-sidebars",function(a){var b=!!a[c.params.sidebar_id];d.set("is_rendered",b)}),d.on("change:is_rendered",function(){var b,c="#accordion-section-sidebar-widgets-"+this.get("id");b=a(c),this.get("is_rendered")?b.stop().slideDown(function(){a(this).css("height","auto")
|