2014-03-22 17:22:13 -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:"",error:""},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,doSearch:function(a){this.terms!==a&&(this.terms=a,this.terms.length>0&&this.search(this.terms),""===this.terms&&this.reset(WidgetCustomizer_exports.available_widgets),this.trigger("update"))},search:function(a){var b,c,d;this.reset(WidgetCustomizer_exports.available_widgets,{silent:!0}),a=a.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"),a=a.replace(/ /g,")(?=.*"),b=new RegExp("^(?=.*"+a+").+","i"),c=this.filter(function(a){return d=_.union(a.get("name"),a.get("id"),a.get("description")),b.test(d)}),this.reset(c)}}),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=_.indexOf(d,a.params.widget_id),e=_.indexOf(d,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===_.indexOf(a.id,"sidebars_widgets[")&&"sidebars_widgets[wp_inactive_widgets]"!==a.id){var b,e=a();b=_.indexOf(e,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_wi
|