Make WordPress Core

Ticket #27554: 27554.2.diff

File 27554.2.diff, 3.2 KB (added by gcorne, 11 years ago)
  • src/wp-includes/js/media-views.js

    diff --git src/wp-includes/js/media-views.js src/wp-includes/js/media-views.js
    index 7bcf5b5..1864f05 100644
     
    18851885         */
    18861886        media.view.MediaFrame.Post = media.view.MediaFrame.Select.extend({
    18871887                initialize: function() {
     1888                        this.counts = {
     1889                                audio: {
     1890                                        count: media.view.settings.attachmentCounts.audio,
     1891                                        state: 'playlist'
     1892                                },
     1893                                video: {
     1894                                        count: media.view.settings.attachmentCounts.video,
     1895                                        state: 'video-playlist'
     1896                                }
     1897                        };
     1898
    18881899                        _.defaults( this.options, {
    18891900                                multiple:  true,
    18901901                                editing:   false,
     
    18951906                         */
    18961907                        media.view.MediaFrame.Select.prototype.initialize.apply( this, arguments );
    18971908                        this.createIframeStates();
     1909
    18981910                },
    18991911
    19001912                createStates: function() {
     
    20322044                },
    20332045
    20342046                bindHandlers: function() {
    2035                         /**
    2036                          * call 'bindHandlers' directly on the parent class
    2037                          */
     2047                        var handlers, checkCounts;
     2048
    20382049                        media.view.MediaFrame.Select.prototype.bindHandlers.apply( this, arguments );
     2050
     2051                        this.on( 'activate', this.activate, this );
     2052
     2053                        // Only bother checking media type counts if one of the counts is zero
     2054                        checkCounts = _.find( this.counts, function( type ) {
     2055                                return type.count === 0;
     2056                        } );
     2057
     2058                        if ( typeof checkCounts !== 'undefined' ) {
     2059                                this.listenTo( media.model.Attachments.all, 'change:type', this.mediaTypeCounts );
     2060                        }
     2061
    20392062                        this.on( 'menu:create:gallery', this.createMenu, this );
    20402063                        this.on( 'menu:create:playlist', this.createMenu, this );
    20412064                        this.on( 'menu:create:video-playlist', this.createMenu, this );
     
    20462069                        this.on( 'toolbar:create:featured-image', this.featuredImageToolbar, this );
    20472070                        this.on( 'toolbar:create:main-embed', this.mainEmbedToolbar, this );
    20482071
    2049                         var handlers = {
     2072                        handlers = {
    20502073                                menu: {
    20512074                                        'default': 'mainMenu',
    20522075                                        'gallery': 'galleryMenu',
     
    20812104                        }, this );
    20822105                },
    20832106
     2107                activate: function() {
     2108                        // Hide menu items for states tied to particular media types if there are no items
     2109                        _.each( this.counts, function( type ) {
     2110                                if ( type.count < 1 ) {
     2111                                        this.menuItemVisibility( type.state, 'hide' );
     2112                                }
     2113                        }, this );
     2114                },
     2115
     2116                mediaTypeCounts: function( model, attr ) {
     2117                        if ( typeof this.counts[ attr ] !== 'undefined' && this.counts[ attr ].count < 1 ) {
     2118                                this.counts[ attr ].count++;
     2119                                this.menuItemVisibility( this.counts[ attr ].state, 'show' );
     2120                        }
     2121                },
     2122
    20842123                // Menus
    20852124                /**
    20862125                 * @param {wp.Backbone.View} view
     
    20932132                                })
    20942133                        });
    20952134                },
     2135
     2136                menuItemVisibility: function( state, visibility ) {
     2137                        var menu = this.menu.get();
     2138                        if ( visibility === 'hide' ) {
     2139                                menu.hide( state );
     2140                        } else if ( visibility === 'show' ) {
     2141                                menu.show( state );
     2142                        }
     2143                },
    20962144                /**
    20972145                 * @param {wp.Backbone.View} view
    20982146                 */
     
    40664114
    40674115                deselect: function() {
    40684116                        this.$el.children().removeClass('active');
     4117                },
     4118
     4119                hide: function( id ) {
     4120                        var view = this.get( id );
     4121
     4122                        if ( ! view ) {
     4123                                return;
     4124                        }
     4125
     4126                        view.$el.addClass('hidden');
     4127                },
     4128
     4129                show: function( id ) {
     4130                        var view = this.get( id );
     4131
     4132                        if ( ! view ) {
     4133                                return;
     4134                        }
     4135
     4136                        view.$el.removeClass('hidden');
    40694137                }
    40704138        });
    40714139