JCG-jquery-fileupload 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (24) hide show
  1. data/README.md +72 -0
  2. data/Rakefile +15 -0
  3. data/lib/jquery-fileupload-rails.rb +8 -0
  4. data/lib/jquery/fileupload/rails/engine.rb +8 -0
  5. data/lib/jquery/fileupload/rails/middleware.rb +59 -0
  6. data/lib/jquery/fileupload/rails/upload.rb +3 -0
  7. data/lib/jquery/fileupload/rails/version.rb +7 -0
  8. data/vendor/assets/images/loading.gif +0 -0
  9. data/vendor/assets/images/progressbar.gif +0 -0
  10. data/vendor/assets/javascripts/jquery-fileupload/basic.js +4 -0
  11. data/vendor/assets/javascripts/jquery-fileupload/cors/jquery.postmessage-transport.js +117 -0
  12. data/vendor/assets/javascripts/jquery-fileupload/cors/jquery.xdr-transport.js +87 -0
  13. data/vendor/assets/javascripts/jquery-fileupload/index.js +9 -0
  14. data/vendor/assets/javascripts/jquery-fileupload/jquery.fileupload-fp.js +223 -0
  15. data/vendor/assets/javascripts/jquery-fileupload/jquery.fileupload-ui.js +799 -0
  16. data/vendor/assets/javascripts/jquery-fileupload/jquery.fileupload.js +1164 -0
  17. data/vendor/assets/javascripts/jquery-fileupload/jquery.iframe-transport.js +185 -0
  18. data/vendor/assets/javascripts/jquery-fileupload/locale.js +29 -0
  19. data/vendor/assets/javascripts/jquery-fileupload/vendor/canvas-to-blob.js +91 -0
  20. data/vendor/assets/javascripts/jquery-fileupload/vendor/jquery.ui.widget.js +530 -0
  21. data/vendor/assets/javascripts/jquery-fileupload/vendor/load-image.js +121 -0
  22. data/vendor/assets/javascripts/jquery-fileupload/vendor/tmpl.js +86 -0
  23. data/vendor/assets/stylesheets/jquery.fileupload-ui.scss +84 -0
  24. metadata +117 -0
