WordPress.org

Make WordPress Core

Changeset 41872


Ignore:
Timestamp:
10/16/2017 06:45:09 AM (8 months ago)
Author:
westonruter
Message:

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.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/js/widgets/media-gallery-widget.js

    r41590 r41872  
    101101            control.selectedAttachments.on( 'reset', control.renderPreview );
    102102            control.updateSelectedAttachments();
     103
     104            /*
     105             * Refresh a Gallery widget partial when the user modifies one of the selected attachments.
     106             * This ensures that when an attachment's caption is updated in the media modal the Gallery
     107             * widget in the preview will then be refreshed to show the change. Normally doing this
     108             * would not be necessary because all of the state should be contained inside the changeset,
     109             * as everything done in the Customizer should not make a change to the site unless the
     110             * changeset itself is published. Attachments are a current exception to this rule.
     111             * For a proposal to include attachments in the customized state, see #37887.
     112             */
     113            if ( wp.customize && wp.customize.previewer ) {
     114                control.selectedAttachments.on( 'change', function() {
     115                    wp.customize.previewer.send( 'refresh-widget-partial', control.model.get( 'widget_id' ) );
     116                } );
     117            }
    103118        },
    104119
  • trunk/src/wp-includes/js/customize-preview-widgets.js

    r41726 r41872  
    3939        api.preview.bind( 'active', function() {
    4040            self.highlightControls();
     41        } );
     42
     43        /*
     44         * Refresh a partial when the controls pane requests it. This is used currently just by the
     45         * Gallery widget so that when an attachment's caption is updated in the media modal,
     46         * the widget in the preview will then be refreshed to show the change. Normally doing this
     47         * would not be necessary because all of the state should be contained inside the changeset,
     48         * as everything done in the Customizer should not make a change to the site unless the
     49         * changeset itself is published. Attachments are a current exception to this rule.
     50         * For a proposal to include attachments in the customized state, see #37887.
     51         */
     52        api.preview.bind( 'refresh-widget-partial', function( widgetId ) {
     53            var partialId = 'widget[' + widgetId + ']';
     54            if ( api.selectiveRefresh.partial.has( partialId ) ) {
     55                api.selectiveRefresh.partial( partialId ).refresh();
     56            } else if ( self.renderedWidgets[ widgetId ] ) {
     57                api.preview.send( 'refresh' ); // Fallback in case theme does not support 'customize-selective-refresh-widgets'.
     58            }
    4159        } );
    4260    };
     
    452470                    } );
    453471                }
     472                delete self.renderedWidgets[ removedWidgetId ];
    454473            } );
    455474
     
    459478                var widgetPartial = sidebarPartial.ensureWidgetPlacementContainers( addedWidgetId );
    460479                addedWidgetPartials.push( widgetPartial );
     480                self.renderedWidgets[ addedWidgetId ] = true;
    461481            } );
    462482
Note: See TracChangeset for help on using the changeset viewer.