This repository has been archived by the owner. It is now read-only.

Gallery Widget #120

Merged
merged 43 commits into from Sep 19, 2017
Commits
Jump to file or symbol
Failed to load files and symbols.
+19 −15
Diff settings

Always

Just for now

Viewing a subset of changes. View all

Add handleAttachmentDestroy to factor out former removeAttachmentId l…

…ogic
  • Loading branch information...
westonruter committed Sep 16, 2017
commit 4e343ef36d7f8c88bf5ebaccd1b679da7ad3d1cc
@@ -83,7 +83,7 @@
component.MediaWidgetControl.prototype.initialize.call( control, options );
_.bindAll( control, 'updateSelectedAttachments' );
_.bindAll( control, 'updateSelectedAttachments', 'handleAttachmentDestroy' );
control.selectedAttachments = new wp.media.model.Attachments();
control.model.on( 'change:ids', control.updateSelectedAttachments );
control.selectedAttachments.on( 'change', control.renderPreview );
@@ -277,16 +277,8 @@
mediaFrame.$el.addClass( 'media-widget' );
mediaFrame.open();
// Clear the selected attachment when it is deleted in the media select frame.
if ( selection ) {
selection.on( 'destroy', function onDestroy( attachment ) {
control.model.set( {
ids: _.difference(
control.parseIdList( control.model.get( 'ids' ) ),
[ attachment.id ]
).join( ',' ) // @todo Array.
} );
});
selection.on( 'destroy', control.handleAttachmentDestroy );
}
},
@@ -352,20 +344,32 @@
mediaFrame.$el.addClass( 'media-widget' );
mediaFrame.open();
// Clear the selected attachment when it is deleted in the media select frame.
if ( selection ) {
selection.on( 'destroy', function onDestroy( attachment ) {
control.model.removeAttachmentId( attachment.get( 'id' ) );
});
selection.on( 'destroy', control.handleAttachmentDestroy );
}
/*
* Make sure focus is set inside of modal so that hitting Esc will close
* the modal and not inadvertently cause the widget to collapse in the customizer.
*/
mediaFrame.$el.find( ':focusable:first' ).focus();
}
},
/**
* Clear the selected attachment when it is deleted in the media select frame.
*
* @param {wp.media.models.Attachment} attachment - Attachment.
* @returns {void}
*/
handleAttachmentDestroy: function handleAttachmentDestroy( attachment ) {
var control = this;
control.model.set( {
ids: _.difference(
control.parseIdList( control.model.get( 'ids' ) ),
[ attachment.id ]
).join( ',' ) // @todo Array.
} );
}
} );
// Exports.
ProTip! Use n and p to navigate between commits in a pull request.