sn-jquery-fileupload-rails 0.4.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +95 -0
  3. data/Rakefile +15 -0
  4. data/app/assets/images/loading.gif +0 -0
  5. data/app/assets/images/progressbar.gif +0 -0
  6. data/app/assets/javascripts/jquery-fileupload/angularjs.js +12 -0
  7. data/app/assets/javascripts/jquery-fileupload/basic-plus.js +11 -0
  8. data/app/assets/javascripts/jquery-fileupload/basic.js +3 -0
  9. data/app/assets/javascripts/jquery-fileupload/cors/jquery.postmessage-transport.js +126 -0
  10. data/app/assets/javascripts/jquery-fileupload/cors/jquery.xdr-transport.js +89 -0
  11. data/app/assets/javascripts/jquery-fileupload/index.js +13 -0
  12. data/app/assets/javascripts/jquery-fileupload/jquery-ui.js +13 -0
  13. data/app/assets/javascripts/jquery-fileupload/jquery.fileupload-angular.js +425 -0
  14. data/app/assets/javascripts/jquery-fileupload/jquery.fileupload-audio.js +112 -0
  15. data/app/assets/javascripts/jquery-fileupload/jquery.fileupload-image.js +320 -0
  16. data/app/assets/javascripts/jquery-fileupload/jquery.fileupload-jquery-ui.js +155 -0
  17. data/app/assets/javascripts/jquery-fileupload/jquery.fileupload-process.js +175 -0
  18. data/app/assets/javascripts/jquery-fileupload/jquery.fileupload-ui.js +710 -0
  19. data/app/assets/javascripts/jquery-fileupload/jquery.fileupload-validate.js +122 -0
  20. data/app/assets/javascripts/jquery-fileupload/jquery.fileupload-video.js +112 -0
  21. data/app/assets/javascripts/jquery-fileupload/jquery.fileupload.js +1477 -0
  22. data/app/assets/javascripts/jquery-fileupload/jquery.iframe-transport.js +217 -0
  23. data/app/assets/javascripts/jquery-fileupload/locale.js +29 -0
  24. data/app/assets/javascripts/jquery-fileupload/vendor/canvas-to-blob.js +95 -0
  25. data/app/assets/javascripts/jquery-fileupload/vendor/jquery.ui.widget.js +572 -0
  26. data/app/assets/javascripts/jquery-fileupload/vendor/load-image.all.min.js +1 -0
  27. data/app/assets/javascripts/jquery-fileupload/vendor/tmpl.js +87 -0
  28. data/app/assets/stylesheets/jquery.fileupload-noscript.scss +22 -0
  29. data/app/assets/stylesheets/jquery.fileupload-ui-noscript.scss +17 -0
  30. data/app/assets/stylesheets/jquery.fileupload-ui.scss +57 -0
  31. data/app/assets/stylesheets/jquery.fileupload.scss +37 -0
  32. data/lib/jquery-fileupload-rails.rb +8 -0
  33. data/lib/jquery/fileupload/rails/engine.rb +8 -0
  34. data/lib/jquery/fileupload/rails/middleware.rb +59 -0
  35. data/lib/jquery/fileupload/rails/upload.rb +3 -0
  36. data/lib/jquery/fileupload/rails/version.rb +7 -0
  37. metadata +135 -0
