Skip to content

Commit 93a70c7

Browse files
committed
Customize: Resolve selective refresh partial placements as selectors only
Props westonruter, jonsurrell, jorbin. git-svn-id: https://develop.svn.wordpress.org/trunk@64879 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 55a2409 commit 93a70c7

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
@@ -412,18 +412,25 @@ wp.customize.widgetsPreview = wp.customize.WidgetCustomizerPreview = (function(
412412
* @return {wp.customize.selectiveRefresh.Partial} The widget instance partial.
413413
*/
414414
ensureWidgetPlacementContainers: function( widgetId ) {
415-
var sidebarPartial = this, widgetPartial, wasInserted = false, partialId = 'widget[' + widgetId + ']';
415+
var sidebarPartial = this, sidebarArgs, widgetPartial, wasInserted = false, partialId = 'widget[' + widgetId + ']';
416416
widgetPartial = api.selectiveRefresh.partial( partialId );
417417
if ( ! widgetPartial ) {
418418
widgetPartial = new self.WidgetPartial( partialId, {
419419
params: {}
420420
} );
421421
}
422422

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

430+
if ( ! sidebarArgs ) {
431+
return;
432+
}
433+
427434
foundWidgetPlacement = _.find( widgetPartial.placements(), function( widgetPlacement ) {
428435
return ( widgetPlacement.context.sidebar_instance_number === sidebarPlacement.context.instanceNumber );
429436
} );
@@ -432,8 +439,8 @@ wp.customize.widgetsPreview = wp.customize.WidgetCustomizerPreview = (function(
432439
}
433440

434441
widgetContainerElement = $(
435-
sidebarPartial.params.sidebarArgs.before_widget.replace( /%1\$s/g, widgetId ).replace( /%2\$s/g, 'widget' ) +
436-
sidebarPartial.params.sidebarArgs.after_widget
442+
sidebarArgs.before_widget.replace( /%1\$s/g, widgetId ).replace( /%2\$s/g, 'widget' ) +
443+
sidebarArgs.after_widget
437444
);
438445

439446
// 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
@@ -268,9 +268,9 @@ wp.customize.selectiveRefresh = ( function( $, api ) {
268268
if ( selector ) {
269269
selector += ', ';
270270
}
271-
selector += '[data-customize-partial-id="' + partial.id + '"]'; // @todo Consider injecting customize-partial-id-${id} classnames instead.
271+
selector += '[data-customize-partial-id="' + CSS.escape( partial.id ) + '"]';
272272

273-
return $( selector ).map( function() {
273+
return $( document ).find( selector ).map( function() {
274274
var container = $( this ), context;
275275

276276
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)