card-mod-format 0.14.1 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (119) hide show
  1. checksums.yaml +4 -4
  2. data/assets/script/decko/clicks_and_hovers.js.coffee +49 -0
  3. data/assets/script/decko/decko.js.coffee +32 -0
  4. data/assets/script/decko/decko_jquery.js.coffee +25 -0
  5. data/assets/script/decko/slot.js.coffee +150 -0
  6. data/assets/script/decko/slot_ready.js.coffee +11 -0
  7. data/assets/script/decko/slotter.js.coffee +208 -0
  8. data/assets/script/jquery/jquery-ui.min.js +13 -0
  9. data/assets/script/jquery/jquery.autosize.js +274 -0
  10. data/assets/script/jquery/jquery.ui.autocomplete.html.js +41 -0
  11. data/assets/script/manifest.yml +38 -0
  12. data/assets/style/common.scss +73 -0
  13. data/assets/style/logo_and_credit.scss +24 -0
  14. data/assets/style/menu.scss +43 -0
  15. data/assets/style/messaging.scss +59 -0
  16. data/assets/style/misc.scss +90 -0
  17. data/assets/style/open_and_closed.scss +68 -0
  18. data/data/files/credit_image.svg +59 -0
  19. data/data/files/mod_format_script_asset_output/file.js +66 -0
  20. data/data/real.yml +67 -0
  21. data/lib/card/format/html_format.rb +0 -2
  22. data/lib/card/mod/format.rb +4 -0
  23. data/lib/card/path.rb +20 -20
  24. data/set/all/base.rb +1 -11
  25. data/set/all/content.rb +3 -11
  26. data/set/all/csv.rb +22 -74
  27. data/set/all/data.rb +2 -2
  28. data/set/all/demo.rb +6 -2
  29. data/set/all/error.rb +1 -1
  30. data/set/all/html/error.rb +1 -1
  31. data/set/all/html/head.rb +22 -12
  32. data/set/all/html/header.rb +10 -40
  33. data/set/all/html/header_wrap.haml +3 -4
  34. data/set/all/html/labeled.haml +1 -1
  35. data/set/all/html/menu.rb +36 -12
  36. data/set/all/html/views.rb +8 -17
  37. data/set/all/html/wrap.rb +5 -4
  38. data/set/all/html.rb +2 -3
  39. data/set/all/json.rb +1 -5
  40. data/set/right/head.rb +1 -0
  41. data/set/type/cardtype.rb +4 -6
  42. data/set/type/json.rb +1 -1
  43. data/set/type/number.rb +1 -16
  44. data/vendor/jquery_file_upload/LICENSE.txt +20 -0
  45. data/vendor/jquery_file_upload/README.md +224 -0
  46. data/vendor/jquery_file_upload/SECURITY.md +227 -0
  47. data/vendor/jquery_file_upload/VULNERABILITIES.md +118 -0
  48. data/vendor/jquery_file_upload/cors/postmessage.html +85 -0
  49. data/vendor/jquery_file_upload/cors/result.html +26 -0
  50. data/vendor/jquery_file_upload/css/jquery.fileupload-noscript.css +22 -0
  51. data/vendor/jquery_file_upload/css/jquery.fileupload-ui-noscript.css +17 -0
  52. data/vendor/jquery_file_upload/css/jquery.fileupload-ui.css +68 -0
  53. data/vendor/jquery_file_upload/css/jquery.fileupload.css +36 -0
  54. data/vendor/jquery_file_upload/docker-compose.yml +55 -0
  55. data/vendor/jquery_file_upload/img/loading.gif +0 -0
  56. data/vendor/jquery_file_upload/img/progressbar.gif +0 -0
  57. data/vendor/jquery_file_upload/index.html +357 -0
  58. data/vendor/jquery_file_upload/js/cors/jquery.postmessage-transport.js +126 -0
  59. data/vendor/jquery_file_upload/js/cors/jquery.xdr-transport.js +97 -0
  60. data/vendor/jquery_file_upload/js/demo.js +75 -0
  61. data/vendor/jquery_file_upload/js/jquery.fileupload-audio.js +101 -0
  62. data/vendor/jquery_file_upload/js/jquery.fileupload-image.js +347 -0
  63. data/vendor/jquery_file_upload/js/jquery.fileupload-process.js +170 -0
  64. data/vendor/jquery_file_upload/js/jquery.fileupload-ui.js +759 -0
  65. data/vendor/jquery_file_upload/js/jquery.fileupload-validate.js +119 -0
  66. data/vendor/jquery_file_upload/js/jquery.fileupload-video.js +101 -0
  67. data/vendor/jquery_file_upload/js/jquery.fileupload.js +1604 -0
  68. data/vendor/jquery_file_upload/js/jquery.iframe-transport.js +227 -0
  69. data/vendor/jquery_file_upload/js/vendor/jquery.ui.widget.js +805 -0
  70. data/vendor/jquery_file_upload/package-lock.json +6853 -0
  71. data/vendor/jquery_file_upload/package.json +116 -0
  72. data/vendor/jquery_file_upload/server/gae-python/app.yaml +18 -0
  73. data/vendor/jquery_file_upload/server/gae-python/main.py +204 -0
  74. data/vendor/jquery_file_upload/server/gae-python/static/favicon.ico +0 -0
  75. data/vendor/jquery_file_upload/server/gae-python/static/robots.txt +2 -0
  76. data/vendor/jquery_file_upload/server/php/Dockerfile +44 -0
  77. data/vendor/jquery_file_upload/server/php/UploadHandler.php +1480 -0
  78. data/vendor/jquery_file_upload/server/php/index.php +15 -0
  79. data/vendor/jquery_file_upload/server/php/php.ini +5 -0
  80. data/vendor/jquery_file_upload/test/index.html +49 -0
  81. data/vendor/jquery_file_upload/test/unit.js +989 -0
  82. data/vendor/jquery_file_upload/test/vendor/chai.js +10854 -0
  83. data/vendor/jquery_file_upload/test/vendor/mocha.css +325 -0
  84. data/vendor/jquery_file_upload/test/vendor/mocha.js +18178 -0
  85. data/vendor/jquery_file_upload/wdio/LICENSE.txt +20 -0
  86. data/vendor/jquery_file_upload/wdio/assets/black+white-3x2.jpg +0 -0
  87. data/vendor/jquery_file_upload/wdio/assets/black+white-60x40.gif +0 -0
  88. data/vendor/jquery_file_upload/wdio/conf/chrome.js +40 -0
  89. data/vendor/jquery_file_upload/wdio/conf/firefox.js +25 -0
  90. data/vendor/jquery_file_upload/wdio/hooks/index.js +36 -0
  91. data/vendor/jquery_file_upload/wdio/test/pages/file-upload.js +79 -0
  92. data/vendor/jquery_file_upload/wdio/test/specs/01-file-upload.js +25 -0
  93. data/vendor/jquery_file_upload/wdio/wdio.conf.js +4 -0
  94. data/vendor/jquery_rails/CHANGELOG.md +359 -0
  95. data/vendor/jquery_rails/CONTRIBUTING.md +132 -0
  96. data/vendor/jquery_rails/Gemfile +22 -0
  97. data/vendor/jquery_rails/MIT-LICENSE +21 -0
  98. data/vendor/jquery_rails/README.md +75 -0
  99. data/vendor/jquery_rails/Rakefile +59 -0
  100. data/vendor/jquery_rails/VERSIONS.md +62 -0
  101. data/vendor/jquery_rails/jquery-rails.gemspec +26 -0
  102. data/vendor/jquery_rails/lib/jquery/assert_select.rb +149 -0
  103. data/vendor/jquery_rails/lib/jquery/rails/engine.rb +6 -0
  104. data/vendor/jquery_rails/lib/jquery/rails/version.rb +9 -0
  105. data/vendor/jquery_rails/lib/jquery/rails.rb +8 -0
  106. data/vendor/jquery_rails/lib/jquery-rails.rb +1 -0
  107. data/vendor/jquery_rails/test/assert_select_jquery_test.rb +85 -0
  108. data/vendor/jquery_rails/test/test_helper.rb +6 -0
  109. data/vendor/jquery_rails/vendor/assets/javascripts/jquery.js +11008 -0
  110. data/vendor/jquery_rails/vendor/assets/javascripts/jquery.min.js +5 -0
  111. data/vendor/jquery_rails/vendor/assets/javascripts/jquery.min.map +1 -0
  112. data/vendor/jquery_rails/vendor/assets/javascripts/jquery2.js +9814 -0
  113. data/vendor/jquery_rails/vendor/assets/javascripts/jquery2.min.js +4 -0
  114. data/vendor/jquery_rails/vendor/assets/javascripts/jquery2.min.map +1 -0
  115. data/vendor/jquery_rails/vendor/assets/javascripts/jquery3.js +10364 -0
  116. data/vendor/jquery_rails/vendor/assets/javascripts/jquery3.min.js +2 -0
  117. data/vendor/jquery_rails/vendor/assets/javascripts/jquery3.min.map +1 -0
  118. data/vendor/jquery_rails/vendor/assets/javascripts/jquery_ujs.js +555 -0
  119. metadata +104 -7
