Skip to content

Commit

Permalink
Media JS: Apply selection when Attachment models are initially rendered.
Browse files Browse the repository at this point in the history
This allows us to automatically retain selections when the library context is changed (e.g. when searching. This changes the Attachment view's select() and deselect() methods so that they can be triggered directly.

see #21390.



git-svn-id: http://core.svn.wordpress.org/trunk@21773 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information
koop committed Sep 6, 2012
1 parent 8763c79 commit 1e28b7c
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions wp-includes/js/media-views.js
Expand Up @@ -547,6 +547,10 @@
else
delete this.$bar;

// Check if the model is selected.
if ( this.controller.selection.has( this.model ) )
this.select();

return this;
},

Expand All @@ -561,13 +565,21 @@
},

select: function( model, collection ) {
if ( collection === this.controller.selection )
this.$el.addClass('selected');
// If a collection is provided, check if it's the selection.
// If it's not, bail; we're in another selection's event loop.
if ( collection && collection !== this.controller.selection )
return;

this.$el.addClass('selected');
},

deselect: function( model, collection ) {
if ( collection === this.controller.selection )
this.$el.removeClass('selected');
// If a collection is provided, check if it's the selection.
// If it's not, bail; we're in another selection's event loop.
if ( collection && collection !== this.controller.selection )
return;

this.$el.removeClass('selected');
}
});

Expand Down

0 comments on commit 1e28b7c

Please sign in to comment.