h2ocube_rails_assets 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. data/README.md +1 -1
  2. data/h2ocube_rails_assets.gemspec +2 -2
  3. data/lib/h2ocube_rails_assets.rb +1 -4
  4. data/vendor/assets/images/jquery.ui/animated-overlay.gif +0 -0
  5. data/vendor/assets/images/jquery.ui/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  6. data/vendor/assets/images/jquery.ui/ui-bg_flat_75_ffffff_40x100.png +0 -0
  7. data/vendor/assets/images/jquery.ui/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  8. data/vendor/assets/images/jquery.ui/ui-bg_glass_65_ffffff_1x400.png +0 -0
  9. data/vendor/assets/images/jquery.ui/ui-bg_glass_75_dadada_1x400.png +0 -0
  10. data/vendor/assets/images/jquery.ui/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  11. data/vendor/assets/images/jquery.ui/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  12. data/vendor/assets/images/jquery.ui/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  13. data/vendor/assets/images/jquery.ui/ui-icons_222222_256x240.png +0 -0
  14. data/vendor/assets/images/jquery.ui/ui-icons_2e83ff_256x240.png +0 -0
  15. data/vendor/assets/images/jquery.ui/ui-icons_454545_256x240.png +0 -0
  16. data/vendor/assets/images/jquery.ui/ui-icons_888888_256x240.png +0 -0
  17. data/vendor/assets/images/jquery.ui/ui-icons_cd0a0a_256x240.png +0 -0
  18. data/vendor/assets/javascripts/_bootstrap.js +189 -80
  19. data/vendor/assets/javascripts/_jquery.fancybox.js +1983 -0
  20. data/vendor/assets/javascripts/_jquery.fileupload.js +1164 -0
  21. data/vendor/assets/javascripts/_jquery.js +1 -1
  22. data/vendor/assets/javascripts/{jquery.ui/jquery-ui.custom.js → _jquery.ui.js} +3717 -3693
  23. data/vendor/assets/javascripts/_jquery.validate.js +1207 -0
  24. data/vendor/assets/javascripts/_sammy.js +2120 -0
  25. data/vendor/assets/javascripts/jquery/1.9.js +229 -187
  26. data/vendor/assets/javascripts/jquery.cookie.js +29 -11
  27. data/vendor/assets/javascripts/jquery.fancybox.js +2 -1985
  28. data/vendor/assets/javascripts/jquery.fileupload.js +4 -1114
  29. data/vendor/assets/javascripts/jquery.iframe-transport.js +20 -7
  30. data/vendor/assets/javascripts/jquery.ui/jquery.ui.accordion.js +131 -290
  31. data/vendor/assets/javascripts/jquery.ui/jquery.ui.autocomplete.js +43 -37
  32. data/vendor/assets/javascripts/jquery.ui/jquery.ui.button.js +9 -8
  33. data/vendor/assets/javascripts/jquery.ui/jquery.ui.core.js +19 -51
  34. data/vendor/assets/javascripts/jquery.ui/jquery.ui.datepicker.js +1082 -878
  35. data/vendor/assets/javascripts/jquery.ui/jquery.ui.dialog.js +483 -542
  36. data/vendor/assets/javascripts/jquery.ui/jquery.ui.draggable.js +319 -212
  37. data/vendor/assets/javascripts/jquery.ui/jquery.ui.droppable.js +177 -100
  38. data/vendor/assets/javascripts/jquery.ui/jquery.ui.effect-blind.js +2 -2
  39. data/vendor/assets/javascripts/jquery.ui/jquery.ui.effect-bounce.js +2 -2
  40. data/vendor/assets/javascripts/jquery.ui/jquery.ui.effect-clip.js +2 -2
  41. data/vendor/assets/javascripts/jquery.ui/jquery.ui.effect-drop.js +2 -2
  42. data/vendor/assets/javascripts/jquery.ui/jquery.ui.effect-explode.js +2 -2
  43. data/vendor/assets/javascripts/jquery.ui/jquery.ui.effect-fade.js +2 -2
  44. data/vendor/assets/javascripts/jquery.ui/jquery.ui.effect-fold.js +2 -2
  45. data/vendor/assets/javascripts/jquery.ui/jquery.ui.effect-highlight.js +2 -2
  46. data/vendor/assets/javascripts/jquery.ui/jquery.ui.effect-pulsate.js +2 -2
  47. data/vendor/assets/javascripts/jquery.ui/jquery.ui.effect-scale.js +2 -2
  48. data/vendor/assets/javascripts/jquery.ui/jquery.ui.effect-shake.js +2 -2
  49. data/vendor/assets/javascripts/jquery.ui/jquery.ui.effect-slide.js +2 -2
  50. data/vendor/assets/javascripts/jquery.ui/jquery.ui.effect-transfer.js +3 -3
  51. data/vendor/assets/javascripts/jquery.ui/jquery.ui.effect.js +93 -101
  52. data/vendor/assets/javascripts/jquery.ui/jquery.ui.menu.js +21 -10
  53. data/vendor/assets/javascripts/jquery.ui/jquery.ui.mouse.js +25 -25
  54. data/vendor/assets/javascripts/jquery.ui/jquery.ui.position.js +42 -62
  55. data/vendor/assets/javascripts/jquery.ui/jquery.ui.progressbar.js +73 -33
  56. data/vendor/assets/javascripts/jquery.ui/jquery.ui.resizable.js +461 -294
  57. data/vendor/assets/javascripts/jquery.ui/jquery.ui.selectable.js +67 -51
  58. data/vendor/assets/javascripts/jquery.ui/jquery.ui.slider.js +179 -151
  59. data/vendor/assets/javascripts/jquery.ui/jquery.ui.sortable.js +411 -257
  60. data/vendor/assets/javascripts/jquery.ui/jquery.ui.spinner.js +19 -5
  61. data/vendor/assets/javascripts/jquery.ui/jquery.ui.tabs.js +47 -567
  62. data/vendor/assets/javascripts/jquery.ui/jquery.ui.tooltip.js +14 -10
  63. data/vendor/assets/javascripts/jquery.ui/jquery.ui.widget.js +33 -40
  64. data/vendor/assets/javascripts/jquery.ui.js +1 -1
  65. data/vendor/assets/javascripts/jquery.validate.js +1 -1258
  66. data/vendor/assets/javascripts/sammy.js +1 -2107
  67. data/vendor/assets/javascripts/underscore.js +101 -75
  68. data/vendor/assets/stylesheets/bootstrap.responsive.css +24 -7
  69. data/vendor/assets/stylesheets/bootstrap.scss +238 -119
  70. data/vendor/assets/stylesheets/jquery.fancybox.scss +6 -6
  71. data/vendor/assets/stylesheets/jquery.ui.scss +918 -217
  72. data/vendor/assets/stylesheets/normalize.css +396 -0
  73. metadata +16 -20