@@ -0,0 +1,101 @@
1
+ /*
2
+ * jQuery File Upload Audio Preview Plugin
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
+ * https://opensource.org/licenses/MIT
10
+ */
11
+
12
+ /* global define, require */
13
+
14
+ (function (factory) {
15
+ 'use strict';
16
+ if (typeof define === 'function' && define.amd) {
17
+ // Register as an anonymous AMD module:
18
+ define(['jquery', 'load-image', './jquery.fileupload-process'], factory);
19
+ } else if (typeof exports === 'object') {
20
+ // Node/CommonJS:
21
+ factory(
22
+ require('jquery'),
23
+ require('blueimp-load-image/js/load-image'),
24
+ require('./jquery.fileupload-process')
25
+ );
26
+ } else {
27
+ // Browser globals:
28
+ factory(window.jQuery, window.loadImage);
29
+ }
30
+ })(function ($, loadImage) {
31
+ 'use strict';
32
+
33
+ // Prepend to the default processQueue:
34
+ $.blueimp.fileupload.prototype.options.processQueue.unshift(
35
+ {
36
+ action: 'loadAudio',
37
+ // Use the action as prefix for the "@" options:
38
+ prefix: true,
39
+ fileTypes: '@',
40
+ maxFileSize: '@',
41
+ disabled: '@disableAudioPreview'
42
+ },
43
+ {
44
+ action: 'setAudio',
45
+ name: '@audioPreviewName',
46
+ disabled: '@disableAudioPreview'
47
+ }
48
+ );
49
+
50
+ // The File Upload Audio Preview plugin extends the fileupload widget
51
+ // with audio preview functionality:
52
+ $.widget('blueimp.fileupload', $.blueimp.fileupload, {
53
+ options: {
54
+ // The regular expression for the types of audio files to load,
55
+ // matched against the file type:
56
+ loadAudioFileTypes: /^audio\/.*$/
57
+ },
58
+
59
+ _audioElement: document.createElement('audio'),
60
+
61
+ processActions: {
62
+ // Loads the audio file given via data.files and data.index
63
+ // as audio element if the browser supports playing it.
64
+ // Accepts the options fileTypes (regular expression)
65
+ // and maxFileSize (integer) to limit the files to load:
66
+ loadAudio: function (data, options) {
67
+ if (options.disabled) {
68
+ return data;
69
+ }
70
+ var file = data.files[data.index],
71
+ url,
72
+ audio;
73
+ if (
74
+ this._audioElement.canPlayType &&
75
+ this._audioElement.canPlayType(file.type) &&
76
+ ($.type(options.maxFileSize) !== 'number' ||
77
+ file.size <= options.maxFileSize) &&
78
+ (!options.fileTypes || options.fileTypes.test(file.type))
79
+ ) {
80
+ url = loadImage.createObjectURL(file);
81
+ if (url) {
82
+ audio = this._audioElement.cloneNode(false);
83
+ audio.src = url;
84
+ audio.controls = true;
85
+ data.audio = audio;
86
+ return data;
87
+ }
88
+ }
89
+ return data;
90
+ },
91
+
92
+ // Sets the audio element as a property of the file object:
93
+ setAudio: function (data, options) {
94
+ if (data.audio && !options.disabled) {
95
+ data.files[data.index][options.name || 'preview'] = data.audio;
96
+ }
97
+ return data;
98
+ }
99
+ }
100
+ });
101
+ });
@@ -0,0 +1,347 @@
1
+ /*
2
+ * jQuery File Upload Image Preview & Resize Plugin
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
+ * https://opensource.org/licenses/MIT
10
+ */
11
+
12
+ /* global define, require */
13
+
14
+ (function (factory) {
15
+ 'use strict';
16
+ if (typeof define === 'function' && define.amd) {
17
+ // Register as an anonymous AMD module:
18
+ define([
19
+ 'jquery',
20
+ 'load-image',
21
+ 'load-image-meta',
22
+ 'load-image-scale',
23
+ 'load-image-exif',
24
+ 'load-image-orientation',
25
+ 'canvas-to-blob',
26
+ './jquery.fileupload-process'
27
+ ], factory);
28
+ } else if (typeof exports === 'object') {
29
+ // Node/CommonJS:
30
+ factory(
31
+ require('jquery'),
32
+ require('blueimp-load-image/js/load-image'),
33
+ require('blueimp-load-image/js/load-image-meta'),
34
+ require('blueimp-load-image/js/load-image-scale'),
35
+ require('blueimp-load-image/js/load-image-exif'),
36
+ require('blueimp-load-image/js/load-image-orientation'),
37
+ require('blueimp-canvas-to-blob'),
38
+ require('./jquery.fileupload-process')
39
+ );
40
+ } else {
41
+ // Browser globals:
42
+ factory(window.jQuery, window.loadImage);
43
+ }
44
+ })(function ($, loadImage) {
45
+ 'use strict';
46
+
47
+ // Prepend to the default processQueue:
48
+ $.blueimp.fileupload.prototype.options.processQueue.unshift(
49
+ {
50
+ action: 'loadImageMetaData',
51
+ maxMetaDataSize: '@',
52
+ disableImageHead: '@',
53
+ disableMetaDataParsers: '@',
54
+ disableExif: '@',
55
+ disableExifOffsets: '@',
56
+ includeExifTags: '@',
57
+ excludeExifTags: '@',
58
+ disableIptc: '@',
59
+ disableIptcOffsets: '@',
60
+ includeIptcTags: '@',
61
+ excludeIptcTags: '@',
62
+ disabled: '@disableImageMetaDataLoad'
63
+ },
64
+ {
65
+ action: 'loadImage',
66
+ // Use the action as prefix for the "@" options:
67
+ prefix: true,
68
+ fileTypes: '@',
69
+ maxFileSize: '@',
70
+ noRevoke: '@',
71
+ disabled: '@disableImageLoad'
72
+ },
73
+ {
74
+ action: 'resizeImage',
75
+ // Use "image" as prefix for the "@" options:
76
+ prefix: 'image',
77
+ maxWidth: '@',
78
+ maxHeight: '@',
79
+ minWidth: '@',
80
+ minHeight: '@',
81
+ crop: '@',
82
+ orientation: '@',
83
+ forceResize: '@',
84
+ disabled: '@disableImageResize',
85
+ imageSmoothingQuality: '@imageSmoothingQuality'
86
+ },
87
+ {
88
+ action: 'saveImage',
89
+ quality: '@imageQuality',
90
+ type: '@imageType',
91
+ disabled: '@disableImageResize'
92
+ },
93
+ {
94
+ action: 'saveImageMetaData',
95
+ disabled: '@disableImageMetaDataSave'
96
+ },
97
+ {
98
+ action: 'resizeImage',
99
+ // Use "preview" as prefix for the "@" options:
100
+ prefix: 'preview',
101
+ maxWidth: '@',
102
+ maxHeight: '@',
103
+ minWidth: '@',
104
+ minHeight: '@',
105
+ crop: '@',
106
+ orientation: '@',
107
+ thumbnail: '@',
108
+ canvas: '@',
109
+ disabled: '@disableImagePreview'
110
+ },
111
+ {
112
+ action: 'setImage',
113
+ name: '@imagePreviewName',
114
+ disabled: '@disableImagePreview'
115
+ },
116
+ {
117
+ action: 'deleteImageReferences',
118
+ disabled: '@disableImageReferencesDeletion'
119
+ }
120
+ );
121
+
122
+ // The File Upload Resize plugin extends the fileupload widget
123
+ // with image resize functionality:
124
+ $.widget('blueimp.fileupload', $.blueimp.fileupload, {
125
+ options: {
126
+ // The regular expression for the types of images to load:
127
+ // matched against the file type:
128
+ loadImageFileTypes: /^image\/(gif|jpeg|png|svg\+xml)$/,
129
+ // The maximum file size of images to load:
130
+ loadImageMaxFileSize: 10000000, // 10MB
131
+ // The maximum width of resized images:
132
+ imageMaxWidth: 1920,
133
+ // The maximum height of resized images:
134
+ imageMaxHeight: 1080,
135
+ // Defines the image orientation (1-8) or takes the orientation
136
+ // value from Exif data if set to true:
137
+ imageOrientation: true,
138
+ // Define if resized images should be cropped or only scaled:
139
+ imageCrop: false,
140
+ // Disable the resize image functionality by default:
141
+ disableImageResize: true,
142
+ // The maximum width of the preview images:
143
+ previewMaxWidth: 80,
144
+ // The maximum height of the preview images:
145
+ previewMaxHeight: 80,
146
+ // Defines the preview orientation (1-8) or takes the orientation
147
+ // value from Exif data if set to true:
148
+ previewOrientation: true,
149
+ // Create the preview using the Exif data thumbnail:
150
+ previewThumbnail: true,
151
+ // Define if preview images should be cropped or only scaled:
152
+ previewCrop: false,
153
+ // Define if preview images should be resized as canvas elements:
154
+ previewCanvas: true
155
+ },
156
+
157
+ processActions: {
158
+ // Loads the image given via data.files and data.index
159
+ // as img element, if the browser supports the File API.
160
+ // Accepts the options fileTypes (regular expression)
161
+ // and maxFileSize (integer) to limit the files to load:
162
+ loadImage: function (data, options) {
163
+ if (options.disabled) {
164
+ return data;
165
+ }
166
+ var that = this,
167
+ file = data.files[data.index],
168
+ // eslint-disable-next-line new-cap
169
+ dfd = $.Deferred();
170
+ if (
171
+ ($.type(options.maxFileSize) === 'number' &&
172
+ file.size > options.maxFileSize) ||
173
+ (options.fileTypes && !options.fileTypes.test(file.type)) ||
174
+ !loadImage(
175
+ file,
176
+ function (img) {
177
+ if (img.src) {
178
+ data.img = img;
179
+ }
180
+ dfd.resolveWith(that, [data]);
181
+ },
182
+ options
183
+ )
184
+ ) {
185
+ return data;
186
+ }
187
+ return dfd.promise();
188
+ },
189
+
190
+ // Resizes the image given as data.canvas or data.img
191
+ // and updates data.canvas or data.img with the resized image.
192
+ // Also stores the resized image as preview property.
193
+ // Accepts the options maxWidth, maxHeight, minWidth,
194
+ // minHeight, canvas and crop:
195
+ resizeImage: function (data, options) {
196
+ if (options.disabled || !(data.canvas || data.img)) {
197
+ return data;
198
+ }
199
+ // eslint-disable-next-line no-param-reassign
200
+ options = $.extend({ canvas: true }, options);
201
+ var that = this,
202
+ // eslint-disable-next-line new-cap
203
+ dfd = $.Deferred(),
204
+ img = (options.canvas && data.canvas) || data.img,
205
+ resolve = function (newImg) {
206
+ if (
207
+ newImg &&
208
+ (newImg.width !== img.width ||
209
+ newImg.height !== img.height ||
210
+ options.forceResize)
211
+ ) {
212
+ data[newImg.getContext ? 'canvas' : 'img'] = newImg;
213
+ }
214
+ data.preview = newImg;
215
+ dfd.resolveWith(that, [data]);
216
+ },
217
+ thumbnail,
218
+ thumbnailBlob;
219
+ if (data.exif && options.thumbnail) {
220
+ thumbnail = data.exif.get('Thumbnail');
221
+ thumbnailBlob = thumbnail && thumbnail.get('Blob');
222
+ if (thumbnailBlob) {
223
+ options.orientation = data.exif.get('Orientation');
224
+ loadImage(thumbnailBlob, resolve, options);
225
+ return dfd.promise();
226
+ }
227
+ }
228
+ if (data.orientation) {
229
+ // Prevent orienting the same image twice:
230
+ delete options.orientation;
231
+ } else {
232
+ data.orientation = options.orientation || loadImage.orientation;
233
+ }
234
+ if (img) {
235
+ resolve(loadImage.scale(img, options, data));
236
+ return dfd.promise();
237
+ }
238
+ return data;
239
+ },
240
+
241
+ // Saves the processed image given as data.canvas
242
+ // inplace at data.index of data.files:
243
+ saveImage: function (data, options) {
244
+ if (!data.canvas || options.disabled) {
245
+ return data;
246
+ }
247
+ var that = this,
248
+ file = data.files[data.index],
249
+ // eslint-disable-next-line new-cap
250
+ dfd = $.Deferred();
251
+ if (data.canvas.toBlob) {
252
+ data.canvas.toBlob(
253
+ function (blob) {
254
+ if (!blob.name) {
255
+ if (file.type === blob.type) {
256
+ blob.name = file.name;
257
+ } else if (file.name) {
258
+ blob.name = file.name.replace(
259
+ /\.\w+$/,
260
+ '.' + blob.type.substr(6)
261
+ );
262
+ }
263
+ }
264
+ // Don't restore invalid meta data:
265
+ if (file.type !== blob.type) {
266
+ delete data.imageHead;
267
+ }
268
+ // Store the created blob at the position
269
+ // of the original file in the files list:
270
+ data.files[data.index] = blob;
271
+ dfd.resolveWith(that, [data]);
272
+ },
273
+ options.type || file.type,
274
+ options.quality
275
+ );
276
+ } else {
277
+ return data;
278
+ }
279
+ return dfd.promise();
280
+ },
281
+
282
+ loadImageMetaData: function (data, options) {
283
+ if (options.disabled) {
284
+ return data;
285
+ }
286
+ var that = this,
287
+ // eslint-disable-next-line new-cap
288
+ dfd = $.Deferred();
289
+ loadImage.parseMetaData(
290
+ data.files[data.index],
291
+ function (result) {
292
+ $.extend(data, result);
293
+ dfd.resolveWith(that, [data]);
294
+ },
295
+ options
296
+ );
297
+ return dfd.promise();
298
+ },
299
+
300
+ saveImageMetaData: function (data, options) {
301
+ if (
302
+ !(
303
+ data.imageHead &&
304
+ data.canvas &&
305
+ data.canvas.toBlob &&
306
+ !options.disabled
307
+ )
308
+ ) {
309
+ return data;
310
+ }
311
+ var that = this,
312
+ file = data.files[data.index],
313
+ // eslint-disable-next-line new-cap
314
+ dfd = $.Deferred();
315
+ if (data.orientation === true && data.exifOffsets) {
316
+ // Reset Exif Orientation data:
317
+ loadImage.writeExifData(data.imageHead, data, 'Orientation', 1);
318
+ }
319
+ loadImage.replaceHead(file, data.imageHead, function (blob) {
320
+ blob.name = file.name;
321
+ data.files[data.index] = blob;
322
+ dfd.resolveWith(that, [data]);
323
+ });
324
+ return dfd.promise();
325
+ },
326
+
327
+ // Sets the resized version of the image as a property of the
328
+ // file object, must be called after "saveImage":
329
+ setImage: function (data, options) {
330
+ if (data.preview && !options.disabled) {
331
+ data.files[data.index][options.name || 'preview'] = data.preview;
332
+ }
333
+ return data;
334
+ },
335
+
336
+ deleteImageReferences: function (data, options) {
337
+ if (!options.disabled) {
338
+ delete data.img;
339
+ delete data.canvas;
340
+ delete data.preview;
341
+ delete data.imageHead;
342
+ }
343
+ return data;
344
+ }
345
+ }
346
+ });
347
+ });
@@ -0,0 +1,170 @@
1
+ /*
2
+ * jQuery File Upload Processing Plugin
3
+ * https://github.com/blueimp/jQuery-File-Upload
4
+ *
5
+ * Copyright 2012, Sebastian Tschan
6
+ * https://blueimp.net
7
+ *
8
+ * Licensed under the MIT license:
9
+ * https://opensource.org/licenses/MIT
10
+ */
11
+
12
+ /* global define, require */
13
+
14
+ (function (factory) {
15
+ 'use strict';
16
+ if (typeof define === 'function' && define.amd) {
17
+ // Register as an anonymous AMD module:
18
+ define(['jquery', './jquery.fileupload'], factory);
19
+ } else if (typeof exports === 'object') {
20
+ // Node/CommonJS:
21
+ factory(require('jquery'), require('./jquery.fileupload'));
22
+ } else {
23
+ // Browser globals:
24
+ factory(window.jQuery);
25
+ }
26
+ })(function ($) {
27
+ 'use strict';
28
+
29
+ var originalAdd = $.blueimp.fileupload.prototype.options.add;
30
+
31
+ // The File Upload Processing plugin extends the fileupload widget
32
+ // with file processing functionality:
33
+ $.widget('blueimp.fileupload', $.blueimp.fileupload, {
34
+ options: {
35
+ // The list of processing actions:
36
+ processQueue: [
37
+ /*
38
+ {
39
+ action: 'log',
40
+ type: 'debug'
41
+ }
42
+ */
43
+ ],
44
+ add: function (e, data) {
45
+ var $this = $(this);
46
+ data.process(function () {
47
+ return $this.fileupload('process', data);
48
+ });
49
+ originalAdd.call(this, e, data);
50
+ }
51
+ },
52
+
53
+ processActions: {
54
+ /*
55
+ log: function (data, options) {
56
+ console[options.type](
57
+ 'Processing "' + data.files[data.index].name + '"'
58
+ );
59
+ }
60
+ */
61
+ },
62
+
63
+ _processFile: function (data, originalData) {
64
+ var that = this,
65
+ // eslint-disable-next-line new-cap
66
+ dfd = $.Deferred().resolveWith(that, [data]),
67
+ chain = dfd.promise();
68
+ this._trigger('process', null, data);
69
+ $.each(data.processQueue, function (i, settings) {
70
+ var func = function (data) {
71
+ if (originalData.errorThrown) {
72
+ // eslint-disable-next-line new-cap
73
+ return $.Deferred().rejectWith(that, [originalData]).promise();
74
+ }
75
+ return that.processActions[settings.action].call(
76
+ that,
77
+ data,
78
+ settings
79
+ );
80
+ };
81
+ chain = chain[that._promisePipe](func, settings.always && func);
82
+ });
83
+ chain
84
+ .done(function () {
85
+ that._trigger('processdone', null, data);
86
+ that._trigger('processalways', null, data);
87
+ })
88
+ .fail(function () {
89
+ that._trigger('processfail', null, data);
90
+ that._trigger('processalways', null, data);
91
+ });
92
+ return chain;
93
+ },
94
+
95
+ // Replaces the settings of each processQueue item that
96
+ // are strings starting with an "@", using the remaining
97
+ // substring as key for the option map,
98
+ // e.g. "@autoUpload" is replaced with options.autoUpload:
99
+ _transformProcessQueue: function (options) {
100
+ var processQueue = [];
101
+ $.each(options.processQueue, function () {
102
+ var settings = {},
103
+ action = this.action,
104
+ prefix = this.prefix === true ? action : this.prefix;
105
+ $.each(this, function (key, value) {
106
+ if ($.type(value) === 'string' && value.charAt(0) === '@') {
107
+ settings[key] =
108
+ options[
109
+ value.slice(1) ||
110
+ (prefix
111
+ ? prefix + key.charAt(0).toUpperCase() + key.slice(1)
112
+ : key)
113
+ ];
114
+ } else {
115
+ settings[key] = value;
116
+ }
117
+ });
118
+ processQueue.push(settings);
119
+ });
120
+ options.processQueue = processQueue;
121
+ },
122
+
123
+ // Returns the number of files currently in the processing queue:
124
+ processing: function () {
125
+ return this._processing;
126
+ },
127
+
128
+ // Processes the files given as files property of the data parameter,
129
+ // returns a Promise object that allows to bind callbacks:
130
+ process: function (data) {
131
+ var that = this,
132
+ options = $.extend({}, this.options, data);
133
+ if (options.processQueue && options.processQueue.length) {
134
+ this._transformProcessQueue(options);
135
+ if (this._processing === 0) {
136
+ this._trigger('processstart');
137
+ }
138
+ $.each(data.files, function (index) {
139
+ var opts = index ? $.extend({}, options) : options,
140
+ func = function () {
141
+ if (data.errorThrown) {
142
+ // eslint-disable-next-line new-cap
143
+ return $.Deferred().rejectWith(that, [data]).promise();
144
+ }
145
+ return that._processFile(opts, data);
146
+ };
147
+ opts.index = index;
148
+ that._processing += 1;
149
+ that._processingQueue = that._processingQueue[that._promisePipe](
150
+ func,
151
+ func
152
+ ).always(function () {
153
+ that._processing -= 1;
154
+ if (that._processing === 0) {
155
+ that._trigger('processstop');
156
+ }
157
+ });
158
+ });
159
+ }
160
+ return this._processingQueue;
161
+ },
162
+
163
+ _create: function () {
164
+ this._super();
165
+ this._processing = 0;
166
+ // eslint-disable-next-line new-cap
167
+ this._processingQueue = $.Deferred().resolveWith(this).promise();
168
+ }
169
+ });
170
+ });