Media Manager: Hide 'Create Playlist' menu items until the user has uploaded audio or video.
props gcorne. fixes #27554. Built from https://develop.svn.wordpress.org/trunk@27841 git-svn-id: http://core.svn.wordpress.org/trunk@27675 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
e1e7e7dacc
commit
e87e153126
|
@ -1885,6 +1885,17 @@
|
||||||
*/
|
*/
|
||||||
media.view.MediaFrame.Post = media.view.MediaFrame.Select.extend({
|
media.view.MediaFrame.Post = media.view.MediaFrame.Select.extend({
|
||||||
initialize: function() {
|
initialize: function() {
|
||||||
|
this.counts = {
|
||||||
|
audio: {
|
||||||
|
count: media.view.settings.attachmentCounts.audio,
|
||||||
|
state: 'playlist'
|
||||||
|
},
|
||||||
|
video: {
|
||||||
|
count: media.view.settings.attachmentCounts.video,
|
||||||
|
state: 'video-playlist'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
_.defaults( this.options, {
|
_.defaults( this.options, {
|
||||||
multiple: true,
|
multiple: true,
|
||||||
editing: false,
|
editing: false,
|
||||||
|
@ -1895,6 +1906,7 @@
|
||||||
*/
|
*/
|
||||||
media.view.MediaFrame.Select.prototype.initialize.apply( this, arguments );
|
media.view.MediaFrame.Select.prototype.initialize.apply( this, arguments );
|
||||||
this.createIframeStates();
|
this.createIframeStates();
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
createStates: function() {
|
createStates: function() {
|
||||||
|
@ -2032,10 +2044,21 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
bindHandlers: function() {
|
bindHandlers: function() {
|
||||||
/**
|
var handlers, checkCounts;
|
||||||
* call 'bindHandlers' directly on the parent class
|
|
||||||
*/
|
|
||||||
media.view.MediaFrame.Select.prototype.bindHandlers.apply( this, arguments );
|
media.view.MediaFrame.Select.prototype.bindHandlers.apply( this, arguments );
|
||||||
|
|
||||||
|
this.on( 'activate', this.activate, this );
|
||||||
|
|
||||||
|
// Only bother checking media type counts if one of the counts is zero
|
||||||
|
checkCounts = _.find( this.counts, function( type ) {
|
||||||
|
return type.count === 0;
|
||||||
|
} );
|
||||||
|
|
||||||
|
if ( typeof checkCounts !== 'undefined' ) {
|
||||||
|
this.listenTo( media.model.Attachments.all, 'change:type', this.mediaTypeCounts );
|
||||||
|
}
|
||||||
|
|
||||||
this.on( 'menu:create:gallery', this.createMenu, this );
|
this.on( 'menu:create:gallery', this.createMenu, this );
|
||||||
this.on( 'menu:create:playlist', this.createMenu, this );
|
this.on( 'menu:create:playlist', this.createMenu, this );
|
||||||
this.on( 'menu:create:video-playlist', this.createMenu, this );
|
this.on( 'menu:create:video-playlist', this.createMenu, this );
|
||||||
|
@ -2046,7 +2069,7 @@
|
||||||
this.on( 'toolbar:create:featured-image', this.featuredImageToolbar, this );
|
this.on( 'toolbar:create:featured-image', this.featuredImageToolbar, this );
|
||||||
this.on( 'toolbar:create:main-embed', this.mainEmbedToolbar, this );
|
this.on( 'toolbar:create:main-embed', this.mainEmbedToolbar, this );
|
||||||
|
|
||||||
var handlers = {
|
handlers = {
|
||||||
menu: {
|
menu: {
|
||||||
'default': 'mainMenu',
|
'default': 'mainMenu',
|
||||||
'gallery': 'galleryMenu',
|
'gallery': 'galleryMenu',
|
||||||
|
@ -2081,6 +2104,22 @@
|
||||||
}, this );
|
}, this );
|
||||||
},
|
},
|
||||||
|
|
||||||
|
activate: function() {
|
||||||
|
// Hide menu items for states tied to particular media types if there are no items
|
||||||
|
_.each( this.counts, function( type ) {
|
||||||
|
if ( type.count < 1 ) {
|
||||||
|
this.menuItemVisibility( type.state, 'hide' );
|
||||||
|
}
|
||||||
|
}, this );
|
||||||
|
},
|
||||||
|
|
||||||
|
mediaTypeCounts: function( model, attr ) {
|
||||||
|
if ( typeof this.counts[ attr ] !== 'undefined' && this.counts[ attr ].count < 1 ) {
|
||||||
|
this.counts[ attr ].count++;
|
||||||
|
this.menuItemVisibility( this.counts[ attr ].state, 'show' );
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
// Menus
|
// Menus
|
||||||
/**
|
/**
|
||||||
* @param {wp.Backbone.View} view
|
* @param {wp.Backbone.View} view
|
||||||
|
@ -2093,6 +2132,15 @@
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
menuItemVisibility: function( state, visibility ) {
|
||||||
|
var menu = this.menu.get();
|
||||||
|
if ( visibility === 'hide' ) {
|
||||||
|
menu.hide( state );
|
||||||
|
} else if ( visibility === 'show' ) {
|
||||||
|
menu.show( state );
|
||||||
|
}
|
||||||
|
},
|
||||||
/**
|
/**
|
||||||
* @param {wp.Backbone.View} view
|
* @param {wp.Backbone.View} view
|
||||||
*/
|
*/
|
||||||
|
@ -4066,6 +4114,26 @@
|
||||||
|
|
||||||
deselect: function() {
|
deselect: function() {
|
||||||
this.$el.children().removeClass('active');
|
this.$el.children().removeClass('active');
|
||||||
|
},
|
||||||
|
|
||||||
|
hide: function( id ) {
|
||||||
|
var view = this.get( id );
|
||||||
|
|
||||||
|
if ( ! view ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
view.$el.addClass('hidden');
|
||||||
|
},
|
||||||
|
|
||||||
|
show: function( id ) {
|
||||||
|
var view = this.get( id );
|
||||||
|
|
||||||
|
if ( ! view ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
view.$el.removeClass('hidden');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue