rails-jquery-fileupload 1.0.2
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.
- checksums.yaml +7 -0
- data/README.md +67 -0
- data/Rakefile +15 -0
- data/lib/jquery/fileupload/rails/engine.rb +8 -0
- data/lib/jquery/fileupload/rails/middleware.rb +59 -0
- data/lib/jquery/fileupload/rails/upload.rb +3 -0
- data/lib/jquery/fileupload/rails/version.rb +7 -0
- data/lib/rails-jquery-fileupload.rb +8 -0
- data/vendor/assets/images/loading.gif +0 -0
- data/vendor/assets/javascripts/jquery-fileupload/all.js +13 -0
- data/vendor/assets/javascripts/jquery-fileupload/basic.js +4 -0
- data/vendor/assets/javascripts/jquery-fileupload/cors/jquery.postmessage-transport.js +117 -0
- data/vendor/assets/javascripts/jquery-fileupload/cors/jquery.xdr-transport.js +87 -0
- data/vendor/assets/javascripts/jquery-fileupload/jquery.fileupload-audio.js +106 -0
- data/vendor/assets/javascripts/jquery-fileupload/jquery.fileupload-image.js +309 -0
- data/vendor/assets/javascripts/jquery-fileupload/jquery.fileupload-process.js +172 -0
- data/vendor/assets/javascripts/jquery-fileupload/jquery.fileupload-ui.js +699 -0
- data/vendor/assets/javascripts/jquery-fileupload/jquery.fileupload-validate.js +119 -0
- data/vendor/assets/javascripts/jquery-fileupload/jquery.fileupload-video.js +106 -0
- data/vendor/assets/javascripts/jquery-fileupload/jquery.fileupload.js +1420 -0
- data/vendor/assets/javascripts/jquery-fileupload/jquery.iframe-transport.js +214 -0
- data/vendor/assets/javascripts/jquery-fileupload/locale.js +29 -0
- data/vendor/assets/javascripts/jquery-fileupload/vendor/canvas-to-blob.js +95 -0
- data/vendor/assets/javascripts/jquery-fileupload/vendor/jquery.ui.widget.js +530 -0
- data/vendor/assets/javascripts/jquery-fileupload/vendor/load-image.js +1446 -0
- data/vendor/assets/javascripts/jquery-fileupload/vendor/tmpl.js +87 -0
- metadata +111 -0
@@ -0,0 +1,309 @@
|
|
1
|
+
/*
|
2
|
+
* jQuery File Upload Image Preview & Resize Plugin 1.7.0
|
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, 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
|
+
'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
|
+
disableImageHead: '@',
|
43
|
+
disableExif: '@',
|
44
|
+
disableExifThumbnail: '@',
|
45
|
+
disableExifSub: '@',
|
46
|
+
disableExifGps: '@',
|
47
|
+
disabled: '@disableImageMetaDataLoad'
|
48
|
+
},
|
49
|
+
{
|
50
|
+
action: 'loadImage',
|
51
|
+
// Use the action as prefix for the "@" options:
|
52
|
+
prefix: true,
|
53
|
+
fileTypes: '@',
|
54
|
+
maxFileSize: '@',
|
55
|
+
noRevoke: '@',
|
56
|
+
disabled: '@disableImageLoad'
|
57
|
+
},
|
58
|
+
{
|
59
|
+
action: 'resizeImage',
|
60
|
+
// Use "image" as prefix for the "@" options:
|
61
|
+
prefix: 'image',
|
62
|
+
maxWidth: '@',
|
63
|
+
maxHeight: '@',
|
64
|
+
minWidth: '@',
|
65
|
+
minHeight: '@',
|
66
|
+
crop: '@',
|
67
|
+
orientation: '@',
|
68
|
+
forceResize: '@',
|
69
|
+
disabled: '@disableImageResize'
|
70
|
+
},
|
71
|
+
{
|
72
|
+
action: 'saveImage',
|
73
|
+
quality: '@imageQuality',
|
74
|
+
type: '@imageType',
|
75
|
+
disabled: '@disableImageResize'
|
76
|
+
},
|
77
|
+
{
|
78
|
+
action: 'saveImageMetaData',
|
79
|
+
disabled: '@disableImageMetaDataSave'
|
80
|
+
},
|
81
|
+
{
|
82
|
+
action: 'resizeImage',
|
83
|
+
// Use "preview" as prefix for the "@" options:
|
84
|
+
prefix: 'preview',
|
85
|
+
maxWidth: '@',
|
86
|
+
maxHeight: '@',
|
87
|
+
minWidth: '@',
|
88
|
+
minHeight: '@',
|
89
|
+
crop: '@',
|
90
|
+
orientation: '@',
|
91
|
+
thumbnail: '@',
|
92
|
+
canvas: '@',
|
93
|
+
disabled: '@disableImagePreview'
|
94
|
+
},
|
95
|
+
{
|
96
|
+
action: 'setImage',
|
97
|
+
name: '@imagePreviewName',
|
98
|
+
disabled: '@disableImagePreview'
|
99
|
+
},
|
100
|
+
{
|
101
|
+
action: 'deleteImageReferences',
|
102
|
+
disabled: '@disableImageReferencesDeletion'
|
103
|
+
}
|
104
|
+
);
|
105
|
+
|
106
|
+
// The File Upload Resize plugin extends the fileupload widget
|
107
|
+
// with image resize functionality:
|
108
|
+
$.widget('blueimp.fileupload', $.blueimp.fileupload, {
|
109
|
+
|
110
|
+
options: {
|
111
|
+
// The regular expression for the types of images to load:
|
112
|
+
// matched against the file type:
|
113
|
+
loadImageFileTypes: /^image\/(gif|jpeg|png)$/,
|
114
|
+
// The maximum file size of images to load:
|
115
|
+
loadImageMaxFileSize: 10000000, // 10MB
|
116
|
+
// The maximum width of resized images:
|
117
|
+
imageMaxWidth: 1920,
|
118
|
+
// The maximum height of resized images:
|
119
|
+
imageMaxHeight: 1080,
|
120
|
+
// Defines the image orientation (1-8) or takes the orientation
|
121
|
+
// value from Exif data if set to true:
|
122
|
+
imageOrientation: false,
|
123
|
+
// Define if resized images should be cropped or only scaled:
|
124
|
+
imageCrop: false,
|
125
|
+
// Disable the resize image functionality by default:
|
126
|
+
disableImageResize: true,
|
127
|
+
// The maximum width of the preview images:
|
128
|
+
previewMaxWidth: 80,
|
129
|
+
// The maximum height of the preview images:
|
130
|
+
previewMaxHeight: 80,
|
131
|
+
// Defines the preview orientation (1-8) or takes the orientation
|
132
|
+
// value from Exif data if set to true:
|
133
|
+
previewOrientation: true,
|
134
|
+
// Create the preview using the Exif data thumbnail:
|
135
|
+
previewThumbnail: true,
|
136
|
+
// Define if preview images should be cropped or only scaled:
|
137
|
+
previewCrop: false,
|
138
|
+
// Define if preview images should be resized as canvas elements:
|
139
|
+
previewCanvas: true
|
140
|
+
},
|
141
|
+
|
142
|
+
processActions: {
|
143
|
+
|
144
|
+
// Loads the image given via data.files and data.index
|
145
|
+
// as img element, if the browser supports the File API.
|
146
|
+
// Accepts the options fileTypes (regular expression)
|
147
|
+
// and maxFileSize (integer) to limit the files to load:
|
148
|
+
loadImage: function (data, options) {
|
149
|
+
if (options.disabled) {
|
150
|
+
return data;
|
151
|
+
}
|
152
|
+
var that = this,
|
153
|
+
file = data.files[data.index],
|
154
|
+
dfd = $.Deferred();
|
155
|
+
if (($.type(options.maxFileSize) === 'number' &&
|
156
|
+
file.size > options.maxFileSize) ||
|
157
|
+
(options.fileTypes &&
|
158
|
+
!options.fileTypes.test(file.type)) ||
|
159
|
+
!loadImage(
|
160
|
+
file,
|
161
|
+
function (img) {
|
162
|
+
if (img.src) {
|
163
|
+
data.img = img;
|
164
|
+
}
|
165
|
+
dfd.resolveWith(that, [data]);
|
166
|
+
},
|
167
|
+
options
|
168
|
+
)) {
|
169
|
+
return data;
|
170
|
+
}
|
171
|
+
return dfd.promise();
|
172
|
+
},
|
173
|
+
|
174
|
+
// Resizes the image given as data.canvas or data.img
|
175
|
+
// and updates data.canvas or data.img with the resized image.
|
176
|
+
// Also stores the resized image as preview property.
|
177
|
+
// Accepts the options maxWidth, maxHeight, minWidth,
|
178
|
+
// minHeight, canvas and crop:
|
179
|
+
resizeImage: function (data, options) {
|
180
|
+
if (options.disabled || !(data.canvas || data.img)) {
|
181
|
+
return data;
|
182
|
+
}
|
183
|
+
options = $.extend({canvas: true}, options);
|
184
|
+
var that = this,
|
185
|
+
dfd = $.Deferred(),
|
186
|
+
img = (options.canvas && data.canvas) || data.img,
|
187
|
+
resolve = function (newImg) {
|
188
|
+
if (newImg && (newImg.width !== img.width ||
|
189
|
+
newImg.height !== img.height ||
|
190
|
+
options.forceResize)) {
|
191
|
+
data[newImg.getContext ? 'canvas' : 'img'] = newImg;
|
192
|
+
}
|
193
|
+
data.preview = newImg;
|
194
|
+
dfd.resolveWith(that, [data]);
|
195
|
+
},
|
196
|
+
thumbnail;
|
197
|
+
if (data.exif) {
|
198
|
+
if (options.orientation === true) {
|
199
|
+
options.orientation = data.exif.get('Orientation');
|
200
|
+
}
|
201
|
+
if (options.thumbnail) {
|
202
|
+
thumbnail = data.exif.get('Thumbnail');
|
203
|
+
if (thumbnail) {
|
204
|
+
loadImage(thumbnail, resolve, options);
|
205
|
+
return dfd.promise();
|
206
|
+
}
|
207
|
+
}
|
208
|
+
}
|
209
|
+
if (img) {
|
210
|
+
resolve(loadImage.scale(img, options));
|
211
|
+
return dfd.promise();
|
212
|
+
}
|
213
|
+
return data;
|
214
|
+
},
|
215
|
+
|
216
|
+
// Saves the processed image given as data.canvas
|
217
|
+
// inplace at data.index of data.files:
|
218
|
+
saveImage: function (data, options) {
|
219
|
+
if (!data.canvas || options.disabled) {
|
220
|
+
return data;
|
221
|
+
}
|
222
|
+
var that = this,
|
223
|
+
file = data.files[data.index],
|
224
|
+
dfd = $.Deferred();
|
225
|
+
if (data.canvas.toBlob) {
|
226
|
+
data.canvas.toBlob(
|
227
|
+
function (blob) {
|
228
|
+
if (!blob.name) {
|
229
|
+
if (file.type === blob.type) {
|
230
|
+
blob.name = file.name;
|
231
|
+
} else if (file.name) {
|
232
|
+
blob.name = file.name.replace(
|
233
|
+
/\..+$/,
|
234
|
+
'.' + blob.type.substr(6)
|
235
|
+
);
|
236
|
+
}
|
237
|
+
}
|
238
|
+
// Don't restore invalid meta data:
|
239
|
+
if (file.type !== blob.type) {
|
240
|
+
delete data.imageHead;
|
241
|
+
}
|
242
|
+
// Store the created blob at the position
|
243
|
+
// of the original file in the files list:
|
244
|
+
data.files[data.index] = blob;
|
245
|
+
dfd.resolveWith(that, [data]);
|
246
|
+
},
|
247
|
+
options.type || file.type,
|
248
|
+
options.quality
|
249
|
+
);
|
250
|
+
} else {
|
251
|
+
return data;
|
252
|
+
}
|
253
|
+
return dfd.promise();
|
254
|
+
},
|
255
|
+
|
256
|
+
loadImageMetaData: function (data, options) {
|
257
|
+
if (options.disabled) {
|
258
|
+
return data;
|
259
|
+
}
|
260
|
+
var that = this,
|
261
|
+
dfd = $.Deferred();
|
262
|
+
loadImage.parseMetaData(data.files[data.index], function (result) {
|
263
|
+
$.extend(data, result);
|
264
|
+
dfd.resolveWith(that, [data]);
|
265
|
+
}, options);
|
266
|
+
return dfd.promise();
|
267
|
+
},
|
268
|
+
|
269
|
+
saveImageMetaData: function (data, options) {
|
270
|
+
if (!(data.imageHead && data.canvas &&
|
271
|
+
data.canvas.toBlob && !options.disabled)) {
|
272
|
+
return data;
|
273
|
+
}
|
274
|
+
var file = data.files[data.index],
|
275
|
+
blob = new Blob([
|
276
|
+
data.imageHead,
|
277
|
+
// Resized images always have a head size of 20 bytes,
|
278
|
+
// including the JPEG marker and a minimal JFIF header:
|
279
|
+
this._blobSlice.call(file, 20)
|
280
|
+
], {type: file.type});
|
281
|
+
blob.name = file.name;
|
282
|
+
data.files[data.index] = blob;
|
283
|
+
return data;
|
284
|
+
},
|
285
|
+
|
286
|
+
// Sets the resized version of the image as a property of the
|
287
|
+
// file object, must be called after "saveImage":
|
288
|
+
setImage: function (data, options) {
|
289
|
+
if (data.preview && !options.disabled) {
|
290
|
+
data.files[data.index][options.name || 'preview'] = data.preview;
|
291
|
+
}
|
292
|
+
return data;
|
293
|
+
},
|
294
|
+
|
295
|
+
deleteImageReferences: function (data, options) {
|
296
|
+
if (!options.disabled) {
|
297
|
+
delete data.img;
|
298
|
+
delete data.canvas;
|
299
|
+
delete data.preview;
|
300
|
+
delete data.imageHead;
|
301
|
+
}
|
302
|
+
return data;
|
303
|
+
}
|
304
|
+
|
305
|
+
}
|
306
|
+
|
307
|
+
});
|
308
|
+
|
309
|
+
}));
|
@@ -0,0 +1,172 @@
|
|
1
|
+
/*
|
2
|
+
* jQuery File Upload Processing Plugin 1.3.0
|
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
|
+
/* jshint nomen:false */
|
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, originalData) {
|
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
|
+
if (originalData.errorThrown) {
|
75
|
+
return $.Deferred()
|
76
|
+
.rejectWith(that, [originalData]).promise();
|
77
|
+
}
|
78
|
+
return that.processActions[settings.action].call(
|
79
|
+
that,
|
80
|
+
data,
|
81
|
+
settings
|
82
|
+
);
|
83
|
+
};
|
84
|
+
chain = chain.pipe(func, settings.always && func);
|
85
|
+
});
|
86
|
+
chain
|
87
|
+
.done(function () {
|
88
|
+
that._trigger('processdone', null, data);
|
89
|
+
that._trigger('processalways', null, data);
|
90
|
+
})
|
91
|
+
.fail(function () {
|
92
|
+
that._trigger('processfail', null, data);
|
93
|
+
that._trigger('processalways', null, data);
|
94
|
+
});
|
95
|
+
return chain;
|
96
|
+
},
|
97
|
+
|
98
|
+
// Replaces the settings of each processQueue item that
|
99
|
+
// are strings starting with an "@", using the remaining
|
100
|
+
// substring as key for the option map,
|
101
|
+
// e.g. "@autoUpload" is replaced with options.autoUpload:
|
102
|
+
_transformProcessQueue: function (options) {
|
103
|
+
var processQueue = [];
|
104
|
+
$.each(options.processQueue, function () {
|
105
|
+
var settings = {},
|
106
|
+
action = this.action,
|
107
|
+
prefix = this.prefix === true ? action : this.prefix;
|
108
|
+
$.each(this, function (key, value) {
|
109
|
+
if ($.type(value) === 'string' &&
|
110
|
+
value.charAt(0) === '@') {
|
111
|
+
settings[key] = options[
|
112
|
+
value.slice(1) || (prefix ? prefix +
|
113
|
+
key.charAt(0).toUpperCase() + key.slice(1) : key)
|
114
|
+
];
|
115
|
+
} else {
|
116
|
+
settings[key] = value;
|
117
|
+
}
|
118
|
+
|
119
|
+
});
|
120
|
+
processQueue.push(settings);
|
121
|
+
});
|
122
|
+
options.processQueue = processQueue;
|
123
|
+
},
|
124
|
+
|
125
|
+
// Returns the number of files currently in the processsing queue:
|
126
|
+
processing: function () {
|
127
|
+
return this._processing;
|
128
|
+
},
|
129
|
+
|
130
|
+
// Processes the files given as files property of the data parameter,
|
131
|
+
// returns a Promise object that allows to bind callbacks:
|
132
|
+
process: function (data) {
|
133
|
+
var that = this,
|
134
|
+
options = $.extend({}, this.options, data);
|
135
|
+
if (options.processQueue && options.processQueue.length) {
|
136
|
+
this._transformProcessQueue(options);
|
137
|
+
if (this._processing === 0) {
|
138
|
+
this._trigger('processstart');
|
139
|
+
}
|
140
|
+
$.each(data.files, function (index) {
|
141
|
+
var opts = index ? $.extend({}, options) : options,
|
142
|
+
func = function () {
|
143
|
+
if (data.errorThrown) {
|
144
|
+
return $.Deferred()
|
145
|
+
.rejectWith(that, [data]).promise();
|
146
|
+
}
|
147
|
+
return that._processFile(opts, data);
|
148
|
+
};
|
149
|
+
opts.index = index;
|
150
|
+
that._processing += 1;
|
151
|
+
that._processingQueue = that._processingQueue.pipe(func, 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
|
+
this._processingQueue = $.Deferred().resolveWith(this)
|
167
|
+
.promise();
|
168
|
+
}
|
169
|
+
|
170
|
+
});
|
171
|
+
|
172
|
+
}));
|