Changeset 23068
- Timestamp:
- 12/05/2012 09:25:17 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/js/media-views.js
r23067 r23068 390 390 391 391 activate: function() { 392 if ( this.get('syncLastSelection') ) {392 if ( this.get('syncLastSelection') ) 393 393 this.getLastSelection(); 394 }395 396 this._excludeStateLibrary();397 this.buildComposite();398 this.on( 'change:library change:exclude', this.buildComposite, this );399 this.on( 'change:excludeState', this._excludeState, this );400 394 401 395 wp.Uploader.queue.on( 'add', this.uploading, this ); … … 419 413 420 414 wp.Uploader.queue.off( null, null, this ); 421 422 this.off( 'change:excludeState', this._excludeState, this );423 this.off( 'change:library change:exclude', this.buildComposite, this );424 425 this.destroyComposite();426 415 }, 427 416 … … 520 509 if ( view && view.get( mode ) ) 521 510 setUserSetting( 'libraryContent', mode ); 522 },523 524 buildComposite: function() {525 var original = this.get('_library'),526 exclude = this.get('exclude'),527 composite;528 529 this.destroyComposite();530 if ( ! this.get('exclude') )531 return;532 533 // Remember the state's original library.534 if ( ! original )535 this.set( '_library', original = this.get('library') );536 537 // Create a composite library in its place.538 composite = new media.model.Attachments( null, {539 props: _.pick( original.props.toJSON(), 'order', 'orderby' )540 });541 542 // Accepts attachments that exist in the original library and543 // that do not exist in the excluded library.544 composite.validator = function( attachment ) {545 return !! original.getByCid( attachment.cid ) && ! exclude.getByCid( attachment.cid );546 };547 548 composite.mirror( original ).observe( exclude );549 550 this.set( 'library', composite );551 },552 553 destroyComposite: function() {554 var composite = this.get('library'),555 original = this.get('_library');556 557 if ( ! original )558 return;559 560 composite.unobserve();561 this.set( 'library', original );562 this.unset('_library');563 },564 565 _excludeState: function() {566 var current = this.get('excludeState'),567 previous = this.previous('excludeState');568 569 if ( previous )570 this.frame.state( previous ).off( 'change:library', this._excludeStateLibrary, this );571 572 if ( current )573 this.frame.state( current ).on( 'change:library', this._excludeStateLibrary, this );574 },575 576 _excludeStateLibrary: function() {577 var current = this.get('excludeState');578 579 if ( ! current )580 return;581 582 this.set( 'exclude', this.frame.state( current ).get('library') );583 511 } 584 512 }); … … 660 588 } 661 589 }); 590 } 591 }); 592 593 // wp.media.controller.GalleryAdd 594 // --------------------------------- 595 media.controller.GalleryAdd = media.controller.Library.extend({ 596 defaults: _.defaults({ 597 id: 'gallery-library', 598 filterable: 'uploaded', 599 multiple: 'add', 600 menu: 'gallery', 601 toolbar: 'gallery-add', 602 title: l10n.addToGalleryTitle, 603 priority: 100 604 }, media.controller.Library.prototype.defaults ), 605 606 initialize: function() { 607 // If we haven't been provided a `library`, create a `Selection`. 608 if ( ! this.get('library') ) 609 this.set( 'library', media.query({ type: 'image' }) ); 610 611 media.controller.Library.prototype.initialize.apply( this, arguments ); 612 }, 613 614 activate: function() { 615 var library = this.get('library'), 616 edit = this.frame.state('gallery-edit').get('library'); 617 618 if ( this.editLibrary && this.editLibrary !== edit ) 619 library.unobserve( this.editLibrary ); 620 621 // Accepts attachments that exist in the original library and 622 // that do not exist in gallery's library. 623 library.validator = function( attachment ) { 624 return !! this.mirroring.getByCid( attachment.cid ) && ! edit.getByCid( attachment.cid ) && media.model.Selection.prototype.validator.apply( this, arguments ); 625 }; 626 627 library.observe( edit ); 628 this.editLibrary = edit; 629 630 media.controller.Library.prototype.activate.apply( this, arguments ); 662 631 } 663 632 }); … … 1595 1564 }), 1596 1565 1597 new media.controller.Library({ 1598 id: 'gallery-library', 1599 library: media.query({ type: 'image' }), 1600 filterable: 'uploaded', 1601 multiple: 'add', 1602 menu: 'gallery', 1603 toolbar: 'gallery-add', 1604 excludeState: 'gallery-edit', 1605 title: l10n.addToGalleryTitle, 1606 priority: 100 1607 }) 1566 new media.controller.GalleryAdd() 1608 1567 ]); 1609 1568 … … 1837 1796 text: l10n.addToGallery, 1838 1797 priority: 80, 1798 requires: { selection: true }, 1839 1799 1840 1800 click: function() {
Note: See TracChangeset
for help on using the changeset viewer.