3
3
window.wp = window.wp || {};
5
(function( exports, $ ) {
5
( function( exports, $ ) {
8
if ( typeof _wpPluploadSettings === 'undefined' )
8
if ( typeof _wpPluploadSettings === 'undefined' ) {
12
13
* An object that helps create a WordPress uploader using plupload.
38
40
this.supported = this.supports.upload;
40
if ( ! this.supported )
42
if ( ! this.supported ) {
43
46
// Use deep extend to ensure that multipart_params and other objects are cloned.
44
47
this.plupload = $.extend( true, { multipart_params: {} }, Uploader.defaults );
53
56
// Proxy all methods so this always refers to the current instance.
54
57
for ( key in this ) {
55
if ( $.isFunction( this[ key ] ) )
58
if ( $.isFunction( this[ key ] ) ) {
56
59
this[ key ] = $.proxy( this[ key ], this );
59
63
// Ensure all elements are jQuery elements and have id attributes
60
64
// Then set the proper plupload arguments to the ids.
61
65
for ( key in elements ) {
66
if ( ! this[ key ] ) {
65
70
this[ key ] = $( this[ key ] ).first();
72
if ( ! this[ key ].prop('id') )
77
if ( ! this[ key ].prop('id') ) {
73
78
this[ key ].prop( 'id', '__wp-uploader-id-' + Uploader.uuid++ );
74
81
this.plupload[ elements[ key ] ] = this[ key ].prop('id');
77
84
// If the uploader has neither a browse button nor a dropzone, bail.
78
if ( ! ( this.browser && this.browser.length ) && ! ( this.dropzone && this.dropzone.length ) )
85
if ( ! ( this.browser && this.browser.length ) && ! ( this.dropzone && this.dropzone.length ) ) {
89
// Make sure flash sends cookies (seems in IE it does without switching to urlstream mode)
90
if ( ! isIE && 'flash' === plupload.predictRuntime( this.plupload ) &&
91
( ! this.plupload.required_features || ! this.plupload.required_features.hasOwnProperty( 'send_binary_string' ) ) ) {
93
this.plupload.required_features = this.plupload.required_features || {};
94
this.plupload.required_features.send_binary_string = true;
81
97
this.uploader = new plupload.Uploader( this.plupload );
82
98
delete this.plupload;
86
102
delete this.params;
88
104
error = function( message, data, file ) {
89
if ( file.attachment )
105
if ( file.attachment ) {
90
106
file.attachment.destroy();
92
109
Uploader.errors.unshift({
93
110
message: message || pluploadL10n.default_error,
98
115
self.error( message, data, file );
101
this.uploader.init();
103
this.supports.dragdrop = this.uploader.features.dragdrop && ! Uploader.browser.mobile;
105
// Generate drag/drop helper classes.
106
(function( dropzone, supported ) {
118
this.uploader.bind( 'init', function( uploader ) {
119
var timer, active, dragdrop,
120
dropzone = self.dropzone;
122
dragdrop = self.supports.dragdrop = uploader.features.dragdrop && ! Uploader.browser.mobile;
124
// Generate drag/drop helper classes.
112
dropzone.toggleClass( 'supports-drag-drop', !! supported );
129
dropzone.toggleClass( 'supports-drag-drop', !! dragdrop );
115
132
return dropzone.unbind('.wp-uploader');
117
135
// 'dragenter' doesn't fire correctly,
118
136
// simulate it with a limited 'dragover'
119
dropzone.bind( 'dragover.wp-uploader', function(){
137
dropzone.bind( 'dragover.wp-uploader', function() {
121
139
clearTimeout( timer );
126
146
dropzone.trigger('dropzone:enter').addClass('drag-over');
130
dropzone.bind('dragleave.wp-uploader, drop.wp-uploader', function(){
150
dropzone.bind('dragleave.wp-uploader, drop.wp-uploader', function() {
131
151
// Using an instant timer prevents the drag-over class from
132
152
// being quickly removed and re-added when elements inside the
133
153
// dropzone are repositioned.
138
158
dropzone.trigger('dropzone:leave').removeClass('drag-over');
141
}( this.dropzone, this.supports.dragdrop ));
162
$(self).trigger( 'uploader:ready' );
165
this.uploader.init();
143
167
if ( this.browser ) {
144
168
this.browser.on( 'mouseenter', this.refresh );
234
259
for ( key in Uploader.errorMap ) {
235
260
if ( pluploadError.code === plupload[ key ] ) {
236
261
message = Uploader.errorMap[ key ];
237
if ( _.isFunction( message ) )
263
if ( _.isFunction( message ) ) {
238
264
message = message( pluploadError.file, pluploadError );
282
312
* Sets values for a map of data.
284
314
param: function( key, value ) {
285
if ( arguments.length === 1 && typeof key === 'string' )
315
if ( arguments.length === 1 && typeof key === 'string' ) {
286
316
return this.uploader.settings.multipart_params[ key ];
288
319
if ( arguments.length > 1 ) {
289
320
this.uploader.settings.multipart_params[ key ] = value;