@@ -0,0 +1,112 @@
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
+ * http://www.opensource.org/licenses/MIT
10
+ */
11
+
12
+ /* jshint nomen:false */
13
+ /* global define, require, window, document */
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
+ 'load-image',
22
+ './jquery.fileupload-process'
23
+ ], factory);
24
+ } else if (typeof exports === 'object') {
25
+ // Node/CommonJS:
26
+ factory(
27
+ require('jquery'),
28
+ require('load-image')
29
+ );
30
+ } else {
31
+ // Browser globals:
32
+ factory(
33
+ window.jQuery,
34
+ window.loadImage
35
+ );
36
+ }
37
+ }(function ($, loadImage) {
38
+ 'use strict';
39
+
40
+ // Prepend to the default processQueue:
41
+ $.blueimp.fileupload.prototype.options.processQueue.unshift(
42
+ {
43
+ action: 'loadAudio',
44
+ // Use the action as prefix for the "@" options:
45
+ prefix: true,
46
+ fileTypes: '@',
47
+ maxFileSize: '@',
48
+ disabled: '@disableAudioPreview'
49
+ },
50
+ {
51
+ action: 'setAudio',
52
+ name: '@audioPreviewName',
53
+ disabled: '@disableAudioPreview'
54
+ }
55
+ );
56
+
57
+ // The File Upload Audio Preview plugin extends the fileupload widget
58
+ // with audio preview functionality:
59
+ $.widget('blueimp.fileupload', $.blueimp.fileupload, {
60
+
61
+ options: {
62
+ // The regular expression for the types of audio files to load,
63
+ // matched against the file type:
64
+ loadAudioFileTypes: /^audio\/.*$/
65
+ },
66
+
67
+ _audioElement: document.createElement('audio'),
68
+
69
+ processActions: {
70
+
71
+ // Loads the audio file given via data.files and data.index
72
+ // as audio element if the browser supports playing it.
73
+ // Accepts the options fileTypes (regular expression)
74
+ // and maxFileSize (integer) to limit the files to load:
75
+ loadAudio: function (data, options) {
76
+ if (options.disabled) {
77
+ return data;
78
+ }
79
+ var file = data.files[data.index],
80
+ url,
81
+ audio;
82
+ if (this._audioElement.canPlayType &&
83
+ this._audioElement.canPlayType(file.type) &&
84
+ ($.type(options.maxFileSize) !== 'number' ||
85
+ file.size <= options.maxFileSize) &&
86
+ (!options.fileTypes ||
87
+ options.fileTypes.test(file.type))) {
88
+ url = loadImage.createObjectURL(file);
89
+ if (url) {
90
+ audio = this._audioElement.cloneNode(false);
91
+ audio.src = url;
92
+ audio.controls = true;
93
+ data.audio = audio;
94
+ return data;
95
+ }
96
+ }
97
+ return data;
98
+ },
99
+
100
+ // Sets the audio element as a property of the file object:
101
+ setAudio: function (data, options) {
102
+ if (data.audio && !options.disabled) {
103
+ data.files[data.index][options.name || 'preview'] = data.audio;
104
+ }
105
+ return data;
106
+ }
107
+
108
+ }
109
+
110
+ });
111
+
112
+ }));
@@ -0,0 +1,320 @@
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
+ * http://www.opensource.org/licenses/MIT
10
+ */
11
+
12
+ /* jshint nomen:false */
13
+ /* global define, require, window, Blob */
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
+ 'load-image',
22
+ 'load-image-meta',
23
+ 'load-image-exif',
24
+ 'canvas-to-blob',
25
+ './jquery.fileupload-process'
26
+ ], factory);
27
+ } else if (typeof exports === 'object') {
28
+ // Node/CommonJS:
29
+ factory(
30
+ require('jquery'),
31
+ require('load-image')
32
+ );
33
+ } else {
34
+ // Browser globals:
35
+ factory(
36
+ window.jQuery,
37
+ window.loadImage
38
+ );
39
+ }
40
+ }(function ($, loadImage) {
41
+ 'use strict';
42
+
43
+ // Prepend to the default processQueue:
44
+ $.blueimp.fileupload.prototype.options.processQueue.unshift(
45
+ {
46
+ action: 'loadImageMetaData',
47
+ disableImageHead: '@',
48
+ disableExif: '@',
49
+ disableExifThumbnail: '@',
50
+ disableExifSub: '@',
51
+ disableExifGps: '@',
52
+ disabled: '@disableImageMetaDataLoad'
53
+ },
54
+ {
55
+ action: 'loadImage',
56
+ // Use the action as prefix for the "@" options:
57
+ prefix: true,
58
+ fileTypes: '@',
59
+ maxFileSize: '@',
60
+ noRevoke: '@',
61
+ disabled: '@disableImageLoad'
62
+ },
63
+ {
64
+ action: 'resizeImage',
65
+ // Use "image" as prefix for the "@" options:
66
+ prefix: 'image',
67
+ maxWidth: '@',
68
+ maxHeight: '@',
69
+ minWidth: '@',
70
+ minHeight: '@',
71
+ crop: '@',
72
+ orientation: '@',
73
+ forceResize: '@',
74
+ disabled: '@disableImageResize'
75
+ },
76
+ {
77
+ action: 'saveImage',
78
+ quality: '@imageQuality',
79
+ type: '@imageType',
80
+ disabled: '@disableImageResize'
81
+ },
82
+ {
83
+ action: 'saveImageMetaData',
84
+ disabled: '@disableImageMetaDataSave'
85
+ },
86
+ {
87
+ action: 'resizeImage',
88
+ // Use "preview" as prefix for the "@" options:
89
+ prefix: 'preview',
90
+ maxWidth: '@',
91
+ maxHeight: '@',
92
+ minWidth: '@',
93
+ minHeight: '@',
94
+ crop: '@',
95
+ orientation: '@',
96
+ thumbnail: '@',
97
+ canvas: '@',
98
+ disabled: '@disableImagePreview'
99
+ },
100
+ {
101
+ action: 'setImage',
102
+ name: '@imagePreviewName',
103
+ disabled: '@disableImagePreview'
104
+ },
105
+ {
106
+ action: 'deleteImageReferences',
107
+ disabled: '@disableImageReferencesDeletion'
108
+ }
109
+ );
110
+
111
+ // The File Upload Resize plugin extends the fileupload widget
112
+ // with image resize functionality:
113
+ $.widget('blueimp.fileupload', $.blueimp.fileupload, {
114
+
115
+ options: {
116
+ // The regular expression for the types of images to load:
117
+ // matched against the file type:
118
+ loadImageFileTypes: /^image\/(gif|jpeg|png|svg\+xml)$/,
119
+ // The maximum file size of images to load:
120
+ loadImageMaxFileSize: 10000000, // 10MB
121
+ // The maximum width of resized images:
122
+ imageMaxWidth: 1920,
123
+ // The maximum height of resized images:
124
+ imageMaxHeight: 1080,
125
+ // Defines the image orientation (1-8) or takes the orientation
126
+ // value from Exif data if set to true:
127
+ imageOrientation: false,
128
+ // Define if resized images should be cropped or only scaled:
129
+ imageCrop: false,
130
+ // Disable the resize image functionality by default:
131
+ disableImageResize: true,
132
+ // The maximum width of the preview images:
133
+ previewMaxWidth: 80,
134
+ // The maximum height of the preview images:
135
+ previewMaxHeight: 80,
136
+ // Defines the preview orientation (1-8) or takes the orientation
137
+ // value from Exif data if set to true:
138
+ previewOrientation: true,
139
+ // Create the preview using the Exif data thumbnail:
140
+ previewThumbnail: true,
141
+ // Define if preview images should be cropped or only scaled:
142
+ previewCrop: false,
143
+ // Define if preview images should be resized as canvas elements:
144
+ previewCanvas: true
145
+ },
146
+
147
+ processActions: {
148
+
149
+ // Loads the image given via data.files and data.index
150
+ // as img element, if the browser supports the File API.
151
+ // Accepts the options fileTypes (regular expression)
152
+ // and maxFileSize (integer) to limit the files to load:
153
+ loadImage: function (data, options) {
154
+ if (options.disabled) {
155
+ return data;
156
+ }
157
+ var that = this,
158
+ file = data.files[data.index],
159
+ dfd = $.Deferred();
160
+ if (($.type(options.maxFileSize) === 'number' &&
161
+ file.size > options.maxFileSize) ||
162
+ (options.fileTypes &&
163
+ !options.fileTypes.test(file.type)) ||
164
+ !loadImage(
165
+ file,
166
+ function (img) {
167
+ if (img.src) {
168
+ data.img = img;
169
+ }
170
+ dfd.resolveWith(that, [data]);
171
+ },
172
+ options
173
+ )) {
174
+ return data;
175
+ }
176
+ return dfd.promise();
177
+ },
178
+
179
+ // Resizes the image given as data.canvas or data.img
180
+ // and updates data.canvas or data.img with the resized image.
181
+ // Also stores the resized image as preview property.
182
+ // Accepts the options maxWidth, maxHeight, minWidth,
183
+ // minHeight, canvas and crop:
184
+ resizeImage: function (data, options) {
185
+ if (options.disabled || !(data.canvas || data.img)) {
186
+ return data;
187
+ }
188
+ options = $.extend({canvas: true}, options);
189
+ var that = this,
190
+ dfd = $.Deferred(),
191
+ img = (options.canvas && data.canvas) || data.img,
192
+ resolve = function (newImg) {
193
+ if (newImg && (newImg.width !== img.width ||
194
+ newImg.height !== img.height ||
195
+ options.forceResize)) {
196
+ data[newImg.getContext ? 'canvas' : 'img'] = newImg;
197
+ }
198
+ data.preview = newImg;
199
+ dfd.resolveWith(that, [data]);
200
+ },
201
+ thumbnail;
202
+ if (data.exif) {
203
+ if (options.orientation === true) {
204
+ options.orientation = data.exif.get('Orientation');
205
+ }
206
+ if (options.thumbnail) {
207
+ thumbnail = data.exif.get('Thumbnail');
208
+ if (thumbnail) {
209
+ loadImage(thumbnail, resolve, options);
210
+ return dfd.promise();
211
+ }
212
+ }
213
+ // Prevent orienting the same image twice:
214
+ if (data.orientation) {
215
+ delete options.orientation;
216
+ } else {
217
+ data.orientation = options.orientation;
218
+ }
219
+ }
220
+ if (img) {
221
+ resolve(loadImage.scale(img, options));
222
+ return dfd.promise();
223
+ }
224
+ return data;
225
+ },
226
+
227
+ // Saves the processed image given as data.canvas
228
+ // inplace at data.index of data.files:
229
+ saveImage: function (data, options) {
230
+ if (!data.canvas || options.disabled) {
231
+ return data;
232
+ }
233
+ var that = this,
234
+ file = data.files[data.index],
235
+ dfd = $.Deferred();
236
+ if (data.canvas.toBlob) {
237
+ data.canvas.toBlob(
238
+ function (blob) {
239
+ if (!blob.name) {
240
+ if (file.type === blob.type) {
241
+ blob.name = file.name;
242
+ } else if (file.name) {
243
+ blob.name = file.name.replace(
244
+ /\.\w+$/,
245
+ '.' + blob.type.substr(6)
246
+ );
247
+ }
248
+ }
249
+ // Don't restore invalid meta data:
250
+ if (file.type !== blob.type) {
251
+ delete data.imageHead;
252
+ }
253
+ // Store the created blob at the position
254
+ // of the original file in the files list:
255
+ data.files[data.index] = blob;
256
+ dfd.resolveWith(that, [data]);
257
+ },
258
+ options.type || file.type,
259
+ options.quality
260
+ );
261
+ } else {
262
+ return data;
263
+ }
264
+ return dfd.promise();
265
+ },
266
+
267
+ loadImageMetaData: function (data, options) {
268
+ if (options.disabled) {
269
+ return data;
270
+ }
271
+ var that = this,
272
+ dfd = $.Deferred();
273
+ loadImage.parseMetaData(data.files[data.index], function (result) {
274
+ $.extend(data, result);
275
+ dfd.resolveWith(that, [data]);
276
+ }, options);
277
+ return dfd.promise();
278
+ },
279
+
280
+ saveImageMetaData: function (data, options) {
281
+ if (!(data.imageHead && data.canvas &&
282
+ data.canvas.toBlob && !options.disabled)) {
283
+ return data;
284
+ }
285
+ var file = data.files[data.index],
286
+ blob = new Blob([
287
+ data.imageHead,
288
+ // Resized images always have a head size of 20 bytes,
289
+ // including the JPEG marker and a minimal JFIF header:
290
+ this._blobSlice.call(file, 20)
291
+ ], {type: file.type});
292
+ blob.name = file.name;
293
+ data.files[data.index] = blob;
294
+ return data;
295
+ },
296
+
297
+ // Sets the resized version of the image as a property of the
298
+ // file object, must be called after "saveImage":
299
+ setImage: function (data, options) {
300
+ if (data.preview && !options.disabled) {
301
+ data.files[data.index][options.name || 'preview'] = data.preview;
302
+ }
303
+ return data;
304
+ },
305
+
306
+ deleteImageReferences: function (data, options) {
307
+ if (!options.disabled) {
308
+ delete data.img;
309
+ delete data.canvas;
310
+ delete data.preview;
311
+ delete data.imageHead;
312
+ }
313
+ return data;
314
+ }
315
+
316
+ }
317
+
318
+ });
319
+
320
+ }));
@@ -0,0 +1,155 @@
1
+ /*
2
+ * jQuery File Upload jQuery UI 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
+ * http://www.opensource.org/licenses/MIT
10
+ */
11
+
12
+ /* jshint nomen:false */
13
+ /* global define, require, window */
14
+
15
+ ;(function (factory) {
16
+ 'use strict';
17
+ if (typeof define === 'function' && define.amd) {
18
+ // Register as an anonymous AMD module:
19
+ define(['jquery', './jquery.fileupload-ui'], factory);
20
+ } else if (typeof exports === 'object') {
21
+ // Node/CommonJS:
22
+ factory(require('jquery'));
23
+ } else {
24
+ // Browser globals:
25
+ factory(window.jQuery);
26
+ }
27
+ }(function ($) {
28
+ 'use strict';
29
+
30
+ $.widget('blueimp.fileupload', $.blueimp.fileupload, {
31
+
32
+ options: {
33
+ processdone: function (e, data) {
34
+ data.context.find('.start').button('enable');
35
+ },
36
+ progress: function (e, data) {
37
+ if (data.context) {
38
+ data.context.find('.progress').progressbar(
39
+ 'option',
40
+ 'value',
41
+ parseInt(data.loaded / data.total * 100, 10)
42
+ );
43
+ }
44
+ },
45
+ progressall: function (e, data) {
46
+ var $this = $(this);
47
+ $this.find('.fileupload-progress')
48
+ .find('.progress').progressbar(
49
+ 'option',
50
+ 'value',
51
+ parseInt(data.loaded / data.total * 100, 10)
52
+ ).end()
53
+ .find('.progress-extended').each(function () {
54
+ $(this).html(
55
+ ($this.data('blueimp-fileupload') ||
56
+ $this.data('fileupload'))
57
+ ._renderExtendedProgress(data)
58
+ );
59
+ });
60
+ }
61
+ },
62
+
63
+ _renderUpload: function (func, files) {
64
+ var node = this._super(func, files),
65
+ showIconText = $(window).width() > 480;
66
+ node.find('.progress').empty().progressbar();
67
+ node.find('.start').button({
68
+ icons: {primary: 'ui-icon-circle-arrow-e'},
69
+ text: showIconText
70
+ });
71
+ node.find('.cancel').button({
72
+ icons: {primary: 'ui-icon-cancel'},
73
+ text: showIconText
74
+ });
75
+ if (node.hasClass('fade')) {
76
+ node.hide();
77
+ }
78
+ return node;
79
+ },
80
+
81
+ _renderDownload: function (func, files) {
82
+ var node = this._super(func, files),
83
+ showIconText = $(window).width() > 480;
84
+ node.find('.delete').button({
85
+ icons: {primary: 'ui-icon-trash'},
86
+ text: showIconText
87
+ });
88
+ if (node.hasClass('fade')) {
89
+ node.hide();
90
+ }
91
+ return node;
92
+ },
93
+
94
+ _startHandler: function (e) {
95
+ $(e.currentTarget).button('disable');
96
+ this._super(e);
97
+ },
98
+
99
+ _transition: function (node) {
100
+ var deferred = $.Deferred();
101
+ if (node.hasClass('fade')) {
102
+ node.fadeToggle(
103
+ this.options.transitionDuration,
104
+ this.options.transitionEasing,
105
+ function () {
106
+ deferred.resolveWith(node);
107
+ }
108
+ );
109
+ } else {
110
+ deferred.resolveWith(node);
111
+ }
112
+ return deferred;
113
+ },
114
+
115
+ _create: function () {
116
+ this._super();
117
+ this.element
118
+ .find('.fileupload-buttonbar')
119
+ .find('.fileinput-button').each(function () {
120
+ var input = $(this).find('input:file').detach();
121
+ $(this)
122
+ .button({icons: {primary: 'ui-icon-plusthick'}})
123
+ .append(input);
124
+ })
125
+ .end().find('.start')
126
+ .button({icons: {primary: 'ui-icon-circle-arrow-e'}})
127
+ .end().find('.cancel')
128
+ .button({icons: {primary: 'ui-icon-cancel'}})
129
+ .end().find('.delete')
130
+ .button({icons: {primary: 'ui-icon-trash'}})
131
+ .end().find('.progress').progressbar();
132
+ },
133
+
134
+ _destroy: function () {
135
+ this.element
136
+ .find('.fileupload-buttonbar')
137
+ .find('.fileinput-button').each(function () {
138
+ var input = $(this).find('input:file').detach();
139
+ $(this)
140
+ .button('destroy')
141
+ .append(input);
142
+ })
143
+ .end().find('.start')
144
+ .button('destroy')
145
+ .end().find('.cancel')
146
+ .button('destroy')
147
+ .end().find('.delete')
148
+ .button('destroy')
149
+ .end().find('.progress').progressbar('destroy');
150
+ this._super();
151
+ }
152
+
153
+ });
154
+
155
+ }));