@@ -1,1114 +1,4 @@
1
- //=require jquery.ui/jquery.ui.widget
2
- //=require jquery.iframe-transport
3
-
4
- /*
5
- * jQuery File Upload Plugin 5.19.4
6
- * https://github.com/blueimp/jQuery-File-Upload
7
- *
8
- * Copyright 2010, Sebastian Tschan
9
- * https://blueimp.net
10
- *
11
- * Licensed under the MIT license:
12
- * http://www.opensource.org/licenses/MIT
13
- */
14
-
15
- /*jslint nomen: true, unparam: true, regexp: true */
16
- /*global define, window, document, File, Blob, FormData, location */
17
-
18
- (function (factory) {
19
- 'use strict';
20
- if (typeof define === 'function' && define.amd) {
21
- // Register as an anonymous AMD module:
22
- define([
23
- 'jquery',
24
- 'jquery.ui.widget'
25
- ], factory);
26
- } else {
27
- // Browser globals:
28
- factory(window.jQuery);
29
- }
30
- }(function ($) {
31
- 'use strict';
32
-
33
- // The FileReader API is not actually used, but works as feature detection,
34
- // as e.g. Safari supports XHR file uploads via the FormData API,
35
- // but not non-multipart XHR file uploads:
36
- $.support.xhrFileUpload = !!(window.XMLHttpRequestUpload && window.FileReader);
37
- $.support.xhrFormDataFileUpload = !!window.FormData;
38
-
39
- // The fileupload widget listens for change events on file input fields defined
40
- // via fileInput setting and paste or drop events of the given dropZone.
41
- // In addition to the default jQuery Widget methods, the fileupload widget
42
- // exposes the "add" and "send" methods, to add or directly send files using
43
- // the fileupload API.
44
- // By default, files added via file input selection, paste, drag & drop or
45
- // "add" method are uploaded immediately, but it is possible to override
46
- // the "add" callback option to queue file uploads.
47
- $.widget('blueimp.fileupload', {
48
-
49
- options: {
50
- // The drop target element(s), by the default the complete document.
51
- // Set to null to disable drag & drop support:
52
- dropZone: $(document),
53
- // The paste target element(s), by the default the complete document.
54
- // Set to null to disable paste support:
55
- pasteZone: $(document),
56
- // The file input field(s), that are listened to for change events.
57
- // If undefined, it is set to the file input fields inside
58
- // of the widget element on plugin initialization.
59
- // Set to null to disable the change listener.
60
- fileInput: undefined,
61
- // By default, the file input field is replaced with a clone after
62
- // each input field change event. This is required for iframe transport
63
- // queues and allows change events to be fired for the same file
64
- // selection, but can be disabled by setting the following option to false:
65
- replaceFileInput: true,
66
- // The parameter name for the file form data (the request argument name).
67
- // If undefined or empty, the name property of the file input field is
68
- // used, or "files[]" if the file input name property is also empty,
69
- // can be a string or an array of strings:
70
- paramName: undefined,
71
- // By default, each file of a selection is uploaded using an individual
72
- // request for XHR type uploads. Set to false to upload file
73
- // selections in one request each:
74
- singleFileUploads: true,
75
- // To limit the number of files uploaded with one XHR request,
76
- // set the following option to an integer greater than 0:
77
- limitMultiFileUploads: undefined,
78
- // Set the following option to true to issue all file upload requests
79
- // in a sequential order:
80
- sequentialUploads: false,
81
- // To limit the number of concurrent uploads,
82
- // set the following option to an integer greater than 0:
83
- limitConcurrentUploads: undefined,
84
- // Set the following option to true to force iframe transport uploads:
85
- forceIframeTransport: false,
86
- // Set the following option to the location of a redirect url on the
87
- // origin server, for cross-domain iframe transport uploads:
88
- redirect: undefined,
89
- // The parameter name for the redirect url, sent as part of the form
90
- // data and set to 'redirect' if this option is empty:
91
- redirectParamName: undefined,
92
- // Set the following option to the location of a postMessage window,
93
- // to enable postMessage transport uploads:
94
- postMessage: undefined,
95
- // By default, XHR file uploads are sent as multipart/form-data.
96
- // The iframe transport is always using multipart/form-data.
97
- // Set to false to enable non-multipart XHR uploads:
98
- multipart: true,
99
- // To upload large files in smaller chunks, set the following option
100
- // to a preferred maximum chunk size. If set to 0, null or undefined,
101
- // or the browser does not support the required Blob API, files will
102
- // be uploaded as a whole.
103
- maxChunkSize: undefined,
104
- // When a non-multipart upload or a chunked multipart upload has been
105
- // aborted, this option can be used to resume the upload by setting
106
- // it to the size of the already uploaded bytes. This option is most
107
- // useful when modifying the options object inside of the "add" or
108
- // "send" callbacks, as the options are cloned for each file upload.
109
- uploadedBytes: undefined,
110
- // By default, failed (abort or error) file uploads are removed from the
111
- // global progress calculation. Set the following option to false to
112
- // prevent recalculating the global progress data:
113
- recalculateProgress: true,
114
- // Interval in milliseconds to calculate and trigger progress events:
115
- progressInterval: 100,
116
- // Interval in milliseconds to calculate progress bitrate:
117
- bitrateInterval: 500,
118
-
119
- // Additional form data to be sent along with the file uploads can be set
120
- // using this option, which accepts an array of objects with name and
121
- // value properties, a function returning such an array, a FormData
122
- // object (for XHR file uploads), or a simple object.
123
- // The form of the first fileInput is given as parameter to the function:
124
- formData: function (form) {
125
- return form.serializeArray();
126
- },
127
-
128
- // The add callback is invoked as soon as files are added to the fileupload
129
- // widget (via file input selection, drag & drop, paste or add API call).
130
- // If the singleFileUploads option is enabled, this callback will be
131
- // called once for each file in the selection for XHR file uplaods, else
132
- // once for each file selection.
133
- // The upload starts when the submit method is invoked on the data parameter.
134
- // The data object contains a files property holding the added files
135
- // and allows to override plugin options as well as define ajax settings.
136
- // Listeners for this callback can also be bound the following way:
137
- // .bind('fileuploadadd', func);
138
- // data.submit() returns a Promise object and allows to attach additional
139
- // handlers using jQuery's Deferred callbacks:
140
- // data.submit().done(func).fail(func).always(func);
141
- add: function (e, data) {
142
- data.submit();
143
- },
144
-
145
- // Other callbacks:
146
- // Callback for the submit event of each file upload:
147
- // submit: function (e, data) {}, // .bind('fileuploadsubmit', func);
148
- // Callback for the start of each file upload request:
149
- // send: function (e, data) {}, // .bind('fileuploadsend', func);
150
- // Callback for successful uploads:
151
- // done: function (e, data) {}, // .bind('fileuploaddone', func);
152
- // Callback for failed (abort or error) uploads:
153
- // fail: function (e, data) {}, // .bind('fileuploadfail', func);
154
- // Callback for completed (success, abort or error) requests:
155
- // always: function (e, data) {}, // .bind('fileuploadalways', func);
156
- // Callback for upload progress events:
157
- // progress: function (e, data) {}, // .bind('fileuploadprogress', func);
158
- // Callback for global upload progress events:
159
- // progressall: function (e, data) {}, // .bind('fileuploadprogressall', func);
160
- // Callback for uploads start, equivalent to the global ajaxStart event:
161
- // start: function (e) {}, // .bind('fileuploadstart', func);
162
- // Callback for uploads stop, equivalent to the global ajaxStop event:
163
- // stop: function (e) {}, // .bind('fileuploadstop', func);
164
- // Callback for change events of the fileInput(s):
165
- // change: function (e, data) {}, // .bind('fileuploadchange', func);
166
- // Callback for paste events to the pasteZone(s):
167
- // paste: function (e, data) {}, // .bind('fileuploadpaste', func);
168
- // Callback for drop events of the dropZone(s):
169
- // drop: function (e, data) {}, // .bind('fileuploaddrop', func);
170
- // Callback for dragover events of the dropZone(s):
171
- // dragover: function (e) {}, // .bind('fileuploaddragover', func);
172
-
173
- // The plugin options are used as settings object for the ajax calls.
174
- // The following are jQuery ajax settings required for the file uploads:
175
- processData: false,
176
- contentType: false,
177
- cache: false
178
- },
179
-
180
- // A list of options that require a refresh after assigning a new value:
181
- _refreshOptionsList: [
182
- 'fileInput',
183
- 'dropZone',
184
- 'pasteZone',
185
- 'multipart',
186
- 'forceIframeTransport'
187
- ],
188
-
189
- _BitrateTimer: function () {
190
- this.timestamp = +(new Date());
191
- this.loaded = 0;
192
- this.bitrate = 0;
193
- this.getBitrate = function (now, loaded, interval) {
194
- var timeDiff = now - this.timestamp;
195
- if (!this.bitrate || !interval || timeDiff > interval) {
196
- this.bitrate = (loaded - this.loaded) * (1000 / timeDiff) * 8;
197
- this.loaded = loaded;
198
- this.timestamp = now;
199
- }
200
- return this.bitrate;
201
- };
202
- },
203
-
204
- _isXHRUpload: function (options) {
205
- return !options.forceIframeTransport &&
206
- ((!options.multipart && $.support.xhrFileUpload) ||
207
- $.support.xhrFormDataFileUpload);
208
- },
209
-
210
- _getFormData: function (options) {
211
- var formData;
212
- if (typeof options.formData === 'function') {
213
- return options.formData(options.form);
214
- }
215
- if ($.isArray(options.formData)) {
216
- return options.formData;
217
- }
218
- if (options.formData) {
219
- formData = [];
220
- $.each(options.formData, function (name, value) {
221
- formData.push({name: name, value: value});
222
- });
223
- return formData;
224
- }
225
- return [];
226
- },
227
-
228
- _getTotal: function (files) {
229
- var total = 0;
230
- $.each(files, function (index, file) {
231
- total += file.size || 1;
232
- });
233
- return total;
234
- },
235
-
236
- _onProgress: function (e, data) {
237
- if (e.lengthComputable) {
238
- var now = +(new Date()),
239
- total,
240
- loaded;
241
- if (data._time && data.progressInterval &&
242
- (now - data._time < data.progressInterval) &&
243
- e.loaded !== e.total) {
244
- return;
245
- }
246
- data._time = now;
247
- total = data.total || this._getTotal(data.files);
248
- loaded = parseInt(
249
- e.loaded / e.total * (data.chunkSize || total),
250
- 10
251
- ) + (data.uploadedBytes || 0);
252
- this._loaded += loaded - (data.loaded || data.uploadedBytes || 0);
253
- data.lengthComputable = true;
254
- data.loaded = loaded;
255
- data.total = total;
256
- data.bitrate = data._bitrateTimer.getBitrate(
257
- now,
258
- loaded,
259
- data.bitrateInterval
260
- );
261
- // Trigger a custom progress event with a total data property set
262
- // to the file size(s) of the current upload and a loaded data
263
- // property calculated accordingly:
264
- this._trigger('progress', e, data);
265
- // Trigger a global progress event for all current file uploads,
266
- // including ajax calls queued for sequential file uploads:
267
- this._trigger('progressall', e, {
268
- lengthComputable: true,
269
- loaded: this._loaded,
270
- total: this._total,
271
- bitrate: this._bitrateTimer.getBitrate(
272
- now,
273
- this._loaded,
274
- data.bitrateInterval
275
- )
276
- });
277
- }
278
- },
279
-
280
- _initProgressListener: function (options) {
281
- var that = this,
282
- xhr = options.xhr ? options.xhr() : $.ajaxSettings.xhr();
283
- // Accesss to the native XHR object is required to add event listeners
284
- // for the upload progress event:
285
- if (xhr.upload) {
286
- $(xhr.upload).bind('progress', function (e) {
287
- var oe = e.originalEvent;
288
- // Make sure the progress event properties get copied over:
289
- e.lengthComputable = oe.lengthComputable;
290
- e.loaded = oe.loaded;
291
- e.total = oe.total;
292
- that._onProgress(e, options);
293
- });
294
- options.xhr = function () {
295
- return xhr;
296
- };
297
- }
298
- },
299
-
300
- _initXHRData: function (options) {
301
- var formData,
302
- file = options.files[0],
303
- // Ignore non-multipart setting if not supported:
304
- multipart = options.multipart || !$.support.xhrFileUpload,
305
- paramName = options.paramName[0];
306
- options.headers = options.headers || {};
307
- if (options.contentRange) {
308
- options.headers['Content-Range'] = options.contentRange;
309
- }
310
- if (!multipart) {
311
- options.headers['Content-Disposition'] = 'attachment; filename="' +
312
- encodeURI(file.name) + '"';
313
- options.contentType = file.type;
314
- options.data = options.blob || file;
315
- } else if ($.support.xhrFormDataFileUpload) {
316
- if (options.postMessage) {
317
- // window.postMessage does not allow sending FormData
318
- // objects, so we just add the File/Blob objects to
319
- // the formData array and let the postMessage window
320
- // create the FormData object out of this array:
321
- formData = this._getFormData(options);
322
- if (options.blob) {
323
- formData.push({
324
- name: paramName,
325
- value: options.blob
326
- });
327
- } else {
328
- $.each(options.files, function (index, file) {
329
- formData.push({
330
- name: options.paramName[index] || paramName,
331
- value: file
332
- });
333
- });
334
- }
335
- } else {
336
- if (options.formData instanceof FormData) {
337
- formData = options.formData;
338
- } else {
339
- formData = new FormData();
340
- $.each(this._getFormData(options), function (index, field) {
341
- formData.append(field.name, field.value);
342
- });
343
- }
344
- if (options.blob) {
345
- options.headers['Content-Disposition'] = 'attachment; filename="' +
346
- encodeURI(file.name) + '"';
347
- options.headers['Content-Description'] = encodeURI(file.type);
348
- formData.append(paramName, options.blob, file.name);
349
- } else {
350
- $.each(options.files, function (index, file) {
351
- // Files are also Blob instances, but some browsers
352
- // (Firefox 3.6) support the File API but not Blobs.
353
- // This check allows the tests to run with
354
- // dummy objects:
355
- if ((window.Blob && file instanceof Blob) ||
356
- (window.File && file instanceof File)) {
357
- formData.append(
358
- options.paramName[index] || paramName,
359
- file,
360
- file.name
361
- );
362
- }
363
- });
364
- }
365
- }
366
- options.data = formData;
367
- }
368
- // Blob reference is not needed anymore, free memory:
369
- options.blob = null;
370
- },
371
-
372
- _initIframeSettings: function (options) {
373
- // Setting the dataType to iframe enables the iframe transport:
374
- options.dataType = 'iframe ' + (options.dataType || '');
375
- // The iframe transport accepts a serialized array as form data:
376
- options.formData = this._getFormData(options);
377
- // Add redirect url to form data on cross-domain uploads:
378
- if (options.redirect && $('<a></a>').prop('href', options.url)
379
- .prop('host') !== location.host) {
380
- options.formData.push({
381
- name: options.redirectParamName || 'redirect',
382
- value: options.redirect
383
- });
384
- }
385
- },
386
-
387
- _initDataSettings: function (options) {
388
- if (this._isXHRUpload(options)) {
389
- if (!this._chunkedUpload(options, true)) {
390
- if (!options.data) {
391
- this._initXHRData(options);
392
- }
393
- this._initProgressListener(options);
394
- }
395
- if (options.postMessage) {
396
- // Setting the dataType to postmessage enables the
397
- // postMessage transport:
398
- options.dataType = 'postmessage ' + (options.dataType || '');
399
- }
400
- } else {
401
- this._initIframeSettings(options, 'iframe');
402
- }
403
- },
404
-
405
- _getParamName: function (options) {
406
- var fileInput = $(options.fileInput),
407
- paramName = options.paramName;
408
- if (!paramName) {
409
- paramName = [];
410
- fileInput.each(function () {
411
- var input = $(this),
412
- name = input.prop('name') || 'files[]',
413
- i = (input.prop('files') || [1]).length;
414
- while (i) {
415
- paramName.push(name);
416
- i -= 1;
417
- }
418
- });
419
- if (!paramName.length) {
420
- paramName = [fileInput.prop('name') || 'files[]'];
421
- }
422
- } else if (!$.isArray(paramName)) {
423
- paramName = [paramName];
424
- }
425
- return paramName;
426
- },
427
-
428
- _initFormSettings: function (options) {
429
- // Retrieve missing options from the input field and the
430
- // associated form, if available:
431
- if (!options.form || !options.form.length) {
432
- options.form = $(options.fileInput.prop('form'));
433
- // If the given file input doesn't have an associated form,
434
- // use the default widget file input's form:
435
- if (!options.form.length) {
436
- options.form = $(this.options.fileInput.prop('form'));
437
- }
438
- }
439
- options.paramName = this._getParamName(options);
440
- if (!options.url) {
441
- options.url = options.form.prop('action') || location.href;
442
- }
443
- // The HTTP request method must be "POST" or "PUT":
444
- options.type = (options.type || options.form.prop('method') || '')
445
- .toUpperCase();
446
- if (options.type !== 'POST' && options.type !== 'PUT') {
447
- options.type = 'POST';
448
- }
449
- if (!options.formAcceptCharset) {
450
- options.formAcceptCharset = options.form.attr('accept-charset');
451
- }
452
- },
453
-
454
- _getAJAXSettings: function (data) {
455
- var options = $.extend({}, this.options, data);
456
- this._initFormSettings(options);
457
- this._initDataSettings(options);
458
- return options;
459
- },
460
-
461
- // Maps jqXHR callbacks to the equivalent
462
- // methods of the given Promise object:
463
- _enhancePromise: function (promise) {
464
- promise.success = promise.done;
465
- promise.error = promise.fail;
466
- promise.complete = promise.always;
467
- return promise;
468
- },
469
-
470
- // Creates and returns a Promise object enhanced with
471
- // the jqXHR methods abort, success, error and complete:
472
- _getXHRPromise: function (resolveOrReject, context, args) {
473
- var dfd = $.Deferred(),
474
- promise = dfd.promise();
475
- context = context || this.options.context || promise;
476
- if (resolveOrReject === true) {
477
- dfd.resolveWith(context, args);
478
- } else if (resolveOrReject === false) {
479
- dfd.rejectWith(context, args);
480
- }
481
- promise.abort = dfd.promise;
482
- return this._enhancePromise(promise);
483
- },
484
-
485
- // Parses the Range header from the server response
486
- // and returns the uploaded bytes:
487
- _getUploadedBytes: function (jqXHR) {
488
- var range = jqXHR.getResponseHeader('Range'),
489
- parts = range && range.split('-'),
490
- upperBytesPos = parts && parts.length > 1 &&
491
- parseInt(parts[1], 10);
492
- return upperBytesPos && upperBytesPos + 1;
493
- },
494
-
495
- // Uploads a file in multiple, sequential requests
496
- // by splitting the file up in multiple blob chunks.
497
- // If the second parameter is true, only tests if the file
498
- // should be uploaded in chunks, but does not invoke any
499
- // upload requests:
500
- _chunkedUpload: function (options, testOnly) {
501
- var that = this,
502
- file = options.files[0],
503
- fs = file.size,
504
- ub = options.uploadedBytes = options.uploadedBytes || 0,
505
- mcs = options.maxChunkSize || fs,
506
- slice = file.slice || file.webkitSlice || file.mozSlice,
507
- dfd = $.Deferred(),
508
- promise = dfd.promise(),
509
- jqXHR,
510
- upload;
511
- if (!(this._isXHRUpload(options) && slice && (ub || mcs < fs)) ||
512
- options.data) {
513
- return false;
514
- }
515
- if (testOnly) {
516
- return true;
517
- }
518
- if (ub >= fs) {
519
- file.error = 'Uploaded bytes exceed file size';
520
- return this._getXHRPromise(
521
- false,
522
- options.context,
523
- [null, 'error', file.error]
524
- );
525
- }
526
- // The chunk upload method:
527
- upload = function (i) {
528
- // Clone the options object for each chunk upload:
529
- var o = $.extend({}, options);
530
- o.blob = slice.call(
531
- file,
532
- ub,
533
- ub + mcs
534
- );
535
- // Store the current chunk size, as the blob itself
536
- // will be dereferenced after data processing:
537
- o.chunkSize = o.blob.size;
538
- // Expose the chunk bytes position range:
539
- o.contentRange = 'bytes ' + ub + '-' +
540
- (ub + o.chunkSize - 1) + '/' + fs;
541
- // Process the upload data (the blob and potential form data):
542
- that._initXHRData(o);
543
- // Add progress listeners for this chunk upload:
544
- that._initProgressListener(o);
545
- jqXHR = ($.ajax(o) || that._getXHRPromise(false, o.context))
546
- .done(function (result, textStatus, jqXHR) {
547
- ub = that._getUploadedBytes(jqXHR) ||
548
- (ub + o.chunkSize);
549
- // Create a progress event if upload is done and
550
- // no progress event has been invoked for this chunk:
551
- if (!o.loaded) {
552
- that._onProgress($.Event('progress', {
553
- lengthComputable: true,
554
- loaded: ub - o.uploadedBytes,
555
- total: ub - o.uploadedBytes
556
- }), o);
557
- }
558
- options.uploadedBytes = o.uploadedBytes = ub;
559
- if (ub < fs) {
560
- // File upload not yet complete,
561
- // continue with the next chunk:
562
- upload();
563
- } else {
564
- dfd.resolveWith(
565
- o.context,
566
- [result, textStatus, jqXHR]
567
- );
568
- }
569
- })
570
- .fail(function (jqXHR, textStatus, errorThrown) {
571
- dfd.rejectWith(
572
- o.context,
573
- [jqXHR, textStatus, errorThrown]
574
- );
575
- });
576
- };
577
- this._enhancePromise(promise);
578
- promise.abort = function () {
579
- return jqXHR.abort();
580
- };
581
- upload();
582
- return promise;
583
- },
584
-
585
- _beforeSend: function (e, data) {
586
- if (this._active === 0) {
587
- // the start callback is triggered when an upload starts
588
- // and no other uploads are currently running,
589
- // equivalent to the global ajaxStart event:
590
- this._trigger('start');
591
- // Set timer for global bitrate progress calculation:
592
- this._bitrateTimer = new this._BitrateTimer();
593
- }
594
- this._active += 1;
595
- // Initialize the global progress values:
596
- this._loaded += data.uploadedBytes || 0;
597
- this._total += this._getTotal(data.files);
598
- },
599
-
600
- _onDone: function (result, textStatus, jqXHR, options) {
601
- if (!this._isXHRUpload(options)) {
602
- // Create a progress event for each iframe load:
603
- this._onProgress($.Event('progress', {
604
- lengthComputable: true,
605
- loaded: 1,
606
- total: 1
607
- }), options);
608
- }
609
- options.result = result;
610
- options.textStatus = textStatus;
611
- options.jqXHR = jqXHR;
612
- this._trigger('done', null, options);
613
- },
614
-
615
- _onFail: function (jqXHR, textStatus, errorThrown, options) {
616
- options.jqXHR = jqXHR;
617
- options.textStatus = textStatus;
618
- options.errorThrown = errorThrown;
619
- this._trigger('fail', null, options);
620
- if (options.recalculateProgress) {
621
- // Remove the failed (error or abort) file upload from
622
- // the global progress calculation:
623
- this._loaded -= options.loaded || options.uploadedBytes || 0;
624
- this._total -= options.total || this._getTotal(options.files);
625
- }
626
- },
627
-
628
- _onAlways: function (jqXHRorResult, textStatus, jqXHRorError, options) {
629
- this._active -= 1;
630
- options.textStatus = textStatus;
631
- if (jqXHRorError && jqXHRorError.always) {
632
- options.jqXHR = jqXHRorError;
633
- options.result = jqXHRorResult;
634
- } else {
635
- options.jqXHR = jqXHRorResult;
636
- options.errorThrown = jqXHRorError;
637
- }
638
- this._trigger('always', null, options);
639
- if (this._active === 0) {
640
- // The stop callback is triggered when all uploads have
641
- // been completed, equivalent to the global ajaxStop event:
642
- this._trigger('stop');
643
- // Reset the global progress values:
644
- this._loaded = this._total = 0;
645
- this._bitrateTimer = null;
646
- }
647
- },
648
-
649
- _onSend: function (e, data) {
650
- var that = this,
651
- jqXHR,
652
- aborted,
653
- slot,
654
- pipe,
655
- options = that._getAJAXSettings(data),
656
- send = function () {
657
- that._sending += 1;
658
- // Set timer for bitrate progress calculation:
659
- options._bitrateTimer = new that._BitrateTimer();
660
- jqXHR = jqXHR || (
661
- ((aborted || that._trigger('send', e, options) === false) &&
662
- that._getXHRPromise(false, options.context, aborted)) ||
663
- that._chunkedUpload(options) || $.ajax(options)
664
- ).done(function (result, textStatus, jqXHR) {
665
- that._onDone(result, textStatus, jqXHR, options);
666
- }).fail(function (jqXHR, textStatus, errorThrown) {
667
- that._onFail(jqXHR, textStatus, errorThrown, options);
668
- }).always(function (jqXHRorResult, textStatus, jqXHRorError) {
669
- that._sending -= 1;
670
- that._onAlways(
671
- jqXHRorResult,
672
- textStatus,
673
- jqXHRorError,
674
- options
675
- );
676
- if (options.limitConcurrentUploads &&
677
- options.limitConcurrentUploads > that._sending) {
678
- // Start the next queued upload,
679
- // that has not been aborted:
680
- var nextSlot = that._slots.shift(),
681
- isPending;
682
- while (nextSlot) {
683
- // jQuery 1.6 doesn't provide .state(),
684
- // while jQuery 1.8+ removed .isRejected():
685
- isPending = nextSlot.state ?
686
- nextSlot.state() === 'pending' :
687
- !nextSlot.isRejected();
688
- if (isPending) {
689
- nextSlot.resolve();
690
- break;
691
- }
692
- nextSlot = that._slots.shift();
693
- }
694
- }
695
- });
696
- return jqXHR;
697
- };
698
- this._beforeSend(e, options);
699
- if (this.options.sequentialUploads ||
700
- (this.options.limitConcurrentUploads &&
701
- this.options.limitConcurrentUploads <= this._sending)) {
702
- if (this.options.limitConcurrentUploads > 1) {
703
- slot = $.Deferred();
704
- this._slots.push(slot);
705
- pipe = slot.pipe(send);
706
- } else {
707
- pipe = (this._sequence = this._sequence.pipe(send, send));
708
- }
709
- // Return the piped Promise object, enhanced with an abort method,
710
- // which is delegated to the jqXHR object of the current upload,
711
- // and jqXHR callbacks mapped to the equivalent Promise methods:
712
- pipe.abort = function () {
713
- aborted = [undefined, 'abort', 'abort'];
714
- if (!jqXHR) {
715
- if (slot) {
716
- slot.rejectWith(options.context, aborted);
717
- }
718
- return send();
719
- }
720
- return jqXHR.abort();
721
- };
722
- return this._enhancePromise(pipe);
723
- }
724
- return send();
725
- },
726
-
727
- _onAdd: function (e, data) {
728
- var that = this,
729
- result = true,
730
- options = $.extend({}, this.options, data),
731
- limit = options.limitMultiFileUploads,
732
- paramName = this._getParamName(options),
733
- paramNameSet,
734
- paramNameSlice,
735
- fileSet,
736
- i;
737
- if (!(options.singleFileUploads || limit) ||
738
- !this._isXHRUpload(options)) {
739
- fileSet = [data.files];
740
- paramNameSet = [paramName];
741
- } else if (!options.singleFileUploads && limit) {
742
- fileSet = [];
743
- paramNameSet = [];
744
- for (i = 0; i < data.files.length; i += limit) {
745
- fileSet.push(data.files.slice(i, i + limit));
746
- paramNameSlice = paramName.slice(i, i + limit);
747
- if (!paramNameSlice.length) {
748
- paramNameSlice = paramName;
749
- }
750
- paramNameSet.push(paramNameSlice);
751
- }
752
- } else {
753
- paramNameSet = paramName;
754
- }
755
- data.originalFiles = data.files;
756
- $.each(fileSet || data.files, function (index, element) {
757
- var newData = $.extend({}, data);
758
- newData.files = fileSet ? element : [element];
759
- newData.paramName = paramNameSet[index];
760
- newData.submit = function () {
761
- newData.jqXHR = this.jqXHR =
762
- (that._trigger('submit', e, this) !== false) &&
763
- that._onSend(e, this);
764
- return this.jqXHR;
765
- };
766
- result = that._trigger('add', e, newData);
767
- return result;
768
- });
769
- return result;
770
- },
771
-
772
- _replaceFileInput: function (input) {
773
- var inputClone = input.clone(true);
774
- $('<form></form>').append(inputClone)[0].reset();
775
- // Detaching allows to insert the fileInput on another form
776
- // without loosing the file input value:
777
- input.after(inputClone).detach();
778
- // Avoid memory leaks with the detached file input:
779
- $.cleanData(input.unbind('remove'));
780
- // Replace the original file input element in the fileInput
781
- // elements set with the clone, which has been copied including
782
- // event handlers:
783
- this.options.fileInput = this.options.fileInput.map(function (i, el) {
784
- if (el === input[0]) {
785
- return inputClone[0];
786
- }
787
- return el;
788
- });
789
- // If the widget has been initialized on the file input itself,
790
- // override this.element with the file input clone:
791
- if (input[0] === this.element[0]) {
792
- this.element = inputClone;
793
- }
794
- },
795
-
796
- _handleFileTreeEntry: function (entry, path) {
797
- var that = this,
798
- dfd = $.Deferred(),
799
- errorHandler = function (e) {
800
- if (e && !e.entry) {
801
- e.entry = entry;
802
- }
803
- // Since $.when returns immediately if one
804
- // Deferred is rejected, we use resolve instead.
805
- // This allows valid files and invalid items
806
- // to be returned together in one set:
807
- dfd.resolve([e]);
808
- },
809
- dirReader;
810
- path = path || '';
811
- if (entry.isFile) {
812
- if (entry._file) {
813
- // Workaround for Chrome bug #149735
814
- entry._file.relativePath = path;
815
- dfd.resolve(entry._file);
816
- } else {
817
- entry.file(function (file) {
818
- file.relativePath = path;
819
- dfd.resolve(file);
820
- }, errorHandler);
821
- }
822
- } else if (entry.isDirectory) {
823
- dirReader = entry.createReader();
824
- dirReader.readEntries(function (entries) {
825
- that._handleFileTreeEntries(
826
- entries,
827
- path + entry.name + '/'
828
- ).done(function (files) {
829
- dfd.resolve(files);
830
- }).fail(errorHandler);
831
- }, errorHandler);
832
- } else {
833
- // Return an empy list for file system items
834
- // other than files or directories:
835
- dfd.resolve([]);
836
- }
837
- return dfd.promise();
838
- },
839
-
840
- _handleFileTreeEntries: function (entries, path) {
841
- var that = this;
842
- return $.when.apply(
843
- $,
844
- $.map(entries, function (entry) {
845
- return that._handleFileTreeEntry(entry, path);
846
- })
847
- ).pipe(function () {
848
- return Array.prototype.concat.apply(
849
- [],
850
- arguments
851
- );
852
- });
853
- },
854
-
855
- _getDroppedFiles: function (dataTransfer) {
856
- dataTransfer = dataTransfer || {};
857
- var items = dataTransfer.items;
858
- if (items && items.length && (items[0].webkitGetAsEntry ||
859
- items[0].getAsEntry)) {
860
- return this._handleFileTreeEntries(
861
- $.map(items, function (item) {
862
- var entry;
863
- if (item.webkitGetAsEntry) {
864
- entry = item.webkitGetAsEntry();
865
- if (entry) {
866
- // Workaround for Chrome bug #149735:
867
- entry._file = item.getAsFile();
868
- }
869
- return entry;
870
- }
871
- return item.getAsEntry();
872
- })
873
- );
874
- }
875
- return $.Deferred().resolve(
876
- $.makeArray(dataTransfer.files)
877
- ).promise();
878
- },
879
-
880
- _getSingleFileInputFiles: function (fileInput) {
881
- fileInput = $(fileInput);
882
- var entries = fileInput.prop('webkitEntries') ||
883
- fileInput.prop('entries'),
884
- files,
885
- value;
886
- if (entries && entries.length) {
887
- return this._handleFileTreeEntries(entries);
888
- }
889
- files = $.makeArray(fileInput.prop('files'));
890
- if (!files.length) {
891
- value = fileInput.prop('value');
892
- if (!value) {
893
- return $.Deferred().resolve([]).promise();
894
- }
895
- // If the files property is not available, the browser does not
896
- // support the File API and we add a pseudo File object with
897
- // the input value as name with path information removed:
898
- files = [{name: value.replace(/^.*\\/, '')}];
899
- } else if (files[0].name === undefined && files[0].fileName) {
900
- // File normalization for Safari 4 and Firefox 3:
901
- $.each(files, function (index, file) {
902
- file.name = file.fileName;
903
- file.size = file.fileSize;
904
- });
905
- }
906
- return $.Deferred().resolve(files).promise();
907
- },
908
-
909
- _getFileInputFiles: function (fileInput) {
910
- if (!(fileInput instanceof $) || fileInput.length === 1) {
911
- return this._getSingleFileInputFiles(fileInput);
912
- }
913
- return $.when.apply(
914
- $,
915
- $.map(fileInput, this._getSingleFileInputFiles)
916
- ).pipe(function () {
917
- return Array.prototype.concat.apply(
918
- [],
919
- arguments
920
- );
921
- });
922
- },
923
-
924
- _onChange: function (e) {
925
- var that = this,
926
- data = {
927
- fileInput: $(e.target),
928
- form: $(e.target.form)
929
- };
930
- this._getFileInputFiles(data.fileInput).always(function (files) {
931
- data.files = files;
932
- if (that.options.replaceFileInput) {
933
- that._replaceFileInput(data.fileInput);
934
- }
935
- if (that._trigger('change', e, data) !== false) {
936
- that._onAdd(e, data);
937
- }
938
- });
939
- },
940
-
941
- _onPaste: function (e) {
942
- var cbd = e.originalEvent.clipboardData,
943
- items = (cbd && cbd.items) || [],
944
- data = {files: []};
945
- $.each(items, function (index, item) {
946
- var file = item.getAsFile && item.getAsFile();
947
- if (file) {
948
- data.files.push(file);
949
- }
950
- });
951
- if (this._trigger('paste', e, data) === false ||
952
- this._onAdd(e, data) === false) {
953
- return false;
954
- }
955
- },
956
-
957
- _onDrop: function (e) {
958
- e.preventDefault();
959
- var that = this,
960
- dataTransfer = e.dataTransfer = e.originalEvent.dataTransfer,
961
- data = {};
962
- this._getDroppedFiles(dataTransfer).always(function (files) {
963
- data.files = files;
964
- if (that._trigger('drop', e, data) !== false) {
965
- that._onAdd(e, data);
966
- }
967
- });
968
- },
969
-
970
- _onDragOver: function (e) {
971
- var dataTransfer = e.dataTransfer = e.originalEvent.dataTransfer;
972
- if (this._trigger('dragover', e) === false) {
973
- return false;
974
- }
975
- if (dataTransfer) {
976
- dataTransfer.dropEffect = 'copy';
977
- }
978
- e.preventDefault();
979
- },
980
-
981
- _initEventHandlers: function () {
982
- if (this._isXHRUpload(this.options)) {
983
- this._on(this.options.dropZone, {
984
- dragover: this._onDragOver,
985
- drop: this._onDrop
986
- });
987
- this._on(this.options.pasteZone, {
988
- paste: this._onPaste
989
- });
990
- }
991
- this._on(this.options.fileInput, {
992
- change: this._onChange
993
- });
994
- },
995
-
996
- _destroyEventHandlers: function () {
997
- this._off(this.options.dropZone, 'dragover drop');
998
- this._off(this.options.pasteZone, 'paste');
999
- this._off(this.options.fileInput, 'change');
1000
- },
1001
-
1002
- _setOption: function (key, value) {
1003
- var refresh = $.inArray(key, this._refreshOptionsList) !== -1;
1004
- if (refresh) {
1005
- this._destroyEventHandlers();
1006
- }
1007
- this._super(key, value);
1008
- if (refresh) {
1009
- this._initSpecialOptions();
1010
- this._initEventHandlers();
1011
- }
1012
- },
1013
-
1014
- _initSpecialOptions: function () {
1015
- var options = this.options;
1016
- if (options.fileInput === undefined) {
1017
- options.fileInput = this.element.is('input[type="file"]') ?
1018
- this.element : this.element.find('input[type="file"]');
1019
- } else if (!(options.fileInput instanceof $)) {
1020
- options.fileInput = $(options.fileInput);
1021
- }
1022
- if (!(options.dropZone instanceof $)) {
1023
- options.dropZone = $(options.dropZone);
1024
- }
1025
- if (!(options.pasteZone instanceof $)) {
1026
- options.pasteZone = $(options.pasteZone);
1027
- }
1028
- },
1029
-
1030
- _create: function () {
1031
- var options = this.options;
1032
- // Initialize options set via HTML5 data-attributes:
1033
- $.extend(options, $(this.element[0].cloneNode(false)).data());
1034
- this._initSpecialOptions();
1035
- this._slots = [];
1036
- this._sequence = this._getXHRPromise(true);
1037
- this._sending = this._active = this._loaded = this._total = 0;
1038
- this._initEventHandlers();
1039
- },
1040
-
1041
- _destroy: function () {
1042
- this._destroyEventHandlers();
1043
- },
1044
-
1045
- // This method is exposed to the widget API and allows adding files
1046
- // using the fileupload API. The data parameter accepts an object which
1047
- // must have a files property and can contain additional options:
1048
- // .fileupload('add', {files: filesList});
1049
- add: function (data) {
1050
- var that = this;
1051
- if (!data || this.options.disabled) {
1052
- return;
1053
- }
1054
- if (data.fileInput && !data.files) {
1055
- this._getFileInputFiles(data.fileInput).always(function (files) {
1056
- data.files = files;
1057
- that._onAdd(null, data);
1058
- });
1059
- } else {
1060
- data.files = $.makeArray(data.files);
1061
- this._onAdd(null, data);
1062
- }
1063
- },
1064
-
1065
- // This method is exposed to the widget API and allows sending files
1066
- // using the fileupload API. The data parameter accepts an object which
1067
- // must have a files or fileInput property and can contain additional options:
1068
- // .fileupload('send', {files: filesList});
1069
- // The method returns a Promise object for the file upload call.
1070
- send: function (data) {
1071
- if (data && !this.options.disabled) {
1072
- if (data.fileInput && !data.files) {
1073
- var that = this,
1074
- dfd = $.Deferred(),
1075
- promise = dfd.promise(),
1076
- jqXHR,
1077
- aborted;
1078
- promise.abort = function () {
1079
- aborted = true;
1080
- if (jqXHR) {
1081
- return jqXHR.abort();
1082
- }
1083
- dfd.reject(null, 'abort', 'abort');
1084
- return promise;
1085
- };
1086
- this._getFileInputFiles(data.fileInput).always(
1087
- function (files) {
1088
- if (aborted) {
1089
- return;
1090
- }
1091
- data.files = files;
1092
- jqXHR = that._onSend(null, data).then(
1093
- function (result, textStatus, jqXHR) {
1094
- dfd.resolve(result, textStatus, jqXHR);
1095
- },
1096
- function (jqXHR, textStatus, errorThrown) {
1097
- dfd.reject(jqXHR, textStatus, errorThrown);
1098
- }
1099
- );
1100
- }
1101
- );
1102
- return this._enhancePromise(promise);
1103
- }
1104
- data.files = $.makeArray(data.files);
1105
- if (data.files.length) {
1106
- return this._onSend(null, data);
1107
- }
1108
- }
1109
- return this._getXHRPromise(false, data && data.context);
1110
- }
1111
-
1112
- });
1113
-
1114
- }));
1
+ //= require jquery
2
+ //= require jquery.ui/jquery.ui.widget
3
+ //= require jquery.iframe-transport
4
+ //= require _jquery.fileupload