Changeset 23089
- Timestamp:
- 12/06/2012 03:55:37 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/js/media-views.js
r23085 r23089 368 368 369 369 // Sync the selection from the last state when 'multiple' matches. 370 sync LastSelection: true370 syncSelection: true 371 371 }, 372 372 373 373 initialize: function() { 374 if ( ! this.get('selection') ) { 374 var selection = this.get('selection'), 375 props; 376 377 // If a library isn't provided, query all media items. 378 if ( ! this.get('library') ) 379 this.set( 'library', media.query() ); 380 381 // If a selection instance isn't provided, create one. 382 if ( ! (selection instanceof media.model.Selection) ) { 383 props = selection; 384 385 if ( ! props ) { 386 props = this.get('library').props.toJSON(); 387 props = _.omit( props, 'orderby', 'query' ); 388 } 389 390 // If the `selection` attribute is set to an object, 391 // it will use those values as the selection instance's 392 // `props` model. Otherwise, it will copy the library's 393 // `props` model. 375 394 this.set( 'selection', new media.model.Selection( null, { 376 multiple: this.get('multiple') 395 multiple: this.get('multiple'), 396 props: props 377 397 }) ); 378 398 } 379 399 380 if ( ! this.get('library') )381 this.set( 'library', media.query() );382 383 400 if ( ! this.get('edge') ) 384 401 this.set( 'edge', 120 ); … … 391 408 392 409 activate: function() { 393 if ( this.get('syncLastSelection') ) 394 this.getLastSelection(); 410 this.syncSelection(); 395 411 396 412 wp.Uploader.queue.on( 'add', this.uploading, this ); … … 407 423 408 424 deactivate: function() { 425 this.recordSelection(); 426 409 427 this.frame.off( 'content:activate', this.saveContentMode, this ); 410 428 … … 456 474 }, 457 475 458 getLastSelection: function() {476 syncSelection: function() { 459 477 var selection = this.get('selection'), 460 lastState = this.frame.lastState(), 461 lastSelection = lastState && lastState.get('selection'), 462 lastMultiple, thisMultiple; 463 464 if ( ! lastSelection ) 478 manager = this.frame._selection; 479 480 if ( ! this.get('syncSelection') || ! manager || ! selection ) 465 481 return; 466 482 467 // We don't care about the method of multiple selection the 468 // selections use, just that they both support (or don't support) 469 // multiple selection. 470 lastMultiple = !! lastSelection.multiple; 471 thisMultiple = !! selection.multiple; 472 473 if ( lastMultiple !== thisMultiple ) 483 // If the selection supports multiple items, validate the stored 484 // attachments based on the new selection's conditions. Record 485 // the attachments that are not included; we'll maintain a 486 // reference to those. Other attachments are considered in flux. 487 if ( selection.multiple ) { 488 selection.reset( [], { silent: true }); 489 selection.validateAll( manager.attachments ); 490 manager.difference = _.difference( manager.attachments.models, selection.models ); 491 } 492 493 // Sync the selection's single item with the master. 494 selection.single( manager.single ); 495 }, 496 497 recordSelection: function() { 498 var selection = this.get('selection'), 499 manager = this.frame._selection, 500 filtered; 501 502 if ( ! this.get('syncSelection') || ! manager || ! selection ) 474 503 return; 475 504 476 selection.reset( lastSelection.toArray() ).single( lastSelection.single() ); 505 // Record the currently active attachments, which is a combination 506 // of the selection's attachments and the set of selected 507 // attachments that this specific selection considered invalid. 508 // Reset the difference and record the single attachment. 509 if ( selection.multiple ) { 510 manager.attachments.reset( selection.toArray().concat( manager.difference ) ); 511 manager.difference = []; 512 } else { 513 manager.attachments.add( selection.toArray() ); 514 } 515 516 manager.single = selection._single; 477 517 }, 478 518 … … 528 568 title: l10n.editGalleryTitle, 529 569 priority: 60, 530 dragInfo: true 570 dragInfo: true, 571 572 // Don't sync the selection, as the Edit Gallery library 573 // *is* the selection. 574 syncSelection: false 531 575 }, 532 576 … … 602 646 toolbar: 'gallery-add', 603 647 title: l10n.addToGalleryTitle, 604 priority: 100 648 priority: 100, 649 650 // Don't sync the selection, as the Edit Gallery library 651 // *is* the selection. 652 syncSelection: false 605 653 }, media.controller.Library.prototype.defaults ), 606 654 … … 642 690 toolbar: 'featured-image', 643 691 title: l10n.setFeaturedImageTitle, 644 priority: 60 692 priority: 60, 693 694 syncSelection: false 645 695 }, media.controller.Library.prototype.defaults ), 646 696 … … 1430 1480 }); 1431 1481 } 1482 1483 this._selection = { 1484 attachments: new Attachments(), 1485 difference: [] 1486 }; 1432 1487 }, 1433 1488 … … 1442 1497 // Main states. 1443 1498 new media.controller.Library({ 1444 selection: options.selection,1445 1499 library: media.query( options.library ), 1446 1500 multiple: options.multiple, … … 1527 1581 1528 1582 createStates: function() { 1529 var options = this.options, 1530 selection = options.selection; 1583 var options = this.options; 1531 1584 1532 1585 // Add the default states. … … 1540 1593 filterable: 'all', 1541 1594 library: media.query( options.library ), 1542 selection: selection,1543 1595 multiple: options.multiple ? 'reset' : false, 1544 1596 editable: true, … … 1566 1618 library: media.query( _.defaults({ 1567 1619 type: 'image' 1568 }, options.library ) ), 1569 1570 selection: new media.model.Selection( selection.models, { 1571 multiple: 'add' 1572 }) 1620 }, options.library ) ) 1573 1621 }), 1574 1622
Note: See TracChangeset
for help on using the changeset viewer.