New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trac 32417: Media widget #215

Closed
wants to merge 22 commits into
base: master
from
Commits
Jump to file or symbol
Failed to load files and symbols.
+28 −4
Diff settings

Always

Just for now

Viewing a subset of changes. View all

Explicitly refresh widget partial when form is re-rendered to show an…

…y changes to attachment data
  • Loading branch information...
westonruter committed Feb 23, 2017
commit dd038c5238a2f4e358222a6ac9d8e2a360cde8b7
@@ -1035,6 +1035,14 @@ wp.customize.selectiveRefresh = ( function( $, api ) {
} );
} );
api.preview.bind( 'refresh-partial', function receiveRefreshPartialMessage( partialId ) {
var partial = self.partial( partialId );
if ( partial ) {
partial.refresh();
} else {
api.preview.send( 'refresh' );
}
} );
} );
return self;
@@ -116,8 +116,10 @@
*/
renderFormView: function( widgetId, props, attachment ) {
var formView, instanceChanged = false;
// Start with container elements for the widgets page, customizer controls, and customizer preview.
var formView = $( '.' + widgetId + ', #customize-control-widget_' + widgetId + ', #' + widgetId );
formView = $( '.' + widgetId + ', #customize-control-widget_' + widgetId + ', #' + widgetId );
// Bail if there is no target form
if ( ! formView.length ) {
@@ -148,11 +150,25 @@
// Populate form fields with selection data from the media frame.
_.each( _.keys( frame.defaultProps ), function( key ) {
formView.find( '#widget-' + widgetId + '-' + key ).val( attachment[ key ] || props[ key ] ).trigger( 'change' );
var input, newValue;
input = formView.find( '#widget-' + widgetId + '-' + key );
newValue = String( attachment[ key ] || props[ key ] );
if ( input.val() !== newValue ) {
input.val( newValue );
input.trigger( 'change' );
instanceChanged = true;
}
} );
// Trigger a sync to update the widget in the customizer preview.
formView.find( '#widget-' + widgetId + '-url' ).trigger( 'change' );
/*
* Force the widget's partial in the preview to refresh even when the instance was not changed.
* This ensures that changes to attachment's caption or description will be shown in the
* preview since these are not in the widget's instance state.
* @todo This should actually also look at `attachment` to see if it is different than before.
*/
if ( ! instanceChanged && wp.customize && wp.customize.Widgets ) {
wp.customize.previewer.send( 'refresh-partial', 'widget[' + widgetId + ']' );
}
// Change button text
formView.find( frame.buttonId ).text( translate( 'changeMedia', 'Change Media' ) );
ProTip! Use n and p to navigate between commits in a pull request.