blueimp-file-upload-rails 8.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,113 @@
1
+ /*
2
+ * jQuery File Upload Audio Preview Plugin 1.0.2
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, 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 {
25
+ // Browser globals:
26
+ factory(
27
+ window.jQuery,
28
+ window.loadImage
29
+ );
30
+ }
31
+ }(function ($, loadImage) {
32
+ 'use strict';
33
+
34
+ // Prepend to the default processQueue:
35
+ $.blueimp.fileupload.prototype.options.processQueue.unshift(
36
+ {
37
+ action: 'loadAudio',
38
+ // Always trigger this action,
39
+ // even if the previous action was rejected:
40
+ always: true,
41
+ // Use the action as prefix for the "@" options:
42
+ prefix: true,
43
+ fileTypes: '@',
44
+ maxFileSize: '@',
45
+ disabled: '@disableAudioPreview'
46
+ },
47
+ {
48
+ action: 'setAudio',
49
+ name: '@audioPreviewName',
50
+ disabled: '@disableAudioPreview'
51
+ }
52
+ );
53
+
54
+ // The File Upload Audio Preview plugin extends the fileupload widget
55
+ // with audio preview functionality:
56
+ $.widget('blueimp.fileupload', $.blueimp.fileupload, {
57
+
58
+ options: {
59
+ // The regular expression for the types of audio files to load,
60
+ // matched against the file type:
61
+ loadAudioFileTypes: /^audio\/.*$/
62
+ },
63
+
64
+ _audioElement: document.createElement('audio'),
65
+
66
+ processActions: {
67
+
68
+ // Loads the audio file given via data.files and data.index
69
+ // as audio element if the browser supports playing it.
70
+ // Accepts the options fileTypes (regular expression)
71
+ // and maxFileSize (integer) to limit the files to load:
72
+ loadAudio: function (data, options) {
73
+ if (options.disabled) {
74
+ return data;
75
+ }
76
+ var that = this,
77
+ file = data.files[data.index],
78
+ dfd = $.Deferred(),
79
+ url,
80
+ audio;
81
+ if (this._audioElement.canPlayType &&
82
+ this._audioElement.canPlayType(file.type) &&
83
+ ($.type(options.maxFileSize) !== 'number' ||
84
+ file.size <= options.maxFileSize) &&
85
+ (!options.fileTypes ||
86
+ options.fileTypes.test(file.type))) {
87
+ url = loadImage.createObjectURL(file);
88
+ if (url) {
89
+ audio = this._audioElement.cloneNode(false);
90
+ audio.src = url;
91
+ audio.controls = true;
92
+ data.audio = audio;
93
+ dfd.resolveWith(that, [data]);
94
+ return dfd.promise();
95
+ }
96
+ }
97
+ dfd.rejectWith(that, [data]);
98
+ return dfd.promise();
99
+ },
100
+
101
+ // Sets the audio element as a property of the file object:
102
+ setAudio: function (data, options) {
103
+ if (data.audio && !options.disabled) {
104
+ data.files[data.index][options.name || 'preview'] = data.audio;
105
+ }
106
+ return data;
107
+ }
108
+
109
+ }
110
+
111
+ });
112
+
113
+ }));
@@ -0,0 +1,299 @@
1
+ /*
2
+ * jQuery File Upload Image Preview & Resize Plugin 1.2.2
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, document, DataView, Blob, Uint8Array */
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
+ 'load-image-ios',
25
+ 'canvas-to-blob',
26
+ './jquery.fileupload-process'
27
+ ], factory);
28
+ } else {
29
+ // Browser globals:
30
+ factory(
31
+ window.jQuery,
32
+ window.loadImage
33
+ );
34
+ }
35
+ }(function ($, loadImage) {
36
+ 'use strict';
37
+
38
+ // Prepend to the default processQueue:
39
+ $.blueimp.fileupload.prototype.options.processQueue.unshift(
40
+ {
41
+ action: 'loadImageMetaData',
42
+ // Always trigger this action,
43
+ // even if the previous action was rejected:
44
+ always: true,
45
+ disableImageHead: '@',
46
+ disableExif: '@',
47
+ disableExifThumbnail: '@',
48
+ disableExifSub: '@',
49
+ disableExifGps: '@',
50
+ disabled: '@disableImageMetaDataLoad'
51
+ },
52
+ {
53
+ action: 'loadImage',
54
+ // Use the action as prefix for the "@" options:
55
+ prefix: true,
56
+ fileTypes: '@',
57
+ maxFileSize: '@',
58
+ noRevoke: '@',
59
+ disabled: '@disableImageLoad'
60
+ },
61
+ {
62
+ action: 'resizeImage',
63
+ // Use "image" as prefix for the "@" options:
64
+ prefix: 'image',
65
+ maxWidth: '@',
66
+ maxHeight: '@',
67
+ minWidth: '@',
68
+ minHeight: '@',
69
+ crop: '@',
70
+ disabled: '@disableImageResize'
71
+ },
72
+ {
73
+ action: 'saveImage',
74
+ disabled: '@disableImageResize'
75
+ },
76
+ {
77
+ action: 'saveImageMetaData',
78
+ disabled: '@disableImageMetaDataSave'
79
+ },
80
+ {
81
+ action: 'resizeImage',
82
+ // Always trigger this action,
83
+ // even if the previous action was rejected:
84
+ always: true,
85
+ // Use "preview" as prefix for the "@" options:
86
+ prefix: 'preview',
87
+ maxWidth: '@',
88
+ maxHeight: '@',
89
+ minWidth: '@',
90
+ minHeight: '@',
91
+ crop: '@',
92
+ orientation: '@',
93
+ thumbnail: '@',
94
+ canvas: '@',
95
+ disabled: '@disableImagePreview'
96
+ },
97
+ {
98
+ action: 'setImage',
99
+ name: '@imagePreviewName',
100
+ disabled: '@disableImagePreview'
101
+ }
102
+ );
103
+
104
+ // The File Upload Resize plugin extends the fileupload widget
105
+ // with image resize functionality:
106
+ $.widget('blueimp.fileupload', $.blueimp.fileupload, {
107
+
108
+ options: {
109
+ // The regular expression for the types of images to load:
110
+ // matched against the file type:
111
+ loadImageFileTypes: /^image\/(gif|jpeg|png)$/,
112
+ // The maximum file size of images to load:
113
+ loadImageMaxFileSize: 10000000, // 10MB
114
+ // The maximum width of resized images:
115
+ imageMaxWidth: 1920,
116
+ // The maximum height of resized images:
117
+ imageMaxHeight: 1080,
118
+ // Define if resized images should be cropped or only scaled:
119
+ imageCrop: false,
120
+ // Disable the resize image functionality by default:
121
+ disableImageResize: true,
122
+ // The maximum width of the preview images:
123
+ previewMaxWidth: 80,
124
+ // The maximum height of the preview images:
125
+ previewMaxHeight: 80,
126
+ // Defines the preview orientation (1-8) or takes the orientation
127
+ // value from Exif data if set to true:
128
+ previewOrientation: true,
129
+ // Create the preview using the Exif data thumbnail:
130
+ previewThumbnail: true,
131
+ // Define if preview images should be cropped or only scaled:
132
+ previewCrop: false,
133
+ // Define if preview images should be resized as canvas elements:
134
+ previewCanvas: true
135
+ },
136
+
137
+ processActions: {
138
+
139
+ // Loads the image given via data.files and data.index
140
+ // as img element if the browser supports canvas.
141
+ // Accepts the options fileTypes (regular expression)
142
+ // and maxFileSize (integer) to limit the files to load:
143
+ loadImage: function (data, options) {
144
+ if (options.disabled) {
145
+ return data;
146
+ }
147
+ var that = this,
148
+ file = data.files[data.index],
149
+ dfd = $.Deferred();
150
+ if (($.type(options.maxFileSize) === 'number' &&
151
+ file.size > options.maxFileSize) ||
152
+ (options.fileTypes &&
153
+ !options.fileTypes.test(file.type)) ||
154
+ !loadImage(
155
+ file,
156
+ function (img) {
157
+ if (!img.src) {
158
+ return dfd.rejectWith(that, [data]);
159
+ }
160
+ data.img = img;
161
+ dfd.resolveWith(that, [data]);
162
+ },
163
+ options
164
+ )) {
165
+ dfd.rejectWith(that, [data]);
166
+ }
167
+ return dfd.promise();
168
+ },
169
+
170
+ // Resizes the image given as data.canvas or data.img
171
+ // and updates data.canvas or data.img with the resized image.
172
+ // Accepts the options maxWidth, maxHeight, minWidth,
173
+ // minHeight, canvas and crop:
174
+ resizeImage: function (data, options) {
175
+ if (options.disabled) {
176
+ return data;
177
+ }
178
+ var that = this,
179
+ dfd = $.Deferred(),
180
+ resolve = function (newImg) {
181
+ data[newImg.getContext ? 'canvas' : 'img'] = newImg;
182
+ dfd.resolveWith(that, [data]);
183
+ },
184
+ thumbnail,
185
+ img,
186
+ newImg;
187
+ options = $.extend({canvas: true}, options);
188
+ if (data.exif) {
189
+ if (options.orientation === true) {
190
+ options.orientation = data.exif.get('Orientation');
191
+ }
192
+ if (options.thumbnail) {
193
+ thumbnail = data.exif.get('Thumbnail');
194
+ if (thumbnail) {
195
+ loadImage(thumbnail, resolve, options);
196
+ return dfd.promise();
197
+ }
198
+ }
199
+ }
200
+ img = (options.canvas && data.canvas) || data.img;
201
+ if (img) {
202
+ newImg = loadImage.scale(img, options);
203
+ if (newImg.width !== img.width ||
204
+ newImg.height !== img.height) {
205
+ resolve(newImg);
206
+ return dfd.promise();
207
+ }
208
+ }
209
+ return data;
210
+ },
211
+
212
+ // Saves the processed image given as data.canvas
213
+ // inplace at data.index of data.files:
214
+ saveImage: function (data, options) {
215
+ if (!data.canvas || options.disabled) {
216
+ return data;
217
+ }
218
+ var that = this,
219
+ file = data.files[data.index],
220
+ name = file.name,
221
+ dfd = $.Deferred(),
222
+ callback = function (blob) {
223
+ if (!blob.name) {
224
+ if (file.type === blob.type) {
225
+ blob.name = file.name;
226
+ } else if (file.name) {
227
+ blob.name = file.name.replace(
228
+ /\..+$/,
229
+ '.' + blob.type.substr(6)
230
+ );
231
+ }
232
+ }
233
+ // Store the created blob at the position
234
+ // of the original file in the files list:
235
+ data.files[data.index] = blob;
236
+ dfd.resolveWith(that, [data]);
237
+ };
238
+ // Use canvas.mozGetAsFile directly, to retain the filename, as
239
+ // Gecko doesn't support the filename option for FormData.append:
240
+ if (data.canvas.mozGetAsFile) {
241
+ callback(data.canvas.mozGetAsFile(
242
+ (/^image\/(jpeg|png)$/.test(file.type) && name) ||
243
+ ((name && name.replace(/\..+$/, '')) ||
244
+ 'blob') + '.png',
245
+ file.type
246
+ ));
247
+ } else if (data.canvas.toBlob) {
248
+ data.canvas.toBlob(callback, file.type);
249
+ } else {
250
+ return data;
251
+ }
252
+ return dfd.promise();
253
+ },
254
+
255
+ loadImageMetaData: function (data, options) {
256
+ if (options.disabled) {
257
+ return data;
258
+ }
259
+ var that = this,
260
+ dfd = $.Deferred();
261
+ loadImage.parseMetaData(data.files[data.index], function (result) {
262
+ $.extend(data, result);
263
+ dfd.resolveWith(that, [data]);
264
+ }, options);
265
+ return dfd.promise();
266
+ },
267
+
268
+ saveImageMetaData: function (data, options) {
269
+ if (!(data.imageHead && data.canvas &&
270
+ data.canvas.toBlob && !options.disabled)) {
271
+ return data;
272
+ }
273
+ var file = data.files[data.index],
274
+ blob = new Blob([
275
+ data.imageHead,
276
+ // Resized images always have a head size of 20 bytes,
277
+ // including the JPEG marker and a minimal JFIF header:
278
+ this._blobSlice.call(file, 20)
279
+ ], {type: file.type});
280
+ blob.name = file.name;
281
+ data.files[data.index] = blob;
282
+ return data;
283
+ },
284
+
285
+ // Sets the resized version of the image as a property of the
286
+ // file object, must be called after "saveImage":
287
+ setImage: function (data, options) {
288
+ var img = data.canvas || data.img;
289
+ if (img && !options.disabled) {
290
+ data.files[data.index][options.name || 'preview'] = img;
291
+ }
292
+ return data;
293
+ }
294
+
295
+ }
296
+
297
+ });
298
+
299
+ }));
@@ -0,0 +1,164 @@
1
+ /*
2
+ * jQuery File Upload Processing Plugin 1.2.2
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
+ * http://www.opensource.org/licenses/MIT
10
+ */
11
+
12
+ /*jslint nomen: true, unparam: 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'
22
+ ], factory);
23
+ } else {
24
+ // Browser globals:
25
+ factory(
26
+ window.jQuery
27
+ );
28
+ }
29
+ }(function ($) {
30
+ 'use strict';
31
+
32
+ var originalAdd = $.blueimp.fileupload.prototype.options.add;
33
+
34
+ // The File Upload Processing plugin extends the fileupload widget
35
+ // with file processing functionality:
36
+ $.widget('blueimp.fileupload', $.blueimp.fileupload, {
37
+
38
+ options: {
39
+ // The list of processing actions:
40
+ processQueue: [
41
+ /*
42
+ {
43
+ action: 'log',
44
+ type: 'debug'
45
+ }
46
+ */
47
+ ],
48
+ add: function (e, data) {
49
+ var $this = $(this);
50
+ data.process(function () {
51
+ return $this.fileupload('process', data);
52
+ });
53
+ originalAdd.call(this, e, data);
54
+ }
55
+ },
56
+
57
+ processActions: {
58
+ /*
59
+ log: function (data, options) {
60
+ console[options.type](
61
+ 'Processing "' + data.files[data.index].name + '"'
62
+ );
63
+ }
64
+ */
65
+ },
66
+
67
+ _processFile: function (data) {
68
+ var that = this,
69
+ dfd = $.Deferred().resolveWith(that, [data]),
70
+ chain = dfd.promise();
71
+ this._trigger('process', null, data);
72
+ $.each(data.processQueue, function (i, settings) {
73
+ var func = function (data) {
74
+ return that.processActions[settings.action].call(
75
+ that,
76
+ data,
77
+ settings
78
+ );
79
+ };
80
+ chain = chain.pipe(func, settings.always && func);
81
+ });
82
+ chain
83
+ .done(function () {
84
+ that._trigger('processdone', null, data);
85
+ that._trigger('processalways', null, data);
86
+ })
87
+ .fail(function () {
88
+ that._trigger('processfail', null, data);
89
+ that._trigger('processalways', null, data);
90
+ });
91
+ return chain;
92
+ },
93
+
94
+ // Replaces the settings of each processQueue item that
95
+ // are strings starting with an "@", using the remaining
96
+ // substring as key for the option map,
97
+ // e.g. "@autoUpload" is replaced with options.autoUpload:
98
+ _transformProcessQueue: function (options) {
99
+ var processQueue = [];
100
+ $.each(options.processQueue, function () {
101
+ var settings = {},
102
+ action = this.action,
103
+ prefix = this.prefix === true ? action : this.prefix;
104
+ $.each(this, function (key, value) {
105
+ if ($.type(value) === 'string' &&
106
+ value.charAt(0) === '@') {
107
+ settings[key] = options[
108
+ value.slice(1) || (prefix ? prefix +
109
+ key.charAt(0).toUpperCase() + key.slice(1) : key)
110
+ ];
111
+ } else {
112
+ settings[key] = value;
113
+ }
114
+
115
+ });
116
+ processQueue.push(settings);
117
+ });
118
+ options.processQueue = processQueue;
119
+ },
120
+
121
+ // Returns the number of files currently in the processsing queue:
122
+ processing: function () {
123
+ return this._processing;
124
+ },
125
+
126
+ // Processes the files given as files property of the data parameter,
127
+ // returns a Promise object that allows to bind callbacks:
128
+ process: function (data) {
129
+ var that = this,
130
+ options = $.extend({}, this.options, data);
131
+ if (options.processQueue && options.processQueue.length) {
132
+ this._transformProcessQueue(options);
133
+ if (this._processing === 0) {
134
+ this._trigger('processstart');
135
+ }
136
+ $.each(data.files, function (index) {
137
+ var opts = index ? $.extend({}, options) : options,
138
+ func = function () {
139
+ return that._processFile(opts);
140
+ };
141
+ opts.index = index;
142
+ that._processing += 1;
143
+ that._processingQueue = that._processingQueue.pipe(func, func)
144
+ .always(function () {
145
+ that._processing -= 1;
146
+ if (that._processing === 0) {
147
+ that._trigger('processstop');
148
+ }
149
+ });
150
+ });
151
+ }
152
+ return this._processingQueue;
153
+ },
154
+
155
+ _create: function () {
156
+ this._super();
157
+ this._processing = 0;
158
+ this._processingQueue = $.Deferred().resolveWith(this)
159
+ .promise();
160
+ }
161
+
162
+ });
163
+
164
+ }));