From 1e28b7c8cb9e56ffee47cac64377d0f9dcf1625b Mon Sep 17 00:00:00 2001 From: Daryl Koopersmith Date: Thu, 6 Sep 2012 13:35:33 +0000 Subject: [PATCH] Media JS: Apply selection when Attachment models are initially rendered. 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 --- wp-includes/js/media-views.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/wp-includes/js/media-views.js b/wp-includes/js/media-views.js index c8abb798bc..a7913cf0cb 100644 --- a/wp-includes/js/media-views.js +++ b/wp-includes/js/media-views.js @@ -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; }, @@ -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'); } });