mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-23 09:37:42 +01:00
Make CollectionEdit
and CollectionAdd
less dynamically quirky. Rename some instance properties for disambiguation. Pass some properties from options
when creating instances in wp.media.view.MediaFrame.Post
.
See #26631. Props gcorne. Built from https://develop.svn.wordpress.org/trunk@27362 git-svn-id: http://core.svn.wordpress.org/trunk@27212 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
330f27f095
commit
c0a9ee8452
@ -762,22 +762,13 @@
|
||||
/**
|
||||
* wp.media.controller.CollectionEdit
|
||||
*
|
||||
* @static
|
||||
* @param {string} prop The shortcode slug
|
||||
* @param {object} args
|
||||
* @returns {wp.media.controller.Library}
|
||||
*/
|
||||
media.controller.CollectionEdit = function ( prop, args ) {
|
||||
/**
|
||||
* @constructor
|
||||
* @augments wp.media.controller.Library
|
||||
* @augments wp.media.controller.State
|
||||
* @augments Backbone.Model
|
||||
*/
|
||||
return media.controller.Library.extend({
|
||||
defaults : _.defaults(args.defaults || {}, {
|
||||
id: prop + '-edit',
|
||||
toolbar: prop + '-edit',
|
||||
media.controller.CollectionEdit = media.controller.Library.extend({
|
||||
defaults: {
|
||||
multiple: false,
|
||||
describe: true,
|
||||
edge: 199,
|
||||
@ -787,13 +778,19 @@
|
||||
content: 'browse',
|
||||
priority: 60,
|
||||
dragInfo: true,
|
||||
SettingsView: false,
|
||||
|
||||
// Don't sync the selection, as the Edit {Collection} library
|
||||
// *is* the selection.
|
||||
syncSelection: false
|
||||
}),
|
||||
},
|
||||
|
||||
initialize: function() {
|
||||
var collectionType = this.get('collectionType');
|
||||
|
||||
this.set( 'id', collectionType + '-edit' );
|
||||
this.set( 'toolbar', collectionType + '-edit' );
|
||||
|
||||
// If we haven't been provided a `library`, create a `Selection`.
|
||||
if ( ! this.get('library') ) {
|
||||
this.set( 'library', new media.model.Selection() );
|
||||
@ -809,12 +806,12 @@
|
||||
var library = this.get('library');
|
||||
|
||||
// Limit the library to images only.
|
||||
library.props.set( 'type', args.type );
|
||||
library.props.set( 'type', this.get( 'type' ) );
|
||||
|
||||
// Watch for uploaded attachments.
|
||||
this.get('library').observe( wp.Uploader.queue );
|
||||
|
||||
this.frame.on( 'content:render:browse', this.settings, this );
|
||||
this.frame.on( 'content:render:browse', this.renderSettings, this );
|
||||
|
||||
media.controller.Library.prototype.activate.apply( this, arguments );
|
||||
},
|
||||
@ -823,31 +820,35 @@
|
||||
// Stop watching for uploaded attachments.
|
||||
this.get('library').unobserve( wp.Uploader.queue );
|
||||
|
||||
this.frame.off( 'content:render:browse', this.settings, this );
|
||||
this.frame.off( 'content:render:browse', this.renderSettings, this );
|
||||
|
||||
media.controller.Library.prototype.deactivate.apply( this, arguments );
|
||||
},
|
||||
|
||||
settings: function( browser ) {
|
||||
var library = this.get('library'), obj = {};
|
||||
renderSettings: function( browser ) {
|
||||
var library = this.get('library'),
|
||||
collectionType = this.get('collectionType'),
|
||||
dragInfoText = this.get('dragInfoText'),
|
||||
SettingsView = this.get('SettingsView'),
|
||||
obj = {};
|
||||
|
||||
if ( ! library || ! browser ) {
|
||||
return;
|
||||
}
|
||||
|
||||
library[ prop ] = library[ prop ] || new Backbone.Model();
|
||||
library[ collectionType ] = library[ collectionType ] || new Backbone.Model();
|
||||
|
||||
obj[ prop ] = new media.view.Settings[ args.settings ]({
|
||||
obj[ collectionType ] = new SettingsView({
|
||||
controller: this,
|
||||
model: library[ prop ],
|
||||
model: library[ collectionType ],
|
||||
priority: 40
|
||||
});
|
||||
|
||||
browser.sidebar.set( obj );
|
||||
|
||||
if ( args.dragInfoText ) {
|
||||
if ( dragInfoText ) {
|
||||
browser.toolbar.set( 'dragInfo', new media.View({
|
||||
el: $( '<div class="instructions">' + args.dragInfoText + '</div>' )[0],
|
||||
el: $( '<div class="instructions">' + dragInfoText + '</div>' )[0],
|
||||
priority: -40
|
||||
}) );
|
||||
}
|
||||
@ -862,7 +863,6 @@
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* wp.media.controller.CollectionAdd
|
||||
@ -872,13 +872,8 @@
|
||||
* @augments wp.media.controller.State
|
||||
* @augments Backbone.Model
|
||||
*/
|
||||
media.controller.CollectionAdd = function (attributes) {
|
||||
var ExtendedLibrary, extended = _.extend( attributes, {
|
||||
media.controller.CollectionAdd = media.controller.Library.extend({
|
||||
defaults: _.defaults( {
|
||||
id: attributes.tag + '-library',
|
||||
title: attributes.title,
|
||||
menu: attributes.tag,
|
||||
toolbar: attributes.tag + '-add',
|
||||
filterable: 'uploaded',
|
||||
multiple: 'add',
|
||||
priority: 100,
|
||||
@ -886,19 +881,26 @@
|
||||
}, media.controller.Library.prototype.defaults ),
|
||||
|
||||
initialize: function() {
|
||||
var collectionType = this.get('collectionType');
|
||||
|
||||
this.set( 'id', collectionType + '-library' );
|
||||
this.set( 'toolbar', collectionType + '-add' );
|
||||
this.set( 'menu', collectionType );
|
||||
|
||||
// If we haven't been provided a `library`, create a `Selection`.
|
||||
if ( ! this.get('library') ) {
|
||||
this.set( 'library', media.query({ type: this.type }) );
|
||||
this.set( 'library', media.query({ type: this.get('type') }) );
|
||||
}
|
||||
media.controller.Library.prototype.initialize.apply( this, arguments );
|
||||
},
|
||||
|
||||
activate: function() {
|
||||
var library = this.get('library'),
|
||||
edit = this.frame.state( this.tag + '-edit' ).get('library');
|
||||
editLibrary = this.get('editLibrary'),
|
||||
edit = this.frame.state( this.get('collectionType') + '-edit' ).get('library');
|
||||
|
||||
if ( this.editLibrary && this.editLibrary !== edit ) {
|
||||
library.unobserve( this.editLibrary );
|
||||
if ( editLibrary && editLibrary !== edit ) {
|
||||
library.unobserve( editLibrary );
|
||||
}
|
||||
|
||||
// Accepts attachments that exist in the original library and
|
||||
@ -912,48 +914,10 @@
|
||||
// trigger the `reset` event.
|
||||
library.reset( library.mirroring.models, { silent: true });
|
||||
library.observe( edit );
|
||||
this.editLibrary = edit;
|
||||
this.set('editLibrary', edit);
|
||||
|
||||
media.controller.Library.prototype.activate.apply( this, arguments );
|
||||
}
|
||||
} );
|
||||
ExtendedLibrary = media.controller.Library.extend( extended );
|
||||
|
||||
return new ExtendedLibrary();
|
||||
};
|
||||
|
||||
// wp.media.controller.GalleryEdit
|
||||
// -------------------------------
|
||||
media.controller.GalleryEdit = media.controller.CollectionEdit( 'gallery', {
|
||||
type: 'image',
|
||||
settings: 'Gallery',
|
||||
defaults: {
|
||||
title: l10n.editGalleryTitle
|
||||
}
|
||||
});
|
||||
|
||||
// wp.media.controller.PlaylistEdit
|
||||
// -------------------------------
|
||||
media.controller.PlaylistEdit = media.controller.CollectionEdit( 'playlist', {
|
||||
type: 'audio',
|
||||
settings: 'Playlist',
|
||||
dragInfoText: l10n.playlistDragInfo,
|
||||
defaults: {
|
||||
title: l10n.editPlaylistTitle,
|
||||
dragInfo : false
|
||||
}
|
||||
});
|
||||
|
||||
// wp.media.controller.VideoPlaylistEdit
|
||||
// -------------------------------
|
||||
media.controller.VideoPlaylistEdit = media.controller.CollectionEdit( 'video-playlist', {
|
||||
type: 'video',
|
||||
settings: 'Playlist',
|
||||
dragInfoText: l10n.videoPlaylistDragInfo,
|
||||
defaults: {
|
||||
title: l10n.editVideoPlaylistTitle,
|
||||
dragInfo : false
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
@ -1776,15 +1740,19 @@
|
||||
new media.controller.Embed(),
|
||||
|
||||
// Gallery states.
|
||||
new media.controller.GalleryEdit({
|
||||
new media.controller.CollectionEdit({
|
||||
type: 'image',
|
||||
collectionType: 'gallery',
|
||||
title: l10n.editGalleryTitle,
|
||||
SettingsView: media.view.Settings.Gallery,
|
||||
library: options.selection,
|
||||
editing: options.editing,
|
||||
menu: 'gallery'
|
||||
}),
|
||||
|
||||
new media.controller.CollectionAdd({
|
||||
tag: 'gallery',
|
||||
type: 'image',
|
||||
collectionType: 'gallery',
|
||||
title: l10n.addToGalleryTitle
|
||||
}),
|
||||
|
||||
@ -1803,15 +1771,21 @@
|
||||
}),
|
||||
|
||||
// Playlist states.
|
||||
new media.controller.PlaylistEdit({
|
||||
new media.controller.CollectionEdit({
|
||||
type: 'audio',
|
||||
collectionType: 'playlist',
|
||||
title: l10n.editPlaylistTitle,
|
||||
SettingsView: media.view.Settings.Playlist,
|
||||
library: options.selection,
|
||||
editing: options.editing,
|
||||
menu: 'playlist'
|
||||
menu: 'playlist',
|
||||
dragInfoText: l10n.playlistDragInfo,
|
||||
dragInfo: false
|
||||
}),
|
||||
|
||||
new media.controller.CollectionAdd({
|
||||
tag: 'playlist',
|
||||
type: 'audio',
|
||||
collectionType: 'playlist',
|
||||
title: l10n.addToPlaylistTitle
|
||||
}),
|
||||
|
||||
@ -1830,15 +1804,21 @@
|
||||
}),
|
||||
|
||||
// Video Playlist states.
|
||||
new media.controller.VideoPlaylistEdit({
|
||||
new media.controller.CollectionEdit({
|
||||
type: 'video',
|
||||
collectionType: 'video-playlist',
|
||||
title: l10n.editVideoPlaylistTitle,
|
||||
SettingsView: media.view.Settings.Playlist,
|
||||
library: options.selection,
|
||||
editing: options.editing,
|
||||
menu: 'video-playlist'
|
||||
menu: 'video-playlist',
|
||||
dragInfoText: l10n.videoPlaylistDragInfo,
|
||||
dragInfo: false
|
||||
}),
|
||||
|
||||
new media.controller.CollectionAdd({
|
||||
tag: 'video-playlist',
|
||||
type: 'video',
|
||||
collectionType: 'video-playlist',
|
||||
title: l10n.addToVideoPlaylistTitle
|
||||
})
|
||||
]);
|
||||
|
2
wp-includes/js/media-views.min.js
vendored
2
wp-includes/js/media-views.min.js
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user