mirror of
https://github.com/WordPress/WordPress.git
synced 2025-02-14 03:21:55 +01:00
Media: Unify the "Insert" and "Insert.Post" toolbars. see #21390.
git-svn-id: http://core.svn.wordpress.org/trunk@22583 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
d6813ffb35
commit
511c14e4ed
@ -1248,7 +1248,7 @@
|
|||||||
|
|
||||||
// Toolbars
|
// Toolbars
|
||||||
mainAttachmentsToolbar: function() {
|
mainAttachmentsToolbar: function() {
|
||||||
this.toolbar.view( new media.view.Toolbar.Insert.Post({
|
this.toolbar.view( new media.view.Toolbar.Insert({
|
||||||
controller: this
|
controller: this
|
||||||
}) );
|
}) );
|
||||||
},
|
},
|
||||||
@ -1738,7 +1738,24 @@
|
|||||||
media.view.Toolbar.Insert = media.view.Toolbar.extend({
|
media.view.Toolbar.Insert = media.view.Toolbar.extend({
|
||||||
initialize: function() {
|
initialize: function() {
|
||||||
var controller = this.options.controller,
|
var controller = this.options.controller,
|
||||||
selection = controller.state().get('selection');
|
selection = controller.state().get('selection'),
|
||||||
|
selectionToLibrary;
|
||||||
|
|
||||||
|
selectionToLibrary = function( state, filter ) {
|
||||||
|
return function() {
|
||||||
|
var controller = this.controller,
|
||||||
|
selection = controller.state().get('selection'),
|
||||||
|
edit = controller.get( state ),
|
||||||
|
models = filter ? filter( selection ) : selection.models;
|
||||||
|
|
||||||
|
edit.set( 'library', new media.model.Selection( models, {
|
||||||
|
props: selection.props.toJSON(),
|
||||||
|
multiple: true
|
||||||
|
}) );
|
||||||
|
|
||||||
|
this.controller.state( state );
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
this.options.items = _.defaults( this.options.items || {}, {
|
this.options.items = _.defaults( this.options.items || {}, {
|
||||||
selection: new media.view.Selection({
|
selection: new media.view.Selection({
|
||||||
@ -1757,39 +1774,8 @@
|
|||||||
controller.state().trigger( 'insert', selection );
|
controller.state().trigger( 'insert', selection );
|
||||||
selection.clear();
|
selection.clear();
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
});
|
|
||||||
|
|
||||||
media.view.Toolbar.prototype.initialize.apply( this, arguments );
|
|
||||||
},
|
|
||||||
|
|
||||||
refresh: function() {
|
|
||||||
var selection = this.controller.state().get('selection');
|
|
||||||
this.get('insert').model.set( 'disabled', ! selection.length );
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// wp.media.view.Toolbar.Insert.Post
|
|
||||||
// ---------------------------------
|
|
||||||
media.view.Toolbar.Insert.Post = media.view.Toolbar.Insert.extend({
|
|
||||||
initialize: function() {
|
|
||||||
var selectionToLibrary = function( state, filter ) {
|
|
||||||
return function() {
|
|
||||||
var controller = this.controller,
|
|
||||||
selection = controller.state().get('selection'),
|
|
||||||
edit = controller.get( state ),
|
|
||||||
models = filter ? filter( selection ) : selection.models;
|
|
||||||
|
|
||||||
edit.set( 'library', new media.model.Selection( models, {
|
|
||||||
props: selection.props.toJSON(),
|
|
||||||
multiple: true
|
|
||||||
}) );
|
|
||||||
|
|
||||||
this.controller.state( state );
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
this.options.items = _.defaults( this.options.items || {}, {
|
|
||||||
gallery: {
|
gallery: {
|
||||||
text: l10n.createNewGallery,
|
text: l10n.createNewGallery,
|
||||||
priority: 40,
|
priority: 40,
|
||||||
@ -1805,15 +1791,14 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
media.view.Toolbar.Insert.prototype.initialize.apply( this, arguments );
|
media.view.Toolbar.prototype.initialize.apply( this, arguments );
|
||||||
},
|
},
|
||||||
|
|
||||||
refresh: function() {
|
refresh: function() {
|
||||||
var selection = this.controller.state().get('selection'),
|
var selection = this.controller.state().get('selection'),
|
||||||
count = selection.length;
|
count = selection.length;
|
||||||
|
|
||||||
// Call the parent's `refresh()` method.
|
this.get('insert').model.set( 'disabled', ! selection.length );
|
||||||
media.view.Toolbar.Insert.prototype.refresh.apply( this, arguments );
|
|
||||||
|
|
||||||
// Check if every attachment in the selection is an image.
|
// Check if every attachment in the selection is an image.
|
||||||
this.get('gallery').$el.toggle( count > 1 && selection.any( function( attachment ) {
|
this.get('gallery').$el.toggle( count > 1 && selection.any( function( attachment ) {
|
||||||
|
Loading…
Reference in New Issue
Block a user