Make WordPress Core

Changeset 27322


Ignore:
Timestamp:
02/27/2014 11:03:02 PM (13 years ago)
Author:
wonderboymusic
Message:

Rather than extending media.controller.CollectionAdd 3 times, make it a constructor that dynamically extends media.controller.Library and use instances of it instead.

See #26631.

File:
1 edited

Legend:

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

    r27309 r27322  
    868868         * wp.media.controller.CollectionAdd
    869869         *
    870          * @static
    871          * @param {string} prop The shortcode slug
    872          * @param {object} args
    873          * @returns {wp.media.controller.Library}
    874          */
    875         media.controller.CollectionAdd = function ( prop, args ) {
    876                 /**
    877                  * @constructor
    878                  * @augments wp.media.controller.Library
    879                  * @augments wp.media.controller.State
    880                  * @augments Backbone.Model
    881                  */
    882                 return media.controller.Library.extend({
    883                         defaults: _.defaults({
    884                                 id:           prop + '-library',
    885                                 filterable:   'uploaded',
    886                                 multiple:     'add',
    887                                 menu:         prop,
    888                                 toolbar:      prop + '-add',
    889                                 priority:     100,
     870         * @constructor
     871         * @augments wp.media.controller.Library
     872         * @augments wp.media.controller.State
     873         * @augments Backbone.Model
     874         */
     875        media.controller.CollectionAdd = function (attributes) {
     876                var ExtendedLibrary, extended = _.extend( attributes, {
     877                        defaults: _.defaults( {
     878                                id: attributes.tag + '-library',
     879                                title: attributes.title,
     880                                menu: attributes.tag,
     881                                toolbar: attributes.tag + '-add',
     882                                filterable: 'uploaded',
     883                                multiple:   'add',
     884                                priority:   100,
    890885                                syncSelection: false
    891                         }, args.defaults || {}, media.controller.Library.prototype.defaults ),
     886                        }, media.controller.Library.prototype.defaults ),
     887
    892888                        initialize: function() {
    893889                                // If we haven't been provided a `library`, create a `Selection`.
    894890                                if ( ! this.get('library') ) {
    895                                         this.set( 'library', media.query({ type: args.type }) );
     891                                        this.set( 'library', media.query({ type: this.type }) );
    896892                                }
    897893                                media.controller.Library.prototype.initialize.apply( this, arguments );
     
    900896                        activate: function() {
    901897                                var library = this.get('library'),
    902                                         edit    = this.frame.state(prop + '-edit').get('library');
     898                                        edit    = this.frame.state( this.tag + '-edit' ).get('library');
    903899
    904900                                if ( this.editLibrary && this.editLibrary !== edit ) {
     
    921917                                media.controller.Library.prototype.activate.apply( this, arguments );
    922918                        }
    923                 });
     919                } );
     920                ExtendedLibrary = media.controller.Library.extend( extended );
     921
     922                return new ExtendedLibrary();
    924923        };
    925924
     
    931930                defaults: {
    932931                        title: l10n.editGalleryTitle
    933                 }
    934         });
    935 
    936         // wp.media.controller.GalleryAdd
    937         // ---------------------------------
    938         media.controller.GalleryAdd = media.controller.CollectionAdd( 'gallery', {
    939                 type: 'image',
    940                 defaults: {
    941                         title: l10n.addToGalleryTitle
    942932                }
    943933        });
     
    955945        });
    956946
    957         // wp.media.controller.PlaylistAdd
    958         // ---------------------------------
    959         media.controller.PlaylistAdd = media.controller.CollectionAdd( 'playlist', {
    960                 type: 'audio',
    961                 defaults: {
    962                         title: l10n.addToPlaylistTitle
    963                 }
    964         });
    965 
    966947        // wp.media.controller.VideoPlaylistEdit
    967948        // -------------------------------
     
    973954                        title: l10n.editVideoPlaylistTitle,
    974955                        dragInfo : false
    975                 }
    976         });
    977 
    978         // wp.media.controller.VideoPlaylistAdd
    979         // ---------------------------------
    980         media.controller.VideoPlaylistAdd = media.controller.CollectionAdd( 'video-playlist', {
    981                 type: 'video',
    982                 defaults: {
    983                         title: l10n.addToVideoPlaylistTitle
    984956                }
    985957        });
     
    18111783                                }),
    18121784
    1813                                 new media.controller.GalleryAdd(),
     1785                                new media.controller.CollectionAdd({
     1786                                        tag: 'gallery',
     1787                                        type: 'image',
     1788                                        title: l10n.addToGalleryTitle
     1789                                }),
    18141790
    18151791                                new media.controller.Library({
     
    18341810                                }),
    18351811
    1836                                 new media.controller.PlaylistAdd(),
     1812                                new media.controller.CollectionAdd({
     1813                                        tag: 'playlist',
     1814                                        type: 'audio',
     1815                                        title: l10n.addToPlaylistTitle
     1816                                }),
    18371817
    18381818                                new media.controller.Library({
     
    18571837                                }),
    18581838
    1859                                 new media.controller.VideoPlaylistAdd()
     1839                                new media.controller.CollectionAdd({
     1840                                        tag: 'video-playlist',
     1841                                        type: 'video',
     1842                                        title: l10n.addToVideoPlaylistTitle
     1843                                })
    18601844                        ]);
    18611845
Note: See TracChangeset for help on using the changeset viewer.