WP Job Manager - Version 1.33.3

Version Description

  • Fix: Upgrade jquery-fileupload to v9.32.0
  • Fix: Set frame origin on pages where shortcodes are embedded
Download this release

Release Info

Developer automattic
Plugin Icon 128x128 WP Job Manager
Version 1.33.3
Comparing to
See all releases

Code changes from version 1.33.2 to 1.33.3

assets/js/jquery-fileupload/jquery.fileupload.js CHANGED
@@ -1,5 +1,5 @@
1
  /*
2
- * jQuery File Upload Plugin v9.30.0
3
  * https://github.com/blueimp/jQuery-File-Upload
4
  *
5
  * Copyright 2010, Sebastian Tschan
@@ -13,1490 +13,1523 @@
13
  /* global define, require, window, document, location, Blob, FormData */
14
 
15
  ;(function (factory) {
16
- 'use strict';
17
- if (typeof define === 'function' && define.amd) {
18
- // Register as an anonymous AMD module:
19
- define([
20
- 'jquery',
21
- 'jquery-ui/ui/widget'
22
- ], factory);
23
- } else if (typeof exports === 'object') {
24
- // Node/CommonJS:
25
- factory(
26
- require('jquery'),
27
- require('./vendor/jquery.ui.widget')
28
- );
29
- } else {
30
- // Browser globals:
31
- factory(window.jQuery);
32
- }
33
  }(function ($) {
34
- 'use strict';
35
-
36
- // Detect file input support, based on
37
- // http://viljamis.com/blog/2012/file-upload-support-on-mobile/
38
- $.support.fileInput = !(new RegExp(
39
- // Handle devices which give false positives for the feature detection:
40
- '(Android (1\\.[0156]|2\\.[01]))' +
41
- '|(Windows Phone (OS 7|8\\.0))|(XBLWP)|(ZuneWP)|(WPDesktop)' +
42
- '|(w(eb)?OSBrowser)|(webOS)' +
43
- '|(Kindle/(1\\.0|2\\.[05]|3\\.0))'
44
- ).test(window.navigator.userAgent) ||
45
- // Feature detection for all other devices:
46
- $('<input type="file"/>').prop('disabled'));
47
-
48
- // The FileReader API is not actually used, but works as feature detection,
49
- // as some Safari versions (5?) support XHR file uploads via the FormData API,
50
- // but not non-multipart XHR file uploads.
51
- // window.XMLHttpRequestUpload is not available on IE10, so we check for
52
- // window.ProgressEvent instead to detect XHR2 file upload capability:
53
- $.support.xhrFileUpload = !!(window.ProgressEvent && window.FileReader);
54
- $.support.xhrFormDataFileUpload = !!window.FormData;
55
-
56
- // Detect support for Blob slicing (required for chunked uploads):
57
- $.support.blobSlice = window.Blob && (Blob.prototype.slice ||
58
- Blob.prototype.webkitSlice || Blob.prototype.mozSlice);
59
-
60
- // Helper function to create drag handlers for dragover/dragenter/dragleave:
61
- function getDragHandler(type) {
62
- var isDragOver = type === 'dragover';
63
- return function (e) {
64
- e.dataTransfer = e.originalEvent && e.originalEvent.dataTransfer;
65
- var dataTransfer = e.dataTransfer;
66
- if (dataTransfer && $.inArray('Files', dataTransfer.types) !== -1 &&
67
- this._trigger(
68
- type,
69
- $.Event(type, {delegatedEvent: e})
70
- ) !== false) {
71
- e.preventDefault();
72
- if (isDragOver) {
73
- dataTransfer.dropEffect = 'copy';
74
- }
75
- }
76
- };
77
- }
78
-
79
- // The fileupload widget listens for change events on file input fields defined
80
- // via fileInput setting and paste or drop events of the given dropZone.
81
- // In addition to the default jQuery Widget methods, the fileupload widget
82
- // exposes the "add" and "send" methods, to add or directly send files using
83
- // the fileupload API.
84
- // By default, files added via file input selection, paste, drag & drop or
85
- // "add" method are uploaded immediately, but it is possible to override
86
- // the "add" callback option to queue file uploads.
87
- $.widget('blueimp.fileupload', {
88
-
89
- options: {
90
- // The drop target element(s), by the default the complete document.
91
- // Set to null to disable drag & drop support:
92
- dropZone: $(document),
93
- // The paste target element(s), by the default undefined.
94
- // Set to a DOM node or jQuery object to enable file pasting:
95
- pasteZone: undefined,
96
- // The file input field(s), that are listened to for change events.
97
- // If undefined, it is set to the file input fields inside
98
- // of the widget element on plugin initialization.
99
- // Set to null to disable the change listener.
100
- fileInput: undefined,
101
- // By default, the file input field is replaced with a clone after
102
- // each input field change event. This is required for iframe transport
103
- // queues and allows change events to be fired for the same file
104
- // selection, but can be disabled by setting the following option to false:
105
- replaceFileInput: true,
106
- // The parameter name for the file form data (the request argument name).
107
- // If undefined or empty, the name property of the file input field is
108
- // used, or "files[]" if the file input name property is also empty,
109
- // can be a string or an array of strings:
110
- paramName: undefined,
111
- // By default, each file of a selection is uploaded using an individual
112
- // request for XHR type uploads. Set to false to upload file
113
- // selections in one request each:
114
- singleFileUploads: true,
115
- // To limit the number of files uploaded with one XHR request,
116
- // set the following option to an integer greater than 0:
117
- limitMultiFileUploads: undefined,
118
- // The following option limits the number of files uploaded with one
119
- // XHR request to keep the request size under or equal to the defined
120
- // limit in bytes:
121
- limitMultiFileUploadSize: undefined,
122
- // Multipart file uploads add a number of bytes to each uploaded file,
123
- // therefore the following option adds an overhead for each file used
124
- // in the limitMultiFileUploadSize configuration:
125
- limitMultiFileUploadSizeOverhead: 512,
126
- // Set the following option to true to issue all file upload requests
127
- // in a sequential order:
128
- sequentialUploads: false,
129
- // To limit the number of concurrent uploads,
130
- // set the following option to an integer greater than 0:
131
- limitConcurrentUploads: undefined,
132
- // Set the following option to true to force iframe transport uploads:
133
- forceIframeTransport: false,
134
- // Set the following option to the location of a redirect url on the
135
- // origin server, for cross-domain iframe transport uploads:
136
- redirect: undefined,
137
- // The parameter name for the redirect url, sent as part of the form
138
- // data and set to 'redirect' if this option is empty:
139
- redirectParamName: undefined,
140
- // Set the following option to the location of a postMessage window,
141
- // to enable postMessage transport uploads:
142
- postMessage: undefined,
143
- // By default, XHR file uploads are sent as multipart/form-data.
144
- // The iframe transport is always using multipart/form-data.
145
- // Set to false to enable non-multipart XHR uploads:
146
- multipart: true,
147
- // To upload large files in smaller chunks, set the following option
148
- // to a preferred maximum chunk size. If set to 0, null or undefined,
149
- // or the browser does not support the required Blob API, files will
150
- // be uploaded as a whole.
151
- maxChunkSize: undefined,
152
- // When a non-multipart upload or a chunked multipart upload has been
153
- // aborted, this option can be used to resume the upload by setting
154
- // it to the size of the already uploaded bytes. This option is most
155
- // useful when modifying the options object inside of the "add" or
156
- // "send" callbacks, as the options are cloned for each file upload.
157
- uploadedBytes: undefined,
158
- // By default, failed (abort or error) file uploads are removed from the
159
- // global progress calculation. Set the following option to false to
160
- // prevent recalculating the global progress data:
161
- recalculateProgress: true,
162
- // Interval in milliseconds to calculate and trigger progress events:
163
- progressInterval: 100,
164
- // Interval in milliseconds to calculate progress bitrate:
165
- bitrateInterval: 500,
166
- // By default, uploads are started automatically when adding files:
167
- autoUpload: true,
168
-
169
- // Error and info messages:
170
- messages: {
171
- uploadedBytes: 'Uploaded bytes exceed file size'
172
- },
173
-
174
- // Translation function, gets the message key to be translated
175
- // and an object with context specific data as arguments:
176
- i18n: function (message, context) {
177
- message = this.messages[message] || message.toString();
178
- if (context) {
179
- $.each(context, function (key, value) {
180
- message = message.replace('{' + key + '}', value);
181
- });
182
- }
183
- return message;
184
- },
185
-
186
- // Additional form data to be sent along with the file uploads can be set
187
- // using this option, which accepts an array of objects with name and
188
- // value properties, a function returning such an array, a FormData
189
- // object (for XHR file uploads), or a simple object.
190
- // The form of the first fileInput is given as parameter to the function:
191
- formData: function (form) {
192
- return form.serializeArray();
193
- },
194
-
195
- // The add callback is invoked as soon as files are added to the fileupload
196
- // widget (via file input selection, drag & drop, paste or add API call).
197
- // If the singleFileUploads option is enabled, this callback will be
198
- // called once for each file in the selection for XHR file uploads, else
199
- // once for each file selection.
200
- //
201
- // The upload starts when the submit method is invoked on the data parameter.
202
- // The data object contains a files property holding the added files
203
- // and allows you to override plugin options as well as define ajax settings.
204
- //
205
- // Listeners for this callback can also be bound the following way:
206
- // .bind('fileuploadadd', func);
207
- //
208
- // data.submit() returns a Promise object and allows to attach additional
209
- // handlers using jQuery's Deferred callbacks:
210
- // data.submit().done(func).fail(func).always(func);
211
- add: function (e, data) {
212
- if (e.isDefaultPrevented()) {
213
- return false;
214
- }
215
- if (data.autoUpload || (data.autoUpload !== false &&
216
- $(this).fileupload('option', 'autoUpload'))) {
217
- data.process().done(function () {
218
- data.submit();
219
- });
220
- }
221
- },
222
-
223
- // Other callbacks:
224
-
225
- // Callback for the submit event of each file upload:
226
- // submit: function (e, data) {}, // .bind('fileuploadsubmit', func);
227
-
228
- // Callback for the start of each file upload request:
229
- // send: function (e, data) {}, // .bind('fileuploadsend', func);
230
-
231
- // Callback for successful uploads:
232
- // done: function (e, data) {}, // .bind('fileuploaddone', func);
233
-
234
- // Callback for failed (abort or error) uploads:
235
- // fail: function (e, data) {}, // .bind('fileuploadfail', func);
236
-
237
- // Callback for completed (success, abort or error) requests:
238
- // always: function (e, data) {}, // .bind('fileuploadalways', func);
239
-
240
- // Callback for upload progress events:
241
- // progress: function (e, data) {}, // .bind('fileuploadprogress', func);
242
-
243
- // Callback for global upload progress events:
244
- // progressall: function (e, data) {}, // .bind('fileuploadprogressall', func);
245
-
246
- // Callback for uploads start, equivalent to the global ajaxStart event:
247
- // start: function (e) {}, // .bind('fileuploadstart', func);
248
-
249
- // Callback for uploads stop, equivalent to the global ajaxStop event:
250
- // stop: function (e) {}, // .bind('fileuploadstop', func);
251
-
252
- // Callback for change events of the fileInput(s):
253
- // change: function (e, data) {}, // .bind('fileuploadchange', func);
254
-
255
- // Callback for paste events to the pasteZone(s):
256
- // paste: function (e, data) {}, // .bind('fileuploadpaste', func);
257
-
258
- // Callback for drop events of the dropZone(s):
259
- // drop: function (e, data) {}, // .bind('fileuploaddrop', func);
260
-
261
- // Callback for dragover events of the dropZone(s):
262
- // dragover: function (e) {}, // .bind('fileuploaddragover', func);
263
-
264
- // Callback before the start of each chunk upload request (before form data initialization):
265
- // chunkbeforesend: function (e, data) {}, // .bind('fileuploadchunkbeforesend', func);
266
-
267
- // Callback for the start of each chunk upload request:
268
- // chunksend: function (e, data) {}, // .bind('fileuploadchunksend', func);
269
-
270
- // Callback for successful chunk uploads:
271
- // chunkdone: function (e, data) {}, // .bind('fileuploadchunkdone', func);
272
-
273
- // Callback for failed (abort or error) chunk uploads:
274
- // chunkfail: function (e, data) {}, // .bind('fileuploadchunkfail', func);
275
-
276
- // Callback for completed (success, abort or error) chunk upload requests:
277
- // chunkalways: function (e, data) {}, // .bind('fileuploadchunkalways', func);
278
-
279
- // The plugin options are used as settings object for the ajax calls.
280
- // The following are jQuery ajax settings required for the file uploads:
281
- processData: false,
282
- contentType: false,
283
- cache: false,
284
- timeout: 0
285
- },
286
-
287
- // A list of options that require reinitializing event listeners and/or
288
- // special initialization code:
289
- _specialOptions: [
290
- 'fileInput',
291
- 'dropZone',
292
- 'pasteZone',
293
- 'multipart',
294
- 'forceIframeTransport'
295
- ],
296
-
297
- _blobSlice: $.support.blobSlice && function () {
298
- var slice = this.slice || this.webkitSlice || this.mozSlice;
299
- return slice.apply(this, arguments);
300
- },
301
-
302
- _BitrateTimer: function () {
303
- this.timestamp = ((Date.now) ? Date.now() : (new Date()).getTime());
304
- this.loaded = 0;
305
- this.bitrate = 0;
306
- this.getBitrate = function (now, loaded, interval) {
307
- var timeDiff = now - this.timestamp;
308
- if (!this.bitrate || !interval || timeDiff > interval) {
309
- this.bitrate = (loaded - this.loaded) * (1000 / timeDiff) * 8;
310
- this.loaded = loaded;
311
- this.timestamp = now;
312
- }
313
- return this.bitrate;
314
- };
315
- },
316
-
317
- _isXHRUpload: function (options) {
318
- return !options.forceIframeTransport &&
319
- ((!options.multipart && $.support.xhrFileUpload) ||
320
- $.support.xhrFormDataFileUpload);
321
- },
322
-
323
- _getFormData: function (options) {
324
- var formData;
325
- if ($.type(options.formData) === 'function') {
326
- return options.formData(options.form);
327
- }
328
- if ($.isArray(options.formData)) {
329
- return options.formData;
330
- }
331
- if ($.type(options.formData) === 'object') {
332
- formData = [];
333
- $.each(options.formData, function (name, value) {
334
- formData.push({name: name, value: value});
335
- });
336
- return formData;
337
- }
338
- return [];
339
- },
340
-
341
- _getTotal: function (files) {
342
- var total = 0;
343
- $.each(files, function (index, file) {
344
- total += file.size || 1;
345
- });
346
- return total;
347
- },
348
-
349
- _initProgressObject: function (obj) {
350
- var progress = {
351
- loaded: 0,
352
- total: 0,
353
- bitrate: 0
354
- };
355
- if (obj._progress) {
356
- $.extend(obj._progress, progress);
357
- } else {
358
- obj._progress = progress;
359
- }
360
- },
361
-
362
- _initResponseObject: function (obj) {
363
- var prop;
364
- if (obj._response) {
365
- for (prop in obj._response) {
366
- if (obj._response.hasOwnProperty(prop)) {
367
- delete obj._response[prop];
368
- }
369
- }
370
- } else {
371
- obj._response = {};
372
- }
373
- },
374
-
375
- _onProgress: function (e, data) {
376
- if (e.lengthComputable) {
377
- var now = ((Date.now) ? Date.now() : (new Date()).getTime()),
378
- loaded;
379
- if (data._time && data.progressInterval &&
380
- (now - data._time < data.progressInterval) &&
381
- e.loaded !== e.total) {
382
- return;
383
- }
384
- data._time = now;
385
- loaded = Math.floor(
386
- e.loaded / e.total * (data.chunkSize || data._progress.total)
387
- ) + (data.uploadedBytes || 0);
388
- // Add the difference from the previously loaded state
389
- // to the global loaded counter:
390
- this._progress.loaded += (loaded - data._progress.loaded);
391
- this._progress.bitrate = this._bitrateTimer.getBitrate(
392
- now,
393
- this._progress.loaded,
394
- data.bitrateInterval
395
- );
396
- data._progress.loaded = data.loaded = loaded;
397
- data._progress.bitrate = data.bitrate = data._bitrateTimer.getBitrate(
398
- now,
399
- loaded,
400
- data.bitrateInterval
401
- );
402
- // Trigger a custom progress event with a total data property set
403
- // to the file size(s) of the current upload and a loaded data
404
- // property calculated accordingly:
405
- this._trigger(
406
- 'progress',
407
- $.Event('progress', {delegatedEvent: e}),
408
- data
409
- );
410
- // Trigger a global progress event for all current file uploads,
411
- // including ajax calls queued for sequential file uploads:
412
- this._trigger(
413
- 'progressall',
414
- $.Event('progressall', {delegatedEvent: e}),
415
- this._progress
416
- );
417
- }
418
- },
419
-
420
- _initProgressListener: function (options) {
421
- var that = this,
422
- xhr = options.xhr ? options.xhr() : $.ajaxSettings.xhr();
423
- // Accesss to the native XHR object is required to add event listeners
424
- // for the upload progress event:
425
- if (xhr.upload) {
426
- $(xhr.upload).bind('progress', function (e) {
427
- var oe = e.originalEvent;
428
- // Make sure the progress event properties get copied over:
429
- e.lengthComputable = oe.lengthComputable;
430
- e.loaded = oe.loaded;
431
- e.total = oe.total;
432
- that._onProgress(e, options);
433
- });
434
- options.xhr = function () {
435
- return xhr;
436
- };
437
- }
438
- },
439
-
440
- _deinitProgressListener: function (options) {
441
- var xhr = options.xhr ? options.xhr() : $.ajaxSettings.xhr();
442
- if (xhr.upload) {
443
- $(xhr.upload).unbind('progress');
444
- }
445
- },
446
-
447
- _isInstanceOf: function (type, obj) {
448
- // Cross-frame instanceof check
449
- return Object.prototype.toString.call(obj) === '[object ' + type + ']';
450
- },
451
-
452
- _initXHRData: function (options) {
453
- var that = this,
454
- formData,
455
- file = options.files[0],
456
- // Ignore non-multipart setting if not supported:
457
- multipart = options.multipart || !$.support.xhrFileUpload,
458
- paramName = $.type(options.paramName) === 'array' ?
459
- options.paramName[0] : options.paramName;
460
- options.headers = $.extend({}, options.headers);
461
- if (options.contentRange) {
462
- options.headers['Content-Range'] = options.contentRange;
463
- }
464
- if (!multipart || options.blob || !this._isInstanceOf('File', file)) {
465
- options.headers['Content-Disposition'] = 'attachment; filename="' +
466
- encodeURI(file.uploadName || file.name) + '"';
467
- }
468
- if (!multipart) {
469
- options.contentType = file.type || 'application/octet-stream';
470
- options.data = options.blob || file;
471
- } else if ($.support.xhrFormDataFileUpload) {
472
- if (options.postMessage) {
473
- // window.postMessage does not allow sending FormData
474
- // objects, so we just add the File/Blob objects to
475
- // the formData array and let the postMessage window
476
- // create the FormData object out of this array:
477
- formData = this._getFormData(options);
478
- if (options.blob) {
479
- formData.push({
480
- name: paramName,
481
- value: options.blob
482
- });
483
- } else {
484
- $.each(options.files, function (index, file) {
485
- formData.push({
486
- name: ($.type(options.paramName) === 'array' &&
487
- options.paramName[index]) || paramName,
488
- value: file
489
- });
490
- });
491
- }
492
- } else {
493
- if (that._isInstanceOf('FormData', options.formData)) {
494
- formData = options.formData;
495
- } else {
496
- formData = new FormData();
497
- $.each(this._getFormData(options), function (index, field) {
498
- formData.append(field.name, field.value);
499
- });
500
- }
501
- if (options.blob) {
502
- formData.append(
503
- paramName,
504
- options.blob,
505
- file.uploadName || file.name
506
- );
507
- } else {
508
- $.each(options.files, function (index, file) {
509
- // This check allows the tests to run with
510
- // dummy objects:
511
- if (that._isInstanceOf('File', file) ||
512
- that._isInstanceOf('Blob', file)) {
513
- formData.append(
514
- ($.type(options.paramName) === 'array' &&
515
- options.paramName[index]) || paramName,
516
- file,
517
- file.uploadName || file.name
518
- );
519
- }
520
- });
521
- }
522
- }
523
- options.data = formData;
524
- }
525
- // Blob reference is not needed anymore, free memory:
526
- options.blob = null;
527
- },
528
-
529
- _initIframeSettings: function (options) {
530
- var targetHost = $('<a></a>').prop('href', options.url).prop('host');
531
- // Setting the dataType to iframe enables the iframe transport:
532
- options.dataType = 'iframe ' + (options.dataType || '');
533
- // The iframe transport accepts a serialized array as form data:
534
- options.formData = this._getFormData(options);
535
- // Add redirect url to form data on cross-domain uploads:
536
- if (options.redirect && targetHost && targetHost !== location.host) {
537
- options.formData.push({
538
- name: options.redirectParamName || 'redirect',
539
- value: options.redirect
540
- });
541
- }
542
- },
543
-
544
- _initDataSettings: function (options) {
545
- if (this._isXHRUpload(options)) {
546
- if (!this._chunkedUpload(options, true)) {
547
- if (!options.data) {
548
- this._initXHRData(options);
549
- }
550
- this._initProgressListener(options);
551
- }
552
- if (options.postMessage) {
553
- // Setting the dataType to postmessage enables the
554
- // postMessage transport:
555
- options.dataType = 'postmessage ' + (options.dataType || '');
556
- }
557
- } else {
558
- this._initIframeSettings(options);
559
- }
560
- },
561
-
562
- _getParamName: function (options) {
563
- var fileInput = $(options.fileInput),
564
- paramName = options.paramName;
565
- if (!paramName) {
566
- paramName = [];
567
- fileInput.each(function () {
568
- var input = $(this),
569
- name = input.prop('name') || 'files[]',
570
- i = (input.prop('files') || [1]).length;
571
- while (i) {
572
- paramName.push(name);
573
- i -= 1;
574
- }
575
- });
576
- if (!paramName.length) {
577
- paramName = [fileInput.prop('name') || 'files[]'];
578
- }
579
- } else if (!$.isArray(paramName)) {
580
- paramName = [paramName];
581
- }
582
- return paramName;
583
- },
584
-
585
- _initFormSettings: function (options) {
586
- // Retrieve missing options from the input field and the
587
- // associated form, if available:
588
- if (!options.form || !options.form.length) {
589
- options.form = $(options.fileInput.prop('form'));
590
- // If the given file input doesn't have an associated form,
591
- // use the default widget file input's form:
592
- if (!options.form.length) {
593
- options.form = $(this.options.fileInput.prop('form'));
594
- }
595
- }
596
- options.paramName = this._getParamName(options);
597
- if (!options.url) {
598
- options.url = options.form.prop('action') || location.href;
599
- }
600
- // The HTTP request method must be "POST" or "PUT":
601
- options.type = (options.type ||
602
- ($.type(options.form.prop('method')) === 'string' &&
603
- options.form.prop('method')) || ''
604
- ).toUpperCase();
605
- if (options.type !== 'POST' && options.type !== 'PUT' &&
606
- options.type !== 'PATCH') {
607
- options.type = 'POST';
608
- }
609
- if (!options.formAcceptCharset) {
610
- options.formAcceptCharset = options.form.attr('accept-charset');
611
- }
612
- },
613
-
614
- _getAJAXSettings: function (data) {
615
- var options = $.extend({}, this.options, data);
616
- this._initFormSettings(options);
617
- this._initDataSettings(options);
618
- return options;
619
- },
620
-
621
- // jQuery 1.6 doesn't provide .state(),
622
- // while jQuery 1.8+ removed .isRejected() and .isResolved():
623
- _getDeferredState: function (deferred) {
624
- if (deferred.state) {
625
- return deferred.state();
626
- }
627
- if (deferred.isResolved()) {
628
- return 'resolved';
629
- }
630
- if (deferred.isRejected()) {
631
- return 'rejected';
632
- }
633
- return 'pending';
634
- },
635
-
636
- // Maps jqXHR callbacks to the equivalent
637
- // methods of the given Promise object:
638
- _enhancePromise: function (promise) {
639
- promise.success = promise.done;
640
- promise.error = promise.fail;
641
- promise.complete = promise.always;
642
- return promise;
643
- },
644
-
645
- // Creates and returns a Promise object enhanced with
646
- // the jqXHR methods abort, success, error and complete:
647
- _getXHRPromise: function (resolveOrReject, context, args) {
648
- var dfd = $.Deferred(),
649
- promise = dfd.promise();
650
- context = context || this.options.context || promise;
651
- if (resolveOrReject === true) {
652
- dfd.resolveWith(context, args);
653
- } else if (resolveOrReject === false) {
654
- dfd.rejectWith(context, args);
655
- }
656
- promise.abort = dfd.promise;
657
- return this._enhancePromise(promise);
658
- },
659
-
660
- // Adds convenience methods to the data callback argument:
661
- _addConvenienceMethods: function (e, data) {
662
- var that = this,
663
- getPromise = function (args) {
664
- return $.Deferred().resolveWith(that, args).promise();
665
- };
666
- data.process = function (resolveFunc, rejectFunc) {
667
- if (resolveFunc || rejectFunc) {
668
- data._processQueue = this._processQueue =
669
- (this._processQueue || getPromise([this])).then(
670
- function () {
671
- if (data.errorThrown) {
672
- return $.Deferred()
673
- .rejectWith(that, [data]).promise();
674
- }
675
- return getPromise(arguments);
676
- }
677
- ).then(resolveFunc, rejectFunc);
678
- }
679
- return this._processQueue || getPromise([this]);
680
- };
681
- data.submit = function () {
682
- if (this.state() !== 'pending') {
683
- data.jqXHR = this.jqXHR =
684
- (that._trigger(
685
- 'submit',
686
- $.Event('submit', {delegatedEvent: e}),
687
- this
688
- ) !== false) && that._onSend(e, this);
689
- }
690
- return this.jqXHR || that._getXHRPromise();
691
- };
692
- data.abort = function () {
693
- if (this.jqXHR) {
694
- return this.jqXHR.abort();
695
- }
696
- this.errorThrown = 'abort';
697
- that._trigger('fail', null, this);
698
- return that._getXHRPromise(false);
699
- };
700
- data.state = function () {
701
- if (this.jqXHR) {
702
- return that._getDeferredState(this.jqXHR);
703
- }
704
- if (this._processQueue) {
705
- return that._getDeferredState(this._processQueue);
706
- }
707
- };
708
- data.processing = function () {
709
- return !this.jqXHR && this._processQueue && that
710
- ._getDeferredState(this._processQueue) === 'pending';
711
- };
712
- data.progress = function () {
713
- return this._progress;
714
- };
715
- data.response = function () {
716
- return this._response;
717
- };
718
- },
719
-
720
- // Parses the Range header from the server response
721
- // and returns the uploaded bytes:
722
- _getUploadedBytes: function (jqXHR) {
723
- var range = jqXHR.getResponseHeader('Range'),
724
- parts = range && range.split('-'),
725
- upperBytesPos = parts && parts.length > 1 &&
726
- parseInt(parts[1], 10);
727
- return upperBytesPos && upperBytesPos + 1;
728
- },
729
-
730
- // Uploads a file in multiple, sequential requests
731
- // by splitting the file up in multiple blob chunks.
732
- // If the second parameter is true, only tests if the file
733
- // should be uploaded in chunks, but does not invoke any
734
- // upload requests:
735
- _chunkedUpload: function (options, testOnly) {
736
- options.uploadedBytes = options.uploadedBytes || 0;
737
- var that = this,
738
- file = options.files[0],
739
- fs = file.size,
740
- ub = options.uploadedBytes,
741
- mcs = options.maxChunkSize || fs,
742
- slice = this._blobSlice,
743
- dfd = $.Deferred(),
744
- promise = dfd.promise(),
745
- jqXHR,
746
- upload;
747
- if (!(this._isXHRUpload(options) && slice && (ub || ($.type(mcs) === 'function' ? mcs(options) : mcs) < fs)) ||
748
- options.data) {
749
- return false;
750
- }
751
- if (testOnly) {
752
- return true;
753
- }
754
- if (ub >= fs) {
755
- file.error = options.i18n('uploadedBytes');
756
- return this._getXHRPromise(
757
- false,
758
- options.context,
759
- [null, 'error', file.error]
760
- );
761
- }
762
- // The chunk upload method:
763
- upload = function () {
764
- // Clone the options object for each chunk upload:
765
- var o = $.extend({}, options),
766
- currentLoaded = o._progress.loaded;
767
- o.blob = slice.call(
768
- file,
769
- ub,
770
- ub + ($.type(mcs) === 'function' ? mcs(o) : mcs),
771
- file.type
772
- );
773
- // Store the current chunk size, as the blob itself
774
- // will be dereferenced after data processing:
775
- o.chunkSize = o.blob.size;
776
- // Expose the chunk bytes position range:
777
- o.contentRange = 'bytes ' + ub + '-' +
778
- (ub + o.chunkSize - 1) + '/' + fs;
779
- // Trigger chunkbeforesend to allow form data to be updated for this chunk
780
- that._trigger('chunkbeforesend', null, o);
781
- // Process the upload data (the blob and potential form data):
782
- that._initXHRData(o);
783
- // Add progress listeners for this chunk upload:
784
- that._initProgressListener(o);
785
- jqXHR = ((that._trigger('chunksend', null, o) !== false && $.ajax(o)) ||
786
- that._getXHRPromise(false, o.context))
787
- .done(function (result, textStatus, jqXHR) {
788
- ub = that._getUploadedBytes(jqXHR) ||
789
- (ub + o.chunkSize);
790
- // Create a progress event if no final progress event
791
- // with loaded equaling total has been triggered
792
- // for this chunk:
793
- if (currentLoaded + o.chunkSize - o._progress.loaded) {
794
- that._onProgress($.Event('progress', {
795
- lengthComputable: true,
796
- loaded: ub - o.uploadedBytes,
797
- total: ub - o.uploadedBytes
798
- }), o);
799
- }
800
- options.uploadedBytes = o.uploadedBytes = ub;
801
- o.result = result;
802
- o.textStatus = textStatus;
803
- o.jqXHR = jqXHR;
804
- that._trigger('chunkdone', null, o);
805
- that._trigger('chunkalways', null, o);
806
- if (ub < fs) {
807
- // File upload not yet complete,
808
- // continue with the next chunk:
809
- upload();
810
- } else {
811
- dfd.resolveWith(
812
- o.context,
813
- [result, textStatus, jqXHR]
814
- );
815
- }
816
- })
817
- .fail(function (jqXHR, textStatus, errorThrown) {
818
- o.jqXHR = jqXHR;
819
- o.textStatus = textStatus;
820
- o.errorThrown = errorThrown;
821
- that._trigger('chunkfail', null, o);
822
- that._trigger('chunkalways', null, o);
823
- dfd.rejectWith(
824
- o.context,
825
- [jqXHR, textStatus, errorThrown]
826
- );
827
- })
828
- .always(function () {
829
- that._deinitProgressListener(o);
830
- });
831
- };
832
- this._enhancePromise(promise);
833
- promise.abort = function () {
834
- return jqXHR.abort();
835
- };
836
- upload();
837
- return promise;
838
- },
839
-
840
- _beforeSend: function (e, data) {
841
- if (this._active === 0) {
842
- // the start callback is triggered when an upload starts
843
- // and no other uploads are currently running,
844
- // equivalent to the global ajaxStart event:
845
- this._trigger('start');
846
- // Set timer for global bitrate progress calculation:
847
- this._bitrateTimer = new this._BitrateTimer();
848
- // Reset the global progress values:
849
- this._progress.loaded = this._progress.total = 0;
850
- this._progress.bitrate = 0;
851
- }
852
- // Make sure the container objects for the .response() and
853
- // .progress() methods on the data object are available
854
- // and reset to their initial state:
855
- this._initResponseObject(data);
856
- this._initProgressObject(data);
857
- data._progress.loaded = data.loaded = data.uploadedBytes || 0;
858
- data._progress.total = data.total = this._getTotal(data.files) || 1;
859
- data._progress.bitrate = data.bitrate = 0;
860
- this._active += 1;
861
- // Initialize the global progress values:
862
- this._progress.loaded += data.loaded;
863
- this._progress.total += data.total;
864
- },
865
-
866
- _onDone: function (result, textStatus, jqXHR, options) {
867
- var total = options._progress.total,
868
- response = options._response;
869
- if (options._progress.loaded < total) {
870
- // Create a progress event if no final progress event
871
- // with loaded equaling total has been triggered:
872
- this._onProgress($.Event('progress', {
873
- lengthComputable: true,
874
- loaded: total,
875
- total: total
876
- }), options);
877
- }
878
- response.result = options.result = result;
879
- response.textStatus = options.textStatus = textStatus;
880
- response.jqXHR = options.jqXHR = jqXHR;
881
- this._trigger('done', null, options);
882
- },
883
-
884
- _onFail: function (jqXHR, textStatus, errorThrown, options) {
885
- var response = options._response;
886
- if (options.recalculateProgress) {
887
- // Remove the failed (error or abort) file upload from
888
- // the global progress calculation:
889
- this._progress.loaded -= options._progress.loaded;
890
- this._progress.total -= options._progress.total;
891
- }
892
- response.jqXHR = options.jqXHR = jqXHR;
893
- response.textStatus = options.textStatus = textStatus;
894
- response.errorThrown = options.errorThrown = errorThrown;
895
- this._trigger('fail', null, options);
896
- },
897
-
898
- _onAlways: function (jqXHRorResult, textStatus, jqXHRorError, options) {
899
- // jqXHRorResult, textStatus and jqXHRorError are added to the
900
- // options object via done and fail callbacks
901
- this._trigger('always', null, options);
902
- },
903
-
904
- _onSend: function (e, data) {
905
- if (!data.submit) {
906
- this._addConvenienceMethods(e, data);
907
- }
908
- var that = this,
909
- jqXHR,
910
- aborted,
911
- slot,
912
- pipe,
913
- options = that._getAJAXSettings(data),
914
- send = function () {
915
- that._sending += 1;
916
- // Set timer for bitrate progress calculation:
917
- options._bitrateTimer = new that._BitrateTimer();
918
- jqXHR = jqXHR || (
919
- ((aborted || that._trigger(
920
- 'send',
921
- $.Event('send', {delegatedEvent: e}),
922
- options
923
- ) === false) &&
924
- that._getXHRPromise(false, options.context, aborted)) ||
925
- that._chunkedUpload(options) || $.ajax(options)
926
- ).done(function (result, textStatus, jqXHR) {
927
- that._onDone(result, textStatus, jqXHR, options);
928
- }).fail(function (jqXHR, textStatus, errorThrown) {
929
- that._onFail(jqXHR, textStatus, errorThrown, options);
930
- }).always(function (jqXHRorResult, textStatus, jqXHRorError) {
931
- that._deinitProgressListener(options);
932
- that._onAlways(
933
- jqXHRorResult,
934
- textStatus,
935
- jqXHRorError,
936
- options
937
- );
938
- that._sending -= 1;
939
- that._active -= 1;
940
- if (options.limitConcurrentUploads &&
941
- options.limitConcurrentUploads > that._sending) {
942
- // Start the next queued upload,
943
- // that has not been aborted:
944
- var nextSlot = that._slots.shift();
945
- while (nextSlot) {
946
- if (that._getDeferredState(nextSlot) === 'pending') {
947
- nextSlot.resolve();
948
- break;
949
- }
950
- nextSlot = that._slots.shift();
951
- }
952
- }
953
- if (that._active === 0) {
954
- // The stop callback is triggered when all uploads have
955
- // been completed, equivalent to the global ajaxStop event:
956
- that._trigger('stop');
957
- }
958
- });
959
- return jqXHR;
960
- };
961
- this._beforeSend(e, options);
962
- if (this.options.sequentialUploads ||
963
- (this.options.limitConcurrentUploads &&
964
- this.options.limitConcurrentUploads <= this._sending)) {
965
- if (this.options.limitConcurrentUploads > 1) {
966
- slot = $.Deferred();
967
- this._slots.push(slot);
968
- pipe = slot.then(send);
969
- } else {
970
- this._sequence = this._sequence.then(send, send);
971
- pipe = this._sequence;
972
- }
973
- // Return the piped Promise object, enhanced with an abort method,
974
- // which is delegated to the jqXHR object of the current upload,
975
- // and jqXHR callbacks mapped to the equivalent Promise methods:
976
- pipe.abort = function () {
977
- aborted = [undefined, 'abort', 'abort'];
978
- if (!jqXHR) {
979
- if (slot) {
980
- slot.rejectWith(options.context, aborted);
981
- }
982
- return send();
983
- }
984
- return jqXHR.abort();
985
- };
986
- return this._enhancePromise(pipe);
987
- }
988
- return send();
989
- },
990
-
991
- _onAdd: function (e, data) {
992
- var that = this,
993
- result = true,
994
- options = $.extend({}, this.options, data),
995
- files = data.files,
996
- filesLength = files.length,
997
- limit = options.limitMultiFileUploads,
998
- limitSize = options.limitMultiFileUploadSize,
999
- overhead = options.limitMultiFileUploadSizeOverhead,
1000
- batchSize = 0,
1001
- paramName = this._getParamName(options),
1002
- paramNameSet,
1003
- paramNameSlice,
1004
- fileSet,
1005
- i,
1006
- j = 0;
1007
- if (!filesLength) {
1008
- return false;
1009
- }
1010
- if (limitSize && files[0].size === undefined) {
1011
- limitSize = undefined;
1012
- }
1013
- if (!(options.singleFileUploads || limit || limitSize) ||
1014
- !this._isXHRUpload(options)) {
1015
- fileSet = [files];
1016
- paramNameSet = [paramName];
1017
- } else if (!(options.singleFileUploads || limitSize) && limit) {
1018
- fileSet = [];
1019
- paramNameSet = [];
1020
- for (i = 0; i < filesLength; i += limit) {
1021
- fileSet.push(files.slice(i, i + limit));
1022
- paramNameSlice = paramName.slice(i, i + limit);
1023
- if (!paramNameSlice.length) {
1024
- paramNameSlice = paramName;
1025
- }
1026
- paramNameSet.push(paramNameSlice);
1027
- }
1028
- } else if (!options.singleFileUploads && limitSize) {
1029
- fileSet = [];
1030
- paramNameSet = [];
1031
- for (i = 0; i < filesLength; i = i + 1) {
1032
- batchSize += files[i].size + overhead;
1033
- if (i + 1 === filesLength ||
1034
- ((batchSize + files[i + 1].size + overhead) > limitSize) ||
1035
- (limit && i + 1 - j >= limit)) {
1036
- fileSet.push(files.slice(j, i + 1));
1037
- paramNameSlice = paramName.slice(j, i + 1);
1038
- if (!paramNameSlice.length) {
1039
- paramNameSlice = paramName;
1040
- }
1041
- paramNameSet.push(paramNameSlice);
1042
- j = i + 1;
1043
- batchSize = 0;
1044
- }
1045
- }
1046
- } else {
1047
- paramNameSet = paramName;
1048
- }
1049
- data.originalFiles = files;
1050
- $.each(fileSet || files, function (index, element) {
1051
- var newData = $.extend({}, data);
1052
- newData.files = fileSet ? element : [element];
1053
- newData.paramName = paramNameSet[index];
1054
- that._initResponseObject(newData);
1055
- that._initProgressObject(newData);
1056
- that._addConvenienceMethods(e, newData);
1057
- result = that._trigger(
1058
- 'add',
1059
- $.Event('add', {delegatedEvent: e}),
1060
- newData
1061
- );
1062
- return result;
1063
- });
1064
- return result;
1065
- },
1066
-
1067
- _replaceFileInput: function (data) {
1068
- var input = data.fileInput,
1069
- inputClone = input.clone(true),
1070
- restoreFocus = input.is(document.activeElement);
1071
- // Add a reference for the new cloned file input to the data argument:
1072
- data.fileInputClone = inputClone;
1073
- $('<form></form>').append(inputClone)[0].reset();
1074
- // Detaching allows to insert the fileInput on another form
1075
- // without loosing the file input value:
1076
- input.after(inputClone).detach();
1077
- // If the fileInput had focus before it was detached,
1078
- // restore focus to the inputClone.
1079
- if (restoreFocus) {
1080
- inputClone.focus();
1081
- }
1082
- // Avoid memory leaks with the detached file input:
1083
- $.cleanData(input.unbind('remove'));
1084
- // Replace the original file input element in the fileInput
1085
- // elements set with the clone, which has been copied including
1086
- // event handlers:
1087
- this.options.fileInput = this.options.fileInput.map(function (i, el) {
1088
- if (el === input[0]) {
1089
- return inputClone[0];
1090
- }
1091
- return el;
1092
- });
1093
- // If the widget has been initialized on the file input itself,
1094
- // override this.element with the file input clone:
1095
- if (input[0] === this.element[0]) {
1096
- this.element = inputClone;
1097
- }
1098
- },
1099
-
1100
- _handleFileTreeEntry: function (entry, path) {
1101
- var that = this,
1102
- dfd = $.Deferred(),
1103
- entries = [],
1104
- dirReader,
1105
- errorHandler = function (e) {
1106
- if (e && !e.entry) {
1107
- e.entry = entry;
1108
- }
1109
- // Since $.when returns immediately if one
1110
- // Deferred is rejected, we use resolve instead.
1111
- // This allows valid files and invalid items
1112
- // to be returned together in one set:
1113
- dfd.resolve([e]);
1114
- },
1115
- successHandler = function (entries) {
1116
- that._handleFileTreeEntries(
1117
- entries,
1118
- path + entry.name + '/'
1119
- ).done(function (files) {
1120
- dfd.resolve(files);
1121
- }).fail(errorHandler);
1122
- },
1123
- readEntries = function () {
1124
- dirReader.readEntries(function (results) {
1125
- if (!results.length) {
1126
- successHandler(entries);
1127
- } else {
1128
- entries = entries.concat(results);
1129
- readEntries();
1130
- }
1131
- }, errorHandler);
1132
- };
1133
- path = path || '';
1134
- if (entry.isFile) {
1135
- if (entry._file) {
1136
- // Workaround for Chrome bug #149735
1137
- entry._file.relativePath = path;
1138
- dfd.resolve(entry._file);
1139
- } else {
1140
- entry.file(function (file) {
1141
- file.relativePath = path;
1142
- dfd.resolve(file);
1143
- }, errorHandler);
1144
- }
1145
- } else if (entry.isDirectory) {
1146
- dirReader = entry.createReader();
1147
- readEntries();
1148
- } else {
1149
- // Return an empty list for file system items
1150
- // other than files or directories:
1151
- dfd.resolve([]);
1152
- }
1153
- return dfd.promise();
1154
- },
1155
-
1156
- _handleFileTreeEntries: function (entries, path) {
1157
- var that = this;
1158
- return $.when.apply(
1159
- $,
1160
- $.map(entries, function (entry) {
1161
- return that._handleFileTreeEntry(entry, path);
1162
- })
1163
- ).then(function () {
1164
- return Array.prototype.concat.apply(
1165
- [],
1166
- arguments
1167
- );
1168
- });
1169
- },
1170
-
1171
- _getDroppedFiles: function (dataTransfer) {
1172
- dataTransfer = dataTransfer || {};
1173
- var items = dataTransfer.items;
1174
- if (items && items.length && (items[0].webkitGetAsEntry ||
1175
- items[0].getAsEntry)) {
1176
- return this._handleFileTreeEntries(
1177
- $.map(items, function (item) {
1178
- var entry;
1179
- if (item.webkitGetAsEntry) {
1180
- entry = item.webkitGetAsEntry();
1181
- if (entry) {
1182
- // Workaround for Chrome bug #149735:
1183
- entry._file = item.getAsFile();
1184
- }
1185
- return entry;
1186
- }
1187
- return item.getAsEntry();
1188
- })
1189
- );
1190
- }
1191
- return $.Deferred().resolve(
1192
- $.makeArray(dataTransfer.files)
1193
- ).promise();
1194
- },
1195
-
1196
- _getSingleFileInputFiles: function (fileInput) {
1197
- fileInput = $(fileInput);
1198
- var entries = fileInput.prop('webkitEntries') ||
1199
- fileInput.prop('entries'),
1200
- files,
1201
- value;
1202
- if (entries && entries.length) {
1203
- return this._handleFileTreeEntries(entries);
1204
- }
1205
- files = $.makeArray(fileInput.prop('files'));
1206
- if (!files.length) {
1207
- value = fileInput.prop('value');
1208
- if (!value) {
1209
- return $.Deferred().resolve([]).promise();
1210
- }
1211
- // If the files property is not available, the browser does not
1212
- // support the File API and we add a pseudo File object with
1213
- // the input value as name with path information removed:
1214
- files = [{name: value.replace(/^.*\\/, '')}];
1215
- } else if (files[0].name === undefined && files[0].fileName) {
1216
- // File normalization for Safari 4 and Firefox 3:
1217
- $.each(files, function (index, file) {
1218
- file.name = file.fileName;
1219
- file.size = file.fileSize;
1220
- });
1221
- }
1222
- return $.Deferred().resolve(files).promise();
1223
- },
1224
-
1225
- _getFileInputFiles: function (fileInput) {
1226
- if (!(fileInput instanceof $) || fileInput.length === 1) {
1227
- return this._getSingleFileInputFiles(fileInput);
1228
- }
1229
- return $.when.apply(
1230
- $,
1231
- $.map(fileInput, this._getSingleFileInputFiles)
1232
- ).then(function () {
1233
- return Array.prototype.concat.apply(
1234
- [],
1235
- arguments
1236
- );
1237
- });
1238
- },
1239
-
1240
- _onChange: function (e) {
1241
- var that = this,
1242
- data = {
1243
- fileInput: $(e.target),
1244
- form: $(e.target.form)
1245
- };
1246
- this._getFileInputFiles(data.fileInput).always(function (files) {
1247
- data.files = files;
1248
- if (that.options.replaceFileInput) {
1249
- that._replaceFileInput(data);
1250
- }
1251
- if (that._trigger(
1252
- 'change',
1253
- $.Event('change', {delegatedEvent: e}),
1254
- data
1255
- ) !== false) {
1256
- that._onAdd(e, data);
1257
- }
1258
- });
1259
- },
1260
-
1261
- _onPaste: function (e) {
1262
- var items = e.originalEvent && e.originalEvent.clipboardData &&
1263
- e.originalEvent.clipboardData.items,
1264
- data = {files: []};
1265
- if (items && items.length) {
1266
- $.each(items, function (index, item) {
1267
- var file = item.getAsFile && item.getAsFile();
1268
- if (file) {
1269
- data.files.push(file);
1270
- }
1271
- });
1272
- if (this._trigger(
1273
- 'paste',
1274
- $.Event('paste', {delegatedEvent: e}),
1275
- data
1276
- ) !== false) {
1277
- this._onAdd(e, data);
1278
- }
1279
- }
1280
- },
1281
-
1282
- _onDrop: function (e) {
1283
- e.dataTransfer = e.originalEvent && e.originalEvent.dataTransfer;
1284
- var that = this,
1285
- dataTransfer = e.dataTransfer,
1286
- data = {};
1287
- if (dataTransfer && dataTransfer.files && dataTransfer.files.length) {
1288
- e.preventDefault();
1289
- this._getDroppedFiles(dataTransfer).always(function (files) {
1290
- data.files = files;
1291
- if (that._trigger(
1292
- 'drop',
1293
- $.Event('drop', {delegatedEvent: e}),
1294
- data
1295
- ) !== false) {
1296
- that._onAdd(e, data);
1297
- }
1298
- });
1299
- }
1300
- },
1301
-
1302
- _onDragOver: getDragHandler('dragover'),
1303
-
1304
- _onDragEnter: getDragHandler('dragenter'),
1305
-
1306
- _onDragLeave: getDragHandler('dragleave'),
1307
-
1308
- _initEventHandlers: function () {
1309
- if (this._isXHRUpload(this.options)) {
1310
- this._on(this.options.dropZone, {
1311
- dragover: this._onDragOver,
1312
- drop: this._onDrop,
1313
- // event.preventDefault() on dragenter is required for IE10+:
1314
- dragenter: this._onDragEnter,
1315
- // dragleave is not required, but added for completeness:
1316
- dragleave: this._onDragLeave
1317
- });
1318
- this._on(this.options.pasteZone, {
1319
- paste: this._onPaste
1320
- });
1321
- }
1322
- if ($.support.fileInput) {
1323
- this._on(this.options.fileInput, {
1324
- change: this._onChange
1325
- });
1326
- }
1327
- },
1328
-
1329
- _destroyEventHandlers: function () {
1330
- this._off(this.options.dropZone, 'dragenter dragleave dragover drop');
1331
- this._off(this.options.pasteZone, 'paste');
1332
- this._off(this.options.fileInput, 'change');
1333
- },
1334
-
1335
- _destroy: function () {
1336
- this._destroyEventHandlers();
1337
- },
1338
-
1339
- _setOption: function (key, value) {
1340
- var reinit = $.inArray(key, this._specialOptions) !== -1;
1341
- if (reinit) {
1342
- this._destroyEventHandlers();
1343
- }
1344
- this._super(key, value);
1345
- if (reinit) {
1346
- this._initSpecialOptions();
1347
- this._initEventHandlers();
1348
- }
1349
- },
1350
-
1351
- _initSpecialOptions: function () {
1352
- var options = this.options;
1353
- if (options.fileInput === undefined) {
1354
- options.fileInput = this.element.is('input[type="file"]') ?
1355
- this.element : this.element.find('input[type="file"]');
1356
- } else if (!(options.fileInput instanceof $)) {
1357
- options.fileInput = $(options.fileInput);
1358
- }
1359
- if (!(options.dropZone instanceof $)) {
1360
- options.dropZone = $(options.dropZone);
1361
- }
1362
- if (!(options.pasteZone instanceof $)) {
1363
- options.pasteZone = $(options.pasteZone);
1364
- }
1365
- },
1366
-
1367
- _getRegExp: function (str) {
1368
- var parts = str.split('/'),
1369
- modifiers = parts.pop();
1370
- parts.shift();
1371
- return new RegExp(parts.join('/'), modifiers);
1372
- },
1373
-
1374
- _isRegExpOption: function (key, value) {
1375
- return key !== 'url' && $.type(value) === 'string' &&
1376
- /^\/.*\/[igm]{0,3}$/.test(value);
1377
- },
1378
-
1379
- _initDataAttributes: function () {
1380
- var that = this,
1381
- options = this.options,
1382
- data = this.element.data();
1383
- // Initialize options set via HTML5 data-attributes:
1384
- $.each(
1385
- this.element[0].attributes,
1386
- function (index, attr) {
1387
- var key = attr.name.toLowerCase(),
1388
- value;
1389
- if (/^data-/.test(key)) {
1390
- // Convert hyphen-ated key to camelCase:
1391
- key = key.slice(5).replace(/-[a-z]/g, function (str) {
1392
- return str.charAt(1).toUpperCase();
1393
- });
1394
- value = data[key];
1395
- if (that._isRegExpOption(key, value)) {
1396
- value = that._getRegExp(value);
1397
- }
1398
- options[key] = value;
1399
- }
1400
- }
1401
- );
1402
- },
1403
-
1404
- _create: function () {
1405
- this._initDataAttributes();
1406
- this._initSpecialOptions();
1407
- this._slots = [];
1408
- this._sequence = this._getXHRPromise(true);
1409
- this._sending = this._active = 0;
1410
- this._initProgressObject(this);
1411
- this._initEventHandlers();
1412
- },
1413
-
1414
- // This method is exposed to the widget API and allows to query
1415
- // the number of active uploads:
1416
- active: function () {
1417
- return this._active;
1418
- },
1419
-
1420
- // This method is exposed to the widget API and allows to query
1421
- // the widget upload progress.
1422
- // It returns an object with loaded, total and bitrate properties
1423
- // for the running uploads:
1424
- progress: function () {
1425
- return this._progress;
1426
- },
1427
-
1428
- // This method is exposed to the widget API and allows adding files
1429
- // using the fileupload API. The data parameter accepts an object which
1430
- // must have a files property and can contain additional options:
1431
- // .fileupload('add', {files: filesList});
1432
- add: function (data) {
1433
- var that = this;
1434
- if (!data || this.options.disabled) {
1435
- return;
1436
- }
1437
- if (data.fileInput && !data.files) {
1438
- this._getFileInputFiles(data.fileInput).always(function (files) {
1439
- data.files = files;
1440
- that._onAdd(null, data);
1441
- });
1442
- } else {
1443
- data.files = $.makeArray(data.files);
1444
- this._onAdd(null, data);
1445
- }
1446
- },
1447
-
1448
- // This method is exposed to the widget API and allows sending files
1449
- // using the fileupload API. The data parameter accepts an object which
1450
- // must have a files or fileInput property and can contain additional options:
1451
- // .fileupload('send', {files: filesList});
1452
- // The method returns a Promise object for the file upload call.
1453
- send: function (data) {
1454
- if (data && !this.options.disabled) {
1455
- if (data.fileInput && !data.files) {
1456
- var that = this,
1457
- dfd = $.Deferred(),
1458
- promise = dfd.promise(),
1459
- jqXHR,
1460
- aborted;
1461
- promise.abort = function () {
1462
- aborted = true;
1463
- if (jqXHR) {
1464
- return jqXHR.abort();
1465
- }
1466
- dfd.reject(null, 'abort', 'abort');
1467
- return promise;
1468
- };
1469
- this._getFileInputFiles(data.fileInput).always(
1470
- function (files) {
1471
- if (aborted) {
1472
- return;
1473
- }
1474
- if (!files.length) {
1475
- dfd.reject();
1476
- return;
1477
- }
1478
- data.files = files;
1479
- jqXHR = that._onSend(null, data);
1480
- jqXHR.then(
1481
- function (result, textStatus, jqXHR) {
1482
- dfd.resolve(result, textStatus, jqXHR);
1483
- },
1484
- function (jqXHR, textStatus, errorThrown) {
1485
- dfd.reject(jqXHR, textStatus, errorThrown);
1486
- }
1487
- );
1488
- }
1489
- );
1490
- return this._enhancePromise(promise);
1491
- }
1492
- data.files = $.makeArray(data.files);
1493
- if (data.files.length) {
1494
- return this._onSend(null, data);
1495
- }
1496
- }
1497
- return this._getXHRPromise(false, data && data.context);
1498
- }
1499
-
1500
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1501
 
1502
  }));
1
  /*
2
+ * jQuery File Upload Plugin v9.32.0
3
  * https://github.com/blueimp/jQuery-File-Upload
4
  *
5
  * Copyright 2010, Sebastian Tschan
13
  /* global define, require, window, document, location, Blob, FormData */
14
 
15
  ;(function (factory) {
16
+ 'use strict';
17
+ if (typeof define === 'function' && define.amd) {
18
+ // Register as an anonymous AMD module:
19
+ define([
20
+ 'jquery',
21
+ 'jquery-ui/ui/widget'
22
+ ], factory);
23
+ } else if (typeof exports === 'object') {
24
+ // Node/CommonJS:
25
+ factory(
26
+ require('jquery'),
27
+ require('./vendor/jquery.ui.widget')
28
+ );
29
+ } else {
30
+ // Browser globals:
31
+ factory(window.jQuery);
32
+ }
33
  }(function ($) {
34
+ 'use strict';
35
+
36
+ // Detect file input support, based on
37
+ // http://viljamis.com/blog/2012/file-upload-support-on-mobile/
38
+ $.support.fileInput = !(new RegExp(
39
+ // Handle devices which give false positives for the feature detection:
40
+ '(Android (1\\.[0156]|2\\.[01]))' +
41
+ '|(Windows Phone (OS 7|8\\.0))|(XBLWP)|(ZuneWP)|(WPDesktop)' +
42
+ '|(w(eb)?OSBrowser)|(webOS)' +
43
+ '|(Kindle/(1\\.0|2\\.[05]|3\\.0))'
44
+ ).test(window.navigator.userAgent) ||
45
+ // Feature detection for all other devices:
46
+ $('<input type="file"/>').prop('disabled'));
47
+
48
+ // The FileReader API is not actually used, but works as feature detection,
49
+ // as some Safari versions (5?) support XHR file uploads via the FormData API,
50
+ // but not non-multipart XHR file uploads.
51
+ // window.XMLHttpRequestUpload is not available on IE10, so we check for
52
+ // window.ProgressEvent instead to detect XHR2 file upload capability:
53
+ $.support.xhrFileUpload = !!(window.ProgressEvent && window.FileReader);
54
+ $.support.xhrFormDataFileUpload = !!window.FormData;
55
+
56
+ // Detect support for Blob slicing (required for chunked uploads):
57
+ $.support.blobSlice = window.Blob && (Blob.prototype.slice ||
58
+ Blob.prototype.webkitSlice || Blob.prototype.mozSlice);
59
+
60
+ // Helper function to create drag handlers for dragover/dragenter/dragleave:
61
+ function getDragHandler(type) {
62
+ var isDragOver = type === 'dragover';
63
+ return function (e) {
64
+ e.dataTransfer = e.originalEvent && e.originalEvent.dataTransfer;
65
+ var dataTransfer = e.dataTransfer;
66
+ if (dataTransfer && $.inArray('Files', dataTransfer.types) !== -1 &&
67
+ this._trigger(
68
+ type,
69
+ $.Event(type, {delegatedEvent: e})
70
+ ) !== false) {
71
+ e.preventDefault();
72
+ if (isDragOver) {
73
+ dataTransfer.dropEffect = 'copy';
74
+ }
75
+ }
76
+ };
77
+ }
78
+
79
+ // The fileupload widget listens for change events on file input fields defined
80
+ // via fileInput setting and paste or drop events of the given dropZone.
81
+ // In addition to the default jQuery Widget methods, the fileupload widget
82
+ // exposes the "add" and "send" methods, to add or directly send files using
83
+ // the fileupload API.
84
+ // By default, files added via file input selection, paste, drag & drop or
85
+ // "add" method are uploaded immediately, but it is possible to override
86
+ // the "add" callback option to queue file uploads.
87
+ $.widget('blueimp.fileupload', {
88
+
89
+ options: {
90
+ // The drop target element(s), by the default the complete document.
91
+ // Set to null to disable drag & drop support:
92
+ dropZone: $(document),
93
+ // The paste target element(s), by the default undefined.
94
+ // Set to a DOM node or jQuery object to enable file pasting:
95
+ pasteZone: undefined,
96
+ // The file input field(s), that are listened to for change events.
97
+ // If undefined, it is set to the file input fields inside
98
+ // of the widget element on plugin initialization.
99
+ // Set to null to disable the change listener.
100
+ fileInput: undefined,
101
+ // By default, the file input field is replaced with a clone after
102
+ // each input field change event. This is required for iframe transport
103
+ // queues and allows change events to be fired for the same file
104
+ // selection, but can be disabled by setting the following option to false:
105
+ replaceFileInput: true,
106
+ // The parameter name for the file form data (the request argument name).
107
+ // If undefined or empty, the name property of the file input field is
108
+ // used, or "files[]" if the file input name property is also empty,
109
+ // can be a string or an array of strings:
110
+ paramName: undefined,
111
+ // By default, each file of a selection is uploaded using an individual
112
+ // request for XHR type uploads. Set to false to upload file
113
+ // selections in one request each:
114
+ singleFileUploads: true,
115
+ // To limit the number of files uploaded with one XHR request,
116
+ // set the following option to an integer greater than 0:
117
+ limitMultiFileUploads: undefined,
118
+ // The following option limits the number of files uploaded with one
119
+ // XHR request to keep the request size under or equal to the defined
120
+ // limit in bytes:
121
+ limitMultiFileUploadSize: undefined,
122
+ // Multipart file uploads add a number of bytes to each uploaded file,
123
+ // therefore the following option adds an overhead for each file used
124
+ // in the limitMultiFileUploadSize configuration:
125
+ limitMultiFileUploadSizeOverhead: 512,
126
+ // Set the following option to true to issue all file upload requests
127
+ // in a sequential order:
128
+ sequentialUploads: false,
129
+ // To limit the number of concurrent uploads,
130
+ // set the following option to an integer greater than 0:
131
+ limitConcurrentUploads: undefined,
132
+ // Set the following option to true to force iframe transport uploads:
133
+ forceIframeTransport: false,
134
+ // Set the following option to the location of a redirect url on the
135
+ // origin server, for cross-domain iframe transport uploads:
136
+ redirect: undefined,
137
+ // The parameter name for the redirect url, sent as part of the form
138
+ // data and set to 'redirect' if this option is empty:
139
+ redirectParamName: undefined,
140
+ // Set the following option to the location of a postMessage window,
141
+ // to enable postMessage transport uploads:
142
+ postMessage: undefined,
143
+ // By default, XHR file uploads are sent as multipart/form-data.
144
+ // The iframe transport is always using multipart/form-data.
145
+ // Set to false to enable non-multipart XHR uploads:
146
+ multipart: true,
147
+ // To upload large files in smaller chunks, set the following option
148
+ // to a preferred maximum chunk size. If set to 0, null or undefined,
149
+ // or the browser does not support the required Blob API, files will
150
+ // be uploaded as a whole.
151
+ maxChunkSize: undefined,
152
+ // When a non-multipart upload or a chunked multipart upload has been
153
+ // aborted, this option can be used to resume the upload by setting
154
+ // it to the size of the already uploaded bytes. This option is most
155
+ // useful when modifying the options object inside of the "add" or
156
+ // "send" callbacks, as the options are cloned for each file upload.
157
+ uploadedBytes: undefined,
158
+ // By default, failed (abort or error) file uploads are removed from the
159
+ // global progress calculation. Set the following option to false to
160
+ // prevent recalculating the global progress data:
161
+ recalculateProgress: true,
162
+ // Interval in milliseconds to calculate and trigger progress events:
163
+ progressInterval: 100,
164
+ // Interval in milliseconds to calculate progress bitrate:
165
+ bitrateInterval: 500,
166
+ // By default, uploads are started automatically when adding files:
167
+ autoUpload: true,
168
+ // By default, duplicate file names are expected to be handled on
169
+ // the server-side. If this is not possible (e.g. when uploading
170
+ // files directly to Amazon S3), the following option can be set to
171
+ // an empty object or an object mapping existing filenames, e.g.:
172
+ // { "image.jpg": true, "image (1).jpg": true }
173
+ // If it is set, all files will be uploaded with unique filenames,
174
+ // adding increasing number suffixes if necessary, e.g.:
175
+ // "image (2).jpg"
176
+ uniqueFilenames: undefined,
177
+
178
+ // Error and info messages:
179
+ messages: {
180
+ uploadedBytes: 'Uploaded bytes exceed file size'
181
+ },
182
+
183
+ // Translation function, gets the message key to be translated
184
+ // and an object with context specific data as arguments:
185
+ i18n: function (message, context) {
186
+ message = this.messages[message] || message.toString();
187
+ if (context) {
188
+ $.each(context, function (key, value) {
189
+ message = message.replace('{' + key + '}', value);
190
+ });
191
+ }
192
+ return message;
193
+ },
194
+
195
+ // Additional form data to be sent along with the file uploads can be set
196
+ // using this option, which accepts an array of objects with name and
197
+ // value properties, a function returning such an array, a FormData
198
+ // object (for XHR file uploads), or a simple object.
199
+ // The form of the first fileInput is given as parameter to the function:
200
+ formData: function (form) {
201
+ return form.serializeArray();
202
+ },
203
+
204
+ // The add callback is invoked as soon as files are added to the fileupload
205
+ // widget (via file input selection, drag & drop, paste or add API call).
206
+ // If the singleFileUploads option is enabled, this callback will be
207
+ // called once for each file in the selection for XHR file uploads, else
208
+ // once for each file selection.
209
+ //
210
+ // The upload starts when the submit method is invoked on the data parameter.
211
+ // The data object contains a files property holding the added files
212
+ // and allows you to override plugin options as well as define ajax settings.
213
+ //
214
+ // Listeners for this callback can also be bound the following way:
215
+ // .bind('fileuploadadd', func);
216
+ //
217
+ // data.submit() returns a Promise object and allows to attach additional
218
+ // handlers using jQuery's Deferred callbacks:
219
+ // data.submit().done(func).fail(func).always(func);
220
+ add: function (e, data) {
221
+ if (e.isDefaultPrevented()) {
222
+ return false;
223
+ }
224
+ if (data.autoUpload || (data.autoUpload !== false &&
225
+ $(this).fileupload('option', 'autoUpload'))) {
226
+ data.process().done(function () {
227
+ data.submit();
228
+ });
229
+ }
230
+ },
231
+
232
+ // Other callbacks:
233
+
234
+ // Callback for the submit event of each file upload:
235
+ // submit: function (e, data) {}, // .bind('fileuploadsubmit', func);
236
+
237
+ // Callback for the start of each file upload request:
238
+ // send: function (e, data) {}, // .bind('fileuploadsend', func);
239
+
240
+ // Callback for successful uploads:
241
+ // done: function (e, data) {}, // .bind('fileuploaddone', func);
242
+
243
+ // Callback for failed (abort or error) uploads:
244
+ // fail: function (e, data) {}, // .bind('fileuploadfail', func);
245
+
246
+ // Callback for completed (success, abort or error) requests:
247
+ // always: function (e, data) {}, // .bind('fileuploadalways', func);
248
+
249
+ // Callback for upload progress events:
250
+ // progress: function (e, data) {}, // .bind('fileuploadprogress', func);
251
+
252
+ // Callback for global upload progress events:
253
+ // progressall: function (e, data) {}, // .bind('fileuploadprogressall', func);
254
+
255
+ // Callback for uploads start, equivalent to the global ajaxStart event:
256
+ // start: function (e) {}, // .bind('fileuploadstart', func);
257
+
258
+ // Callback for uploads stop, equivalent to the global ajaxStop event:
259
+ // stop: function (e) {}, // .bind('fileuploadstop', func);
260
+
261
+ // Callback for change events of the fileInput(s):
262
+ // change: function (e, data) {}, // .bind('fileuploadchange', func);
263
+
264
+ // Callback for paste events to the pasteZone(s):
265
+ // paste: function (e, data) {}, // .bind('fileuploadpaste', func);
266
+
267
+ // Callback for drop events of the dropZone(s):
268
+ // drop: function (e, data) {}, // .bind('fileuploaddrop', func);
269
+
270
+ // Callback for dragover events of the dropZone(s):
271
+ // dragover: function (e) {}, // .bind('fileuploaddragover', func);
272
+
273
+ // Callback before the start of each chunk upload request (before form data initialization):
274
+ // chunkbeforesend: function (e, data) {}, // .bind('fileuploadchunkbeforesend', func);
275
+
276
+ // Callback for the start of each chunk upload request:
277
+ // chunksend: function (e, data) {}, // .bind('fileuploadchunksend', func);
278
+
279
+ // Callback for successful chunk uploads:
280
+ // chunkdone: function (e, data) {}, // .bind('fileuploadchunkdone', func);
281
+
282
+ // Callback for failed (abort or error) chunk uploads:
283
+ // chunkfail: function (e, data) {}, // .bind('fileuploadchunkfail', func);
284
+
285
+ // Callback for completed (success, abort or error) chunk upload requests:
286
+ // chunkalways: function (e, data) {}, // .bind('fileuploadchunkalways', func);
287
+
288
+ // The plugin options are used as settings object for the ajax calls.
289
+ // The following are jQuery ajax settings required for the file uploads:
290
+ processData: false,
291
+ contentType: false,
292
+ cache: false,
293
+ timeout: 0
294
+ },
295
+
296
+ // A list of options that require reinitializing event listeners and/or
297
+ // special initialization code:
298
+ _specialOptions: [
299
+ 'fileInput',
300
+ 'dropZone',
301
+ 'pasteZone',
302
+ 'multipart',
303
+ 'forceIframeTransport'
304
+ ],
305
+
306
+ _blobSlice: $.support.blobSlice && function () {
307
+ var slice = this.slice || this.webkitSlice || this.mozSlice;
308
+ return slice.apply(this, arguments);
309
+ },
310
+
311
+ _BitrateTimer: function () {
312
+ this.timestamp = ((Date.now) ? Date.now() : (new Date()).getTime());
313
+ this.loaded = 0;
314
+ this.bitrate = 0;
315
+ this.getBitrate = function (now, loaded, interval) {
316
+ var timeDiff = now - this.timestamp;
317
+ if (!this.bitrate || !interval || timeDiff > interval) {
318
+ this.bitrate = (loaded - this.loaded) * (1000 / timeDiff) * 8;
319
+ this.loaded = loaded;
320
+ this.timestamp = now;
321
+ }
322
+ return this.bitrate;
323
+ };
324
+ },
325
+
326
+ _isXHRUpload: function (options) {
327
+ return !options.forceIframeTransport &&
328
+ ((!options.multipart && $.support.xhrFileUpload) ||
329
+ $.support.xhrFormDataFileUpload);
330
+ },
331
+
332
+ _getFormData: function (options) {
333
+ var formData;
334
+ if ($.type(options.formData) === 'function') {
335
+ return options.formData(options.form);
336
+ }
337
+ if ($.isArray(options.formData)) {
338
+ return options.formData;
339
+ }
340
+ if ($.type(options.formData) === 'object') {
341
+ formData = [];
342
+ $.each(options.formData, function (name, value) {
343
+ formData.push({name: name, value: value});
344
+ });
345
+ return formData;
346
+ }
347
+ return [];
348
+ },
349
+
350
+ _getTotal: function (files) {
351
+ var total = 0;
352
+ $.each(files, function (index, file) {
353
+ total += file.size || 1;
354
+ });
355
+ return total;
356
+ },
357
+
358
+ _initProgressObject: function (obj) {
359
+ var progress = {
360
+ loaded: 0,
361
+ total: 0,
362
+ bitrate: 0
363
+ };
364
+ if (obj._progress) {
365
+ $.extend(obj._progress, progress);
366
+ } else {
367
+ obj._progress = progress;
368
+ }
369
+ },
370
+
371
+ _initResponseObject: function (obj) {
372
+ var prop;
373
+ if (obj._response) {
374
+ for (prop in obj._response) {
375
+ if (obj._response.hasOwnProperty(prop)) {
376
+ delete obj._response[prop];
377
+ }
378
+ }
379
+ } else {
380
+ obj._response = {};
381
+ }
382
+ },
383
+
384
+ _onProgress: function (e, data) {
385
+ if (e.lengthComputable) {
386
+ var now = ((Date.now) ? Date.now() : (new Date()).getTime()),
387
+ loaded;
388
+ if (data._time && data.progressInterval &&
389
+ (now - data._time < data.progressInterval) &&
390
+ e.loaded !== e.total) {
391
+ return;
392
+ }
393
+ data._time = now;
394
+ loaded = Math.floor(
395
+ e.loaded / e.total * (data.chunkSize || data._progress.total)
396
+ ) + (data.uploadedBytes || 0);
397
+ // Add the difference from the previously loaded state
398
+ // to the global loaded counter:
399
+ this._progress.loaded += (loaded - data._progress.loaded);
400
+ this._progress.bitrate = this._bitrateTimer.getBitrate(
401
+ now,
402
+ this._progress.loaded,
403
+ data.bitrateInterval
404
+ );
405
+ data._progress.loaded = data.loaded = loaded;
406
+ data._progress.bitrate = data.bitrate = data._bitrateTimer.getBitrate(
407
+ now,
408
+ loaded,
409
+ data.bitrateInterval
410
+ );
411
+ // Trigger a custom progress event with a total data property set
412
+ // to the file size(s) of the current upload and a loaded data
413
+ // property calculated accordingly:
414
+ this._trigger(
415
+ 'progress',
416
+ $.Event('progress', {delegatedEvent: e}),
417
+ data
418
+ );
419
+ // Trigger a global progress event for all current file uploads,
420
+ // including ajax calls queued for sequential file uploads:
421
+ this._trigger(
422
+ 'progressall',
423
+ $.Event('progressall', {delegatedEvent: e}),
424
+ this._progress
425
+ );
426
+ }
427
+ },
428
+
429
+ _initProgressListener: function (options) {
430
+ var that = this,
431
+ xhr = options.xhr ? options.xhr() : $.ajaxSettings.xhr();
432
+ // Accesss to the native XHR object is required to add event listeners
433
+ // for the upload progress event:
434
+ if (xhr.upload) {
435
+ $(xhr.upload).bind('progress', function (e) {
436
+ var oe = e.originalEvent;
437
+ // Make sure the progress event properties get copied over:
438
+ e.lengthComputable = oe.lengthComputable;
439
+ e.loaded = oe.loaded;
440
+ e.total = oe.total;
441
+ that._onProgress(e, options);
442
+ });
443
+ options.xhr = function () {
444
+ return xhr;
445
+ };
446
+ }
447
+ },
448
+
449
+ _deinitProgressListener: function (options) {
450
+ var xhr = options.xhr ? options.xhr() : $.ajaxSettings.xhr();
451
+ if (xhr.upload) {
452
+ $(xhr.upload).unbind('progress');
453
+ }
454
+ },
455
+
456
+ _isInstanceOf: function (type, obj) {
457
+ // Cross-frame instanceof check
458
+ return Object.prototype.toString.call(obj) === '[object ' + type + ']';
459
+ },
460
+
461
+ _getUniqueFilename: function (name, map) {
462
+ name = String(name);
463
+ if (map[name]) {
464
+ name = name.replace(
465
+ /(?: \(([\d]+)\))?(\.[^.]+)?$/,
466
+ function (_, p1, p2) {
467
+ var index = p1 ? Number(p1) + 1 : 1;
468
+ var ext = p2 || '';
469
+ return ' (' + index + ')' + ext;
470
+ }
471
+ );
472
+ return this._getUniqueFilename(name, map);
473
+ }
474
+ map[name] = true;
475
+ return name;
476
+ },
477
+
478
+ _initXHRData: function (options) {
479
+ var that = this,
480
+ formData,
481
+ file = options.files[0],
482
+ // Ignore non-multipart setting if not supported:
483
+ multipart = options.multipart || !$.support.xhrFileUpload,
484
+ paramName = $.type(options.paramName) === 'array' ?
485
+ options.paramName[0] : options.paramName;
486
+ options.headers = $.extend({}, options.headers);
487
+ if (options.contentRange) {
488
+ options.headers['Content-Range'] = options.contentRange;
489
+ }
490
+ if (!multipart || options.blob || !this._isInstanceOf('File', file)) {
491
+ options.headers['Content-Disposition'] = 'attachment; filename="' +
492
+ encodeURI(file.uploadName || file.name) + '"';
493
+ }
494
+ if (!multipart) {
495
+ options.contentType = file.type || 'application/octet-stream';
496
+ options.data = options.blob || file;
497
+ } else if ($.support.xhrFormDataFileUpload) {
498
+ if (options.postMessage) {
499
+ // window.postMessage does not allow sending FormData
500
+ // objects, so we just add the File/Blob objects to
501
+ // the formData array and let the postMessage window
502
+ // create the FormData object out of this array:
503
+ formData = this._getFormData(options);
504
+ if (options.blob) {
505
+ formData.push({
506
+ name: paramName,
507
+ value: options.blob
508
+ });
509
+ } else {
510
+ $.each(options.files, function (index, file) {
511
+ formData.push({
512
+ name: ($.type(options.paramName) === 'array' &&
513
+ options.paramName[index]) || paramName,
514
+ value: file
515
+ });
516
+ });
517
+ }
518
+ } else {
519
+ if (that._isInstanceOf('FormData', options.formData)) {
520
+ formData = options.formData;
521
+ } else {
522
+ formData = new FormData();
523
+ $.each(this._getFormData(options), function (index, field) {
524
+ formData.append(field.name, field.value);
525
+ });
526
+ }
527
+ if (options.blob) {
528
+ formData.append(
529
+ paramName,
530
+ options.blob,
531
+ file.uploadName || file.name
532
+ );
533
+ } else {
534
+ $.each(options.files, function (index, file) {
535
+ // This check allows the tests to run with
536
+ // dummy objects:
537
+ if (that._isInstanceOf('File', file) ||
538
+ that._isInstanceOf('Blob', file)) {
539
+ var fileName = file.uploadName || file.name;
540
+ if (options.uniqueFilenames) {
541
+ fileName = that._getUniqueFilename(
542
+ fileName,
543
+ options.uniqueFilenames
544
+ );
545
+ }
546
+ formData.append(
547
+ ($.type(options.paramName) === 'array' &&
548
+ options.paramName[index]) || paramName,
549
+ file,
550
+ fileName
551
+ );
552
+ }
553
+ });
554
+ }
555
+ }
556
+ options.data = formData;
557
+ }
558
+ // Blob reference is not needed anymore, free memory:
559
+ options.blob = null;
560
+ },
561
+
562
+ _initIframeSettings: function (options) {
563
+ var targetHost = $('<a></a>').prop('href', options.url).prop('host');
564
+ // Setting the dataType to iframe enables the iframe transport:
565
+ options.dataType = 'iframe ' + (options.dataType || '');
566
+ // The iframe transport accepts a serialized array as form data:
567
+ options.formData = this._getFormData(options);
568
+ // Add redirect url to form data on cross-domain uploads:
569
+ if (options.redirect && targetHost && targetHost !== location.host) {
570
+ options.formData.push({
571
+ name: options.redirectParamName || 'redirect',
572
+ value: options.redirect
573
+ });
574
+ }
575
+ },
576
+
577
+ _initDataSettings: function (options) {
578
+ if (this._isXHRUpload(options)) {
579
+ if (!this._chunkedUpload(options, true)) {
580
+ if (!options.data) {
581
+ this._initXHRData(options);
582
+ }
583
+ this._initProgressListener(options);
584
+ }
585
+ if (options.postMessage) {
586
+ // Setting the dataType to postmessage enables the
587
+ // postMessage transport:
588
+ options.dataType = 'postmessage ' + (options.dataType || '');
589
+ }
590
+ } else {
591
+ this._initIframeSettings(options);
592
+ }
593
+ },
594
+
595
+ _getParamName: function (options) {
596
+ var fileInput = $(options.fileInput),
597
+ paramName = options.paramName;
598
+ if (!paramName) {
599
+ paramName = [];
600
+ fileInput.each(function () {
601
+ var input = $(this),
602
+ name = input.prop('name') || 'files[]',
603
+ i = (input.prop('files') || [1]).length;
604
+ while (i) {
605
+ paramName.push(name);
606
+ i -= 1;
607
+ }
608
+ });
609
+ if (!paramName.length) {
610
+ paramName = [fileInput.prop('name') || 'files[]'];
611
+ }
612
+ } else if (!$.isArray(paramName)) {
613
+ paramName = [paramName];
614
+ }
615
+ return paramName;
616
+ },
617
+
618
+ _initFormSettings: function (options) {
619
+ // Retrieve missing options from the input field and the
620
+ // associated form, if available:
621
+ if (!options.form || !options.form.length) {
622
+ options.form = $(options.fileInput.prop('form'));
623
+ // If the given file input doesn't have an associated form,
624
+ // use the default widget file input's form:
625
+ if (!options.form.length) {
626
+ options.form = $(this.options.fileInput.prop('form'));
627
+ }
628
+ }
629
+ options.paramName = this._getParamName(options);
630
+ if (!options.url) {
631
+ options.url = options.form.prop('action') || location.href;
632
+ }
633
+ // The HTTP request method must be "POST" or "PUT":
634
+ options.type = (options.type ||
635
+ ($.type(options.form.prop('method')) === 'string' &&
636
+ options.form.prop('method')) || ''
637
+ ).toUpperCase();
638
+ if (options.type !== 'POST' && options.type !== 'PUT' &&
639
+ options.type !== 'PATCH') {
640
+ options.type = 'POST';
641
+ }
642
+ if (!options.formAcceptCharset) {
643
+ options.formAcceptCharset = options.form.attr('accept-charset');
644
+ }
645
+ },
646
+
647
+ _getAJAXSettings: function (data) {
648
+ var options = $.extend({}, this.options, data);
649
+ this._initFormSettings(options);
650
+ this._initDataSettings(options);
651
+ return options;
652
+ },
653
+
654
+ // jQuery 1.6 doesn't provide .state(),
655
+ // while jQuery 1.8+ removed .isRejected() and .isResolved():
656
+ _getDeferredState: function (deferred) {
657
+ if (deferred.state) {
658
+ return deferred.state();
659
+ }
660
+ if (deferred.isResolved()) {
661
+ return 'resolved';
662
+ }
663
+ if (deferred.isRejected()) {
664
+ return 'rejected';
665
+ }
666
+ return 'pending';
667
+ },
668
+
669
+ // Maps jqXHR callbacks to the equivalent
670
+ // methods of the given Promise object:
671
+ _enhancePromise: function (promise) {
672
+ promise.success = promise.done;
673
+ promise.error = promise.fail;
674
+ promise.complete = promise.always;
675
+ return promise;
676
+ },
677
+
678
+ // Creates and returns a Promise object enhanced with
679
+ // the jqXHR methods abort, success, error and complete:
680
+ _getXHRPromise: function (resolveOrReject, context, args) {
681
+ var dfd = $.Deferred(),
682
+ promise = dfd.promise();
683
+ context = context || this.options.context || promise;
684
+ if (resolveOrReject === true) {
685
+ dfd.resolveWith(context, args);
686
+ } else if (resolveOrReject === false) {
687
+ dfd.rejectWith(context, args);
688
+ }
689
+ promise.abort = dfd.promise;
690
+ return this._enhancePromise(promise);
691
+ },
692
+
693
+ // Adds convenience methods to the data callback argument:
694
+ _addConvenienceMethods: function (e, data) {
695
+ var that = this,
696
+ getPromise = function (args) {
697
+ return $.Deferred().resolveWith(that, args).promise();
698
+ };
699
+ data.process = function (resolveFunc, rejectFunc) {
700
+ if (resolveFunc || rejectFunc) {
701
+ data._processQueue = this._processQueue =
702
+ (this._processQueue || getPromise([this])).then(
703
+ function () {
704
+ if (data.errorThrown) {
705
+ return $.Deferred()
706
+ .rejectWith(that, [data]).promise();
707
+ }
708
+ return getPromise(arguments);
709
+ }
710
+ ).then(resolveFunc, rejectFunc);
711
+ }
712
+ return this._processQueue || getPromise([this]);
713
+ };
714
+ data.submit = function () {
715
+ if (this.state() !== 'pending') {
716
+ data.jqXHR = this.jqXHR =
717
+ (that._trigger(
718
+ 'submit',
719
+ $.Event('submit', {delegatedEvent: e}),
720
+ this
721
+ ) !== false) && that._onSend(e, this);
722
+ }
723
+ return this.jqXHR || that._getXHRPromise();
724
+ };
725
+ data.abort = function () {
726
+ if (this.jqXHR) {
727
+ return this.jqXHR.abort();
728
+ }
729
+ this.errorThrown = 'abort';
730
+ that._trigger('fail', null, this);
731
+ return that._getXHRPromise(false);
732
+ };
733
+ data.state = function () {
734
+ if (this.jqXHR) {
735
+ return that._getDeferredState(this.jqXHR);
736
+ }
737
+ if (this._processQueue) {
738
+ return that._getDeferredState(this._processQueue);
739
+ }
740
+ };
741
+ data.processing = function () {
742
+ return !this.jqXHR && this._processQueue && that
743
+ ._getDeferredState(this._processQueue) === 'pending';
744
+ };
745
+ data.progress = function () {
746
+ return this._progress;
747
+ };
748
+ data.response = function () {
749
+ return this._response;
750
+ };
751
+ },
752
+
753
+ // Parses the Range header from the server response
754
+ // and returns the uploaded bytes:
755
+ _getUploadedBytes: function (jqXHR) {
756
+ var range = jqXHR.getResponseHeader('Range'),
757
+ parts = range && range.split('-'),
758
+ upperBytesPos = parts && parts.length > 1 &&
759
+ parseInt(parts[1], 10);
760
+ return upperBytesPos && upperBytesPos + 1;
761
+ },
762
+
763
+ // Uploads a file in multiple, sequential requests
764
+ // by splitting the file up in multiple blob chunks.
765
+ // If the second parameter is true, only tests if the file
766
+ // should be uploaded in chunks, but does not invoke any
767
+ // upload requests:
768
+ _chunkedUpload: function (options, testOnly) {
769
+ options.uploadedBytes = options.uploadedBytes || 0;
770
+ var that = this,
771
+ file = options.files[0],
772
+ fs = file.size,
773
+ ub = options.uploadedBytes,
774
+ mcs = options.maxChunkSize || fs,
775
+ slice = this._blobSlice,
776
+ dfd = $.Deferred(),
777
+ promise = dfd.promise(),
778
+ jqXHR,
779
+ upload;
780
+ if (!(this._isXHRUpload(options) && slice && (ub || ($.type(mcs) === 'function' ? mcs(options) : mcs) < fs)) ||
781
+ options.data) {
782
+ return false;
783
+ }
784
+ if (testOnly) {
785
+ return true;
786
+ }
787
+ if (ub >= fs) {
788
+ file.error = options.i18n('uploadedBytes');
789
+ return this._getXHRPromise(
790
+ false,
791
+ options.context,
792
+ [null, 'error', file.error]
793
+ );
794
+ }
795
+ // The chunk upload method:
796
+ upload = function () {
797
+ // Clone the options object for each chunk upload:
798
+ var o = $.extend({}, options),
799
+ currentLoaded = o._progress.loaded;
800
+ o.blob = slice.call(
801
+ file,
802
+ ub,
803
+ ub + ($.type(mcs) === 'function' ? mcs(o) : mcs),
804
+ file.type
805
+ );
806
+ // Store the current chunk size, as the blob itself
807
+ // will be dereferenced after data processing:
808
+ o.chunkSize = o.blob.size;
809
+ // Expose the chunk bytes position range:
810
+ o.contentRange = 'bytes ' + ub + '-' +
811
+ (ub + o.chunkSize - 1) + '/' + fs;
812
+ // Trigger chunkbeforesend to allow form data to be updated for this chunk
813
+ that._trigger('chunkbeforesend', null, o);
814
+ // Process the upload data (the blob and potential form data):
815
+ that._initXHRData(o);
816
+ // Add progress listeners for this chunk upload:
817
+ that._initProgressListener(o);
818
+ jqXHR = ((that._trigger('chunksend', null, o) !== false && $.ajax(o)) ||
819
+ that._getXHRPromise(false, o.context))
820
+ .done(function (result, textStatus, jqXHR) {
821
+ ub = that._getUploadedBytes(jqXHR) ||
822
+ (ub + o.chunkSize);
823
+ // Create a progress event if no final progress event
824
+ // with loaded equaling total has been triggered
825
+ // for this chunk:
826
+ if (currentLoaded + o.chunkSize - o._progress.loaded) {
827
+ that._onProgress($.Event('progress', {
828
+ lengthComputable: true,
829
+ loaded: ub - o.uploadedBytes,
830
+ total: ub - o.uploadedBytes
831
+ }), o);
832
+ }
833
+ options.uploadedBytes = o.uploadedBytes = ub;
834
+ o.result = result;
835
+ o.textStatus = textStatus;
836
+ o.jqXHR = jqXHR;
837
+ that._trigger('chunkdone', null, o);
838
+ that._trigger('chunkalways', null, o);
839
+ if (ub < fs) {
840
+ // File upload not yet complete,
841
+ // continue with the next chunk:
842
+ upload();
843
+ } else {
844
+ dfd.resolveWith(
845
+ o.context,
846
+ [result, textStatus, jqXHR]
847
+ );
848
+ }
849
+ })
850
+ .fail(function (jqXHR, textStatus, errorThrown) {
851
+ o.jqXHR = jqXHR;
852
+ o.textStatus = textStatus;
853
+ o.errorThrown = errorThrown;
854
+ that._trigger('chunkfail', null, o);
855
+ that._trigger('chunkalways', null, o);
856
+ dfd.rejectWith(
857
+ o.context,
858
+ [jqXHR, textStatus, errorThrown]
859
+ );
860
+ })
861
+ .always(function () {
862
+ that._deinitProgressListener(o);
863
+ });
864
+ };
865
+ this._enhancePromise(promise);
866
+ promise.abort = function () {
867
+ return jqXHR.abort();
868
+ };
869
+ upload();
870
+ return promise;
871
+ },
872
+
873
+ _beforeSend: function (e, data) {
874
+ if (this._active === 0) {
875
+ // the start callback is triggered when an upload starts
876
+ // and no other uploads are currently running,
877
+ // equivalent to the global ajaxStart event:
878
+ this._trigger('start');
879
+ // Set timer for global bitrate progress calculation:
880
+ this._bitrateTimer = new this._BitrateTimer();
881
+ // Reset the global progress values:
882
+ this._progress.loaded = this._progress.total = 0;
883
+ this._progress.bitrate = 0;
884
+ }
885
+ // Make sure the container objects for the .response() and
886
+ // .progress() methods on the data object are available
887
+ // and reset to their initial state:
888
+ this._initResponseObject(data);
889
+ this._initProgressObject(data);
890
+ data._progress.loaded = data.loaded = data.uploadedBytes || 0;
891
+ data._progress.total = data.total = this._getTotal(data.files) || 1;
892
+ data._progress.bitrate = data.bitrate = 0;
893
+ this._active += 1;
894
+ // Initialize the global progress values:
895
+ this._progress.loaded += data.loaded;
896
+ this._progress.total += data.total;
897
+ },
898
+
899
+ _onDone: function (result, textStatus, jqXHR, options) {
900
+ var total = options._progress.total,
901
+ response = options._response;
902
+ if (options._progress.loaded < total) {
903
+ // Create a progress event if no final progress event
904
+ // with loaded equaling total has been triggered:
905
+ this._onProgress($.Event('progress', {
906
+ lengthComputable: true,
907
+ loaded: total,
908
+ total: total
909
+ }), options);
910
+ }
911
+ response.result = options.result = result;
912
+ response.textStatus = options.textStatus = textStatus;
913
+ response.jqXHR = options.jqXHR = jqXHR;
914
+ this._trigger('done', null, options);
915
+ },
916
+
917
+ _onFail: function (jqXHR, textStatus, errorThrown, options) {
918
+ var response = options._response;
919
+ if (options.recalculateProgress) {
920
+ // Remove the failed (error or abort) file upload from
921
+ // the global progress calculation:
922
+ this._progress.loaded -= options._progress.loaded;
923
+ this._progress.total -= options._progress.total;
924
+ }
925
+ response.jqXHR = options.jqXHR = jqXHR;
926
+ response.textStatus = options.textStatus = textStatus;
927
+ response.errorThrown = options.errorThrown = errorThrown;
928
+ this._trigger('fail', null, options);
929
+ },
930
+
931
+ _onAlways: function (jqXHRorResult, textStatus, jqXHRorError, options) {
932
+ // jqXHRorResult, textStatus and jqXHRorError are added to the
933
+ // options object via done and fail callbacks
934
+ this._trigger('always', null, options);
935
+ },
936
+
937
+ _onSend: function (e, data) {
938
+ if (!data.submit) {
939
+ this._addConvenienceMethods(e, data);
940
+ }
941
+ var that = this,
942
+ jqXHR,
943
+ aborted,
944
+ slot,
945
+ pipe,
946
+ options = that._getAJAXSettings(data),
947
+ send = function () {
948
+ that._sending += 1;
949
+ // Set timer for bitrate progress calculation:
950
+ options._bitrateTimer = new that._BitrateTimer();
951
+ jqXHR = jqXHR || (
952
+ ((aborted || that._trigger(
953
+ 'send',
954
+ $.Event('send', {delegatedEvent: e}),
955
+ options
956
+ ) === false) &&
957
+ that._getXHRPromise(false, options.context, aborted)) ||
958
+ that._chunkedUpload(options) || $.ajax(options)
959
+ ).done(function (result, textStatus, jqXHR) {
960
+ that._onDone(result, textStatus, jqXHR, options);
961
+ }).fail(function (jqXHR, textStatus, errorThrown) {
962
+ that._onFail(jqXHR, textStatus, errorThrown, options);
963
+ }).always(function (jqXHRorResult, textStatus, jqXHRorError) {
964
+ that._deinitProgressListener(options);
965
+ that._onAlways(
966
+ jqXHRorResult,
967
+ textStatus,
968
+ jqXHRorError,
969
+ options
970
+ );
971
+ that._sending -= 1;
972
+ that._active -= 1;
973
+ if (options.limitConcurrentUploads &&
974
+ options.limitConcurrentUploads > that._sending) {
975
+ // Start the next queued upload,
976
+ // that has not been aborted:
977
+ var nextSlot = that._slots.shift();
978
+ while (nextSlot) {
979
+ if (that._getDeferredState(nextSlot) === 'pending') {
980
+ nextSlot.resolve();
981
+ break;
982
+ }
983
+ nextSlot = that._slots.shift();
984
+ }
985
+ }
986
+ if (that._active === 0) {
987
+ // The stop callback is triggered when all uploads have
988
+ // been completed, equivalent to the global ajaxStop event:
989
+ that._trigger('stop');
990
+ }
991
+ });
992
+ return jqXHR;
993
+ };
994
+ this._beforeSend(e, options);
995
+ if (this.options.sequentialUploads ||
996
+ (this.options.limitConcurrentUploads &&
997
+ this.options.limitConcurrentUploads <= this._sending)) {
998
+ if (this.options.limitConcurrentUploads > 1) {
999
+ slot = $.Deferred();
1000
+ this._slots.push(slot);
1001
+ pipe = slot.then(send);
1002
+ } else {
1003
+ this._sequence = this._sequence.then(send, send);
1004
+ pipe = this._sequence;
1005
+ }
1006
+ // Return the piped Promise object, enhanced with an abort method,
1007
+ // which is delegated to the jqXHR object of the current upload,
1008
+ // and jqXHR callbacks mapped to the equivalent Promise methods:
1009
+ pipe.abort = function () {
1010
+ aborted = [undefined, 'abort', 'abort'];
1011
+ if (!jqXHR) {
1012
+ if (slot) {
1013
+ slot.rejectWith(options.context, aborted);
1014
+ }
1015
+ return send();
1016
+ }
1017
+ return jqXHR.abort();
1018
+ };
1019
+ return this._enhancePromise(pipe);
1020
+ }
1021
+ return send();
1022
+ },
1023
+
1024
+ _onAdd: function (e, data) {
1025
+ var that = this,
1026
+ result = true,
1027
+ options = $.extend({}, this.options, data),
1028
+ files = data.files,
1029
+ filesLength = files.length,
1030
+ limit = options.limitMultiFileUploads,
1031
+ limitSize = options.limitMultiFileUploadSize,
1032
+ overhead = options.limitMultiFileUploadSizeOverhead,
1033
+ batchSize = 0,
1034
+ paramName = this._getParamName(options),
1035
+ paramNameSet,
1036
+ paramNameSlice,
1037
+ fileSet,
1038
+ i,
1039
+ j = 0;
1040
+ if (!filesLength) {
1041
+ return false;
1042
+ }
1043
+ if (limitSize && files[0].size === undefined) {
1044
+ limitSize = undefined;
1045
+ }
1046
+ if (!(options.singleFileUploads || limit || limitSize) ||
1047
+ !this._isXHRUpload(options)) {
1048
+ fileSet = [files];
1049
+ paramNameSet = [paramName];
1050
+ } else if (!(options.singleFileUploads || limitSize) && limit) {
1051
+ fileSet = [];
1052
+ paramNameSet = [];
1053
+ for (i = 0; i < filesLength; i += limit) {
1054
+ fileSet.push(files.slice(i, i + limit));
1055
+ paramNameSlice = paramName.slice(i, i + limit);
1056
+ if (!paramNameSlice.length) {
1057
+ paramNameSlice = paramName;
1058
+ }
1059
+ paramNameSet.push(paramNameSlice);
1060
+ }
1061
+ } else if (!options.singleFileUploads && limitSize) {
1062
+ fileSet = [];
1063
+ paramNameSet = [];
1064
+ for (i = 0; i < filesLength; i = i + 1) {
1065
+ batchSize += files[i].size + overhead;
1066
+ if (i + 1 === filesLength ||
1067
+ ((batchSize + files[i + 1].size + overhead) > limitSize) ||
1068
+ (limit && i + 1 - j >= limit)) {
1069
+ fileSet.push(files.slice(j, i + 1));
1070
+ paramNameSlice = paramName.slice(j, i + 1);
1071
+ if (!paramNameSlice.length) {
1072
+ paramNameSlice = paramName;
1073
+ }
1074
+ paramNameSet.push(paramNameSlice);
1075
+ j = i + 1;
1076
+ batchSize = 0;
1077
+ }
1078
+ }
1079
+ } else {
1080
+ paramNameSet = paramName;
1081
+ }
1082
+ data.originalFiles = files;
1083
+ $.each(fileSet || files, function (index, element) {
1084
+ var newData = $.extend({}, data);
1085
+ newData.files = fileSet ? element : [element];
1086
+ newData.paramName = paramNameSet[index];
1087
+ that._initResponseObject(newData);
1088
+ that._initProgressObject(newData);
1089
+ that._addConvenienceMethods(e, newData);
1090
+ result = that._trigger(
1091
+ 'add',
1092
+ $.Event('add', {delegatedEvent: e}),
1093
+ newData
1094
+ );
1095
+ return result;
1096
+ });
1097
+ return result;
1098
+ },
1099
+
1100
+ _replaceFileInput: function (data) {
1101
+ var input = data.fileInput,
1102
+ inputClone = input.clone(true),
1103
+ restoreFocus = input.is(document.activeElement);
1104
+ // Add a reference for the new cloned file input to the data argument:
1105
+ data.fileInputClone = inputClone;
1106
+ $('<form></form>').append(inputClone)[0].reset();
1107
+ // Detaching allows to insert the fileInput on another form
1108
+ // without loosing the file input value:
1109
+ input.after(inputClone).detach();
1110
+ // If the fileInput had focus before it was detached,
1111
+ // restore focus to the inputClone.
1112
+ if (restoreFocus) {
1113
+ inputClone.focus();
1114
+ }
1115
+ // Avoid memory leaks with the detached file input:
1116
+ $.cleanData(input.unbind('remove'));
1117
+ // Replace the original file input element in the fileInput
1118
+ // elements set with the clone, which has been copied including
1119
+ // event handlers:
1120
+ this.options.fileInput = this.options.fileInput.map(function (i, el) {
1121
+ if (el === input[0]) {
1122
+ return inputClone[0];
1123
+ }
1124
+ return el;
1125
+ });
1126
+ // If the widget has been initialized on the file input itself,
1127
+ // override this.element with the file input clone:
1128
+ if (input[0] === this.element[0]) {
1129
+ this.element = inputClone;
1130
+ }
1131
+ },
1132
+
1133
+ _handleFileTreeEntry: function (entry, path) {
1134
+ var that = this,
1135
+ dfd = $.Deferred(),
1136
+ entries = [],
1137
+ dirReader,
1138
+ errorHandler = function (e) {
1139
+ if (e && !e.entry) {
1140
+ e.entry = entry;
1141
+ }
1142
+ // Since $.when returns immediately if one
1143
+ // Deferred is rejected, we use resolve instead.
1144
+ // This allows valid files and invalid items
1145
+ // to be returned together in one set:
1146
+ dfd.resolve([e]);
1147
+ },
1148
+ successHandler = function (entries) {
1149
+ that._handleFileTreeEntries(
1150
+ entries,
1151
+ path + entry.name + '/'
1152
+ ).done(function (files) {
1153
+ dfd.resolve(files);
1154
+ }).fail(errorHandler);
1155
+ },
1156
+ readEntries = function () {
1157
+ dirReader.readEntries(function (results) {
1158
+ if (!results.length) {
1159
+ successHandler(entries);
1160
+ } else {
1161
+ entries = entries.concat(results);
1162
+ readEntries();
1163
+ }
1164
+ }, errorHandler);
1165
+ };
1166
+ path = path || '';
1167
+ if (entry.isFile) {
1168
+ if (entry._file) {
1169
+ // Workaround for Chrome bug #149735
1170
+ entry._file.relativePath = path;
1171
+ dfd.resolve(entry._file);
1172
+ } else {
1173
+ entry.file(function (file) {
1174
+ file.relativePath = path;
1175
+ dfd.resolve(file);
1176
+ }, errorHandler);
1177
+ }
1178
+ } else if (entry.isDirectory) {
1179
+ dirReader = entry.createReader();
1180
+ readEntries();
1181
+ } else {
1182
+ // Return an empty list for file system items
1183
+ // other than files or directories:
1184
+ dfd.resolve([]);
1185
+ }
1186
+ return dfd.promise();
1187
+ },
1188
+
1189
+ _handleFileTreeEntries: function (entries, path) {
1190
+ var that = this;
1191
+ return $.when.apply(
1192
+ $,
1193
+ $.map(entries, function (entry) {
1194
+ return that._handleFileTreeEntry(entry, path);
1195
+ })
1196
+ ).then(function () {
1197
+ return Array.prototype.concat.apply(
1198
+ [],
1199
+ arguments
1200
+ );
1201
+ });
1202
+ },
1203
+
1204
+ _getDroppedFiles: function (dataTransfer) {
1205
+ dataTransfer = dataTransfer || {};
1206
+ var items = dataTransfer.items;
1207
+ if (items && items.length && (items[0].webkitGetAsEntry ||
1208
+ items[0].getAsEntry)) {
1209
+ return this._handleFileTreeEntries(
1210
+ $.map(items, function (item) {
1211
+ var entry;
1212
+ if (item.webkitGetAsEntry) {
1213
+ entry = item.webkitGetAsEntry();
1214
+ if (entry) {
1215
+ // Workaround for Chrome bug #149735:
1216
+ entry._file = item.getAsFile();
1217
+ }
1218
+ return entry;
1219
+ }
1220
+ return item.getAsEntry();
1221
+ })
1222
+ );
1223
+ }
1224
+ return $.Deferred().resolve(
1225
+ $.makeArray(dataTransfer.files)
1226
+ ).promise();
1227
+ },
1228
+
1229
+ _getSingleFileInputFiles: function (fileInput) {
1230
+ fileInput = $(fileInput);
1231
+ var entries = fileInput.prop('webkitEntries') ||
1232
+ fileInput.prop('entries'),
1233
+ files,
1234
+ value;
1235
+ if (entries && entries.length) {
1236
+ return this._handleFileTreeEntries(entries);
1237
+ }
1238
+ files = $.makeArray(fileInput.prop('files'));
1239
+ if (!files.length) {
1240
+ value = fileInput.prop('value');
1241
+ if (!value) {
1242
+ return $.Deferred().resolve([]).promise();
1243
+ }
1244
+ // If the files property is not available, the browser does not
1245
+ // support the File API and we add a pseudo File object with
1246
+ // the input value as name with path information removed:
1247
+ files = [{name: value.replace(/^.*\\/, '')}];
1248
+ } else if (files[0].name === undefined && files[0].fileName) {
1249
+ // File normalization for Safari 4 and Firefox 3:
1250
+ $.each(files, function (index, file) {
1251
+ file.name = file.fileName;
1252
+ file.size = file.fileSize;
1253
+ });
1254
+ }
1255
+ return $.Deferred().resolve(files).promise();
1256
+ },
1257
+
1258
+ _getFileInputFiles: function (fileInput) {
1259
+ if (!(fileInput instanceof $) || fileInput.length === 1) {
1260
+ return this._getSingleFileInputFiles(fileInput);
1261
+ }
1262
+ return $.when.apply(
1263
+ $,
1264
+ $.map(fileInput, this._getSingleFileInputFiles)
1265
+ ).then(function () {
1266
+ return Array.prototype.concat.apply(
1267
+ [],
1268
+ arguments
1269
+ );
1270
+ });
1271
+ },
1272
+
1273
+ _onChange: function (e) {
1274
+ var that = this,
1275
+ data = {
1276
+ fileInput: $(e.target),
1277
+ form: $(e.target.form)
1278
+ };
1279
+ this._getFileInputFiles(data.fileInput).always(function (files) {
1280
+ data.files = files;
1281
+ if (that.options.replaceFileInput) {
1282
+ that._replaceFileInput(data);
1283
+ }
1284
+ if (that._trigger(
1285
+ 'change',
1286
+ $.Event('change', {delegatedEvent: e}),
1287
+ data
1288
+ ) !== false) {
1289
+ that._onAdd(e, data);
1290
+ }
1291
+ });
1292
+ },
1293
+
1294
+ _onPaste: function (e) {
1295
+ var items = e.originalEvent && e.originalEvent.clipboardData &&
1296
+ e.originalEvent.clipboardData.items,
1297
+ data = {files: []};
1298
+ if (items && items.length) {
1299
+ $.each(items, function (index, item) {
1300
+ var file = item.getAsFile && item.getAsFile();
1301
+ if (file) {
1302
+ data.files.push(file);
1303
+ }
1304
+ });
1305
+ if (this._trigger(
1306
+ 'paste',
1307
+ $.Event('paste', {delegatedEvent: e}),
1308
+ data
1309
+ ) !== false) {
1310
+ this._onAdd(e, data);
1311
+ }
1312
+ }
1313
+ },
1314
+
1315
+ _onDrop: function (e) {
1316
+ e.dataTransfer = e.originalEvent && e.originalEvent.dataTransfer;
1317
+ var that = this,
1318
+ dataTransfer = e.dataTransfer,
1319
+ data = {};
1320
+ if (dataTransfer && dataTransfer.files && dataTransfer.files.length) {
1321
+ e.preventDefault();
1322
+ this._getDroppedFiles(dataTransfer).always(function (files) {
1323
+ data.files = files;
1324
+ if (that._trigger(
1325
+ 'drop',
1326
+ $.Event('drop', {delegatedEvent: e}),
1327
+ data
1328
+ ) !== false) {
1329
+ that._onAdd(e, data);
1330
+ }
1331
+ });
1332
+ }
1333
+ },
1334
+
1335
+ _onDragOver: getDragHandler('dragover'),
1336
+
1337
+ _onDragEnter: getDragHandler('dragenter'),
1338
+
1339
+ _onDragLeave: getDragHandler('dragleave'),
1340
+
1341
+ _initEventHandlers: function () {
1342
+ if (this._isXHRUpload(this.options)) {
1343
+ this._on(this.options.dropZone, {
1344
+ dragover: this._onDragOver,
1345
+ drop: this._onDrop,
1346
+ // event.preventDefault() on dragenter is required for IE10+:
1347
+ dragenter: this._onDragEnter,
1348
+ // dragleave is not required, but added for completeness:
1349
+ dragleave: this._onDragLeave
1350
+ });
1351
+ this._on(this.options.pasteZone, {
1352
+ paste: this._onPaste
1353
+ });
1354
+ }
1355
+ if ($.support.fileInput) {
1356
+ this._on(this.options.fileInput, {
1357
+ change: this._onChange
1358
+ });
1359
+ }
1360
+ },
1361
+
1362
+ _destroyEventHandlers: function () {
1363
+ this._off(this.options.dropZone, 'dragenter dragleave dragover drop');
1364
+ this._off(this.options.pasteZone, 'paste');
1365
+ this._off(this.options.fileInput, 'change');
1366
+ },
1367
+
1368
+ _destroy: function () {
1369
+ this._destroyEventHandlers();
1370
+ },
1371
+
1372
+ _setOption: function (key, value) {
1373
+ var reinit = $.inArray(key, this._specialOptions) !== -1;
1374
+ if (reinit) {
1375
+ this._destroyEventHandlers();
1376
+ }
1377
+ this._super(key, value);
1378
+ if (reinit) {
1379
+ this._initSpecialOptions();
1380
+ this._initEventHandlers();
1381
+ }
1382
+ },
1383
+
1384
+ _initSpecialOptions: function () {
1385
+ var options = this.options;
1386
+ if (options.fileInput === undefined) {
1387
+ options.fileInput = this.element.is('input[type="file"]') ?
1388
+ this.element : this.element.find('input[type="file"]');
1389
+ } else if (!(options.fileInput instanceof $)) {
1390
+ options.fileInput = $(options.fileInput);
1391
+ }
1392
+ if (!(options.dropZone instanceof $)) {
1393
+ options.dropZone = $(options.dropZone);
1394
+ }
1395
+ if (!(options.pasteZone instanceof $)) {
1396
+ options.pasteZone = $(options.pasteZone);
1397
+ }
1398
+ },
1399
+
1400
+ _getRegExp: function (str) {
1401
+ var parts = str.split('/'),
1402
+ modifiers = parts.pop();
1403
+ parts.shift();
1404
+ return new RegExp(parts.join('/'), modifiers);
1405
+ },
1406
+
1407
+ _isRegExpOption: function (key, value) {
1408
+ return key !== 'url' && $.type(value) === 'string' &&
1409
+ /^\/.*\/[igm]{0,3}$/.test(value);
1410
+ },
1411
+
1412
+ _initDataAttributes: function () {
1413
+ var that = this,
1414
+ options = this.options,
1415
+ data = this.element.data();
1416
+ // Initialize options set via HTML5 data-attributes:
1417
+ $.each(
1418
+ this.element[0].attributes,
1419
+ function (index, attr) {
1420
+ var key = attr.name.toLowerCase(),
1421
+ value;
1422
+ if (/^data-/.test(key)) {
1423
+ // Convert hyphen-ated key to camelCase:
1424
+ key = key.slice(5).replace(/-[a-z]/g, function (str) {
1425
+ return str.charAt(1).toUpperCase();
1426
+ });
1427
+ value = data[key];
1428
+ if (that._isRegExpOption(key, value)) {
1429
+ value = that._getRegExp(value);
1430
+ }
1431
+ options[key] = value;
1432
+ }
1433
+ }
1434
+ );
1435
+ },
1436
+
1437
+ _create: function () {
1438
+ this._initDataAttributes();
1439
+ this._initSpecialOptions();
1440
+ this._slots = [];
1441
+ this._sequence = this._getXHRPromise(true);
1442
+ this._sending = this._active = 0;
1443
+ this._initProgressObject(this);
1444
+ this._initEventHandlers();
1445
+ },
1446
+
1447
+ // This method is exposed to the widget API and allows to query
1448
+ // the number of active uploads:
1449
+ active: function () {
1450
+ return this._active;
1451
+ },
1452
+
1453
+ // This method is exposed to the widget API and allows to query
1454
+ // the widget upload progress.
1455
+ // It returns an object with loaded, total and bitrate properties
1456
+ // for the running uploads:
1457
+ progress: function () {
1458
+ return this._progress;
1459
+ },
1460
+
1461
+ // This method is exposed to the widget API and allows adding files
1462
+ // using the fileupload API. The data parameter accepts an object which
1463
+ // must have a files property and can contain additional options:
1464
+ // .fileupload('add', {files: filesList});
1465
+ add: function (data) {
1466
+ var that = this;
1467
+ if (!data || this.options.disabled) {
1468
+ return;
1469
+ }
1470
+ if (data.fileInput && !data.files) {
1471
+ this._getFileInputFiles(data.fileInput).always(function (files) {
1472
+ data.files = files;
1473
+ that._onAdd(null, data);
1474
+ });
1475
+ } else {
1476
+ data.files = $.makeArray(data.files);
1477
+ this._onAdd(null, data);
1478
+ }
1479
+ },
1480
+
1481
+ // This method is exposed to the widget API and allows sending files
1482
+ // using the fileupload API. The data parameter accepts an object which
1483
+ // must have a files or fileInput property and can contain additional options:
1484
+ // .fileupload('send', {files: filesList});
1485
+ // The method returns a Promise object for the file upload call.
1486
+ send: function (data) {
1487
+ if (data && !this.options.disabled) {
1488
+ if (data.fileInput && !data.files) {
1489
+ var that = this,
1490
+ dfd = $.Deferred(),
1491
+ promise = dfd.promise(),
1492
+ jqXHR,
1493
+ aborted;
1494
+ promise.abort = function () {
1495
+ aborted = true;
1496
+ if (jqXHR) {
1497
+ return jqXHR.abort();
1498
+ }
1499
+ dfd.reject(null, 'abort', 'abort');
1500
+ return promise;
1501
+ };
1502
+ this._getFileInputFiles(data.fileInput).always(
1503
+ function (files) {
1504
+ if (aborted) {
1505
+ return;
1506
+ }
1507
+ if (!files.length) {
1508
+ dfd.reject();
1509
+ return;
1510
+ }
1511
+ data.files = files;
1512
+ jqXHR = that._onSend(null, data);
1513
+ jqXHR.then(
1514
+ function (result, textStatus, jqXHR) {
1515
+ dfd.resolve(result, textStatus, jqXHR);
1516
+ },
1517
+ function (jqXHR, textStatus, errorThrown) {
1518
+ dfd.reject(jqXHR, textStatus, errorThrown);
1519
+ }
1520
+ );
1521
+ }
1522
+ );
1523
+ return this._enhancePromise(promise);
1524
+ }
1525
+ data.files = $.makeArray(data.files);
1526
+ if (data.files.length) {
1527
+ return this._onSend(null, data);
1528
+ }
1529
+ }
1530
+ return this._getXHRPromise(false, data && data.context);
1531
+ }
1532
+
1533
+ });
1534
 
1535
  }));
assets/js/jquery-fileupload/jquery.iframe-transport.js CHANGED
@@ -1,5 +1,5 @@
1
  /*
2
- * jQuery Iframe Transport Plugin v9.30.0
3
  * https://github.com/blueimp/jQuery-File-Upload
4
  *
5
  * Copyright 2011, Sebastian Tschan
@@ -12,213 +12,213 @@
12
  /* global define, require, window, document, JSON */
13
 
14
  ;(function (factory) {
15
- 'use strict';
16
- if (typeof define === 'function' && define.amd) {
17
- // Register as an anonymous AMD module:
18
- define(['jquery'], factory);
19
- } else if (typeof exports === 'object') {
20
- // Node/CommonJS:
21
- factory(require('jquery'));
22
- } else {
23
- // Browser globals:
24
- factory(window.jQuery);
25
- }
26
  }(function ($) {
27
- 'use strict';
28
 
29
- // Helper variable to create unique names for the transport iframes:
30
- var counter = 0,
31
- jsonAPI = $,
32
- jsonParse = 'parseJSON';
33
 
34
- if ('JSON' in window && 'parse' in JSON) {
35
- jsonAPI = JSON;
36
- jsonParse = 'parse';
37
- }
38
 
39
- // The iframe transport accepts four additional options:
40
- // options.fileInput: a jQuery collection of file input fields
41
- // options.paramName: the parameter name for the file form data,
42
- // overrides the name property of the file input field(s),
43
- // can be a string or an array of strings.
44
- // options.formData: an array of objects with name and value properties,
45
- // equivalent to the return data of .serializeArray(), e.g.:
46
- // [{name: 'a', value: 1}, {name: 'b', value: 2}]
47
- // options.initialIframeSrc: the URL of the initial iframe src,
48
- // by default set to "javascript:false;"
49
- $.ajaxTransport('iframe', function (options) {
50
- if (options.async) {
51
- // javascript:false as initial iframe src
52
- // prevents warning popups on HTTPS in IE6:
53
- /*jshint scripturl: true */
54
- var initialIframeSrc = options.initialIframeSrc || 'javascript:false;',
55
- /*jshint scripturl: false */
56
- form,
57
- iframe,
58
- addParamChar;
59
- return {
60
- send: function (_, completeCallback) {
61
- form = $('<form style="display:none;"></form>');
62
- form.attr('accept-charset', options.formAcceptCharset);
63
- addParamChar = /\?/.test(options.url) ? '&' : '?';
64
- // XDomainRequest only supports GET and POST:
65
- if (options.type === 'DELETE') {
66
- options.url = options.url + addParamChar + '_method=DELETE';
67
- options.type = 'POST';
68
- } else if (options.type === 'PUT') {
69
- options.url = options.url + addParamChar + '_method=PUT';
70
- options.type = 'POST';
71
- } else if (options.type === 'PATCH') {
72
- options.url = options.url + addParamChar + '_method=PATCH';
73
- options.type = 'POST';
74
- }
75
- // IE versions below IE8 cannot set the name property of
76
- // elements that have already been added to the DOM,
77
- // so we set the name along with the iframe HTML markup:
78
- counter += 1;
79
- iframe = $(
80
- '<iframe src="' + initialIframeSrc +
81
- '" name="iframe-transport-' + counter + '"></iframe>'
82
- ).bind('load', function () {
83
- var fileInputClones,
84
- paramNames = $.isArray(options.paramName) ?
85
- options.paramName : [options.paramName];
86
- iframe
87
- .unbind('load')
88
- .bind('load', function () {
89
- var response;
90
- // Wrap in a try/catch block to catch exceptions thrown
91
- // when trying to access cross-domain iframe contents:
92
- try {
93
- response = iframe.contents();
94
- // Google Chrome and Firefox do not throw an
95
- // exception when calling iframe.contents() on
96
- // cross-domain requests, so we unify the response:
97
- if (!response.length || !response[0].firstChild) {
98
- throw new Error();
99
- }
100
- } catch (e) {
101
- response = undefined;
102
- }
103
- // The complete callback returns the
104
- // iframe content document as response object:
105
- completeCallback(
106
- 200,
107
- 'success',
108
- {'iframe': response}
109
- );
110
- // Fix for IE endless progress bar activity bug
111
- // (happens on form submits to iframe targets):
112
- $('<iframe src="' + initialIframeSrc + '"></iframe>')
113
- .appendTo(form);
114
- window.setTimeout(function () {
115
- // Removing the form in a setTimeout call
116
- // allows Chrome's developer tools to display
117
- // the response result
118
- form.remove();
119
- }, 0);
120
- });
121
- form
122
- .prop('target', iframe.prop('name'))
123
- .prop('action', options.url)
124
- .prop('method', options.type);
125
- if (options.formData) {
126
- $.each(options.formData, function (index, field) {
127
- $('<input type="hidden"/>')
128
- .prop('name', field.name)
129
- .val(field.value)
130
- .appendTo(form);
131
- });
132
- }
133
- if (options.fileInput && options.fileInput.length &&
134
- options.type === 'POST') {
135
- fileInputClones = options.fileInput.clone();
136
- // Insert a clone for each file input field:
137
- options.fileInput.after(function (index) {
138
- return fileInputClones[index];
139
- });
140
- if (options.paramName) {
141
- options.fileInput.each(function (index) {
142
- $(this).prop(
143
- 'name',
144
- paramNames[index] || options.paramName
145
- );
146
- });
147
- }
148
- // Appending the file input fields to the hidden form
149
- // removes them from their original location:
150
- form
151
- .append(options.fileInput)
152
- .prop('enctype', 'multipart/form-data')
153
- // enctype must be set as encoding for IE:
154
- .prop('encoding', 'multipart/form-data');
155
- // Remove the HTML5 form attribute from the input(s):
156
- options.fileInput.removeAttr('form');
157
- }
158
- form.submit();
159
- // Insert the file input fields at their original location
160
- // by replacing the clones with the originals:
161
- if (fileInputClones && fileInputClones.length) {
162
- options.fileInput.each(function (index, input) {
163
- var clone = $(fileInputClones[index]);
164
- // Restore the original name and form properties:
165
- $(input)
166
- .prop('name', clone.prop('name'))
167
- .attr('form', clone.attr('form'));
168
- clone.replaceWith(input);
169
- });
170
- }
171
- });
172
- form.append(iframe).appendTo(document.body);
173
- },
174
- abort: function () {
175
- if (iframe) {
176
- // javascript:false as iframe src aborts the request
177
- // and prevents warning popups on HTTPS in IE6.
178
- // concat is used to avoid the "Script URL" JSLint error:
179
- iframe
180
- .unbind('load')
181
- .prop('src', initialIframeSrc);
182
- }
183
- if (form) {
184
- form.remove();
185
- }
186
- }
187
- };
188
- }
189
- });
190
 
191
- // The iframe transport returns the iframe content document as response.
192
- // The following adds converters from iframe to text, json, html, xml
193
- // and script.
194
- // Please note that the Content-Type for JSON responses has to be text/plain
195
- // or text/html, if the browser doesn't include application/json in the
196
- // Accept header, else IE will show a download dialog.
197
- // The Content-Type for XML responses on the other hand has to be always
198
- // application/xml or text/xml, so IE properly parses the XML response.
199
- // See also
200
- // https://github.com/blueimp/jQuery-File-Upload/wiki/Setup#content-type-negotiation
201
- $.ajaxSetup({
202
- converters: {
203
- 'iframe text': function (iframe) {
204
- return iframe && $(iframe[0].body).text();
205
- },
206
- 'iframe json': function (iframe) {
207
- return iframe && jsonAPI[jsonParse]($(iframe[0].body).text());
208
- },
209
- 'iframe html': function (iframe) {
210
- return iframe && $(iframe[0].body).html();
211
- },
212
- 'iframe xml': function (iframe) {
213
- var xmlDoc = iframe && iframe[0];
214
- return xmlDoc && $.isXMLDoc(xmlDoc) ? xmlDoc :
215
- $.parseXML((xmlDoc.XMLDocument && xmlDoc.XMLDocument.xml) ||
216
- $(xmlDoc.body).html());
217
- },
218
- 'iframe script': function (iframe) {
219
- return iframe && $.globalEval($(iframe[0].body).text());
220
- }
221
- }
222
- });
223
 
224
  }));
1
  /*
2
+ * jQuery Iframe Transport Plugin v9.32.0
3
  * https://github.com/blueimp/jQuery-File-Upload
4
  *
5
  * Copyright 2011, Sebastian Tschan
12
  /* global define, require, window, document, JSON */
13
 
14
  ;(function (factory) {
15
+ 'use strict';
16
+ if (typeof define === 'function' && define.amd) {
17
+ // Register as an anonymous AMD module:
18
+ define(['jquery'], factory);
19
+ } else if (typeof exports === 'object') {
20
+ // Node/CommonJS:
21
+ factory(require('jquery'));
22
+ } else {
23
+ // Browser globals:
24
+ factory(window.jQuery);
25
+ }
26
  }(function ($) {
27
+ 'use strict';
28
 
29
+ // Helper variable to create unique names for the transport iframes:
30
+ var counter = 0,
31
+ jsonAPI = $,
32
+ jsonParse = 'parseJSON';
33
 
34
+ if ('JSON' in window && 'parse' in JSON) {
35
+ jsonAPI = JSON;
36
+ jsonParse = 'parse';
37
+ }
38
 
39
+ // The iframe transport accepts four additional options:
40
+ // options.fileInput: a jQuery collection of file input fields
41
+ // options.paramName: the parameter name for the file form data,
42
+ // overrides the name property of the file input field(s),
43
+ // can be a string or an array of strings.
44
+ // options.formData: an array of objects with name and value properties,
45
+ // equivalent to the return data of .serializeArray(), e.g.:
46
+ // [{name: 'a', value: 1}, {name: 'b', value: 2}]
47
+ // options.initialIframeSrc: the URL of the initial iframe src,
48
+ // by default set to "javascript:false;"
49
+ $.ajaxTransport('iframe', function (options) {
50
+ if (options.async) {
51
+ // javascript:false as initial iframe src
52
+ // prevents warning popups on HTTPS in IE6:
53
+ /*jshint scripturl: true */
54
+ var initialIframeSrc = options.initialIframeSrc || 'javascript:false;',
55
+ /*jshint scripturl: false */
56
+ form,
57
+ iframe,
58
+ addParamChar;
59
+ return {
60
+ send: function (_, completeCallback) {
61
+ form = $('<form style="display:none;"></form>');
62
+ form.attr('accept-charset', options.formAcceptCharset);
63
+ addParamChar = /\?/.test(options.url) ? '&' : '?';
64
+ // XDomainRequest only supports GET and POST:
65
+ if (options.type === 'DELETE') {
66
+ options.url = options.url + addParamChar + '_method=DELETE';
67
+ options.type = 'POST';
68
+ } else if (options.type === 'PUT') {
69
+ options.url = options.url + addParamChar + '_method=PUT';
70
+ options.type = 'POST';
71
+ } else if (options.type === 'PATCH') {
72
+ options.url = options.url + addParamChar + '_method=PATCH';
73
+ options.type = 'POST';
74
+ }
75
+ // IE versions below IE8 cannot set the name property of
76
+ // elements that have already been added to the DOM,
77
+ // so we set the name along with the iframe HTML markup:
78
+ counter += 1;
79
+ iframe = $(
80
+ '<iframe src="' + initialIframeSrc +
81
+ '" name="iframe-transport-' + counter + '"></iframe>'
82
+ ).bind('load', function () {
83
+ var fileInputClones,
84
+ paramNames = $.isArray(options.paramName) ?
85
+ options.paramName : [options.paramName];
86
+ iframe
87
+ .unbind('load')
88
+ .bind('load', function () {
89
+ var response;
90
+ // Wrap in a try/catch block to catch exceptions thrown
91
+ // when trying to access cross-domain iframe contents:
92
+ try {
93
+ response = iframe.contents();
94
+ // Google Chrome and Firefox do not throw an
95
+ // exception when calling iframe.contents() on
96
+ // cross-domain requests, so we unify the response:
97
+ if (!response.length || !response[0].firstChild) {
98
+ throw new Error();
99
+ }
100
+ } catch (e) {
101
+ response = undefined;
102
+ }
103
+ // The complete callback returns the
104
+ // iframe content document as response object:
105
+ completeCallback(
106
+ 200,
107
+ 'success',
108
+ {'iframe': response}
109
+ );
110
+ // Fix for IE endless progress bar activity bug
111
+ // (happens on form submits to iframe targets):
112
+ $('<iframe src="' + initialIframeSrc + '"></iframe>')
113
+ .appendTo(form);
114
+ window.setTimeout(function () {
115
+ // Removing the form in a setTimeout call
116
+ // allows Chrome's developer tools to display
117
+ // the response result
118
+ form.remove();
119
+ }, 0);
120
+ });
121
+ form
122
+ .prop('target', iframe.prop('name'))
123
+ .prop('action', options.url)
124
+ .prop('method', options.type);
125
+ if (options.formData) {
126
+ $.each(options.formData, function (index, field) {
127
+ $('<input type="hidden"/>')
128
+ .prop('name', field.name)
129
+ .val(field.value)
130
+ .appendTo(form);
131
+ });
132
+ }
133
+ if (options.fileInput && options.fileInput.length &&
134
+ options.type === 'POST') {
135
+ fileInputClones = options.fileInput.clone();
136
+ // Insert a clone for each file input field:
137
+ options.fileInput.after(function (index) {
138
+ return fileInputClones[index];
139
+ });
140
+ if (options.paramName) {
141
+ options.fileInput.each(function (index) {
142
+ $(this).prop(
143
+ 'name',
144
+ paramNames[index] || options.paramName
145
+ );
146
+ });
147
+ }
148
+ // Appending the file input fields to the hidden form
149
+ // removes them from their original location:
150
+ form
151
+ .append(options.fileInput)
152
+ .prop('enctype', 'multipart/form-data')
153
+ // enctype must be set as encoding for IE:
154
+ .prop('encoding', 'multipart/form-data');
155
+ // Remove the HTML5 form attribute from the input(s):
156
+ options.fileInput.removeAttr('form');
157
+ }
158
+ form.submit();
159
+ // Insert the file input fields at their original location
160
+ // by replacing the clones with the originals:
161
+ if (fileInputClones && fileInputClones.length) {
162
+ options.fileInput.each(function (index, input) {
163
+ var clone = $(fileInputClones[index]);
164
+ // Restore the original name and form properties:
165
+ $(input)
166
+ .prop('name', clone.prop('name'))
167
+ .attr('form', clone.attr('form'));
168
+ clone.replaceWith(input);
169
+ });
170
+ }
171
+ });
172
+ form.append(iframe).appendTo(document.body);
173
+ },
174
+ abort: function () {
175
+ if (iframe) {
176
+ // javascript:false as iframe src aborts the request
177
+ // and prevents warning popups on HTTPS in IE6.
178
+ // concat is used to avoid the "Script URL" JSLint error:
179
+ iframe
180
+ .unbind('load')
181
+ .prop('src', initialIframeSrc);
182
+ }
183
+ if (form) {
184
+ form.remove();
185
+ }
186
+ }
187
+ };
188
+ }
189
+ });
190
 
191
+ // The iframe transport returns the iframe content document as response.
192
+ // The following adds converters from iframe to text, json, html, xml
193
+ // and script.
194
+ // Please note that the Content-Type for JSON responses has to be text/plain
195
+ // or text/html, if the browser doesn't include application/json in the
196
+ // Accept header, else IE will show a download dialog.
197
+ // The Content-Type for XML responses on the other hand has to be always
198
+ // application/xml or text/xml, so IE properly parses the XML response.
199
+ // See also
200
+ // https://github.com/blueimp/jQuery-File-Upload/wiki/Setup#content-type-negotiation
201
+ $.ajaxSetup({
202
+ converters: {
203
+ 'iframe text': function (iframe) {
204
+ return iframe && $(iframe[0].body).text();
205
+ },
206
+ 'iframe json': function (iframe) {
207
+ return iframe && jsonAPI[jsonParse]($(iframe[0].body).text());
208
+ },
209
+ 'iframe html': function (iframe) {
210
+ return iframe && $(iframe[0].body).html();
211
+ },
212
+ 'iframe xml': function (iframe) {
213
+ var xmlDoc = iframe && iframe[0];
214
+ return xmlDoc && $.isXMLDoc(xmlDoc) ? xmlDoc :
215
+ $.parseXML((xmlDoc.XMLDocument && xmlDoc.XMLDocument.xml) ||
216
+ $(xmlDoc.body).html());
217
+ },
218
+ 'iframe script': function (iframe) {
219
+ return iframe && $.globalEval($(iframe[0].body).text());
220
+ }
221
+ }
222
+ });
223
 
224
  }));
changelog.txt CHANGED
@@ -1,3 +1,7 @@
 
 
 
 
1
  = 1.33.2 =
2
  * Fix: Issue with `[jobs]` filter form on some themes and plugins.
3
 
1
+ = 1.33.3 =
2
+ * Fix: Upgrade jquery-fileupload to v9.32.0
3
+ * Fix: Set frame origin on pages where shortcodes are embedded
4
+
5
  = 1.33.2 =
6
  * Fix: Issue with `[jobs]` filter form on some themes and plugins.
7
 
includes/class-wp-job-manager.php CHANGED
@@ -94,6 +94,7 @@ class WP_Job_Manager {
94
  add_action( 'wp_logout', array( $this, 'cleanup_job_posting_cookies' ) );
95
  add_action( 'init', array( 'WP_Job_Manager_Email_Notifications', 'init' ) );
96
  add_action( 'rest_api_init', array( $this, 'rest_init' ) );
 
97
 
98
  // Filters.
99
  add_filter( 'wp_privacy_personal_data_exporters', array( 'WP_Job_Manager_Data_Exporter', 'register_wpjm_user_data_exporter' ) );
@@ -142,7 +143,7 @@ class WP_Job_Manager {
142
  $content = sprintf(
143
  // translators: Placeholders %1$s and %2$s are the names of the two cookies used in WP Job Manager.
144
  __(
145
- 'This site adds the following cookies to help users resume job submissions that they
146
  have started but have not completed: %1$s and %2$s', 'wp-job-manager'
147
  ),
148
  '<code>wp-job-manager-submitting-job-id</code>', '<code>wp-job-manager-submitting-job-key</code>'
@@ -295,7 +296,6 @@ class WP_Job_Manager {
295
 
296
  $enhanced_select_shortcodes = array( 'submit_job_form', 'job_dashboard', 'jobs' );
297
  $enhanced_select_used_on_page = has_wpjm_shortcode( null, $enhanced_select_shortcodes );
298
-
299
  /**
300
  * Set the constant `JOB_MANAGER_DISABLE_CHOSEN_LEGACY_COMPAT` to true to test for future behavior once
301
  * this legacy code is removed and `chosen` is no longer packaged with the plugin.
@@ -372,8 +372,8 @@ class WP_Job_Manager {
372
  }
373
 
374
  if ( job_manager_user_can_upload_file_via_ajax() ) {
375
- wp_register_script( 'jquery-iframe-transport', JOB_MANAGER_PLUGIN_URL . '/assets/js/jquery-fileupload/jquery.iframe-transport.js', array( 'jquery' ), '9.30.0', true );
376
- wp_register_script( 'jquery-fileupload', JOB_MANAGER_PLUGIN_URL . '/assets/js/jquery-fileupload/jquery.fileupload.js', array( 'jquery', 'jquery-iframe-transport', 'jquery-ui-widget' ), '9.30.0', true );
377
  wp_register_script( 'wp-job-manager-ajax-file-upload', JOB_MANAGER_PLUGIN_URL . '/assets/js/ajax-file-upload.min.js', array( 'jquery', 'jquery-fileupload' ), JOB_MANAGER_VERSION, true );
378
 
379
  ob_start();
@@ -472,4 +472,22 @@ class WP_Job_Manager {
472
  wp_register_style( 'wp-job-manager-job-listings', JOB_MANAGER_PLUGIN_URL . '/assets/css/job-listings.css', array(), JOB_MANAGER_VERSION );
473
  }
474
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
475
  }
94
  add_action( 'wp_logout', array( $this, 'cleanup_job_posting_cookies' ) );
95
  add_action( 'init', array( 'WP_Job_Manager_Email_Notifications', 'init' ) );
96
  add_action( 'rest_api_init', array( $this, 'rest_init' ) );
97
+ add_action( 'template_redirect', array( $this, 'send_frame_options_header' ) );
98
 
99
  // Filters.
100
  add_filter( 'wp_privacy_personal_data_exporters', array( 'WP_Job_Manager_Data_Exporter', 'register_wpjm_user_data_exporter' ) );
143
  $content = sprintf(
144
  // translators: Placeholders %1$s and %2$s are the names of the two cookies used in WP Job Manager.
145
  __(
146
+ 'This site adds the following cookies to help users resume job submissions that they
147
  have started but have not completed: %1$s and %2$s', 'wp-job-manager'
148
  ),
149
  '<code>wp-job-manager-submitting-job-id</code>', '<code>wp-job-manager-submitting-job-key</code>'
296
 
297
  $enhanced_select_shortcodes = array( 'submit_job_form', 'job_dashboard', 'jobs' );
298
  $enhanced_select_used_on_page = has_wpjm_shortcode( null, $enhanced_select_shortcodes );
 
299
  /**
300
  * Set the constant `JOB_MANAGER_DISABLE_CHOSEN_LEGACY_COMPAT` to true to test for future behavior once
301
  * this legacy code is removed and `chosen` is no longer packaged with the plugin.
372
  }
373
 
374
  if ( job_manager_user_can_upload_file_via_ajax() ) {
375
+ wp_register_script( 'jquery-iframe-transport', JOB_MANAGER_PLUGIN_URL . '/assets/js/jquery-fileupload/jquery.iframe-transport.js', array( 'jquery' ), '9.32.0', true );
376
+ wp_register_script( 'jquery-fileupload', JOB_MANAGER_PLUGIN_URL . '/assets/js/jquery-fileupload/jquery.fileupload.js', array( 'jquery', 'jquery-iframe-transport', 'jquery-ui-widget' ), '9.32.0', true );
377
  wp_register_script( 'wp-job-manager-ajax-file-upload', JOB_MANAGER_PLUGIN_URL . '/assets/js/ajax-file-upload.min.js', array( 'jquery', 'jquery-fileupload' ), JOB_MANAGER_VERSION, true );
378
 
379
  ob_start();
472
  wp_register_style( 'wp-job-manager-job-listings', JOB_MANAGER_PLUGIN_URL . '/assets/css/job-listings.css', array(), JOB_MANAGER_VERSION );
473
  }
474
  }
475
+
476
+ /**
477
+ *
478
+ * Ensure all user wpjm pages or pages containing wpjm shortcodes
479
+ * get an X-Frame-Options header.
480
+ *
481
+ * Disabling is not recommended, but if you must you can
482
+ *
483
+ * remove_action( 'template_redirect', array( WPJM(), 'send_frame_options_header' ) )
484
+ *
485
+ * @since 1.33.3
486
+ *
487
+ **/
488
+ public function send_frame_options_header() {
489
+ if ( is_wpjm() ) {
490
+ send_frame_options_header();
491
+ }
492
+ }
493
  }
languages/wp-job-manager.pot CHANGED
@@ -2,9 +2,9 @@
2
  # This file is distributed under the GPL2+.
3
  msgid ""
4
  msgstr ""
5
- "Project-Id-Version: WP Job Manager 1.33.2\n"
6
  "Report-Msgid-Bugs-To: https://github.com/Automattic/WP-Job-Manager/issues\n"
7
- "POT-Creation-Date: 2019-06-12 17:05:27+00:00\n"
8
  "MIME-Version: 1.0\n"
9
  "Content-Type: text/plain; charset=utf-8\n"
10
  "Content-Transfer-Encoding: 8bit\n"
@@ -1453,16 +1453,16 @@ msgstr ""
1453
  msgid "Enable Usage Tracking"
1454
  msgstr ""
1455
 
1456
- #: includes/class-wp-job-manager.php:144
1457
  #. translators: Placeholders %1$s and %2$s are the names of the two cookies
1458
  #. used in WP Job Manager.
1459
  msgid ""
1460
  "This site adds the following cookies to help users resume job submissions "
1461
- "that they \n"
1462
  "\t\t\t\thave started but have not completed: %1$s and %2$s"
1463
  msgstr ""
1464
 
1465
- #: includes/class-wp-job-manager.php:284
1466
  msgid "Load previous listings"
1467
  msgstr ""
1468
 
2
  # This file is distributed under the GPL2+.
3
  msgid ""
4
  msgstr ""
5
+ "Project-Id-Version: WP Job Manager 1.33.3\n"
6
  "Report-Msgid-Bugs-To: https://github.com/Automattic/WP-Job-Manager/issues\n"
7
+ "POT-Creation-Date: 2019-07-08 16:37:22+00:00\n"
8
  "MIME-Version: 1.0\n"
9
  "Content-Type: text/plain; charset=utf-8\n"
10
  "Content-Transfer-Encoding: 8bit\n"
1453
  msgid "Enable Usage Tracking"
1454
  msgstr ""
1455
 
1456
+ #: includes/class-wp-job-manager.php:145
1457
  #. translators: Placeholders %1$s and %2$s are the names of the two cookies
1458
  #. used in WP Job Manager.
1459
  msgid ""
1460
  "This site adds the following cookies to help users resume job submissions "
1461
+ "that they\n"
1462
  "\t\t\t\thave started but have not completed: %1$s and %2$s"
1463
  msgstr ""
1464
 
1465
+ #: includes/class-wp-job-manager.php:285
1466
  msgid "Load previous listings"
1467
  msgstr ""
1468
 
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: mikejolley, automattic, adamkheckler, alexsanford1, annezazu, cena
3
  Tags: job manager, job listing, job board, job management, job lists, job list, job, jobs, company, hiring, employment, employer, employees, candidate, freelance, internship, job listings, positions, board, application, hiring, listing, manager, recruiting, recruitment, talent
4
  Requires at least: 4.7.0
5
  Tested up to: 5.2
6
- Stable tag: 1.33.2
7
  License: GPLv3
8
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
9
 
@@ -151,6 +151,9 @@ It then creates a database based on the parameters passed to it.
151
  6. Job listings in admin.
152
 
153
  == Changelog ==
 
 
 
154
 
155
  = 1.33.2 =
156
  * Fix: Issue with `[jobs]` filter form on some themes and plugins.
3
  Tags: job manager, job listing, job board, job management, job lists, job list, job, jobs, company, hiring, employment, employer, employees, candidate, freelance, internship, job listings, positions, board, application, hiring, listing, manager, recruiting, recruitment, talent
4
  Requires at least: 4.7.0
5
  Tested up to: 5.2
6
+ Stable tag: 1.33.3
7
  License: GPLv3
8
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
9
 
151
  6. Job listings in admin.
152
 
153
  == Changelog ==
154
+ = 1.33.3 =
155
+ * Fix: Upgrade jquery-fileupload to v9.32.0
156
+ * Fix: Set frame origin on pages where shortcodes are embedded
157
 
158
  = 1.33.2 =
159
  * Fix: Issue with `[jobs]` filter form on some themes and plugins.
wp-job-manager.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: WP Job Manager
4
  * Plugin URI: https://wpjobmanager.com/
5
  * Description: Manage job listings from the WordPress admin panel, and allow users to post jobs directly to your site.
6
- * Version: 1.33.2
7
  * Author: Automattic
8
  * Author URI: https://wpjobmanager.com/
9
  * Requires at least: 4.7.0
@@ -20,7 +20,7 @@ if ( ! defined( 'ABSPATH' ) ) {
20
  }
21
 
22
  // Define constants.
23
- define( 'JOB_MANAGER_VERSION', '1.33.2' );
24
  define( 'JOB_MANAGER_PLUGIN_DIR', untrailingslashit( plugin_dir_path( __FILE__ ) ) );
25
  define( 'JOB_MANAGER_PLUGIN_URL', untrailingslashit( plugins_url( basename( plugin_dir_path( __FILE__ ) ), basename( __FILE__ ) ) ) );
26
  define( 'JOB_MANAGER_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
3
  * Plugin Name: WP Job Manager
4
  * Plugin URI: https://wpjobmanager.com/
5
  * Description: Manage job listings from the WordPress admin panel, and allow users to post jobs directly to your site.
6
+ * Version: 1.33.3
7
  * Author: Automattic
8
  * Author URI: https://wpjobmanager.com/
9
  * Requires at least: 4.7.0
20
  }
21
 
22
  // Define constants.
23
+ define( 'JOB_MANAGER_VERSION', '1.33.3' );
24
  define( 'JOB_MANAGER_PLUGIN_DIR', untrailingslashit( plugin_dir_path( __FILE__ ) ) );
25
  define( 'JOB_MANAGER_PLUGIN_URL', untrailingslashit( plugins_url( basename( plugin_dir_path( __FILE__ ) ), basename( __FILE__ ) ) ) );
26
  define( 'JOB_MANAGER_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );