~ubuntu-branches/debian/jessie/wordpress/jessie

« back to all changes in this revision

Viewing changes to wp-includes/js/plupload/wp-plupload.js

  • Committer: Package Import Robot
  • Author(s): Craig Small
  • Date: 2014-04-17 20:56:19 UTC
  • mfrom: (1.2.35)
  • Revision ID: package-import@ubuntu.com-20140417205619-nurbet6eho4yvwfv
Tags: 3.9+dfsg-1
* New upstream release
* 3.9 seems to handle different locations for plugins so the
  plugin directory handling patches have been cut back.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 
3
3
window.wp = window.wp || {};
4
4
 
5
 
(function( exports, $ ) {
 
5
( function( exports, $ ) {
6
6
        var Uploader;
7
7
 
8
 
        if ( typeof _wpPluploadSettings === 'undefined' )
 
8
        if ( typeof _wpPluploadSettings === 'undefined' ) {
9
9
                return;
 
10
        }
10
11
 
11
12
        /**
12
13
         * An object that helps create a WordPress uploader using plupload.
24
25
         */
25
26
        Uploader = function( options ) {
26
27
                var self = this,
 
28
                        isIE = navigator.userAgent.indexOf('Trident/') != -1 || navigator.userAgent.indexOf('MSIE ') != -1,
27
29
                        elements = {
28
30
                                container: 'container',
29
31
                                browser:   'browse_button',
37
39
 
38
40
                this.supported = this.supports.upload;
39
41
 
40
 
                if ( ! this.supported )
 
42
                if ( ! this.supported ) {
41
43
                        return;
 
44
                }
42
45
 
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 );
52
55
 
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 );
 
60
                        }
57
61
                }
58
62
 
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 ) {
62
 
                        if ( ! this[ key ] )
 
66
                        if ( ! this[ key ] ) {
63
67
                                continue;
 
68
                        }
64
69
 
65
70
                        this[ key ] = $( this[ key ] ).first();
66
71
 
69
74
                                continue;
70
75
                        }
71
76
 
72
 
                        if ( ! this[ key ].prop('id') )
 
77
                        if ( ! this[ key ].prop('id') ) {
73
78
                                this[ key ].prop( 'id', '__wp-uploader-id-' + Uploader.uuid++ );
 
79
                        }
 
80
 
74
81
                        this.plupload[ elements[ key ] ] = this[ key ].prop('id');
75
82
                }
76
83
 
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 ) ) {
79
86
                        return;
 
87
                }
 
88
 
 
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' ) ) ) {
 
92
 
 
93
                        this.plupload.required_features = this.plupload.required_features || {};
 
94
                        this.plupload.required_features.send_binary_string = true;
 
95
                }
80
96
 
81
97
                this.uploader = new plupload.Uploader( this.plupload );
82
98
                delete this.plupload;
86
102
                delete this.params;
87
103
 
88
104
                error = function( message, data, file ) {
89
 
                        if ( file.attachment )
 
105
                        if ( file.attachment ) {
90
106
                                file.attachment.destroy();
 
107
                        }
91
108
 
92
109
                        Uploader.errors.unshift({
93
110
                                message: message || pluploadL10n.default_error,
98
115
                        self.error( message, data, file );
99
116
                };
100
117
 
101
 
                this.uploader.init();
102
 
 
103
 
                this.supports.dragdrop = this.uploader.features.dragdrop && ! Uploader.browser.mobile;
104
 
 
105
 
                // Generate drag/drop helper classes.
106
 
                (function( dropzone, supported ) {
107
 
                        var timer, active;
108
 
 
109
 
                        if ( ! dropzone )
 
118
                this.uploader.bind( 'init', function( uploader ) {
 
119
                        var timer, active, dragdrop,
 
120
                                dropzone = self.dropzone;
 
121
 
 
122
                        dragdrop = self.supports.dragdrop = uploader.features.dragdrop && ! Uploader.browser.mobile;
 
123
 
 
124
                        // Generate drag/drop helper classes.
 
125
                        if ( ! dropzone ) {
110
126
                                return;
111
 
 
112
 
                        dropzone.toggleClass( 'supports-drag-drop', !! supported );
113
 
 
114
 
                        if ( ! supported )
 
127
                        }
 
128
 
 
129
                        dropzone.toggleClass( 'supports-drag-drop', !! dragdrop );
 
130
 
 
131
                        if ( ! dragdrop ) {
115
132
                                return dropzone.unbind('.wp-uploader');
 
133
                        }
116
134
 
117
135
                        // 'dragenter' doesn't fire correctly,
118
136
                        // simulate it with a limited 'dragover'
119
 
                        dropzone.bind( 'dragover.wp-uploader', function(){
120
 
                                if ( timer )
 
137
                        dropzone.bind( 'dragover.wp-uploader', function() {
 
138
                                if ( timer ) {
121
139
                                        clearTimeout( timer );
 
140
                                }
122
141
 
123
 
                                if ( active )
 
142
                                if ( active ) {
124
143
                                        return;
 
144
                                }
125
145
 
126
146
                                dropzone.trigger('dropzone:enter').addClass('drag-over');
127
147
                                active = true;
128
148
                        });
129
149
 
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');
139
159
                                }, 0 );
140
160
                        });
141
 
                }( this.dropzone, this.supports.dragdrop ));
 
161
 
 
162
                        $(self).trigger( 'uploader:ready' );
 
163
                });
 
164
 
 
165
                this.uploader.init();
142
166
 
143
167
                if ( this.browser ) {
144
168
                        this.browser.on( 'mouseenter', this.refresh );
153
177
                                var attributes, image;
154
178
 
155
179
                                // Ignore failed uploads.
156
 
                                if ( plupload.FAILED === file.status )
 
180
                                if ( plupload.FAILED === file.status ) {
157
181
                                        return;
 
182
                                }
158
183
 
159
184
                                // Generate attributes for a new `Attachment` model.
160
185
                                attributes = _.extend({
234
259
                        for ( key in Uploader.errorMap ) {
235
260
                                if ( pluploadError.code === plupload[ key ] ) {
236
261
                                        message = Uploader.errorMap[ key ];
237
 
                                        if ( _.isFunction( message ) )
 
262
 
 
263
                                        if ( _.isFunction( message ) ) {
238
264
                                                message = message( pluploadError.file, pluploadError );
 
265
                                        }
 
266
 
239
267
                                        break;
240
268
                                }
241
269
                        }
244
272
                        up.refresh();
245
273
                });
246
274
 
247
 
                this.init();
 
275
                this.uploader.bind( 'PostInit', function() {
 
276
                        self.init();
 
277
                });
248
278
        };
249
279
 
250
280
        // Adds the 'defaults' and 'browser' properties.
282
312
                 *    Sets values for a map of data.
283
313
                 */
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 ];
 
317
                        }
287
318
 
288
319
                        if ( arguments.length > 1 ) {
289
320
                                this.uploader.settings.multipart_params[ key ] = value;