s3_cors_fileupload 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (29) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +12 -2
  3. data/Gemfile +1 -1
  4. data/Gemfile.lock +19 -19
  5. data/README.md +13 -1
  6. data/lib/generators/s3_cors_fileupload/install/templates/s3_uploads.js +1 -2
  7. data/lib/generators/s3_cors_fileupload/install/templates/source_file.rb +1 -1
  8. data/lib/generators/s3_cors_fileupload/install/templates/views/erb/_template_download.html.erb +19 -16
  9. data/lib/generators/s3_cors_fileupload/install/templates/views/erb/_template_upload.html.erb +31 -26
  10. data/lib/generators/s3_cors_fileupload/install/templates/views/erb/_template_uploaded.html.erb +18 -13
  11. data/lib/generators/s3_cors_fileupload/install/templates/views/erb/index.html.erb +1 -1
  12. data/lib/generators/s3_cors_fileupload/install/templates/views/haml/_template_download.html.haml +16 -21
  13. data/lib/generators/s3_cors_fileupload/install/templates/views/haml/_template_upload.html.haml +15 -18
  14. data/lib/generators/s3_cors_fileupload/install/templates/views/haml/_template_uploaded.html.haml +12 -13
  15. data/lib/generators/s3_cors_fileupload/install/templates/views/haml/index.html.haml +1 -1
  16. data/lib/s3_cors_fileupload/rails/form_helper.rb +16 -14
  17. data/lib/s3_cors_fileupload/version.rb +3 -3
  18. data/vendor/assets/javascripts/s3_cors_fileupload/index.js +4 -1
  19. data/vendor/assets/javascripts/s3_cors_fileupload/jquery.fileupload-image.js +213 -0
  20. data/vendor/assets/javascripts/s3_cors_fileupload/jquery.fileupload-process.js +164 -0
  21. data/vendor/assets/javascripts/s3_cors_fileupload/jquery.fileupload-ui.js +62 -228
  22. data/vendor/assets/javascripts/s3_cors_fileupload/jquery.fileupload-validate.js +116 -0
  23. data/vendor/assets/javascripts/s3_cors_fileupload/jquery.fileupload.js +212 -84
  24. data/vendor/assets/javascripts/s3_cors_fileupload/jquery.iframe-transport.js +24 -4
  25. data/vendor/assets/javascripts/s3_cors_fileupload/vendor/jquery.ui.widget.js +1 -1
  26. data/vendor/assets/javascripts/s3_cors_fileupload/vendor/load-image.js +138 -172
  27. data/vendor/assets/javascripts/s3_cors_fileupload/vendor/tmpl.js +3 -4
  28. data/vendor/assets/stylesheets/jquery.fileupload-ui.css.erb +12 -28
  29. metadata +5 -2
