Widgets: Update preview for Gallery widget when one of its attachments is modified in the media modal, outside the customized state.
* Ensure that changes to captions are shown in preview when modified in media modal. * Also keep `wp.customize.widgetsPreview.renderedWidgets` updated when widgets are added or removed. See #41914, #37887, #40403. Fixes #41979. git-svn-id: https://develop.svn.wordpress.org/trunk@41872 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
75034a401f
commit
850db3c6a0
|
@ -100,6 +100,21 @@
|
||||||
control.selectedAttachments.on( 'change', control.renderPreview );
|
control.selectedAttachments.on( 'change', control.renderPreview );
|
||||||
control.selectedAttachments.on( 'reset', control.renderPreview );
|
control.selectedAttachments.on( 'reset', control.renderPreview );
|
||||||
control.updateSelectedAttachments();
|
control.updateSelectedAttachments();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Refresh a Gallery widget partial when the user modifies one of the selected attachments.
|
||||||
|
* This ensures that when an attachment's caption is updated in the media modal the Gallery
|
||||||
|
* widget in the preview will then be refreshed to show the change. Normally doing this
|
||||||
|
* would not be necessary because all of the state should be contained inside the changeset,
|
||||||
|
* as everything done in the Customizer should not make a change to the site unless the
|
||||||
|
* changeset itself is published. Attachments are a current exception to this rule.
|
||||||
|
* For a proposal to include attachments in the customized state, see #37887.
|
||||||
|
*/
|
||||||
|
if ( wp.customize && wp.customize.previewer ) {
|
||||||
|
control.selectedAttachments.on( 'change', function() {
|
||||||
|
wp.customize.previewer.send( 'refresh-widget-partial', control.model.get( 'widget_id' ) );
|
||||||
|
} );
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -39,6 +39,24 @@ wp.customize.widgetsPreview = wp.customize.WidgetCustomizerPreview = (function(
|
||||||
api.preview.bind( 'active', function() {
|
api.preview.bind( 'active', function() {
|
||||||
self.highlightControls();
|
self.highlightControls();
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Refresh a partial when the controls pane requests it. This is used currently just by the
|
||||||
|
* Gallery widget so that when an attachment's caption is updated in the media modal,
|
||||||
|
* the widget in the preview will then be refreshed to show the change. Normally doing this
|
||||||
|
* would not be necessary because all of the state should be contained inside the changeset,
|
||||||
|
* as everything done in the Customizer should not make a change to the site unless the
|
||||||
|
* changeset itself is published. Attachments are a current exception to this rule.
|
||||||
|
* For a proposal to include attachments in the customized state, see #37887.
|
||||||
|
*/
|
||||||
|
api.preview.bind( 'refresh-widget-partial', function( widgetId ) {
|
||||||
|
var partialId = 'widget[' + widgetId + ']';
|
||||||
|
if ( api.selectiveRefresh.partial.has( partialId ) ) {
|
||||||
|
api.selectiveRefresh.partial( partialId ).refresh();
|
||||||
|
} else if ( self.renderedWidgets[ widgetId ] ) {
|
||||||
|
api.preview.send( 'refresh' ); // Fallback in case theme does not support 'customize-selective-refresh-widgets'.
|
||||||
|
}
|
||||||
|
} );
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -451,6 +469,7 @@ wp.customize.widgetsPreview = wp.customize.WidgetCustomizerPreview = (function(
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
delete self.renderedWidgets[ removedWidgetId ];
|
||||||
} );
|
} );
|
||||||
|
|
||||||
// Handle insertion of widgets.
|
// Handle insertion of widgets.
|
||||||
|
@ -458,6 +477,7 @@ wp.customize.widgetsPreview = wp.customize.WidgetCustomizerPreview = (function(
|
||||||
_.each( widgetsAdded, function( addedWidgetId ) {
|
_.each( widgetsAdded, function( addedWidgetId ) {
|
||||||
var widgetPartial = sidebarPartial.ensureWidgetPlacementContainers( addedWidgetId );
|
var widgetPartial = sidebarPartial.ensureWidgetPlacementContainers( addedWidgetId );
|
||||||
addedWidgetPartials.push( widgetPartial );
|
addedWidgetPartials.push( widgetPartial );
|
||||||
|
self.renderedWidgets[ addedWidgetId ] = true;
|
||||||
} );
|
} );
|
||||||
|
|
||||||
_.each( addedWidgetPartials, function( widgetPartial ) {
|
_.each( addedWidgetPartials, function( widgetPartial ) {
|
||||||
|
|
Loading…
Reference in New Issue