Changeset 22335
- Timestamp:
- 10/30/2012 11:15:16 PM (12 years ago)
- Location:
- trunk/wp-includes
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/css/media-views.css
r22332 r22335 245 245 background: #777; 246 246 border: 1px solid #fff; 247 /*border-width: 0 1px 1px 0;*/248 247 border-width: 0 0 1px 1px; 249 248 box-shadow: -1px 1px 0 rgba( 0, 0, 0, 0.1 ); -
trunk/wp-includes/js/media-models.js
r22323 r22335 623 623 Attachments.prototype.initialize.apply( this, arguments ); 624 624 this.multiple = options && options.multiple; 625 626 // Refresh the `single` model whenever the selection changes. 627 // Binds `single` instead of using the context argument to ensure 628 // it receives no parameters. 629 this.on( 'add remove reset', _.bind( this.single, this ) ); 625 630 }, 626 631 … … 639 644 // Removes all models from the selection. 640 645 clear: function( options ) { 641 return this.remove( this.models, options ); 646 this.remove( this.models, options ).single(); 647 return this; 642 648 }, 643 649 … … 646 652 // as we need them to fire. 647 653 reset: function( models, options ) { 648 return this.clear( options ).add( models, options ); 654 this.clear( options ).add( models, options ).single(); 655 return this; 649 656 }, 650 657 … … 654 661 has: function( attachment ) { 655 662 return !! ( this.getByCid( attachment.cid ) || this.get( attachment.id ) ); 663 }, 664 665 single: function( model ) { 666 var previous = this._single; 667 668 // If a `model` is provided, use it as the single model. 669 if ( model ) 670 this._single = model; 671 672 // If the single model isn't in the selection, remove it. 673 if ( this._single && ! this.has( this._single ) ) 674 delete this._single; 675 676 this._single = this._single || this.last(); 677 678 // If single has changed, fire an event. 679 if ( this._single !== previous ) { 680 if ( this._single ) 681 this._single.trigger( 'selection:single', this._single, this ); 682 if ( previous ) 683 previous.trigger( 'selection:unsingle', previous, this ); 684 } 685 686 // Return the single model, or the last model as a fallback. 687 return this._single; 656 688 } 657 689 }); -
trunk/wp-includes/js/media-views.js
r22333 r22335 213 213 214 214 details: function( options ) { 215 var model = this.get(' details'),215 var model = this.get('selection').single(), 216 216 view; 217 217 … … 233 233 234 234 toggleSelection: function( model ) { 235 var details = this.get('details'), 236 selection = this.get('selection'), 237 selected = selection.has( model ); 238 239 if ( ! selection ) 240 return; 241 242 if ( ! selected ) 243 selection.add( model ); 244 245 // If the model is not the same as the details model, 246 // it now becomes the details model. If the model is 247 // in the selection, it is not removed. 248 if ( details !== model ) { 249 this.set( 'details', model ); 250 return; 251 } 252 253 // The model is the details model. 254 // Removed it from the selection. 255 selection.remove( model ); 256 257 // Show the last selected item, or clear the details view. 258 if ( selection.length ) 259 this.set( 'details', selection.last() ); 260 else 261 this.unset('details'); 262 235 var selection = this.get('selection'); 236 237 if ( selection.has( model ) ) { 238 // If the model is the single model, remove it. 239 // If it is not the same as the single model, 240 // it now becomes the single model. 241 selection[ selection.single() === model ? 'remove' : 'single' ]( model ); 242 } else { 243 selection.add( model ).single(); 244 } 245 246 return this; 263 247 } 264 248 }); … … 1088 1072 1089 1073 // Update the model's details view. 1090 this. controller.state().on( 'change:details', this.details, this );1074 this.model.on( 'selection:single selection:unsingle', this.details, this ); 1091 1075 this.details(); 1092 1076 … … 1095 1079 1096 1080 destroy: function() { 1097 this. controller.state().off( 'change:details', this.details, this );1081 this.model.off( 'single', this.details, this ); 1098 1082 }, 1099 1083 … … 1137 1121 }, 1138 1122 1139 details: function() { 1140 var details = this.controller.state().get('details'); 1123 details: function( model, collection ) { 1124 var selection = this.controller.state().get('selection'), 1125 details; 1126 1127 if ( selection !== collection ) 1128 return; 1129 1130 details = selection.single(); 1141 1131 this.$el.toggleClass( 'details', details === this.model ); 1142 1132 },
Note: See TracChangeset
for help on using the changeset viewer.