Changeset 27841
- Timestamp:
- 03/29/2014 08:01:13 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/js/media-views.js
r27840 r27841 1886 1886 media.view.MediaFrame.Post = media.view.MediaFrame.Select.extend({ 1887 1887 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 1888 1899 _.defaults( this.options, { 1889 1900 multiple: true, … … 1896 1907 media.view.MediaFrame.Select.prototype.initialize.apply( this, arguments ); 1897 1908 this.createIframeStates(); 1909 1898 1910 }, 1899 1911 … … 2033 2045 2034 2046 bindHandlers: function() { 2035 /** 2036 * call 'bindHandlers' directly on the parent class 2037 */ 2047 var handlers, checkCounts; 2048 2038 2049 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 2039 2062 this.on( 'menu:create:gallery', this.createMenu, this ); 2040 2063 this.on( 'menu:create:playlist', this.createMenu, this ); … … 2047 2070 this.on( 'toolbar:create:main-embed', this.mainEmbedToolbar, this ); 2048 2071 2049 varhandlers = {2072 handlers = { 2050 2073 menu: { 2051 2074 'default': 'mainMenu', … … 2082 2105 }, 2083 2106 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 2084 2123 // Menus 2085 2124 /** … … 2093 2132 }) 2094 2133 }); 2134 }, 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 } 2095 2143 }, 2096 2144 /** … … 4067 4115 deselect: function() { 4068 4116 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'); 4069 4137 } 4070 4138 });
Note: See TracChangeset
for help on using the changeset viewer.