Make WordPress Core

Changeset 28048


Ignore:
Timestamp:
04/08/2014 03:53:42 PM (11 years ago)
Author:
wonderboymusic
Message:

Restore GalleryAdd() and GalleryEdit() in media-views.js to ensure back-compat.

See [27362].

File:
1 edited

Legend:

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

    r28046 r28048  
    766766        activate: function() {
    767767            this.frame.modal.$el.addClass('image-details');
     768        }
     769    });
     770
     771    /**
     772     * wp.media.controller.GalleryEdit
     773     *
     774     * @constructor
     775     * @augments wp.media.controller.Library
     776     * @augments wp.media.controller.State
     777     * @augments Backbone.Model
     778     */
     779    media.controller.GalleryEdit = media.controller.Library.extend({
     780        defaults: {
     781            id:         'gallery-edit',
     782            multiple:   false,
     783            describe:   true,
     784            edge:       199,
     785            editing:    false,
     786            sortable:   true,
     787            searchable: false,
     788            toolbar:    'gallery-edit',
     789            content:    'browse',
     790            title:      l10n.editGalleryTitle,
     791            priority:   60,
     792            dragInfo:   true,
     793
     794            // Don't sync the selection, as the Edit Gallery library
     795            // *is* the selection.
     796            syncSelection: false
     797        },
     798
     799        initialize: function() {
     800            // If we haven't been provided a `library`, create a `Selection`.
     801            if ( ! this.get('library') )
     802                this.set( 'library', new media.model.Selection() );
     803
     804            // The single `Attachment` view to be used in the `Attachments` view.
     805            if ( ! this.get('AttachmentView') )
     806                this.set( 'AttachmentView', media.view.Attachment.EditLibrary );
     807            media.controller.Library.prototype.initialize.apply( this, arguments );
     808        },
     809
     810        activate: function() {
     811            var library = this.get('library');
     812
     813            // Limit the library to images only.
     814            library.props.set( 'type', 'image' );
     815
     816            // Watch for uploaded attachments.
     817            this.get('library').observe( wp.Uploader.queue );
     818
     819            this.frame.on( 'content:render:browse', this.gallerySettings, this );
     820
     821            media.controller.Library.prototype.activate.apply( this, arguments );
     822        },
     823
     824        deactivate: function() {
     825            // Stop watching for uploaded attachments.
     826            this.get('library').unobserve( wp.Uploader.queue );
     827
     828            this.frame.off( 'content:render:browse', this.gallerySettings, this );
     829
     830            media.controller.Library.prototype.deactivate.apply( this, arguments );
     831        },
     832
     833        gallerySettings: function( browser ) {
     834            var library = this.get('library');
     835
     836            if ( ! library || ! browser )
     837                return;
     838
     839            library.gallery = library.gallery || new Backbone.Model();
     840
     841            browser.sidebar.set({
     842                gallery: new media.view.Settings.Gallery({
     843                    controller: this,
     844                    model:      library.gallery,
     845                    priority:   40
     846                })
     847            });
     848
     849            browser.toolbar.set( 'reverse', {
     850                text:     l10n.reverseOrder,
     851                priority: 80,
     852
     853                click: function() {
     854                    library.reset( library.toArray().reverse() );
     855                }
     856            });
     857        }
     858    });
     859
     860    /**
     861     * wp.media.controller.GalleryAdd
     862     *
     863     * @constructor
     864     * @augments wp.media.controller.Library
     865     * @augments wp.media.controller.State
     866     * @augments Backbone.Model
     867     */
     868    media.controller.GalleryAdd = media.controller.Library.extend({
     869        defaults: _.defaults({
     870            id:           'gallery-library',
     871            filterable:   'uploaded',
     872            multiple:     'add',
     873            menu:         'gallery',
     874            toolbar:      'gallery-add',
     875            title:        l10n.addToGalleryTitle,
     876            priority:     100,
     877
     878            // Don't sync the selection, as the Edit Gallery library
     879            // *is* the selection.
     880            syncSelection: false
     881        }, media.controller.Library.prototype.defaults ),
     882
     883        initialize: function() {
     884            // If we haven't been provided a `library`, create a `Selection`.
     885            if ( ! this.get('library') )
     886                this.set( 'library', media.query({ type: 'image' }) );
     887
     888            media.controller.Library.prototype.initialize.apply( this, arguments );
     889        },
     890
     891        activate: function() {
     892            var library = this.get('library'),
     893                edit    = this.frame.state('gallery-edit').get('library');
     894
     895            if ( this.editLibrary && this.editLibrary !== edit )
     896                library.unobserve( this.editLibrary );
     897
     898            // Accepts attachments that exist in the original library and
     899            // that do not exist in gallery's library.
     900            library.validator = function( attachment ) {
     901                return !! this.mirroring.get( attachment.cid ) && ! edit.get( attachment.cid ) && media.model.Selection.prototype.validator.apply( this, arguments );
     902            };
     903
     904            // Reset the library to ensure that all attachments are re-added
     905            // to the collection. Do so silently, as calling `observe` will
     906            // trigger the `reset` event.
     907            library.reset( library.mirroring.models, { silent: true });
     908            library.observe( edit );
     909            this.editLibrary = edit;
     910
     911            media.controller.Library.prototype.activate.apply( this, arguments );
    768912        }
    769913    });
     
    19622106
    19632107                // Gallery states.
    1964                 new media.controller.CollectionEdit({
    1965                     type:           'image',
    1966                     collectionType: 'gallery',
    1967                     title:           l10n.editGalleryTitle,
    1968                     SettingsView:    media.view.Settings.Gallery,
    1969                     library:         options.selection,
    1970                     editing:         options.editing,
    1971                     menu:           'gallery'
     2108                new media.controller.GalleryEdit({
     2109                    library: options.selection,
     2110                    editing: options.editing,
     2111                    menu:    'gallery'
    19722112                }),
    19732113
    1974                 new media.controller.CollectionAdd({
    1975                     type:           'image',
    1976                     collectionType: 'gallery',
    1977                     title:          l10n.addToGalleryTitle
    1978                 }),
     2114                new media.controller.GalleryAdd(),
    19792115
    19802116                new media.controller.Library({
Note: See TracChangeset for help on using the changeset viewer.