WordPress/wp-includes/js/customize-preview-widgets.min.js

1 line
7.4 KiB
JavaScript
Raw Normal View History

wp.customize.widgetsPreview=wp.customize.WidgetCustomizerPreview=function(a,b,c,d){var e;return e={renderedSidebars:{},renderedWidgets:{},registeredSidebars:[],registeredWidgets:{},widgetSelectors:[],preview:null,l10n:{widgetTooltip:""},selectiveRefreshableWidgets:{}},e.init=function(){var a=this;a.preview=d.preview,b.isEmpty(a.selectiveRefreshableWidgets)||a.addPartials(),a.buildWidgetSelectors(),a.highlightControls(),a.preview.bind("highlight-widget",a.highlightWidget),d.preview.bind("active",function(){a.highlightControls()})},e.WidgetPartial=d.selectiveRefresh.Partial.extend({initialize:function(a,c){var f,g=this;if(f=a.match(/^widget\[(.+)]$/),!f)throw new Error("Illegal id for widget partial.");g.widgetId=f[1],g.widgetIdParts=e.parseWidgetId(g.widgetId),c=c||{},c.params=b.extend({settings:[e.getWidgetSettingId(g.widgetId)],containerInclusive:!0},c.params||{}),d.selectiveRefresh.Partial.prototype.initialize.call(g,a,c)},refresh:function(){var b,c=this;return e.selectiveRefreshableWidgets[c.widgetIdParts.idBase]?d.selectiveRefresh.Partial.prototype.refresh.call(c):(b=a.Deferred(),b.reject(),c.fallback(),b.promise())},renderContent:function(a){var b=this;d.selectiveRefresh.Partial.prototype.renderContent.call(b,a)&&(d.preview.send("widget-updated",b.widgetId),d.selectiveRefresh.trigger("widget-updated",b))}}),e.SidebarPartial=d.selectiveRefresh.Partial.extend({initialize:function(a,c){var e,f=this;if(e=a.match(/^sidebar\[(.+)]$/),!e)throw new Error("Illegal id for sidebar partial.");if(f.sidebarId=e[1],c=c||{},c.params=b.extend({settings:["sidebars_widgets["+f.sidebarId+"]"]},c.params||{}),d.selectiveRefresh.Partial.prototype.initialize.call(f,a,c),!f.params.sidebarArgs)throw new Error("The sidebarArgs param was not provided.");if(f.params.settings.length>1)throw new Error("Expected SidebarPartial to only have one associated setting")},ready:function(){var a=this;b.each(a.settings(),function(c){d(c).bind(b.bind(a.handleSettingChange,a))}),d.selectiveRefresh.bind("partial-content-rendered",function(c){var f=c.partial.extended(e.WidgetPartial)&&-1!==b.indexOf(a.getWidgetIds(),c.partial.widgetId);f&&d.selectiveRefresh.trigger("sidebar-updated",a)}),d.bind("change",function(c){var d,f;f=e.parseWidgetSettingId(c.id),f&&(d=f.idBase,f.number&&(d+="-"+String(f.number)),-1!==b.indexOf(a.getWidgetIds(),d)&&a.ensureWidgetPlacementContainers(d))})},findDynamicSidebarBoundaryNodes:function(){var a,c,d=this,e={};return a=/^(dynamic_sidebar_before|dynamic_sidebar_after):(.+):(\d+)$/,c=function(f){b.each(f,function(f){var g;if(8===f.nodeType){if(g=f.nodeValue.match(a),!g||g[2]!==d.sidebarId)return;b.isUndefined(e[g[3]])&&(e[g[3]]={before:null,after:null,instanceNumber:parseInt(g[3],10)}),"dynamic_sidebar_before"===g[1]?e[g[3]].before=f:e[g[3]].after=f}else 1===f.nodeType&&c(f.childNodes)})},c(document.body.childNodes),b.values(e)},placements:function(){var a=this;return b.map(a.findDynamicSidebarBoundaryNodes(),function(b){return new d.selectiveRefresh.Placement({partial:a,container:null,startNode:b.before,endNode:b.after,context:{instanceNumber:b.instanceNumber}})})},getWidgetIds:function(){var a,c,e=this;if(a=e.settings()[0],!a)throw new Error("Missing associated setting.");if(!d.has(a))throw new Error("Setting does not exist.");if(c=d(a).get(),!b.isArray(c))throw new Error("Expected setting to be array of widget IDs");return c.slice(0)},reflowWidgets:function(){var a,c,e,f=this,g=[];return c=f.getWidgetIds(),a=f.placements(),e={},b.each(c,function(a){var b=d.selectiveRefresh.partial("widget["+a+"]");b&&(e[a]=b)}),b.each(a,function(a){var c,f=[],h=!1,i=-1;b.each(e,function(d){b.each(d.placements(),function(b){a.context.instanceNumber===b.context.sidebar_instance_number&&(c=b.container.index(),f.push({partial:d,placement:b,position:c}),i>c&&(h=!0),i=c)})}),h&&(b.each(f,function(b){a.endNode.parentNode.insertBefore(b.placement.container[0],a.endNode),d.selectiveRefresh.trigger("partial-content-moved",b.placement)}),g.push(a))}),g.length>0&&d.selectiveRefresh.trigger("sidebar-updated",f),g},ensureWidgetPlacementContainers:function(c)