mirror of
https://github.com/WordPress/WordPress.git
synced 2025-01-04 07:28:22 +01:00
d568679946
* Add a new folder in `wp-includes/js`, `media` * Create manifest files for `views`, `models`, `grid`, and `audio-video` * Make `browserify` an `npm` dependency * Add Grunt tasks for `browserify` and `uglify:media` on `build` and `watch` * Update the paths loaded for media files in `script-loader` * All new files were created using `svn cp` from their original location Please run `npm install`. While developing media JS, you must run `grunt watch`. See #28510. Built from https://develop.svn.wordpress.org/trunk@31373 git-svn-id: http://core.svn.wordpress.org/trunk@31354 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 = require( '../view.js' ),
|
|
UploaderStatus = require( './status.js' ),
|
|
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 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; |