mirror of
https://github.com/WordPress/WordPress.git
synced 2025-01-27 02:31:40 +01:00
a5478d7adb
* The way that the JS modules for media are currently set up turns the existing global `wp.media` namespace into a read-only API, this is bad. * For the existing module implementation to work with plugins, those looking to override or extend a class would have to modify their own plugin to use `browserify` - we can't expect this to happen * Because the general way that plugins override media classes is via machete (resetting them to something else), we cannot use `require( 'module' )` in the internal code for media modules We CAN continue to use `require( 'fun/js' )` in the manifests for media. Future code/projects should carefully consider what is made to be public API. In 3.5, EVERYTHING was made public, so everything shall remain public. See #31684, #28510. Built from https://develop.svn.wordpress.org/trunk@31935 git-svn-id: http://core.svn.wordpress.org/trunk@31914 1a063a9b-81f0-0310-95a4-ce76da25c4cd
132 lines
2.9 KiB
JavaScript
132 lines
2.9 KiB
JavaScript
/*globals wp, _ */
|
|
|
|
/**
|
|
* wp.media.view.UploaderInline
|
|
*
|
|
* The inline uploader that shows up in the 'Upload Files' tab.
|
|
*
|
|
* @class
|
|
* @augments wp.media.View
|
|
* @augments wp.Backbone.View
|
|
* @augments Backbone.View
|
|
*/
|
|
var View = wp.media.View,
|
|
UploaderInline;
|
|
|
|
UploaderInline = View.extend({
|
|
tagName: 'div',
|
|
className: 'uploader-inline',
|
|
template: wp.template('uploader-inline'),
|
|
|
|
events: {
|
|
'click .close': 'hide'
|
|
},
|
|
|
|
initialize: function() {
|
|
_.defaults( this.options, {
|
|
message: '',
|
|
status: true,
|
|
canClose: false
|
|
});
|
|
|
|
if ( ! this.options.$browser && this.controller.uploader ) {
|
|
this.options.$browser = this.controller.uploader.$browser;
|
|
}
|
|
|
|
if ( _.isUndefined( this.options.postId ) ) {
|
|
this.options.postId = wp.media.view.settings.post.id;
|
|
}
|
|
|
|
if ( this.options.status ) {
|
|
this.views.set( '.upload-inline-status', new wp.media.view.UploaderStatus({
|
|
controller: this.controller
|
|
}) );
|
|
}
|
|
},
|
|
|
|
prepare: function() {
|
|
var suggestedWidth = this.controller.state().get('suggestedWidth'),
|
|
suggestedHeight = this.controller.state().get('suggestedHeight'),
|
|
data = {};
|
|
|
|
data.message = this.options.message;
|
|
data.canClose = this.options.canClose;
|
|
|
|
if ( suggestedWidth && suggestedHeight ) {
|
|
data.suggestedWidth = suggestedWidth;
|
|
data.suggestedHeight = suggestedHeight;
|
|
}
|
|
|
|
return data;
|
|
},
|
|
/**
|
|
* @returns {wp.media.view.UploaderInline} Returns itself to allow chaining
|
|
*/
|
|
dispose: function() {
|
|
if ( this.disposing ) {
|
|
/**
|
|
* call 'dispose' directly on the parent class
|
|
*/
|
|
return View.prototype.dispose.apply( this, arguments );
|
|
}
|
|
|
|
// Run remove on `dispose`, so we can be sure to refresh the
|
|
// uploader with a view-less DOM. Track whether we're disposing
|
|
// so we don't trigger an infinite loop.
|
|
this.disposing = true;
|
|
return this.remove();
|
|
},
|
|
/**
|
|
* @returns {wp.media.view.UploaderInline} Returns itself to allow chaining
|
|
*/
|
|
remove: function() {
|
|
/**
|
|
* call 'remove' directly on the parent class
|
|
*/
|
|
var result = View.prototype.remove.apply( this, arguments );
|
|
|
|
_.defer( _.bind( this.refresh, this ) );
|
|
return result;
|
|
},
|
|
|
|
refresh: function() {
|
|
var uploader = this.controller.uploader;
|
|
|
|
if ( uploader ) {
|
|
uploader.refresh();
|
|
}
|
|
},
|
|
/**
|
|
* @returns {wp.media.view.UploaderInline}
|
|
*/
|
|
ready: function() {
|
|
var $browser = this.options.$browser,
|
|
$placeholder;
|
|
|
|
if ( this.controller.uploader ) {
|
|
$placeholder = this.$('.browser');
|
|
|
|
// Check if we've already replaced the placeholder.
|
|
if ( $placeholder[0] === $browser[0] ) {
|
|
return;
|
|
}
|
|
|
|
$browser.detach().text( $placeholder.text() );
|
|
$browser[0].className = $placeholder[0].className;
|
|
$placeholder.replaceWith( $browser.show() );
|
|
}
|
|
|
|
this.refresh();
|
|
return this;
|
|
},
|
|
show: function() {
|
|
this.$el.removeClass( 'hidden' );
|
|
},
|
|
hide: function() {
|
|
this.$el.addClass( 'hidden' );
|
|
}
|
|
|
|
});
|
|
|
|
module.exports = UploaderInline;
|