Make WordPress Core

Changeset 22583


Ignore:
Timestamp:
11/14/2012 10:40:34 PM (14 years ago)
Author:
koopersmith
Message:

Media: Unify the "Insert" and "Insert.Post" toolbars. see #21390.

File:
1 edited

Legend:

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

    r22580 r22583  
    12491249                // Toolbars
    12501250                mainAttachmentsToolbar: function() {
    1251                         this.toolbar.view( new media.view.Toolbar.Insert.Post({
     1251                        this.toolbar.view( new media.view.Toolbar.Insert({
    12521252                                controller: this
    12531253                        }) );
     
    17391739                initialize: function() {
    17401740                        var controller = this.options.controller,
    1741                                 selection = controller.state().get('selection');
     1741                                selection = controller.state().get('selection'),
     1742                                selectionToLibrary;
     1743
     1744                        selectionToLibrary = function( state, filter ) {
     1745                                return function() {
     1746                                        var controller = this.controller,
     1747                                                selection = controller.state().get('selection'),
     1748                                                edit = controller.get( state ),
     1749                                                models = filter ? filter( selection ) : selection.models;
     1750
     1751                                        edit.set( 'library', new media.model.Selection( models, {
     1752                                                props:    selection.props.toJSON(),
     1753                                                multiple: true
     1754                                        }) );
     1755
     1756                                        this.controller.state( state );
     1757                                };
     1758                        };
    17421759
    17431760                        this.options.items = _.defaults( this.options.items || {}, {
     
    17581775                                                selection.clear();
    17591776                                        }
    1760                                 }
    1761                         });
    1762 
    1763                         media.view.Toolbar.prototype.initialize.apply( this, arguments );
    1764                 },
    1765 
    1766                 refresh: function() {
    1767                         var selection = this.controller.state().get('selection');
    1768                         this.get('insert').model.set( 'disabled', ! selection.length );
    1769                 }
    1770         });
    1771 
    1772         // wp.media.view.Toolbar.Insert.Post
    1773         // ---------------------------------
    1774         media.view.Toolbar.Insert.Post = media.view.Toolbar.Insert.extend({
    1775                 initialize: function() {
    1776                         var selectionToLibrary = function( state, filter ) {
    1777                                         return function() {
    1778                                                 var controller = this.controller,
    1779                                                         selection = controller.state().get('selection'),
    1780                                                         edit = controller.get( state ),
    1781                                                         models = filter ? filter( selection ) : selection.models;
    1782 
    1783                                                 edit.set( 'library', new media.model.Selection( models, {
    1784                                                         props:    selection.props.toJSON(),
    1785                                                         multiple: true
    1786                                                 }) );
    1787 
    1788                                                 this.controller.state( state );
    1789                                         };
    1790                                 };
    1791 
    1792                         this.options.items = _.defaults( this.options.items || {}, {
     1777                                },
     1778
    17931779                                gallery: {
    17941780                                        text:     l10n.createNewGallery,
     
    18061792                        });
    18071793
    1808                         media.view.Toolbar.Insert.prototype.initialize.apply( this, arguments );
     1794                        media.view.Toolbar.prototype.initialize.apply( this, arguments );
    18091795                },
    18101796
     
    18131799                                count = selection.length;
    18141800
    1815                         // Call the parent's `refresh()` method.
    1816                         media.view.Toolbar.Insert.prototype.refresh.apply( this, arguments );
     1801                        this.get('insert').model.set( 'disabled', ! selection.length );
    18171802
    18181803                        // Check if every attachment in the selection is an image.
Note: See TracChangeset for help on using the changeset viewer.