@@ -0,0 +1,799 @@
1
+ /*
2
+ * jQuery File Upload User Interface Plugin 7.3
3
+ * https://github.com/blueimp/jQuery-File-Upload
4
+ *
5
+ * Copyright 2010, Sebastian Tschan
6
+ * https://blueimp.net
7
+ *
8
+ * Licensed under the MIT license:
9
+ * http://www.opensource.org/licenses/MIT
10
+ */
11
+
12
+ /*jslint nomen: true, unparam: true, regexp: true */
13
+ /*global define, window, URL, webkitURL, FileReader */
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
+ 'tmpl',
22
+ 'load-image',
23
+ './jquery.fileupload-fp'
24
+ ], factory);
25
+ } else {
26
+ // Browser globals:
27
+ factory(
28
+ window.jQuery,
29
+ window.tmpl,
30
+ window.loadImage
31
+ );
32
+ }
33
+ }(function ($, tmpl, loadImage) {
34
+ 'use strict';
35
+
36
+ // The UI version extends the file upload widget
37
+ // and adds complete user interface interaction:
38
+ $.widget('blueimp.fileupload', $.blueimp.fileupload, {
39
+
40
+ options: {
41
+ // By default, files added to the widget are uploaded as soon
42
+ // as the user clicks on the start buttons. To enable automatic
43
+ // uploads, set the following option to true:
44
+ autoUpload: false,
45
+ // The following option limits the number of files that are
46
+ // allowed to be uploaded using this widget:
47
+ maxNumberOfFiles: undefined,
48
+ // The maximum allowed file size:
49
+ maxFileSize: 20000000,
50
+ // The minimum allowed file size:
51
+ minFileSize: undefined,
52
+ // The regular expression for allowed file types, matches
53
+ // against either file type or file name:
54
+ acceptFileTypes: /.+$/i,
55
+ // The regular expression to define for which files a preview
56
+ // image is shown, matched against the file type:
57
+ previewSourceFileTypes: /^image\/(gif|jpeg|png)$/,
58
+ // The maximum file size of images that are to be displayed as preview:
59
+ previewSourceMaxFileSize: 10000000, // 5MB
60
+ // The maximum width of the preview images:
61
+ previewMaxWidth: 80,
62
+ // The maximum height of the preview images:
63
+ previewMaxHeight: 80,
64
+ // By default, preview images are displayed as canvas elements
65
+ // if supported by the browser. Set the following option to false
66
+ // to always display preview images as img elements:
67
+ previewAsCanvas: true,
68
+ // The ID of the upload template:
69
+ uploadTemplateId: 'template-upload',
70
+ // The ID of the download template:
71
+ downloadTemplateId: 'template-download',
72
+ // The container for the list of files. If undefined, it is set to
73
+ // an element with class "files" inside of the widget element:
74
+ filesContainer: undefined,
75
+ // By default, files are appended to the files container.
76
+ // Set the following option to true, to prepend files instead:
77
+ prependFiles: false,
78
+ // The expected data type of the upload response, sets the dataType
79
+ // option of the $.ajax upload requests:
80
+ dataType: 'json',
81
+
82
+ // The add callback is invoked as soon as files are added to the fileupload
83
+ // widget (via file input selection, drag & drop or add API call).
84
+ // See the basic file upload widget for more information:
85
+ add: function (e, data) {
86
+ var that = $(this).data('blueimp-fileupload') ||
87
+ $(this).data('fileupload'),
88
+ options = that.options,
89
+ files = data.files;
90
+ $(this).fileupload('process', data).done(function () {
91
+ that._adjustMaxNumberOfFiles(-files.length);
92
+ data.maxNumberOfFilesAdjusted = true;
93
+ data.files.valid = data.isValidated = that._validate(files);
94
+ data.context = that._renderUpload(files).data('data', data);
95
+ options.filesContainer[
96
+ options.prependFiles ? 'prepend' : 'append'
97
+ ](data.context);
98
+ that._renderPreviews(data);
99
+ that._forceReflow(data.context);
100
+ that._transition(data.context).done(
101
+ function () {
102
+ if ((that._trigger('added', e, data) !== false) &&
103
+ (options.autoUpload || data.autoUpload) &&
104
+ data.autoUpload !== false && data.isValidated) {
105
+ data.submit();
106
+ }
107
+ }
108
+ );
109
+ });
110
+ },
111
+ // Callback for the start of each file upload request:
112
+ send: function (e, data) {
113
+ var that = $(this).data('blueimp-fileupload') ||
114
+ $(this).data('fileupload');
115
+ if (!data.isValidated) {
116
+ if (!data.maxNumberOfFilesAdjusted) {
117
+ that._adjustMaxNumberOfFiles(-data.files.length);
118
+ data.maxNumberOfFilesAdjusted = true;
119
+ }
120
+ if (!that._validate(data.files)) {
121
+ return false;
122
+ }
123
+ }
124
+ if (data.context && data.dataType &&
125
+ data.dataType.substr(0, 6) === 'iframe') {
126
+ // Iframe Transport does not support progress events.
127
+ // In lack of an indeterminate progress bar, we set
128
+ // the progress to 100%, showing the full animated bar:
129
+ data.context
130
+ .find('.progress').addClass(
131
+ !$.support.transition && 'progress-animated'
132
+ )
133
+ .attr('aria-valuenow', 100)
134
+ .find('.bar').css(
135
+ 'width',
136
+ '100%'
137
+ );
138
+ }
139
+ return that._trigger('sent', e, data);
140
+ },
141
+ // Callback for successful uploads:
142
+ done: function (e, data) {
143
+ var that = $(this).data('blueimp-fileupload') ||
144
+ $(this).data('fileupload'),
145
+ files = that._getFilesFromResponse(data),
146
+ template,
147
+ deferred;
148
+ if (data.context) {
149
+ data.context.each(function (index) {
150
+ var file = files[index] ||
151
+ {error: 'Empty file upload result'},
152
+ deferred = that._addFinishedDeferreds();
153
+ if (file.error) {
154
+ that._adjustMaxNumberOfFiles(1);
155
+ }
156
+ that._transition($(this)).done(
157
+ function () {
158
+ var node = $(this);
159
+ template = that._renderDownload([file])
160
+ .replaceAll(node);
161
+ that._forceReflow(template);
162
+ that._transition(template).done(
163
+ function () {
164
+ data.context = $(this);
165
+ that._trigger('completed', e, data);
166
+ that._trigger('finished', e, data);
167
+ deferred.resolve();
168
+ }
169
+ );
170
+ }
171
+ );
172
+ });
173
+ } else {
174
+ if (files.length) {
175
+ $.each(files, function (index, file) {
176
+ if (data.maxNumberOfFilesAdjusted && file.error) {
177
+ that._adjustMaxNumberOfFiles(1);
178
+ } else if (!data.maxNumberOfFilesAdjusted &&
179
+ !file.error) {
180
+ that._adjustMaxNumberOfFiles(-1);
181
+ }
182
+ });
183
+ data.maxNumberOfFilesAdjusted = true;
184
+ }
185
+ template = that._renderDownload(files)
186
+ .appendTo(that.options.filesContainer);
187
+ that._forceReflow(template);
188
+ deferred = that._addFinishedDeferreds();
189
+ that._transition(template).done(
190
+ function () {
191
+ data.context = $(this);
192
+ that._trigger('completed', e, data);
193
+ that._trigger('finished', e, data);
194
+ deferred.resolve();
195
+ }
196
+ );
197
+ }
198
+ },
199
+ // Callback for failed (abort or error) uploads:
200
+ fail: function (e, data) {
201
+ var that = $(this).data('blueimp-fileupload') ||
202
+ $(this).data('fileupload'),
203
+ template,
204
+ deferred;
205
+ if (data.maxNumberOfFilesAdjusted) {
206
+ that._adjustMaxNumberOfFiles(data.files.length);
207
+ }
208
+ if (data.context) {
209
+ data.context.each(function (index) {
210
+ if (data.errorThrown !== 'abort') {
211
+ var file = data.files[index];
212
+ file.error = file.error || data.errorThrown ||
213
+ true;
214
+ deferred = that._addFinishedDeferreds();
215
+ that._transition($(this)).done(
216
+ function () {
217
+ var node = $(this);
218
+ template = that._renderDownload([file])
219
+ .replaceAll(node);
220
+ that._forceReflow(template);
221
+ that._transition(template).done(
222
+ function () {
223
+ data.context = $(this);
224
+ that._trigger('failed', e, data);
225
+ that._trigger('finished', e, data);
226
+ deferred.resolve();
227
+ }
228
+ );
229
+ }
230
+ );
231
+ } else {
232
+ deferred = that._addFinishedDeferreds();
233
+ that._transition($(this)).done(
234
+ function () {
235
+ $(this).remove();
236
+ that._trigger('failed', e, data);
237
+ that._trigger('finished', e, data);
238
+ deferred.resolve();
239
+ }
240
+ );
241
+ }
242
+ });
243
+ } else if (data.errorThrown !== 'abort') {
244
+ data.context = that._renderUpload(data.files)
245
+ .appendTo(that.options.filesContainer)
246
+ .data('data', data);
247
+ that._forceReflow(data.context);
248
+ deferred = that._addFinishedDeferreds();
249
+ that._transition(data.context).done(
250
+ function () {
251
+ data.context = $(this);
252
+ that._trigger('failed', e, data);
253
+ that._trigger('finished', e, data);
254
+ deferred.resolve();
255
+ }
256
+ );
257
+ } else {
258
+ that._trigger('failed', e, data);
259
+ that._trigger('finished', e, data);
260
+ that._addFinishedDeferreds().resolve();
261
+ }
262
+ },
263
+ // Callback for upload progress events:
264
+ progress: function (e, data) {
265
+ if (data.context) {
266
+ var progress = parseInt(data.loaded / data.total * 100, 10);
267
+ data.context.find('.progress')
268
+ .attr('aria-valuenow', progress)
269
+ .find('.bar').css(
270
+ 'width',
271
+ progress + '%'
272
+ );
273
+ }
274
+ },
275
+ // Callback for global upload progress events:
276
+ progressall: function (e, data) {
277
+ var $this = $(this),
278
+ progress = parseInt(data.loaded / data.total * 100, 10),
279
+ globalProgressNode = $this.find('.fileupload-progress'),
280
+ extendedProgressNode = globalProgressNode
281
+ .find('.progress-extended');
282
+ if (extendedProgressNode.length) {
283
+ extendedProgressNode.html(
284
+ ($this.data('blueimp-fileupload') || $this.data('fileupload'))
285
+ ._renderExtendedProgress(data)
286
+ );
287
+ }
288
+ globalProgressNode
289
+ .find('.progress')
290
+ .attr('aria-valuenow', progress)
291
+ .find('.bar').css(
292
+ 'width',
293
+ progress + '%'
294
+ );
295
+ },
296
+ // Callback for uploads start, equivalent to the global ajaxStart event:
297
+ start: function (e) {
298
+ var that = $(this).data('blueimp-fileupload') ||
299
+ $(this).data('fileupload');
300
+ that._resetFinishedDeferreds();
301
+ that._transition($(this).find('.fileupload-progress')).done(
302
+ function () {
303
+ that._trigger('started', e);
304
+ }
305
+ );
306
+ },
307
+ // Callback for uploads stop, equivalent to the global ajaxStop event:
308
+ stop: function (e) {
309
+ var that = $(this).data('blueimp-fileupload') ||
310
+ $(this).data('fileupload'),
311
+ deferred = that._addFinishedDeferreds();
312
+ $.when.apply($, that._getFinishedDeferreds())
313
+ .done(function () {
314
+ that._trigger('stopped', e);
315
+ });
316
+ that._transition($(this).find('.fileupload-progress')).done(
317
+ function () {
318
+ $(this).find('.progress')
319
+ .attr('aria-valuenow', '0')
320
+ .find('.bar').css('width', '0%');
321
+ $(this).find('.progress-extended').html(' ');
322
+ deferred.resolve();
323
+ }
324
+ );
325
+ },
326
+ // Callback for file deletion:
327
+ destroy: function (e, data) {
328
+ var that = $(this).data('blueimp-fileupload') ||
329
+ $(this).data('fileupload');
330
+ if (data.url) {
331
+ $.ajax(data);
332
+ that._adjustMaxNumberOfFiles(1);
333
+ }
334
+ that._transition(data.context).done(
335
+ function () {
336
+ $(this).remove();
337
+ that._trigger('destroyed', e, data);
338
+ }
339
+ );
340
+ }
341
+ },
342
+
343
+ _resetFinishedDeferreds: function () {
344
+ this._finishedUploads = [];
345
+ },
346
+
347
+ _addFinishedDeferreds: function (deferred) {
348
+ if (!deferred) {
349
+ deferred = $.Deferred();
350
+ }
351
+ this._finishedUploads.push(deferred);
352
+ return deferred;
353
+ },
354
+
355
+ _getFinishedDeferreds: function () {
356
+ return this._finishedUploads;
357
+ },
358
+
359
+ _getFilesFromResponse: function (data) {
360
+ if (data.result && $.isArray(data.result.files)) {
361
+ return data.result.files;
362
+ }
363
+ return [];
364
+ },
365
+
366
+ // Link handler, that allows to download files
367
+ // by drag & drop of the links to the desktop:
368
+ _enableDragToDesktop: function () {
369
+ var link = $(this),
370
+ url = link.prop('href'),
371
+ name = link.prop('download'),
372
+ type = 'application/octet-stream';
373
+ link.bind('dragstart', function (e) {
374
+ try {
375
+ e.originalEvent.dataTransfer.setData(
376
+ 'DownloadURL',
377
+ [type, name, url].join(':')
378
+ );
379
+ } catch (err) {}
380
+ });
381
+ },
382
+
383
+ _adjustMaxNumberOfFiles: function (operand) {
384
+ if (typeof this.options.maxNumberOfFiles === 'number') {
385
+ this.options.maxNumberOfFiles += operand;
386
+ if (this.options.maxNumberOfFiles < 1) {
387
+ this._disableFileInputButton();
388
+ } else {
389
+ this._enableFileInputButton();
390
+ }
391
+ }
392
+ },
393
+
394
+ _formatFileSize: function (bytes) {
395
+ if (typeof bytes !== 'number') {
396
+ return '';
397
+ }
398
+ if (bytes >= 1000000000) {
399
+ return (bytes / 1000000000).toFixed(2) + ' GB';
400
+ }
401
+ if (bytes >= 1000000) {
402
+ return (bytes / 1000000).toFixed(2) + ' MB';
403
+ }
404
+ return (bytes / 1000).toFixed(2) + ' KB';
405
+ },
406
+
407
+ _formatBitrate: function (bits) {
408
+ if (typeof bits !== 'number') {
409
+ return '';
410
+ }
411
+ if (bits >= 1000000000) {
412
+ return (bits / 1000000000).toFixed(2) + ' Gbit/s';
413
+ }
414
+ if (bits >= 1000000) {
415
+ return (bits / 1000000).toFixed(2) + ' Mbit/s';
416
+ }
417
+ if (bits >= 1000) {
418
+ return (bits / 1000).toFixed(2) + ' kbit/s';
419
+ }
420
+ return bits.toFixed(2) + ' bit/s';
421
+ },
422
+
423
+ _formatTime: function (seconds) {
424
+ var date = new Date(seconds * 1000),
425
+ days = parseInt(seconds / 86400, 10);
426
+ days = days ? days + 'd ' : '';
427
+ return days +
428
+ ('0' + date.getUTCHours()).slice(-2) + ':' +
429
+ ('0' + date.getUTCMinutes()).slice(-2) + ':' +
430
+ ('0' + date.getUTCSeconds()).slice(-2);
431
+ },
432
+
433
+ _formatPercentage: function (floatValue) {
434
+ return (floatValue * 100).toFixed(2) + ' %';
435
+ },
436
+
437
+ _renderExtendedProgress: function (data) {
438
+ return this._formatBitrate(data.bitrate) + ' | ' +
439
+ this._formatTime(
440
+ (data.total - data.loaded) * 8 / data.bitrate
441
+ ) + ' | ' +
442
+ this._formatPercentage(
443
+ data.loaded / data.total
444
+ ) + ' | ' +
445
+ this._formatFileSize(data.loaded) + ' / ' +
446
+ this._formatFileSize(data.total);
447
+ },
448
+
449
+ _hasError: function (file) {
450
+ if (file.error) {
451
+ return file.error;
452
+ }
453
+ // The number of added files is subtracted from
454
+ // maxNumberOfFiles before validation, so we check if
455
+ // maxNumberOfFiles is below 0 (instead of below 1):
456
+ if (this.options.maxNumberOfFiles < 0) {
457
+ return 'Maximum number of files exceeded';
458
+ }
459
+ // Files are accepted if either the file type or the file name
460
+ // matches against the acceptFileTypes regular expression, as
461
+ // only browsers with support for the File API report the type:
462
+ if (!(this.options.acceptFileTypes.test(file.type) ||
463
+ this.options.acceptFileTypes.test(file.name))) {
464
+ return 'Filetype not allowed';
465
+ }
466
+ if (this.options.maxFileSize &&
467
+ file.size > this.options.maxFileSize) {
468
+ return 'File is too big';
469
+ }
470
+ if (typeof file.size === 'number' &&
471
+ file.size < this.options.minFileSize) {
472
+ return 'File is too small';
473
+ }
474
+ return null;
475
+ },
476
+
477
+ _validate: function (files) {
478
+ var that = this,
479
+ valid = !!files.length;
480
+ $.each(files, function (index, file) {
481
+ file.error = that._hasError(file);
482
+ if (file.error) {
483
+ valid = false;
484
+ }
485
+ });
486
+ return valid;
487
+ },
488
+
489
+ _renderTemplate: function (func, files) {
490
+ if (!func) {
491
+ return $();
492
+ }
493
+ var result = func({
494
+ files: files,
495
+ formatFileSize: this._formatFileSize,
496
+ options: this.options
497
+ });
498
+ if (result instanceof $) {
499
+ return result;
500
+ }
501
+ return $(this.options.templatesContainer).html(result).children();
502
+ },
503
+
504
+ _renderPreview: function (file, node) {
505
+ var that = this,
506
+ options = this.options,
507
+ dfd = $.Deferred();
508
+ return ((loadImage && loadImage(
509
+ file,
510
+ function (img) {
511
+ node.append(img);
512
+ that._forceReflow(node);
513
+ that._transition(node).done(function () {
514
+ dfd.resolveWith(node);
515
+ });
516
+ if (!$.contains(that.document[0].body, node[0])) {
517
+ // If the element is not part of the DOM,
518
+ // transition events are not triggered,
519
+ // so we have to resolve manually:
520
+ dfd.resolveWith(node);
521
+ }
522
+ },
523
+ {
524
+ maxWidth: options.previewMaxWidth,
525
+ maxHeight: options.previewMaxHeight,
526
+ canvas: options.previewAsCanvas
527
+ }
528
+ )) || dfd.resolveWith(node)) && dfd;
529
+ },
530
+
531
+ _renderPreviews: function (data) {
532
+ var that = this,
533
+ options = this.options;
534
+ data.context.find('.preview span').each(function (index, element) {
535
+ var file = data.files[index];
536
+ if (options.previewSourceFileTypes.test(file.type) &&
537
+ ($.type(options.previewSourceMaxFileSize) !== 'number' ||
538
+ file.size < options.previewSourceMaxFileSize)) {
539
+ that._processingQueue = that._processingQueue.pipe(function () {
540
+ var dfd = $.Deferred(),
541
+ ev = $.Event('previewdone', {
542
+ target: element
543
+ });
544
+ that._renderPreview(file, $(element)).done(
545
+ function () {
546
+ that._trigger(ev.type, ev, data);
547
+ dfd.resolveWith(that);
548
+ }
549
+ );
550
+ return dfd.promise();
551
+ });
552
+ }
553
+ });
554
+ return this._processingQueue;
555
+ },
556
+
557
+ _renderUpload: function (files) {
558
+ return this._renderTemplate(
559
+ this.options.uploadTemplate,
560
+ files
561
+ );
562
+ },
563
+
564
+ _renderDownload: function (files) {
565
+ return this._renderTemplate(
566
+ this.options.downloadTemplate,
567
+ files
568
+ ).find('a[download]').each(this._enableDragToDesktop).end();
569
+ },
570
+
571
+ _startHandler: function (e) {
572
+ e.preventDefault();
573
+ var button = $(e.currentTarget),
574
+ template = button.closest('.template-upload'),
575
+ data = template.data('data');
576
+ if (data && data.submit && !data.jqXHR && data.submit()) {
577
+ button.prop('disabled', true);
578
+ }
579
+ },
580
+
581
+ _cancelHandler: function (e) {
582
+ e.preventDefault();
583
+ var template = $(e.currentTarget).closest('.template-upload'),
584
+ data = template.data('data') || {};
585
+ if (!data.jqXHR) {
586
+ data.errorThrown = 'abort';
587
+ this._trigger('fail', e, data);
588
+ } else {
589
+ data.jqXHR.abort();
590
+ }
591
+ },
592
+
593
+ _deleteHandler: function (e) {
594
+ e.preventDefault();
595
+ var button = $(e.currentTarget);
596
+ this._trigger('destroy', e, $.extend({
597
+ context: button.closest('.template-download'),
598
+ type: 'DELETE',
599
+ dataType: this.options.dataType
600
+ }, button.data()));
601
+ },
602
+
603
+ _forceReflow: function (node) {
604
+ return $.support.transition && node.length &&
605
+ node[0].offsetWidth;
606
+ },
607
+
608
+ _transition: function (node) {
609
+ var dfd = $.Deferred();
610
+ if ($.support.transition && node.hasClass('fade')) {
611
+ node.bind(
612
+ $.support.transition.end,
613
+ function (e) {
614
+ // Make sure we don't respond to other transitions events
615
+ // in the container element, e.g. from button elements:
616
+ if (e.target === node[0]) {
617
+ node.unbind($.support.transition.end);
618
+ dfd.resolveWith(node);
619
+ }
620
+ }
621
+ ).toggleClass('in');
622
+ } else {
623
+ node.toggleClass('in');
624
+ dfd.resolveWith(node);
625
+ }
626
+ return dfd;
627
+ },
628
+
629
+ _initButtonBarEventHandlers: function () {
630
+ var fileUploadButtonBar = this.element.find('.fileupload-buttonbar'),
631
+ filesList = this.options.filesContainer;
632
+ this._on(fileUploadButtonBar.find('.start'), {
633
+ click: function (e) {
634
+ e.preventDefault();
635
+ filesList.find('.start button').click();
636
+ }
637
+ });
638
+ this._on(fileUploadButtonBar.find('.cancel'), {
639
+ click: function (e) {
640
+ e.preventDefault();
641
+ filesList.find('.cancel button').click();
642
+ }
643
+ });
644
+ this._on(fileUploadButtonBar.find('.delete'), {
645
+ click: function (e) {
646
+ e.preventDefault();
647
+ filesList.find('.delete input:checked')
648
+ .siblings('button').click();
649
+ fileUploadButtonBar.find('.toggle')
650
+ .prop('checked', false);
651
+ }
652
+ });
653
+ this._on(fileUploadButtonBar.find('.toggle'), {
654
+ change: function (e) {
655
+ filesList.find('.delete input').prop(
656
+ 'checked',
657
+ $(e.currentTarget).is(':checked')
658
+ );
659
+ }
660
+ });
661
+ },
662
+
663
+ _destroyButtonBarEventHandlers: function () {
664
+ this._off(
665
+ this.element.find('.fileupload-buttonbar button'),
666
+ 'click'
667
+ );
668
+ this._off(
669
+ this.element.find('.fileupload-buttonbar .toggle'),
670
+ 'change.'
671
+ );
672
+ },
673
+
674
+ _initEventHandlers: function () {
675
+ this._super();
676
+ this._on(this.options.filesContainer, {
677
+ 'click .start button': this._startHandler,
678
+ 'click .cancel button': this._cancelHandler,
679
+ 'click .delete button': this._deleteHandler
680
+ });
681
+ this._initButtonBarEventHandlers();
682
+ },
683
+
684
+ _destroyEventHandlers: function () {
685
+ this._destroyButtonBarEventHandlers();
686
+ this._off(this.options.filesContainer, 'click');
687
+ this._super();
688
+ },
689
+
690
+ _enableFileInputButton: function () {
691
+ this.element.find('.fileinput-button input')
692
+ .prop('disabled', false)
693
+ .parent().removeClass('disabled');
694
+ },
695
+
696
+ _disableFileInputButton: function () {
697
+ this.element.find('.fileinput-button input')
698
+ .prop('disabled', true)
699
+ .parent().addClass('disabled');
700
+ },
701
+
702
+ _initTemplates: function () {
703
+ var options = this.options;
704
+ options.templatesContainer = this.document[0].createElement(
705
+ options.filesContainer.prop('nodeName')
706
+ );
707
+ if (tmpl) {
708
+ if (options.uploadTemplateId) {
709
+ options.uploadTemplate = tmpl(options.uploadTemplateId);
710
+ }
711
+ if (options.downloadTemplateId) {
712
+ options.downloadTemplate = tmpl(options.downloadTemplateId);
713
+ }
714
+ }
715
+ },
716
+
717
+ _initFilesContainer: function () {
718
+ var options = this.options;
719
+ if (options.filesContainer === undefined) {
720
+ options.filesContainer = this.element.find('.files');
721
+ } else if (!(options.filesContainer instanceof $)) {
722
+ options.filesContainer = $(options.filesContainer);
723
+ }
724
+ },
725
+
726
+ _stringToRegExp: function (str) {
727
+ var parts = str.split('/'),
728
+ modifiers = parts.pop();
729
+ parts.shift();
730
+ return new RegExp(parts.join('/'), modifiers);
731
+ },
732
+
733
+ _initRegExpOptions: function () {
734
+ var options = this.options;
735
+ if ($.type(options.acceptFileTypes) === 'string') {
736
+ options.acceptFileTypes = this._stringToRegExp(
737
+ options.acceptFileTypes
738
+ );
739
+ }
740
+ if ($.type(options.previewSourceFileTypes) === 'string') {
741
+ options.previewSourceFileTypes = this._stringToRegExp(
742
+ options.previewSourceFileTypes
743
+ );
744
+ }
745
+ },
746
+
747
+ _initSpecialOptions: function () {
748
+ this._super();
749
+ this._initFilesContainer();
750
+ this._initTemplates();
751
+ this._initRegExpOptions();
752
+ },
753
+
754
+ _setOption: function (key, value) {
755
+ this._super(key, value);
756
+ if (key === 'maxNumberOfFiles') {
757
+ this._adjustMaxNumberOfFiles(0);
758
+ }
759
+ },
760
+
761
+ _create: function () {
762
+ this._super();
763
+ this._refreshOptionsList.push(
764
+ 'filesContainer',
765
+ 'uploadTemplateId',
766
+ 'downloadTemplateId'
767
+ );
768
+ if (!this._processingQueue) {
769
+ this._processingQueue = $.Deferred().resolveWith(this).promise();
770
+ this.process = function () {
771
+ return this._processingQueue;
772
+ };
773
+ }
774
+ this._resetFinishedDeferreds();
775
+ },
776
+
777
+ enable: function () {
778
+ var wasDisabled = false;
779
+ if (this.options.disabled) {
780
+ wasDisabled = true;
781
+ }
782
+ this._super();
783
+ if (wasDisabled) {
784
+ this.element.find('input, button').prop('disabled', false);
785
+ this._enableFileInputButton();
786
+ }
787
+ },
788
+
789
+ disable: function () {
790
+ if (!this.options.disabled) {
791
+ this.element.find('input, button').prop('disabled', true);
792
+ this._disableFileInputButton();
793
+ }
794
+ this._super();
795
+ }
796
+
797
+ });
798
+
799
+ }));