forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinline.js
More file actions
143 lines (123 loc) · 3.45 KB
/
inline.js
File metadata and controls
143 lines (123 loc) · 3.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
var View = wp.media.View,
UploaderInline;
/**
* wp.media.view.UploaderInline
*
* The inline uploader that shows up in the 'Upload Files' tab.
*
* @memberOf wp.media.view
*
* @class
* @augments wp.media.View
* @augments wp.Backbone.View
* @augments Backbone.View
*/
UploaderInline = View.extend(/** @lends wp.media.view.UploaderInline.prototype */{
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;
},
/**
* @return {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();
},
/**
* @return {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();
}
},
/**
* @return {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;
$browser[0].setAttribute( 'aria-describedby', $placeholder[0].getAttribute('aria-describedby') );
$placeholder.replaceWith( $browser.show() );
}
this.refresh();
return this;
},
show: function() {
this.$el.removeClass( 'hidden' );
if ( this.controller.$uploaderToggler && this.controller.$uploaderToggler.length ) {
this.controller.$uploaderToggler.attr( 'aria-expanded', 'true' );
}
},
hide: function() {
this.$el.addClass( 'hidden' );
if ( this.controller.$uploaderToggler && this.controller.$uploaderToggler.length ) {
this.controller.$uploaderToggler
.attr( 'aria-expanded', 'false' )
// Move focus back to the toggle button when closing the uploader.
.trigger( 'focus' );
}
}
});
module.exports = UploaderInline;