@@ -1,5 +1,5 @@
1
1
  /*
2
- * jQuery File Upload User Interface Plugin 7.4.1
2
+ * jQuery File Upload User Interface Plugin 8.5.0
3
3
  * https://github.com/blueimp/jQuery-File-Upload
4
4
  *
5
5
  * Copyright 2010, Sebastian Tschan
@@ -19,20 +19,27 @@
19
19
  define([
20
20
  'jquery',
21
21
  'tmpl',
22
- 'load-image',
23
- './jquery.fileupload-fp'
22
+ './jquery.fileupload-image',
23
+ './jquery.fileupload-audio',
24
+ './jquery.fileupload-video',
25
+ './jquery.fileupload-validate'
24
26
  ], factory);
25
27
  } else {
26
28
  // Browser globals:
27
29
  factory(
28
30
  window.jQuery,
29
- window.tmpl,
30
- window.loadImage
31
+ window.tmpl
31
32
  );
32
33
  }
33
34
  }(function ($, tmpl, loadImage) {
34
35
  'use strict';
35
36
 
37
+ $.blueimp.fileupload.prototype._specialOptions.push(
38
+ 'filesContainer',
39
+ 'uploadTemplateId',
40
+ 'downloadTemplateId'
41
+ );
42
+
36
43
  // The UI version extends the file upload widget
37
44
  // and adds complete user interface interaction:
38
45
  $.widget('blueimp.fileupload', $.blueimp.fileupload, {
@@ -42,29 +49,6 @@
42
49
  // as the user clicks on the start buttons. To enable automatic
43
50
  // uploads, set the following option to true:
44
51
  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: undefined,
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: 5000000, // 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
52
  // The ID of the upload template:
69
53
  uploadTemplateId: 'template-upload',
70
54
  // The ID of the download template:
@@ -79,29 +63,43 @@
79
63
  // option of the $.ajax upload requests:
80
64
  dataType: 'json',
81
65
 
66
+ // Function returning the current number of files,
67
+ // used by the maxNumberOfFiles validation:
68
+ getNumberOfFiles: function () {
69
+ return this.filesContainer.children().length;
70
+ },
71
+
72
+ // Callback to retrieve the list of files from the server response:
73
+ getFilesFromResponse: function (data) {
74
+ if (data.result && $.isArray(data.result.files)) {
75
+ return data.result.files;
76
+ }
77
+ return [];
78
+ },
79
+
82
80
  // The add callback is invoked as soon as files are added to the fileupload
83
81
  // widget (via file input selection, drag & drop or add API call).
84
82
  // See the basic file upload widget for more information:
85
83
  add: function (e, data) {
86
- var that = $(this).data('blueimp-fileupload') ||
87
- $(this).data('fileupload'),
84
+ var $this = $(this),
85
+ that = $this.data('blueimp-fileupload') ||
86
+ $this.data('fileupload'),
88
87
  options = that.options,
89
88
  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);
89
+ data.process(function () {
90
+ return $this.fileupload('process', data);
91
+ }).always(function () {
94
92
  data.context = that._renderUpload(files).data('data', data);
93
+ that._renderPreviews(data);
95
94
  options.filesContainer[
96
95
  options.prependFiles ? 'prepend' : 'append'
97
96
  ](data.context);
98
- that._renderPreviews(data);
99
97
  that._forceReflow(data.context);
100
98
  that._transition(data.context).done(
101
99
  function () {
102
100
  if ((that._trigger('added', e, data) !== false) &&
103
101
  (options.autoUpload || data.autoUpload) &&
104
- data.autoUpload !== false && data.isValidated) {
102
+ data.autoUpload !== false && !data.files.error) {
105
103
  data.submit();
106
104
  }
107
105
  }
@@ -112,15 +110,6 @@
112
110
  send: function (e, data) {
113
111
  var that = $(this).data('blueimp-fileupload') ||
114
112
  $(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
113
  if (data.context && data.dataType &&
125
114
  data.dataType.substr(0, 6) === 'iframe') {
126
115
  // Iframe Transport does not support progress events.
@@ -142,7 +131,9 @@
142
131
  done: function (e, data) {
143
132
  var that = $(this).data('blueimp-fileupload') ||
144
133
  $(this).data('fileupload'),
145
- files = that._getFilesFromResponse(data),
134
+ getFilesFromResponse = data.getFilesFromResponse ||
135
+ that.options.getFilesFromResponse,
136
+ files = getFilesFromResponse(data),
146
137
  template,
147
138
  deferred;
148
139
  if (data.context) {
@@ -150,9 +141,6 @@
150
141
  var file = files[index] ||
151
142
  {error: 'Empty file upload result'},
152
143
  deferred = that._addFinishedDeferreds();
153
- if (file.error) {
154
- that._adjustMaxNumberOfFiles(1);
155
- }
156
144
  that._transition($(this)).done(
157
145
  function () {
158
146
  var node = $(this);
@@ -171,17 +159,6 @@
171
159
  );
172
160
  });
173
161
  } 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
162
  template = that._renderDownload(files)
186
163
  .appendTo(that.options.filesContainer);
187
164
  that._forceReflow(template);
@@ -202,9 +179,6 @@
202
179
  $(this).data('fileupload'),
203
180
  template,
204
181
  deferred;
205
- if (data.maxNumberOfFilesAdjusted) {
206
- that._adjustMaxNumberOfFiles(data.files.length);
207
- }
208
182
  if (data.context) {
209
183
  data.context.each(function (index) {
210
184
  if (data.errorThrown !== 'abort') {
@@ -323,22 +297,31 @@
323
297
  }
324
298
  );
325
299
  },
300
+ processstart: function () {
301
+ $(this).addClass('fileupload-processing');
302
+ },
303
+ processstop: function () {
304
+ $(this).removeClass('fileupload-processing');
305
+ },
326
306
  // Callback for file deletion:
327
307
  destroy: function (e, data) {
328
308
  if (data.confirmation && !confirm(data.confirmation))
329
309
  return; // abort the deletion if the user rejects the confirmation dialog
330
310
  var that = $(this).data('blueimp-fileupload') ||
331
- $(this).data('fileupload');
311
+ $(this).data('fileupload'),
312
+ removeNode = function () {
313
+ that._transition(data.context).done(
314
+ function () {
315
+ $(this).remove();
316
+ that._trigger('destroyed', e, data);
317
+ }
318
+ );
319
+ };
332
320
  if (data.url) {
333
- $.ajax(data);
334
- that._adjustMaxNumberOfFiles(1);
321
+ $.ajax(data).done(removeNode);
322
+ } else {
323
+ removeNode();
335
324
  }
336
- that._transition(data.context).done(
337
- function () {
338
- $(this).remove();
339
- that._trigger('destroyed', e, data);
340
- }
341
- );
342
325
  }
343
326
  },
344
327
 
@@ -358,13 +341,6 @@
358
341
  return this._finishedUploads;
359
342
  },
360
343
 
361
- _getFilesFromResponse: function (data) {
362
- if (data.result && $.isArray(data.result.files)) {
363
- return data.result.files;
364
- }
365
- return [];
366
- },
367
-
368
344
  // Link handler, that allows to download files
369
345
  // by drag & drop of the links to the desktop:
370
346
  _enableDragToDesktop: function () {
@@ -378,21 +354,10 @@
378
354
  'DownloadURL',
379
355
  [type, name, url].join(':')
380
356
  );
381
- } catch (err) {}
357
+ } catch (ignore) {}
382
358
  });
383
359
  },
384
360
 
385
- _adjustMaxNumberOfFiles: function (operand) {
386
- if (typeof this.options.maxNumberOfFiles === 'number') {
387
- this.options.maxNumberOfFiles += operand;
388
- if (this.options.maxNumberOfFiles < 1) {
389
- this._disableFileInputButton();
390
- } else {
391
- this._enableFileInputButton();
392
- }
393
- }
394
- },
395
-
396
361
  _formatFileSize: function (bytes) {
397
362
  if (typeof bytes !== 'number') {
398
363
  return '';
@@ -448,46 +413,6 @@
448
413
  this._formatFileSize(data.total);
449
414
  },
450
415
 
451
- _hasError: function (file) {
452
- if (file.error) {
453
- return file.error;
454
- }
455
- // The number of added files is subtracted from
456
- // maxNumberOfFiles before validation, so we check if
457
- // maxNumberOfFiles is below 0 (instead of below 1):
458
- if (this.options.maxNumberOfFiles < 0) {
459
- return 'Maximum number of files exceeded';
460
- }
461
- // Files are accepted if either the file type or the file name
462
- // matches against the acceptFileTypes regular expression, as
463
- // only browsers with support for the File API report the type:
464
- if (!(this.options.acceptFileTypes.test(file.type) ||
465
- this.options.acceptFileTypes.test(file.name))) {
466
- return 'Filetype not allowed';
467
- }
468
- if (this.options.maxFileSize &&
469
- file.size > this.options.maxFileSize) {
470
- return 'File is too big';
471
- }
472
- if (typeof file.size === 'number' &&
473
- file.size < this.options.minFileSize) {
474
- return 'File is too small';
475
- }
476
- return null;
477
- },
478
-
479
- _validate: function (files) {
480
- var that = this,
481
- valid = !!files.length;
482
- $.each(files, function (index, file) {
483
- file.error = that._hasError(file);
484
- if (file.error) {
485
- valid = false;
486
- }
487
- });
488
- return valid;
489
- },
490
-
491
416
  _renderTemplate: function (func, files) {
492
417
  if (!func) {
493
418
  return $();
@@ -503,63 +428,10 @@
503
428
  return $(this.options.templatesContainer).html(result).children();
504
429
  },
505
430
 
506
- _renderPreview: function (file, node) {
507
- var that = this,
508
- options = this.options,
509
- dfd = $.Deferred();
510
- return ((loadImage && loadImage(
511
- file,
512
- function (img) {
513
- node.append(img);
514
- that._forceReflow(node);
515
- that._transition(node).done(function () {
516
- dfd.resolveWith(node);
517
- });
518
- if (!$.contains(that.document[0].body, node[0])) {
519
- // If the element is not part of the DOM,
520
- // transition events are not triggered,
521
- // so we have to resolve manually:
522
- dfd.resolveWith(node);
523
- }
524
- node.on('remove', function () {
525
- // If the element is removed before the
526
- // transition finishes, transition events are
527
- // not triggered, resolve manually:
528
- dfd.resolveWith(node);
529
- });
530
- },
531
- {
532
- maxWidth: options.previewMaxWidth,
533
- maxHeight: options.previewMaxHeight,
534
- canvas: options.previewAsCanvas
535
- }
536
- )) || dfd.resolveWith(node)) && dfd;
537
- },
538
-
539
431
  _renderPreviews: function (data) {
540
- var that = this,
541
- options = this.options;
542
- data.context.find('.preview span').each(function (index, element) {
543
- var file = data.files[index];
544
- if (options.previewSourceFileTypes.test(file.type) &&
545
- ($.type(options.previewSourceMaxFileSize) !== 'number' ||
546
- file.size < options.previewSourceMaxFileSize)) {
547
- that._processingQueue = that._processingQueue.pipe(function () {
548
- var dfd = $.Deferred(),
549
- ev = $.Event('previewdone', {
550
- target: element
551
- });
552
- that._renderPreview(file, $(element)).done(
553
- function () {
554
- that._trigger(ev.type, ev, data);
555
- dfd.resolveWith(that);
556
- }
557
- );
558
- return dfd.promise();
559
- });
560
- }
432
+ data.context.find('.preview').each(function (index, elm) {
433
+ $(elm).append(data.files[index].preview);
561
434
  });
562
- return this._processingQueue;
563
435
  },
564
436
 
565
437
  _renderUpload: function (files) {
@@ -603,8 +475,7 @@
603
475
  var button = $(e.currentTarget);
604
476
  this._trigger('destroy', e, $.extend({
605
477
  context: button.closest('.template-download'),
606
- type: 'DELETE',
607
- dataType: this.options.dataType
478
+ type: 'DELETE'
608
479
  }, button.data()));
609
480
  },
610
481
 
@@ -733,55 +604,18 @@
733
604
  }
734
605
  },
735
606
 
736
- _stringToRegExp: function (str) {
737
- var parts = str.split('/'),
738
- modifiers = parts.pop();
739
- parts.shift();
740
- return new RegExp(parts.join('/'), modifiers);
741
- },
742
-
743
- _initRegExpOptions: function () {
744
- var options = this.options;
745
- if ($.type(options.acceptFileTypes) === 'string') {
746
- options.acceptFileTypes = this._stringToRegExp(
747
- options.acceptFileTypes
748
- );
749
- }
750
- if ($.type(options.previewSourceFileTypes) === 'string') {
751
- options.previewSourceFileTypes = this._stringToRegExp(
752
- options.previewSourceFileTypes
753
- );
754
- }
755
- },
756
-
757
607
  _initSpecialOptions: function () {
758
608
  this._super();
759
609
  this._initFilesContainer();
760
610
  this._initTemplates();
761
- this._initRegExpOptions();
762
- },
763
-
764
- _setOption: function (key, value) {
765
- this._super(key, value);
766
- if (key === 'maxNumberOfFiles') {
767
- this._adjustMaxNumberOfFiles(0);
768
- }
769
611
  },
770
612
 
771
613
  _create: function () {
772
614
  this._super();
773
- this._refreshOptionsList.push(
774
- 'filesContainer',
775
- 'uploadTemplateId',
776
- 'downloadTemplateId'
777
- );
778
- if (!this._processingQueue) {
779
- this._processingQueue = $.Deferred().resolveWith(this).promise();
780
- this.process = function () {
781
- return this._processingQueue;
782
- };
783
- }
784
615
  this._resetFinishedDeferreds();
616
+ if (!$.support.fileInput) {
617
+ this._disableFileInputButton();
618
+ }
785
619
  },
786
620
 
787
621
  enable: function () {
@@ -0,0 +1,116 @@
1
+ /*
2
+ * jQuery File Upload Validation Plugin 1.1
3
+ * https://github.com/blueimp/jQuery-File-Upload
4
+ *
5
+ * Copyright 2013, 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 */
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.fileupload-process'
22
+ ], factory);
23
+ } else {
24
+ // Browser globals:
25
+ factory(
26
+ window.jQuery
27
+ );
28
+ }
29
+ }(function ($) {
30
+ 'use strict';
31
+
32
+ // Append to the default processQueue:
33
+ $.blueimp.fileupload.prototype.options.processQueue.push(
34
+ {
35
+ action: 'validate',
36
+ // Always trigger this action,
37
+ // even if the previous action was rejected:
38
+ always: true,
39
+ // Options taken from the global options map:
40
+ acceptFileTypes: '@',
41
+ maxFileSize: '@',
42
+ minFileSize: '@',
43
+ maxNumberOfFiles: '@',
44
+ disabled: '@disableValidation'
45
+ }
46
+ );
47
+
48
+ // The File Upload Validation plugin extends the fileupload widget
49
+ // with file validation functionality:
50
+ $.widget('blueimp.fileupload', $.blueimp.fileupload, {
51
+
52
+ options: {
53
+ /*
54
+ // The regular expression for allowed file types, matches
55
+ // against either file type or file name:
56
+ acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i,
57
+ // The maximum allowed file size in bytes:
58
+ maxFileSize: 10000000, // 10 MB
59
+ // The minimum allowed file size in bytes:
60
+ minFileSize: undefined, // No minimal file size
61
+ // The limit of files to be uploaded:
62
+ maxNumberOfFiles: 10,
63
+ */
64
+
65
+ // Function returning the current number of files,
66
+ // has to be overriden for maxNumberOfFiles validation:
67
+ getNumberOfFiles: $.noop,
68
+
69
+ // Error and info messages:
70
+ messages: {
71
+ maxNumberOfFiles: 'Maximum number of files exceeded',
72
+ acceptFileTypes: 'File type not allowed',
73
+ maxFileSize: 'File is too large',
74
+ minFileSize: 'File is too small'
75
+ }
76
+ },
77
+
78
+ processActions: {
79
+
80
+ validate: function (data, options) {
81
+ if (options.disabled) {
82
+ return data;
83
+ }
84
+ var dfd = $.Deferred(),
85
+ settings = this.options,
86
+ file = data.files[data.index],
87
+ numberOfFiles = settings.getNumberOfFiles();
88
+ if (numberOfFiles && $.type(options.maxNumberOfFiles) === 'number' &&
89
+ numberOfFiles + data.files.length > options.maxNumberOfFiles) {
90
+ file.error = settings.i18n('maxNumberOfFiles');
91
+ } else if (options.acceptFileTypes &&
92
+ !(options.acceptFileTypes.test(file.type) ||
93
+ options.acceptFileTypes.test(file.name))) {
94
+ file.error = settings.i18n('acceptFileTypes');
95
+ } else if (options.maxFileSize && file.size > options.maxFileSize) {
96
+ file.error = settings.i18n('maxFileSize');
97
+ } else if ($.type(file.size) === 'number' &&
98
+ file.size < options.minFileSize) {
99
+ file.error = settings.i18n('minFileSize');
100
+ } else {
101
+ delete file.error;
102
+ }
103
+ if (file.error || data.files.error) {
104
+ data.files.error = true;
105
+ dfd.rejectWith(this, [data]);
106
+ } else {
107
+ dfd.resolveWith(this, [data]);
108
+ }
109
+ return dfd.promise();
110
+ }
111
+
112
+ }
113
+
114
+ });
115
+
116
+ }));