Skip to content

Commit da2b308

Browse files
committed
Customize: Resolve selective refresh partial placements as selectors only
Merges [64879] to the 7.1 branch. Props westonruter, jonsurrell, jorbin. git-svn-id: https://develop.svn.wordpress.org/branches/7.1@64891 602fd350-edb4-49c9-b593-d223f7449a82
1 parent dcc2af6 commit da2b308

3 files changed

Lines changed: 14 additions & 7 deletions

File tree

‎src/js/_enqueues/wp/customize/preview-widgets.js‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -415,18 +415,25 @@ wp.customize.widgetsPreview = wp.customize.WidgetCustomizerPreview = (function(
415415
* @return {wp.customize.selectiveRefresh.Partial} The widget instance partial.
416416
*/
417417
ensureWidgetPlacementContainers: function( widgetId ) {
418-
var sidebarPartial = this, widgetPartial, wasInserted = false, partialId = 'widget[' + widgetId + ']';
418+
var sidebarPartial = this, sidebarArgs, widgetPartial, wasInserted = false, partialId = 'widget[' + widgetId + ']';
419419
widgetPartial = api.selectiveRefresh.partial( partialId );
420420
if ( ! widgetPartial ) {
421421
widgetPartial = new self.WidgetPartial( partialId, {
422422
params: {}
423423
} );
424424
}
425425

426+
// Build containers from the registered sidebar, since partial params can be declared in post content.
427+
sidebarArgs = _.findWhere( self.registeredSidebars, { id: sidebarPartial.sidebarId } );
428+
426429
// Make sure that there is a container element for the widget in the sidebar, if at least a placeholder.
427430
_.each( sidebarPartial.placements(), function( sidebarPlacement ) {
428431
var foundWidgetPlacement, widgetContainerElement;
429432

433+
if ( ! sidebarArgs ) {
434+
return;
435+
}
436+
430437
foundWidgetPlacement = _.find( widgetPartial.placements(), function( widgetPlacement ) {
431438
return ( widgetPlacement.context.sidebar_instance_number === sidebarPlacement.context.instanceNumber );
432439
} );
@@ -435,8 +442,8 @@ wp.customize.widgetsPreview = wp.customize.WidgetCustomizerPreview = (function(
435442
}
436443

437444
widgetContainerElement = $(
438-
sidebarPartial.params.sidebarArgs.before_widget.replace( /%1\$s/g, widgetId ).replace( /%2\$s/g, 'widget' ) +
439-
sidebarPartial.params.sidebarArgs.after_widget
445+
sidebarArgs.before_widget.replace( /%1\$s/g, widgetId ).replace( /%2\$s/g, 'widget' ) +
446+
sidebarArgs.after_widget
440447
);
441448

442449
// Handle rare case where before_widget and after_widget are empty.

‎src/js/_enqueues/wp/customize/selective-refresh.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,9 @@ wp.customize.selectiveRefresh = ( function( $, api ) {
262262
if ( selector ) {
263263
selector += ', ';
264264
}
265-
selector += '[data-customize-partial-id="' + partial.id + '"]'; // @todo Consider injecting customize-partial-id-${id} classnames instead.
265+
selector += '[data-customize-partial-id="' + CSS.escape( partial.id ) + '"]';
266266

267-
return $( selector ).map( function() {
267+
return $( document ).find( selector ).map( function() {
268268
var container = $( this ), context;
269269

270270
context = container.data( 'customize-partial-placement-context' );

‎src/wp-content/themes/twentytwenty/assets/js/customize-preview.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

4343
partial = this;
4444
params = partial.params;
45-
cover = $( params.selector );
45+
cover = $( document ).find( params.selector );
4646

4747
if ( cover.length && cover.hasClass( 'bg-image' ) ) {
4848
cover.toggleClass( 'bg-attachment-fixed' );
@@ -79,7 +79,7 @@
7979
ranges = _.range( attrs.min, attrs.max + attrs.step, attrs.step );
8080
params = partial.params;
8181
setting = api( params.primarySetting );
82-
cover = $( params.selector );
82+
cover = $( document ).find( params.selector );
8383

8484
if ( cover.length ) {
8585
classNames = _.map( ranges, function( val ) {

0 commit comments

Comments
 (0)