Edit File by line
/home/zeestwma/richards.../wp-inclu.../js
File: customize-preview-widgets.js
/**
[0] Fix | Delete
* @output wp-includes/js/customize-preview-widgets.js
[1] Fix | Delete
*/
[2] Fix | Delete
[3] Fix | Delete
/* global _wpWidgetCustomizerPreviewSettings */
[4] Fix | Delete
[5] Fix | Delete
/**
[6] Fix | Delete
* Handles the initialization, refreshing and rendering of widget partials and sidebar widgets.
[7] Fix | Delete
*
[8] Fix | Delete
* @since 4.5.0
[9] Fix | Delete
*
[10] Fix | Delete
* @namespace wp.customize.widgetsPreview
[11] Fix | Delete
*
[12] Fix | Delete
* @param {jQuery} $ The jQuery object.
[13] Fix | Delete
* @param {Object} _ The utilities library.
[14] Fix | Delete
* @param {Object} wp Current WordPress environment instance.
[15] Fix | Delete
* @param {Object} api Information from the API.
[16] Fix | Delete
*
[17] Fix | Delete
* @return {Object} Widget-related variables.
[18] Fix | Delete
*/
[19] Fix | Delete
wp.customize.widgetsPreview = wp.customize.WidgetCustomizerPreview = (function( $, _, wp, api ) {
[20] Fix | Delete
[21] Fix | Delete
var self;
[22] Fix | Delete
[23] Fix | Delete
self = {
[24] Fix | Delete
renderedSidebars: {},
[25] Fix | Delete
renderedWidgets: {},
[26] Fix | Delete
registeredSidebars: [],
[27] Fix | Delete
registeredWidgets: {},
[28] Fix | Delete
widgetSelectors: [],
[29] Fix | Delete
preview: null,
[30] Fix | Delete
l10n: {
[31] Fix | Delete
widgetTooltip: ''
[32] Fix | Delete
},
[33] Fix | Delete
selectiveRefreshableWidgets: {}
[34] Fix | Delete
};
[35] Fix | Delete
[36] Fix | Delete
/**
[37] Fix | Delete
* Initializes the widgets preview.
[38] Fix | Delete
*
[39] Fix | Delete
* @since 4.5.0
[40] Fix | Delete
*
[41] Fix | Delete
* @memberOf wp.customize.widgetsPreview
[42] Fix | Delete
*
[43] Fix | Delete
* @return {void}
[44] Fix | Delete
*/
[45] Fix | Delete
self.init = function() {
[46] Fix | Delete
var self = this;
[47] Fix | Delete
[48] Fix | Delete
self.preview = api.preview;
[49] Fix | Delete
if ( ! _.isEmpty( self.selectiveRefreshableWidgets ) ) {
[50] Fix | Delete
self.addPartials();
[51] Fix | Delete
}
[52] Fix | Delete
[53] Fix | Delete
self.buildWidgetSelectors();
[54] Fix | Delete
self.highlightControls();
[55] Fix | Delete
[56] Fix | Delete
self.preview.bind( 'highlight-widget', self.highlightWidget );
[57] Fix | Delete
[58] Fix | Delete
api.preview.bind( 'active', function() {
[59] Fix | Delete
self.highlightControls();
[60] Fix | Delete
} );
[61] Fix | Delete
[62] Fix | Delete
/*
[63] Fix | Delete
* Refresh a partial when the controls pane requests it. This is used currently just by the
[64] Fix | Delete
* Gallery widget so that when an attachment's caption is updated in the media modal,
[65] Fix | Delete
* the widget in the preview will then be refreshed to show the change. Normally doing this
[66] Fix | Delete
* would not be necessary because all of the state should be contained inside the changeset,
[67] Fix | Delete
* as everything done in the Customizer should not make a change to the site unless the
[68] Fix | Delete
* changeset itself is published. Attachments are a current exception to this rule.
[69] Fix | Delete
* For a proposal to include attachments in the customized state, see #37887.
[70] Fix | Delete
*/
[71] Fix | Delete
api.preview.bind( 'refresh-widget-partial', function( widgetId ) {
[72] Fix | Delete
var partialId = 'widget[' + widgetId + ']';
[73] Fix | Delete
if ( api.selectiveRefresh.partial.has( partialId ) ) {
[74] Fix | Delete
api.selectiveRefresh.partial( partialId ).refresh();
[75] Fix | Delete
} else if ( self.renderedWidgets[ widgetId ] ) {
[76] Fix | Delete
api.preview.send( 'refresh' ); // Fallback in case theme does not support 'customize-selective-refresh-widgets'.
[77] Fix | Delete
}
[78] Fix | Delete
} );
[79] Fix | Delete
};
[80] Fix | Delete
[81] Fix | Delete
self.WidgetPartial = api.selectiveRefresh.Partial.extend(/** @lends wp.customize.widgetsPreview.WidgetPartial.prototype */{
[82] Fix | Delete
[83] Fix | Delete
/**
[84] Fix | Delete
* Represents a partial widget instance.
[85] Fix | Delete
*
[86] Fix | Delete
* @since 4.5.0
[87] Fix | Delete
*
[88] Fix | Delete
* @constructs
[89] Fix | Delete
* @augments wp.customize.selectiveRefresh.Partial
[90] Fix | Delete
*
[91] Fix | Delete
* @alias wp.customize.widgetsPreview.WidgetPartial
[92] Fix | Delete
* @memberOf wp.customize.widgetsPreview
[93] Fix | Delete
*
[94] Fix | Delete
* @param {string} id The partial's ID.
[95] Fix | Delete
* @param {Object} options Options used to initialize the partial's
[96] Fix | Delete
* instance.
[97] Fix | Delete
* @param {Object} options.params The options parameters.
[98] Fix | Delete
*/
[99] Fix | Delete
initialize: function( id, options ) {
[100] Fix | Delete
var partial = this, matches;
[101] Fix | Delete
matches = id.match( /^widget\[(.+)]$/ );
[102] Fix | Delete
if ( ! matches ) {
[103] Fix | Delete
throw new Error( 'Illegal id for widget partial.' );
[104] Fix | Delete
}
[105] Fix | Delete
[106] Fix | Delete
partial.widgetId = matches[1];
[107] Fix | Delete
partial.widgetIdParts = self.parseWidgetId( partial.widgetId );
[108] Fix | Delete
options = options || {};
[109] Fix | Delete
options.params = _.extend(
[110] Fix | Delete
{
[111] Fix | Delete
settings: [ self.getWidgetSettingId( partial.widgetId ) ],
[112] Fix | Delete
containerInclusive: true
[113] Fix | Delete
},
[114] Fix | Delete
options.params || {}
[115] Fix | Delete
);
[116] Fix | Delete
[117] Fix | Delete
api.selectiveRefresh.Partial.prototype.initialize.call( partial, id, options );
[118] Fix | Delete
},
[119] Fix | Delete
[120] Fix | Delete
/**
[121] Fix | Delete
* Refreshes the widget partial.
[122] Fix | Delete
*
[123] Fix | Delete
* @since 4.5.0
[124] Fix | Delete
*
[125] Fix | Delete
* @return {Promise|void} Either a promise postponing the refresh, or void.
[126] Fix | Delete
*/
[127] Fix | Delete
refresh: function() {
[128] Fix | Delete
var partial = this, refreshDeferred;
[129] Fix | Delete
if ( ! self.selectiveRefreshableWidgets[ partial.widgetIdParts.idBase ] ) {
[130] Fix | Delete
refreshDeferred = $.Deferred();
[131] Fix | Delete
refreshDeferred.reject();
[132] Fix | Delete
partial.fallback();
[133] Fix | Delete
return refreshDeferred.promise();
[134] Fix | Delete
} else {
[135] Fix | Delete
return api.selectiveRefresh.Partial.prototype.refresh.call( partial );
[136] Fix | Delete
}
[137] Fix | Delete
},
[138] Fix | Delete
[139] Fix | Delete
/**
[140] Fix | Delete
* Sends the widget-updated message to the parent so the spinner will get
[141] Fix | Delete
* removed from the widget control.
[142] Fix | Delete
*
[143] Fix | Delete
* @inheritDoc
[144] Fix | Delete
* @param {wp.customize.selectiveRefresh.Placement} placement The placement
[145] Fix | Delete
* function.
[146] Fix | Delete
*
[147] Fix | Delete
* @return {void}
[148] Fix | Delete
*/
[149] Fix | Delete
renderContent: function( placement ) {
[150] Fix | Delete
var partial = this;
[151] Fix | Delete
if ( api.selectiveRefresh.Partial.prototype.renderContent.call( partial, placement ) ) {
[152] Fix | Delete
api.preview.send( 'widget-updated', partial.widgetId );
[153] Fix | Delete
api.selectiveRefresh.trigger( 'widget-updated', partial );
[154] Fix | Delete
}
[155] Fix | Delete
}
[156] Fix | Delete
});
[157] Fix | Delete
[158] Fix | Delete
self.SidebarPartial = api.selectiveRefresh.Partial.extend(/** @lends wp.customize.widgetsPreview.SidebarPartial.prototype */{
[159] Fix | Delete
[160] Fix | Delete
/**
[161] Fix | Delete
* Represents a partial widget area.
[162] Fix | Delete
*
[163] Fix | Delete
* @since 4.5.0
[164] Fix | Delete
*
[165] Fix | Delete
* @class
[166] Fix | Delete
* @augments wp.customize.selectiveRefresh.Partial
[167] Fix | Delete
*
[168] Fix | Delete
* @memberOf wp.customize.widgetsPreview
[169] Fix | Delete
* @alias wp.customize.widgetsPreview.SidebarPartial
[170] Fix | Delete
*
[171] Fix | Delete
* @param {string} id The partial's ID.
[172] Fix | Delete
* @param {Object} options Options used to initialize the partial's instance.
[173] Fix | Delete
* @param {Object} options.params The options parameters.
[174] Fix | Delete
*/
[175] Fix | Delete
initialize: function( id, options ) {
[176] Fix | Delete
var partial = this, matches;
[177] Fix | Delete
matches = id.match( /^sidebar\[(.+)]$/ );
[178] Fix | Delete
if ( ! matches ) {
[179] Fix | Delete
throw new Error( 'Illegal id for sidebar partial.' );
[180] Fix | Delete
}
[181] Fix | Delete
partial.sidebarId = matches[1];
[182] Fix | Delete
[183] Fix | Delete
options = options || {};
[184] Fix | Delete
options.params = _.extend(
[185] Fix | Delete
{
[186] Fix | Delete
settings: [ 'sidebars_widgets[' + partial.sidebarId + ']' ]
[187] Fix | Delete
},
[188] Fix | Delete
options.params || {}
[189] Fix | Delete
);
[190] Fix | Delete
[191] Fix | Delete
api.selectiveRefresh.Partial.prototype.initialize.call( partial, id, options );
[192] Fix | Delete
[193] Fix | Delete
if ( ! partial.params.sidebarArgs ) {
[194] Fix | Delete
throw new Error( 'The sidebarArgs param was not provided.' );
[195] Fix | Delete
}
[196] Fix | Delete
if ( partial.params.settings.length > 1 ) {
[197] Fix | Delete
throw new Error( 'Expected SidebarPartial to only have one associated setting' );
[198] Fix | Delete
}
[199] Fix | Delete
},
[200] Fix | Delete
[201] Fix | Delete
/**
[202] Fix | Delete
* Sets up the partial.
[203] Fix | Delete
*
[204] Fix | Delete
* @since 4.5.0
[205] Fix | Delete
*
[206] Fix | Delete
* @return {void}
[207] Fix | Delete
*/
[208] Fix | Delete
ready: function() {
[209] Fix | Delete
var sidebarPartial = this;
[210] Fix | Delete
[211] Fix | Delete
// Watch for changes to the sidebar_widgets setting.
[212] Fix | Delete
_.each( sidebarPartial.settings(), function( settingId ) {
[213] Fix | Delete
api( settingId ).bind( _.bind( sidebarPartial.handleSettingChange, sidebarPartial ) );
[214] Fix | Delete
} );
[215] Fix | Delete
[216] Fix | Delete
// Trigger an event for this sidebar being updated whenever a widget inside is rendered.
[217] Fix | Delete
api.selectiveRefresh.bind( 'partial-content-rendered', function( placement ) {
[218] Fix | Delete
var isAssignedWidgetPartial = (
[219] Fix | Delete
placement.partial.extended( self.WidgetPartial ) &&
[220] Fix | Delete
( -1 !== _.indexOf( sidebarPartial.getWidgetIds(), placement.partial.widgetId ) )
[221] Fix | Delete
);
[222] Fix | Delete
if ( isAssignedWidgetPartial ) {
[223] Fix | Delete
api.selectiveRefresh.trigger( 'sidebar-updated', sidebarPartial );
[224] Fix | Delete
}
[225] Fix | Delete
} );
[226] Fix | Delete
[227] Fix | Delete
// Make sure that a widget partial has a container in the DOM prior to a refresh.
[228] Fix | Delete
api.bind( 'change', function( widgetSetting ) {
[229] Fix | Delete
var widgetId, parsedId;
[230] Fix | Delete
parsedId = self.parseWidgetSettingId( widgetSetting.id );
[231] Fix | Delete
if ( ! parsedId ) {
[232] Fix | Delete
return;
[233] Fix | Delete
}
[234] Fix | Delete
widgetId = parsedId.idBase;
[235] Fix | Delete
if ( parsedId.number ) {
[236] Fix | Delete
widgetId += '-' + String( parsedId.number );
[237] Fix | Delete
}
[238] Fix | Delete
if ( -1 !== _.indexOf( sidebarPartial.getWidgetIds(), widgetId ) ) {
[239] Fix | Delete
sidebarPartial.ensureWidgetPlacementContainers( widgetId );
[240] Fix | Delete
}
[241] Fix | Delete
} );
[242] Fix | Delete
},
[243] Fix | Delete
[244] Fix | Delete
/**
[245] Fix | Delete
* Gets the before/after boundary nodes for all instances of this sidebar
[246] Fix | Delete
* (usually one).
[247] Fix | Delete
*
[248] Fix | Delete
* Note that TreeWalker is not implemented in IE8.
[249] Fix | Delete
*
[250] Fix | Delete
* @since 4.5.0
[251] Fix | Delete
*
[252] Fix | Delete
* @return {Array.<{before: Comment, after: Comment, instanceNumber: number}>}
[253] Fix | Delete
* An array with an object for each sidebar instance, containing the
[254] Fix | Delete
* node before and after the sidebar instance and its instance number.
[255] Fix | Delete
*/
[256] Fix | Delete
findDynamicSidebarBoundaryNodes: function() {
[257] Fix | Delete
var partial = this, regExp, boundaryNodes = {}, recursiveCommentTraversal;
[258] Fix | Delete
regExp = /^(dynamic_sidebar_before|dynamic_sidebar_after):(.+):(\d+)$/;
[259] Fix | Delete
recursiveCommentTraversal = function( childNodes ) {
[260] Fix | Delete
_.each( childNodes, function( node ) {
[261] Fix | Delete
var matches;
[262] Fix | Delete
if ( 8 === node.nodeType ) {
[263] Fix | Delete
matches = node.nodeValue.match( regExp );
[264] Fix | Delete
if ( ! matches || matches[2] !== partial.sidebarId ) {
[265] Fix | Delete
return;
[266] Fix | Delete
}
[267] Fix | Delete
if ( _.isUndefined( boundaryNodes[ matches[3] ] ) ) {
[268] Fix | Delete
boundaryNodes[ matches[3] ] = {
[269] Fix | Delete
before: null,
[270] Fix | Delete
after: null,
[271] Fix | Delete
instanceNumber: parseInt( matches[3], 10 )
[272] Fix | Delete
};
[273] Fix | Delete
}
[274] Fix | Delete
if ( 'dynamic_sidebar_before' === matches[1] ) {
[275] Fix | Delete
boundaryNodes[ matches[3] ].before = node;
[276] Fix | Delete
} else {
[277] Fix | Delete
boundaryNodes[ matches[3] ].after = node;
[278] Fix | Delete
}
[279] Fix | Delete
} else if ( 1 === node.nodeType ) {
[280] Fix | Delete
recursiveCommentTraversal( node.childNodes );
[281] Fix | Delete
}
[282] Fix | Delete
} );
[283] Fix | Delete
};
[284] Fix | Delete
[285] Fix | Delete
recursiveCommentTraversal( document.body.childNodes );
[286] Fix | Delete
return _.values( boundaryNodes );
[287] Fix | Delete
},
[288] Fix | Delete
[289] Fix | Delete
/**
[290] Fix | Delete
* Gets the placements for this partial.
[291] Fix | Delete
*
[292] Fix | Delete
* @since 4.5.0
[293] Fix | Delete
*
[294] Fix | Delete
* @return {Array} An array containing placement objects for each of the
[295] Fix | Delete
* dynamic sidebar boundary nodes.
[296] Fix | Delete
*/
[297] Fix | Delete
placements: function() {
[298] Fix | Delete
var partial = this;
[299] Fix | Delete
return _.map( partial.findDynamicSidebarBoundaryNodes(), function( boundaryNodes ) {
[300] Fix | Delete
return new api.selectiveRefresh.Placement( {
[301] Fix | Delete
partial: partial,
[302] Fix | Delete
container: null,
[303] Fix | Delete
startNode: boundaryNodes.before,
[304] Fix | Delete
endNode: boundaryNodes.after,
[305] Fix | Delete
context: {
[306] Fix | Delete
instanceNumber: boundaryNodes.instanceNumber
[307] Fix | Delete
}
[308] Fix | Delete
} );
[309] Fix | Delete
} );
[310] Fix | Delete
},
[311] Fix | Delete
[312] Fix | Delete
/**
[313] Fix | Delete
* Get the list of widget IDs associated with this widget area.
[314] Fix | Delete
*
[315] Fix | Delete
* @since 4.5.0
[316] Fix | Delete
*
[317] Fix | Delete
* @throws {Error} If there's no settingId.
[318] Fix | Delete
* @throws {Error} If the setting doesn't exist in the API.
[319] Fix | Delete
* @throws {Error} If the API doesn't pass an array of widget IDs.
[320] Fix | Delete
*
[321] Fix | Delete
* @return {Array} A shallow copy of the array containing widget IDs.
[322] Fix | Delete
*/
[323] Fix | Delete
getWidgetIds: function() {
[324] Fix | Delete
var sidebarPartial = this, settingId, widgetIds;
[325] Fix | Delete
settingId = sidebarPartial.settings()[0];
[326] Fix | Delete
if ( ! settingId ) {
[327] Fix | Delete
throw new Error( 'Missing associated setting.' );
[328] Fix | Delete
}
[329] Fix | Delete
if ( ! api.has( settingId ) ) {
[330] Fix | Delete
throw new Error( 'Setting does not exist.' );
[331] Fix | Delete
}
[332] Fix | Delete
widgetIds = api( settingId ).get();
[333] Fix | Delete
if ( ! _.isArray( widgetIds ) ) {
[334] Fix | Delete
throw new Error( 'Expected setting to be array of widget IDs' );
[335] Fix | Delete
}
[336] Fix | Delete
return widgetIds.slice( 0 );
[337] Fix | Delete
},
[338] Fix | Delete
[339] Fix | Delete
/**
[340] Fix | Delete
* Reflows widgets in the sidebar, ensuring they have the proper position in the
[341] Fix | Delete
* DOM.
[342] Fix | Delete
*
[343] Fix | Delete
* @since 4.5.0
[344] Fix | Delete
*
[345] Fix | Delete
* @return {Array.<wp.customize.selectiveRefresh.Placement>} List of placements
[346] Fix | Delete
* that were reflowed.
[347] Fix | Delete
*/
[348] Fix | Delete
reflowWidgets: function() {
[349] Fix | Delete
var sidebarPartial = this, sidebarPlacements, widgetIds, widgetPartials, sortedSidebarContainers = [];
[350] Fix | Delete
widgetIds = sidebarPartial.getWidgetIds();
[351] Fix | Delete
sidebarPlacements = sidebarPartial.placements();
[352] Fix | Delete
[353] Fix | Delete
widgetPartials = {};
[354] Fix | Delete
_.each( widgetIds, function( widgetId ) {
[355] Fix | Delete
var widgetPartial = api.selectiveRefresh.partial( 'widget[' + widgetId + ']' );
[356] Fix | Delete
if ( widgetPartial ) {
[357] Fix | Delete
widgetPartials[ widgetId ] = widgetPartial;
[358] Fix | Delete
}
[359] Fix | Delete
} );
[360] Fix | Delete
[361] Fix | Delete
_.each( sidebarPlacements, function( sidebarPlacement ) {
[362] Fix | Delete
var sidebarWidgets = [], needsSort = false, thisPosition, lastPosition = -1;
[363] Fix | Delete
[364] Fix | Delete
// Gather list of widget partial containers in this sidebar, and determine if a sort is needed.
[365] Fix | Delete
_.each( widgetPartials, function( widgetPartial ) {
[366] Fix | Delete
_.each( widgetPartial.placements(), function( widgetPlacement ) {
[367] Fix | Delete
[368] Fix | Delete
if ( sidebarPlacement.context.instanceNumber === widgetPlacement.context.sidebar_instance_number ) {
[369] Fix | Delete
thisPosition = widgetPlacement.container.index();
[370] Fix | Delete
sidebarWidgets.push( {
[371] Fix | Delete
partial: widgetPartial,
[372] Fix | Delete
placement: widgetPlacement,
[373] Fix | Delete
position: thisPosition
[374] Fix | Delete
} );
[375] Fix | Delete
if ( thisPosition < lastPosition ) {
[376] Fix | Delete
needsSort = true;
[377] Fix | Delete
}
[378] Fix | Delete
lastPosition = thisPosition;
[379] Fix | Delete
}
[380] Fix | Delete
} );
[381] Fix | Delete
} );
[382] Fix | Delete
[383] Fix | Delete
if ( needsSort ) {
[384] Fix | Delete
_.each( sidebarWidgets, function( sidebarWidget ) {
[385] Fix | Delete
sidebarPlacement.endNode.parentNode.insertBefore(
[386] Fix | Delete
sidebarWidget.placement.container[0],
[387] Fix | Delete
sidebarPlacement.endNode
[388] Fix | Delete
);
[389] Fix | Delete
[390] Fix | Delete
// @todo Rename partial-placement-moved?
[391] Fix | Delete
api.selectiveRefresh.trigger( 'partial-content-moved', sidebarWidget.placement );
[392] Fix | Delete
} );
[393] Fix | Delete
[394] Fix | Delete
sortedSidebarContainers.push( sidebarPlacement );
[395] Fix | Delete
}
[396] Fix | Delete
} );
[397] Fix | Delete
[398] Fix | Delete
if ( sortedSidebarContainers.length > 0 ) {
[399] Fix | Delete
api.selectiveRefresh.trigger( 'sidebar-updated', sidebarPartial );
[400] Fix | Delete
}
[401] Fix | Delete
[402] Fix | Delete
return sortedSidebarContainers;
[403] Fix | Delete
},
[404] Fix | Delete
[405] Fix | Delete
/**
[406] Fix | Delete
* Makes sure there is a widget instance container in this sidebar for the given
[407] Fix | Delete
* widget ID.
[408] Fix | Delete
*
[409] Fix | Delete
* @since 4.5.0
[410] Fix | Delete
*
[411] Fix | Delete
* @param {string} widgetId The widget ID.
[412] Fix | Delete
*
[413] Fix | Delete
* @return {wp.customize.selectiveRefresh.Partial} The widget instance partial.
[414] Fix | Delete
*/
[415] Fix | Delete
ensureWidgetPlacementContainers: function( widgetId ) {
[416] Fix | Delete
var sidebarPartial = this, widgetPartial, wasInserted = false, partialId = 'widget[' + widgetId + ']';
[417] Fix | Delete
widgetPartial = api.selectiveRefresh.partial( partialId );
[418] Fix | Delete
if ( ! widgetPartial ) {
[419] Fix | Delete
widgetPartial = new self.WidgetPartial( partialId, {
[420] Fix | Delete
params: {}
[421] Fix | Delete
} );
[422] Fix | Delete
}
[423] Fix | Delete
[424] Fix | Delete
// Make sure that there is a container element for the widget in the sidebar, if at least a placeholder.
[425] Fix | Delete
_.each( sidebarPartial.placements(), function( sidebarPlacement ) {
[426] Fix | Delete
var foundWidgetPlacement, widgetContainerElement;
[427] Fix | Delete
[428] Fix | Delete
foundWidgetPlacement = _.find( widgetPartial.placements(), function( widgetPlacement ) {
[429] Fix | Delete
return ( widgetPlacement.context.sidebar_instance_number === sidebarPlacement.context.instanceNumber );
[430] Fix | Delete
} );
[431] Fix | Delete
if ( foundWidgetPlacement ) {
[432] Fix | Delete
return;
[433] Fix | Delete
}
[434] Fix | Delete
[435] Fix | Delete
widgetContainerElement = $(
[436] Fix | Delete
sidebarPartial.params.sidebarArgs.before_widget.replace( /%1\$s/g, widgetId ).replace( /%2\$s/g, 'widget' ) +
[437] Fix | Delete
sidebarPartial.params.sidebarArgs.after_widget
[438] Fix | Delete
);
[439] Fix | Delete
[440] Fix | Delete
// Handle rare case where before_widget and after_widget are empty.
[441] Fix | Delete
if ( ! widgetContainerElement[0] ) {
[442] Fix | Delete
return;
[443] Fix | Delete
}
[444] Fix | Delete
[445] Fix | Delete
widgetContainerElement.attr( 'data-customize-partial-id', widgetPartial.id );
[446] Fix | Delete
widgetContainerElement.attr( 'data-customize-partial-type', 'widget' );
[447] Fix | Delete
widgetContainerElement.attr( 'data-customize-widget-id', widgetId );
[448] Fix | Delete
[449] Fix | Delete
/*
[450] Fix | Delete
* Make sure the widget container element has the customize-container context data.
[451] Fix | Delete
* The sidebar_instance_number is used to disambiguate multiple instances of the
[452] Fix | Delete
* same sidebar are rendered onto the template, and so the same widget is embedded
[453] Fix | Delete
* multiple times.
[454] Fix | Delete
*/
[455] Fix | Delete
widgetContainerElement.data( 'customize-partial-placement-context', {
[456] Fix | Delete
'sidebar_id': sidebarPartial.sidebarId,
[457] Fix | Delete
'sidebar_instance_number': sidebarPlacement.context.instanceNumber
[458] Fix | Delete
} );
[459] Fix | Delete
[460] Fix | Delete
sidebarPlacement.endNode.parentNode.insertBefore( widgetContainerElement[0], sidebarPlacement.endNode );
[461] Fix | Delete
wasInserted = true;
[462] Fix | Delete
} );
[463] Fix | Delete
[464] Fix | Delete
api.selectiveRefresh.partial.add( widgetPartial );
[465] Fix | Delete
[466] Fix | Delete
if ( wasInserted ) {
[467] Fix | Delete
sidebarPartial.reflowWidgets();
[468] Fix | Delete
}
[469] Fix | Delete
[470] Fix | Delete
return widgetPartial;
[471] Fix | Delete
},
[472] Fix | Delete
[473] Fix | Delete
/**
[474] Fix | Delete
* Handles changes to the sidebars_widgets[] setting.
[475] Fix | Delete
*
[476] Fix | Delete
* @since 4.5.0
[477] Fix | Delete
*
[478] Fix | Delete
* @param {Array} newWidgetIds New widget IDs.
[479] Fix | Delete
* @param {Array} oldWidgetIds Old widget IDs.
[480] Fix | Delete
*
[481] Fix | Delete
* @return {void}
[482] Fix | Delete
*/
[483] Fix | Delete
handleSettingChange: function( newWidgetIds, oldWidgetIds ) {
[484] Fix | Delete
var sidebarPartial = this, needsRefresh, widgetsRemoved, widgetsAdded, addedWidgetPartials = [];
[485] Fix | Delete
[486] Fix | Delete
needsRefresh = (
[487] Fix | Delete
( oldWidgetIds.length > 0 && 0 === newWidgetIds.length ) ||
[488] Fix | Delete
( newWidgetIds.length > 0 && 0 === oldWidgetIds.length )
[489] Fix | Delete
);
[490] Fix | Delete
if ( needsRefresh ) {
[491] Fix | Delete
sidebarPartial.fallback();
[492] Fix | Delete
return;
[493] Fix | Delete
}
[494] Fix | Delete
[495] Fix | Delete
// Handle removal of widgets.
[496] Fix | Delete
widgetsRemoved = _.difference( oldWidgetIds, newWidgetIds );
[497] Fix | Delete
_.each( widgetsRemoved, function( removedWidgetId ) {
[498] Fix | Delete
var widgetPartial = api.selectiveRefresh.partial( 'widget[' + removedWidgetId + ']' );
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function