Make WordPress Core

Changeset 21773


Ignore:
Timestamp:
09/06/2012 01:35:33 PM (13 years ago)
Author:
koopersmith
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/js/media-views.js

    r21771 r21773  
    548548                delete this.$bar;
    549549
     550            // Check if the model is selected.
     551            if ( this.controller.selection.has( this.model ) )
     552                this.select();
     553
    550554            return this;
    551555        },
     
    562566
    563567        select: function( model, collection ) {
    564             if ( collection === this.controller.selection )
    565                 this.$el.addClass('selected');
     568            // If a collection is provided, check if it's the selection.
     569            // If it's not, bail; we're in another selection's event loop.
     570            if ( collection && collection !== this.controller.selection )
     571                return;
     572
     573            this.$el.addClass('selected');
    566574        },
    567575
    568576        deselect: function( model, collection ) {
    569             if ( collection === this.controller.selection )
    570                 this.$el.removeClass('selected');
     577            // If a collection is provided, check if it's the selection.
     578            // If it's not, bail; we're in another selection's event loop.
     579            if ( collection && collection !== this.controller.selection )
     580                return;
     581
     582            this.$el.removeClass('selected');
    571583        }
    572584    });
Note: See TracChangeset for help on using the changeset viewer.