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

1 line
7.6 KiB
JavaScript
Raw Normal View History

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