jquery-fileupload-rails 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +14 -6
- data/lib/jquery/fileupload/rails/version.rb +1 -1
- data/vendor/assets/javascripts/jquery-fileupload/basic.js +4 -0
- data/vendor/assets/javascripts/jquery-fileupload/cors/jquery.xdr-transport.js +2 -2
- data/vendor/assets/javascripts/jquery-fileupload/index.js +3 -0
- data/vendor/assets/javascripts/jquery-fileupload/jquery.fileupload-ip.js +4 -3
- data/vendor/assets/javascripts/jquery-fileupload/jquery.fileupload-ui.js +3 -3
- data/vendor/assets/javascripts/jquery-fileupload/jquery.fileupload.js +79 -25
- data/vendor/assets/javascripts/jquery-fileupload/jquery.iframe-transport.js +11 -5
- data/vendor/assets/javascripts/jquery-fileupload/vendor/canvas-to-blob.js +85 -0
- data/vendor/assets/javascripts/jquery-fileupload/vendor/load-image.js +114 -0
- data/vendor/assets/javascripts/jquery-fileupload/vendor/tmpl.js +86 -0
- metadata +28 -11
data/README.md
CHANGED
@@ -19,23 +19,31 @@ Require jquery-fileupload in your app/assets/application.js file.
|
|
19
19
|
The snippet above will add the following js files to the mainfest file.
|
20
20
|
|
21
21
|
//=require jquery-fileupload/vendor/jquery.ui.widget
|
22
|
+
//=require jquery-fileupload/vendor/load-image
|
23
|
+
//=require jquery-fileupload/vendor/canvas-to-blob
|
24
|
+
//=require jquery-fileupload/vendor/tmpl
|
22
25
|
//=require jquery-fileupload/jquery.iframe-transport
|
23
26
|
//=require jquery-fileupload/jquery.fileupload
|
24
27
|
//=require jquery-fileupload/jquery.fileupload-ip
|
25
28
|
//=require jquery-fileupload/jquery.fileupload-ui
|
26
29
|
//=require jquery-fileupload/locale
|
27
|
-
|
30
|
+
|
31
|
+
If you only need the basic files, just add the code below to your application.js file. [Basic setup guide](https://github.com/blueimp/jQuery-File-Upload/wiki/Basic-plugin)
|
32
|
+
|
33
|
+
//=require jquery-fileupload/basic
|
34
|
+
|
35
|
+
The basic setup only includes the following files:
|
36
|
+
|
37
|
+
//=require jquery-fileupload/vendor/jquery.ui.widget
|
38
|
+
//=require jquery-fileupload/jquery.iframe-transport
|
39
|
+
//=require jquery-fileupload/jquery.fileupload
|
40
|
+
|
28
41
|
## Using the stylesheet
|
29
42
|
|
30
43
|
Require the stylesheet file to app/assets/stylesheets/application.css
|
31
44
|
|
32
45
|
*= require jquery.fileupload-ui
|
33
46
|
|
34
|
-
## Changelog
|
35
|
-
<ul>
|
36
|
-
<li>Released gem v.0.1.0</li>
|
37
|
-
</ul>
|
38
|
-
|
39
47
|
## Thanks
|
40
48
|
Thanks to [Sebastian Tschan](https://github.com/blueimp) for writing an awesome file upload plugin.
|
41
49
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/*
|
2
|
-
* jQuery XDomainRequest Transport Plugin 1.1.
|
2
|
+
* jQuery XDomainRequest Transport Plugin 1.1.2
|
3
3
|
* https://github.com/blueimp/jQuery-File-Upload
|
4
4
|
*
|
5
5
|
* Copyright 2011, Sebastian Tschan
|
@@ -26,7 +26,7 @@
|
|
26
26
|
}
|
27
27
|
}(function ($) {
|
28
28
|
'use strict';
|
29
|
-
if (window.XDomainRequest &&
|
29
|
+
if (window.XDomainRequest && !$.support.cors) {
|
30
30
|
$.ajaxTransport(function (s) {
|
31
31
|
if (s.crossDomain && s.async) {
|
32
32
|
if (s.timeout) {
|
@@ -1,4 +1,7 @@
|
|
1
1
|
//=require jquery-fileupload/vendor/jquery.ui.widget
|
2
|
+
//=require jquery-fileupload/vendor/load-image
|
3
|
+
//=require jquery-fileupload/vendor/canvas-to-blob
|
4
|
+
//=require jquery-fileupload/vendor/tmpl
|
2
5
|
//=require jquery-fileupload/jquery.iframe-transport
|
3
6
|
//=require jquery-fileupload/jquery.fileupload
|
4
7
|
//=require jquery-fileupload/jquery.fileupload-ip
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/*
|
2
|
-
* jQuery File Upload Image Processing Plugin 1.0.
|
2
|
+
* jQuery File Upload Image Processing Plugin 1.0.6
|
3
3
|
* https://github.com/blueimp/jQuery-File-Upload
|
4
4
|
*
|
5
5
|
* Copyright 2012, Sebastian Tschan
|
@@ -112,9 +112,10 @@
|
|
112
112
|
resize: function (data) {
|
113
113
|
var that = this,
|
114
114
|
options = $.extend({}, this.options, data),
|
115
|
-
resizeAll = $.type(options.resizeSourceMaxFileSize) !== 'number'
|
115
|
+
resizeAll = $.type(options.resizeSourceMaxFileSize) !== 'number',
|
116
|
+
isXHRUpload = this._isXHRUpload(options);
|
116
117
|
$.each(data.files, function (index, file) {
|
117
|
-
if (that._resizeSupport &&
|
118
|
+
if (isXHRUpload && that._resizeSupport &&
|
118
119
|
(options.resizeMaxWidth || options.resizeMaxHeight ||
|
119
120
|
options.resizeMinWidth || options.resizeMinHeight) &&
|
120
121
|
(resizeAll || file.size < options.resizeSourceMaxFileSize) &&
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/*
|
2
|
-
* jQuery File Upload User Interface Plugin 6.6.
|
2
|
+
* jQuery File Upload User Interface Plugin 6.6.3
|
3
3
|
* https://github.com/blueimp/jQuery-File-Upload
|
4
4
|
*
|
5
5
|
* Copyright 2010, Sebastian Tschan
|
@@ -81,9 +81,9 @@
|
|
81
81
|
var that = $(this).data('fileupload'),
|
82
82
|
options = that.options,
|
83
83
|
files = data.files;
|
84
|
-
that._adjustMaxNumberOfFiles(-files.length);
|
85
|
-
data.isAdjusted = true;
|
86
84
|
$(this).fileupload('resize', data).done(data, function () {
|
85
|
+
that._adjustMaxNumberOfFiles(-files.length);
|
86
|
+
data.isAdjusted = true;
|
87
87
|
data.files.valid = data.isValidated = that._validate(files);
|
88
88
|
data.context = that._renderUpload(files)
|
89
89
|
.appendTo(options.filesContainer)
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/*
|
2
|
-
* jQuery File Upload Plugin 5.
|
2
|
+
* jQuery File Upload Plugin 5.10.0
|
3
3
|
* https://github.com/blueimp/jQuery-File-Upload
|
4
4
|
*
|
5
5
|
* Copyright 2010, Sebastian Tschan
|
@@ -10,7 +10,7 @@
|
|
10
10
|
*/
|
11
11
|
|
12
12
|
/*jslint nomen: true, unparam: true, regexp: true */
|
13
|
-
/*global define, window, document,
|
13
|
+
/*global define, window, document, Blob, FormData, location */
|
14
14
|
|
15
15
|
(function (factory) {
|
16
16
|
'use strict';
|
@@ -27,6 +27,12 @@
|
|
27
27
|
}(function ($) {
|
28
28
|
'use strict';
|
29
29
|
|
30
|
+
// The FileReader API is not actually used, but works as feature detection,
|
31
|
+
// as e.g. Safari supports XHR file uploads via the FormData API,
|
32
|
+
// but not non-multipart XHR file uploads:
|
33
|
+
$.support.xhrFileUpload = !!(window.XMLHttpRequestUpload && window.FileReader);
|
34
|
+
$.support.xhrFormDataFileUpload = !!window.FormData;
|
35
|
+
|
30
36
|
// The fileupload widget listens for change events on file input fields defined
|
31
37
|
// via fileInput setting and paste or drop events of the given dropZone.
|
32
38
|
// In addition to the default jQuery Widget methods, the fileupload widget
|
@@ -57,7 +63,8 @@
|
|
57
63
|
replaceFileInput: true,
|
58
64
|
// The parameter name for the file form data (the request argument name).
|
59
65
|
// If undefined or empty, the name property of the file input field is
|
60
|
-
// used, or "files[]" if the file input name property is also empty
|
66
|
+
// used, or "files[]" if the file input name property is also empty,
|
67
|
+
// can be a string or an array of strings:
|
61
68
|
paramName: undefined,
|
62
69
|
// By default, each file of a selection is uploaded using an individual
|
63
70
|
// request for XHR type uploads. Set to false to upload file
|
@@ -165,13 +172,18 @@
|
|
165
172
|
},
|
166
173
|
|
167
174
|
// A list of options that require a refresh after assigning a new value:
|
168
|
-
_refreshOptionsList: [
|
175
|
+
_refreshOptionsList: [
|
176
|
+
'namespace',
|
177
|
+
'dropZone',
|
178
|
+
'fileInput',
|
179
|
+
'multipart',
|
180
|
+
'forceIframeTransport'
|
181
|
+
],
|
169
182
|
|
170
183
|
_isXHRUpload: function (options) {
|
171
|
-
var undef = 'undefined';
|
172
184
|
return !options.forceIframeTransport &&
|
173
|
-
|
174
|
-
|
185
|
+
((!options.multipart && $.support.xhrFileUpload) ||
|
186
|
+
$.support.xhrFormDataFileUpload);
|
175
187
|
},
|
176
188
|
|
177
189
|
_getFormData: function (options) {
|
@@ -245,8 +257,11 @@
|
|
245
257
|
|
246
258
|
_initXHRData: function (options) {
|
247
259
|
var formData,
|
248
|
-
file = options.files[0]
|
249
|
-
|
260
|
+
file = options.files[0],
|
261
|
+
// Ignore non-multipart setting if not supported:
|
262
|
+
multipart = options.multipart || !$.support.xhrFileUpload,
|
263
|
+
paramName = options.paramName[0];
|
264
|
+
if (!multipart || options.blob) {
|
250
265
|
// For non-multipart uploads and chunked uploads,
|
251
266
|
// file meta data is not part of the request body,
|
252
267
|
// so we transmit this data as part of the HTTP headers.
|
@@ -262,13 +277,13 @@
|
|
262
277
|
// Non-chunked non-multipart upload:
|
263
278
|
options.contentType = file.type;
|
264
279
|
options.data = file;
|
265
|
-
} else if (!
|
280
|
+
} else if (!multipart) {
|
266
281
|
// Chunked non-multipart upload:
|
267
282
|
options.contentType = 'application/octet-stream';
|
268
283
|
options.data = options.blob;
|
269
284
|
}
|
270
285
|
}
|
271
|
-
if (
|
286
|
+
if (multipart && $.support.xhrFormDataFileUpload) {
|
272
287
|
if (options.postMessage) {
|
273
288
|
// window.postMessage does not allow sending FormData
|
274
289
|
// objects, so we just add the File/Blob objects to
|
@@ -277,13 +292,13 @@
|
|
277
292
|
formData = this._getFormData(options);
|
278
293
|
if (options.blob) {
|
279
294
|
formData.push({
|
280
|
-
name:
|
295
|
+
name: paramName,
|
281
296
|
value: options.blob
|
282
297
|
});
|
283
298
|
} else {
|
284
299
|
$.each(options.files, function (index, file) {
|
285
300
|
formData.push({
|
286
|
-
name: options.paramName,
|
301
|
+
name: options.paramName[index] || paramName,
|
287
302
|
value: file
|
288
303
|
});
|
289
304
|
});
|
@@ -298,14 +313,18 @@
|
|
298
313
|
});
|
299
314
|
}
|
300
315
|
if (options.blob) {
|
301
|
-
formData.append(
|
316
|
+
formData.append(paramName, options.blob, file.name);
|
302
317
|
} else {
|
303
318
|
$.each(options.files, function (index, file) {
|
304
319
|
// File objects are also Blob instances.
|
305
320
|
// This check allows the tests to run with
|
306
321
|
// dummy objects:
|
307
322
|
if (file instanceof Blob) {
|
308
|
-
formData.append(
|
323
|
+
formData.append(
|
324
|
+
options.paramName[index] || paramName,
|
325
|
+
file,
|
326
|
+
file.name
|
327
|
+
);
|
309
328
|
}
|
310
329
|
});
|
311
330
|
}
|
@@ -349,16 +368,36 @@
|
|
349
368
|
}
|
350
369
|
},
|
351
370
|
|
371
|
+
_getParamName: function (options) {
|
372
|
+
var fileInput = $(options.fileInput),
|
373
|
+
paramName = options.paramName;
|
374
|
+
if (!paramName) {
|
375
|
+
paramName = [];
|
376
|
+
fileInput.each(function () {
|
377
|
+
var input = $(this),
|
378
|
+
name = input.prop('name') || 'files[]',
|
379
|
+
i = (input.prop('files') || [1]).length;
|
380
|
+
while (i) {
|
381
|
+
paramName.push(name);
|
382
|
+
i -= 1;
|
383
|
+
}
|
384
|
+
});
|
385
|
+
if (!paramName.length) {
|
386
|
+
paramName = [fileInput.prop('name') || 'files[]'];
|
387
|
+
}
|
388
|
+
} else if (!$.isArray(paramName)) {
|
389
|
+
paramName = [paramName];
|
390
|
+
}
|
391
|
+
return paramName;
|
392
|
+
},
|
393
|
+
|
352
394
|
_initFormSettings: function (options) {
|
353
395
|
// Retrieve missing options from the input field and the
|
354
396
|
// associated form, if available:
|
355
397
|
if (!options.form || !options.form.length) {
|
356
398
|
options.form = $(options.fileInput.prop('form'));
|
357
399
|
}
|
358
|
-
|
359
|
-
options.paramName = options.fileInput.prop('name') ||
|
360
|
-
'files[]';
|
361
|
-
}
|
400
|
+
options.paramName = this._getParamName(options);
|
362
401
|
if (!options.url) {
|
363
402
|
options.url = options.form.prop('action') || location.href;
|
364
403
|
}
|
@@ -621,21 +660,34 @@
|
|
621
660
|
result = true,
|
622
661
|
options = $.extend({}, this.options, data),
|
623
662
|
limit = options.limitMultiFileUploads,
|
663
|
+
paramName = this._getParamName(options),
|
664
|
+
paramNameSet,
|
665
|
+
paramNameSlice,
|
624
666
|
fileSet,
|
625
667
|
i;
|
626
668
|
if (!(options.singleFileUploads || limit) ||
|
627
669
|
!this._isXHRUpload(options)) {
|
628
670
|
fileSet = [data.files];
|
671
|
+
paramNameSet = [paramName];
|
629
672
|
} else if (!options.singleFileUploads && limit) {
|
630
673
|
fileSet = [];
|
674
|
+
paramNameSet = [];
|
631
675
|
for (i = 0; i < data.files.length; i += limit) {
|
632
676
|
fileSet.push(data.files.slice(i, i + limit));
|
677
|
+
paramNameSlice = paramName.slice(i, i + limit);
|
678
|
+
if (!paramNameSlice.length) {
|
679
|
+
paramNameSlice = paramName;
|
680
|
+
}
|
681
|
+
paramNameSet.push(paramNameSlice);
|
633
682
|
}
|
683
|
+
} else {
|
684
|
+
paramNameSet = paramName;
|
634
685
|
}
|
635
686
|
data.originalFiles = data.files;
|
636
687
|
$.each(fileSet || data.files, function (index, element) {
|
637
|
-
var
|
638
|
-
|
688
|
+
var newData = $.extend({}, data);
|
689
|
+
newData.files = fileSet ? element : [element];
|
690
|
+
newData.paramName = paramNameSet[index];
|
639
691
|
newData.submit = function () {
|
640
692
|
newData.jqXHR = this.jqXHR =
|
641
693
|
(that._trigger('submit', e, this) !== false) &&
|
@@ -748,10 +800,12 @@
|
|
748
800
|
|
749
801
|
_initEventHandlers: function () {
|
750
802
|
var ns = this.options.namespace;
|
751
|
-
this.options
|
752
|
-
.
|
753
|
-
|
754
|
-
|
803
|
+
if (this._isXHRUpload(this.options)) {
|
804
|
+
this.options.dropZone
|
805
|
+
.bind('dragover.' + ns, {fileupload: this}, this._onDragOver)
|
806
|
+
.bind('drop.' + ns, {fileupload: this}, this._onDrop)
|
807
|
+
.bind('paste.' + ns, {fileupload: this}, this._onPaste);
|
808
|
+
}
|
755
809
|
this.options.fileInput
|
756
810
|
.bind('change.' + ns, {fileupload: this}, this._onChange);
|
757
811
|
},
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/*
|
2
|
-
* jQuery Iframe Transport Plugin 1.
|
2
|
+
* jQuery Iframe Transport Plugin 1.4
|
3
3
|
* https://github.com/blueimp/jQuery-File-Upload
|
4
4
|
*
|
5
5
|
* Copyright 2011, Sebastian Tschan
|
@@ -30,7 +30,8 @@
|
|
30
30
|
// The iframe transport accepts three additional options:
|
31
31
|
// options.fileInput: a jQuery collection of file input fields
|
32
32
|
// options.paramName: the parameter name for the file form data,
|
33
|
-
// overrides the name property of the file input field(s)
|
33
|
+
// overrides the name property of the file input field(s),
|
34
|
+
// can be a string or an array of strings.
|
34
35
|
// options.formData: an array of objects with name and value properties,
|
35
36
|
// equivalent to the return data of .serializeArray(), e.g.:
|
36
37
|
// [{name: 'a', value: 1}, {name: 'b', value: 2}]
|
@@ -50,7 +51,9 @@
|
|
50
51
|
'<iframe src="javascript:false;" name="iframe-transport-' +
|
51
52
|
(counter += 1) + '"></iframe>'
|
52
53
|
).bind('load', function () {
|
53
|
-
var fileInputClones
|
54
|
+
var fileInputClones,
|
55
|
+
paramNames = $.isArray(options.paramName) ?
|
56
|
+
options.paramName : [options.paramName];
|
54
57
|
iframe
|
55
58
|
.unbind('load')
|
56
59
|
.bind('load', function () {
|
@@ -101,8 +104,11 @@
|
|
101
104
|
return fileInputClones[index];
|
102
105
|
});
|
103
106
|
if (options.paramName) {
|
104
|
-
options.fileInput.each(function () {
|
105
|
-
$(this).prop(
|
107
|
+
options.fileInput.each(function (index) {
|
108
|
+
$(this).prop(
|
109
|
+
'name',
|
110
|
+
paramNames[index] || options.paramName
|
111
|
+
);
|
106
112
|
});
|
107
113
|
}
|
108
114
|
// Appending the file input fields to the hidden form
|
@@ -0,0 +1,85 @@
|
|
1
|
+
/*
|
2
|
+
* JavaScript Canvas to Blob 1.0.1
|
3
|
+
* https://github.com/blueimp/JavaScript-Canvas-to-Blob
|
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
|
+
* Based on stackoverflow user Stoive's code snippet:
|
12
|
+
* http://stackoverflow.com/q/4998908
|
13
|
+
*/
|
14
|
+
|
15
|
+
/*jslint nomen: true, regexp: true */
|
16
|
+
/*global window, atob, ArrayBuffer, Uint8Array, define */
|
17
|
+
|
18
|
+
(function ($) {
|
19
|
+
'use strict';
|
20
|
+
|
21
|
+
var BlobBuilder = window.MozBlobBuilder ||
|
22
|
+
window.WebKitBlobBuilder || window.BlobBuilder,
|
23
|
+
blobTypes = /^image\/(jpeg|png)$/,
|
24
|
+
|
25
|
+
// Converts a canvas element to a Blob or File object:
|
26
|
+
canvasToBlob = function (canvas, callback, options) {
|
27
|
+
options = options || {};
|
28
|
+
if (canvas.toBlob) {
|
29
|
+
canvas.toBlob(callback, options.type);
|
30
|
+
return true;
|
31
|
+
} else if (canvas.mozGetAsFile) {
|
32
|
+
var name = options.name;
|
33
|
+
callback(canvas.mozGetAsFile(
|
34
|
+
(blobTypes.test(options.type) && name) ||
|
35
|
+
((name && name.replace(/\..+$/, '')) || 'blob') + '.png',
|
36
|
+
options.type
|
37
|
+
));
|
38
|
+
return true;
|
39
|
+
} else if (canvas.toDataURL && BlobBuilder && window.atob &&
|
40
|
+
window.ArrayBuffer && window.Uint8Array) {
|
41
|
+
callback(canvasToBlob.dataURItoBlob(
|
42
|
+
canvas.toDataURL(options.type)
|
43
|
+
));
|
44
|
+
return true;
|
45
|
+
}
|
46
|
+
return false;
|
47
|
+
};
|
48
|
+
|
49
|
+
// Converts a dataURI to a Blob:
|
50
|
+
canvasToBlob.dataURItoBlob = function (dataURI) {
|
51
|
+
var byteString,
|
52
|
+
arrayBuffer,
|
53
|
+
intArray,
|
54
|
+
i,
|
55
|
+
bb,
|
56
|
+
mimeString;
|
57
|
+
if (dataURI.split(',')[0].indexOf('base64') >= 0) {
|
58
|
+
// Convert base64 to raw binary data held in a string:
|
59
|
+
byteString = atob(dataURI.split(',')[1]);
|
60
|
+
} else {
|
61
|
+
// Convert base64/URLEncoded data component to raw binary data:
|
62
|
+
byteString = decodeURIComponent(dataURI.split(',')[1]);
|
63
|
+
}
|
64
|
+
// Write the bytes of the string to an ArrayBuffer:
|
65
|
+
arrayBuffer = new ArrayBuffer(byteString.length);
|
66
|
+
intArray = new Uint8Array(arrayBuffer);
|
67
|
+
for (i = 0; i < byteString.length; i += 1) {
|
68
|
+
intArray[i] = byteString.charCodeAt(i);
|
69
|
+
}
|
70
|
+
// Write the ArrayBuffer to a blob:
|
71
|
+
bb = new BlobBuilder();
|
72
|
+
bb.append(arrayBuffer);
|
73
|
+
// Separate out the mime component:
|
74
|
+
mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0];
|
75
|
+
return bb.getBlob(mimeString);
|
76
|
+
};
|
77
|
+
|
78
|
+
if (typeof define !== 'undefined' && define.amd) {
|
79
|
+
define(function () {
|
80
|
+
return canvasToBlob;
|
81
|
+
});
|
82
|
+
} else {
|
83
|
+
$.canvasToBlob = canvasToBlob;
|
84
|
+
}
|
85
|
+
}(this));
|
@@ -0,0 +1,114 @@
|
|
1
|
+
/*
|
2
|
+
* JavaScript Load Image 1.1.4
|
3
|
+
* https://github.com/blueimp/JavaScript-Load-Image
|
4
|
+
*
|
5
|
+
* Copyright 2011, 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 */
|
13
|
+
/*global window, document, URL, webkitURL, Blob, File, FileReader, define */
|
14
|
+
|
15
|
+
(function ($) {
|
16
|
+
'use strict';
|
17
|
+
|
18
|
+
// Loads an image for a given File object.
|
19
|
+
// Invokes the callback with an img or optional canvas
|
20
|
+
// element (if supported by the browser) as parameter:
|
21
|
+
var loadImage = function (file, callback, options) {
|
22
|
+
var img = document.createElement('img'),
|
23
|
+
url,
|
24
|
+
oUrl;
|
25
|
+
img.onerror = callback;
|
26
|
+
img.onload = function () {
|
27
|
+
if (oUrl) {
|
28
|
+
loadImage.revokeObjectURL(oUrl);
|
29
|
+
}
|
30
|
+
callback(loadImage.scale(img, options));
|
31
|
+
};
|
32
|
+
if ((window.Blob && file instanceof Blob) ||
|
33
|
+
// Files are also Blob instances, but some browsers
|
34
|
+
// (Firefox 3.6) support the File API but not Blobs:
|
35
|
+
(window.File && file instanceof File)) {
|
36
|
+
url = oUrl = loadImage.createObjectURL(file);
|
37
|
+
} else {
|
38
|
+
url = file;
|
39
|
+
}
|
40
|
+
if (url) {
|
41
|
+
img.src = url;
|
42
|
+
return img;
|
43
|
+
} else {
|
44
|
+
return loadImage.readFile(file, function (url) {
|
45
|
+
img.src = url;
|
46
|
+
});
|
47
|
+
}
|
48
|
+
},
|
49
|
+
urlAPI = (window.createObjectURL && window) ||
|
50
|
+
(window.URL && URL) || (window.webkitURL && webkitURL);
|
51
|
+
|
52
|
+
// Scales the given image (img HTML element)
|
53
|
+
// using the given options.
|
54
|
+
// Returns a canvas object if the canvas option is true
|
55
|
+
// and the browser supports canvas, else the scaled image:
|
56
|
+
loadImage.scale = function (img, options) {
|
57
|
+
options = options || {};
|
58
|
+
var canvas = document.createElement('canvas'),
|
59
|
+
scale = Math.max(
|
60
|
+
(options.minWidth || img.width) / img.width,
|
61
|
+
(options.minHeight || img.height) / img.height
|
62
|
+
);
|
63
|
+
if (scale > 1) {
|
64
|
+
img.width = parseInt(img.width * scale, 10);
|
65
|
+
img.height = parseInt(img.height * scale, 10);
|
66
|
+
}
|
67
|
+
scale = Math.min(
|
68
|
+
(options.maxWidth || img.width) / img.width,
|
69
|
+
(options.maxHeight || img.height) / img.height
|
70
|
+
);
|
71
|
+
if (scale < 1) {
|
72
|
+
img.width = parseInt(img.width * scale, 10);
|
73
|
+
img.height = parseInt(img.height * scale, 10);
|
74
|
+
}
|
75
|
+
if (!options.canvas || !canvas.getContext) {
|
76
|
+
return img;
|
77
|
+
}
|
78
|
+
canvas.width = img.width;
|
79
|
+
canvas.height = img.height;
|
80
|
+
canvas.getContext('2d')
|
81
|
+
.drawImage(img, 0, 0, img.width, img.height);
|
82
|
+
return canvas;
|
83
|
+
};
|
84
|
+
|
85
|
+
loadImage.createObjectURL = function (file) {
|
86
|
+
return urlAPI ? urlAPI.createObjectURL(file) : false;
|
87
|
+
};
|
88
|
+
|
89
|
+
loadImage.revokeObjectURL = function (url) {
|
90
|
+
return urlAPI ? urlAPI.revokeObjectURL(url) : false;
|
91
|
+
};
|
92
|
+
|
93
|
+
// Loads a given File object via FileReader interface,
|
94
|
+
// invokes the callback with a data url:
|
95
|
+
loadImage.readFile = function (file, callback) {
|
96
|
+
if (window.FileReader && FileReader.prototype.readAsDataURL) {
|
97
|
+
var fileReader = new FileReader();
|
98
|
+
fileReader.onload = function (e) {
|
99
|
+
callback(e.target.result);
|
100
|
+
};
|
101
|
+
fileReader.readAsDataURL(file);
|
102
|
+
return fileReader;
|
103
|
+
}
|
104
|
+
return false;
|
105
|
+
};
|
106
|
+
|
107
|
+
if (typeof define !== 'undefined' && define.amd) {
|
108
|
+
define(function () {
|
109
|
+
return loadImage;
|
110
|
+
});
|
111
|
+
} else {
|
112
|
+
$.loadImage = loadImage;
|
113
|
+
}
|
114
|
+
}(this));
|
@@ -0,0 +1,86 @@
|
|
1
|
+
/*
|
2
|
+
* JavaScript Templates 2.1.0
|
3
|
+
* https://github.com/blueimp/JavaScript-Templates
|
4
|
+
*
|
5
|
+
* Copyright 2011, Sebastian Tschan
|
6
|
+
* https://blueimp.net
|
7
|
+
*
|
8
|
+
* Licensed under the MIT license:
|
9
|
+
* http://www.opensource.org/licenses/MIT
|
10
|
+
*
|
11
|
+
* Inspired by John Resig's JavaScript Micro-Templating:
|
12
|
+
* http://ejohn.org/blog/javascript-micro-templating/
|
13
|
+
*/
|
14
|
+
|
15
|
+
/*jslint evil: true, regexp: true */
|
16
|
+
/*global document, define */
|
17
|
+
|
18
|
+
(function ($) {
|
19
|
+
"use strict";
|
20
|
+
var tmpl = function (str, data) {
|
21
|
+
var f = !/[^\w\-\.:]/.test(str) ? tmpl.cache[str] = tmpl.cache[str] ||
|
22
|
+
tmpl(tmpl.load(str)) :
|
23
|
+
new Function(
|
24
|
+
tmpl.arg + ',tmpl',
|
25
|
+
"var _e=tmpl.encode" + tmpl.helper + ",_s='" +
|
26
|
+
str.replace(tmpl.regexp, tmpl.func) +
|
27
|
+
"';return _s;"
|
28
|
+
);
|
29
|
+
return data ? f(data, tmpl) : function (data) {
|
30
|
+
return f(data, tmpl);
|
31
|
+
};
|
32
|
+
};
|
33
|
+
tmpl.cache = {};
|
34
|
+
tmpl.load = function (id) {
|
35
|
+
return document.getElementById(id).innerHTML;
|
36
|
+
};
|
37
|
+
tmpl.regexp = /([\s'\\])(?![^%]*%\})|(?:\{%(=|#)([\s\S]+?)%\})|(\{%)|(%\})/g;
|
38
|
+
tmpl.func = function (s, p1, p2, p3, p4, p5) {
|
39
|
+
if (p1) { // whitespace, quote and backspace in interpolation context
|
40
|
+
return {
|
41
|
+
"\n": "\\n",
|
42
|
+
"\r": "\\r",
|
43
|
+
"\t": "\\t",
|
44
|
+
" " : " "
|
45
|
+
}[s] || "\\" + s;
|
46
|
+
}
|
47
|
+
if (p2) { // interpolation: {%=prop%}, or unescaped: {%#prop%}
|
48
|
+
if (p2 === "=") {
|
49
|
+
return "'+_e(" + p3 + ")+'";
|
50
|
+
}
|
51
|
+
return "'+(" + p3 + "||'')+'";
|
52
|
+
}
|
53
|
+
if (p4) { // evaluation start tag: {%
|
54
|
+
return "';";
|
55
|
+
}
|
56
|
+
if (p5) { // evaluation end tag: %}
|
57
|
+
return "_s+='";
|
58
|
+
}
|
59
|
+
};
|
60
|
+
tmpl.encReg = /[<>&"'\x00]/g;
|
61
|
+
tmpl.encMap = {
|
62
|
+
"<" : "<",
|
63
|
+
">" : ">",
|
64
|
+
"&" : "&",
|
65
|
+
"\"" : """,
|
66
|
+
"'" : "'"
|
67
|
+
};
|
68
|
+
tmpl.encode = function (s) {
|
69
|
+
return String(s || "").replace(
|
70
|
+
tmpl.encReg,
|
71
|
+
function (c) {
|
72
|
+
return tmpl.encMap[c] || "";
|
73
|
+
}
|
74
|
+
);
|
75
|
+
};
|
76
|
+
tmpl.arg = "o";
|
77
|
+
tmpl.helper = ",print=function(s,e){_s+=e&&(s||'')||_e(s);}" +
|
78
|
+
",include=function(s,d){_s+=tmpl(s,d);}";
|
79
|
+
if (typeof define === "function" && define.amd) {
|
80
|
+
define(function () {
|
81
|
+
return tmpl;
|
82
|
+
});
|
83
|
+
} else {
|
84
|
+
$.tmpl = tmpl;
|
85
|
+
}
|
86
|
+
}(this));
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jquery-fileupload-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,12 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
13
|
-
default_executable:
|
12
|
+
date: 2012-04-27 00:00:00.000000000 Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
15
|
name: railties
|
17
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
18
17
|
none: false
|
19
18
|
requirements:
|
20
19
|
- - ! '>='
|
@@ -22,10 +21,15 @@ dependencies:
|
|
22
21
|
version: '3.1'
|
23
22
|
type: :runtime
|
24
23
|
prerelease: false
|
25
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.1'
|
26
30
|
- !ruby/object:Gem::Dependency
|
27
31
|
name: actionpack
|
28
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
29
33
|
none: false
|
30
34
|
requirements:
|
31
35
|
- - ! '>='
|
@@ -33,10 +37,15 @@ dependencies:
|
|
33
37
|
version: '3.1'
|
34
38
|
type: :runtime
|
35
39
|
prerelease: false
|
36
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '3.1'
|
37
46
|
- !ruby/object:Gem::Dependency
|
38
47
|
name: rails
|
39
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
40
49
|
none: false
|
41
50
|
requirements:
|
42
51
|
- - ! '>='
|
@@ -44,7 +53,12 @@ dependencies:
|
|
44
53
|
version: '3.1'
|
45
54
|
type: :development
|
46
55
|
prerelease: false
|
47
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.1'
|
48
62
|
description: jQuery File Upload by Sebastian Tschan integrated for Rails 3.1 Asset
|
49
63
|
Pipeline
|
50
64
|
email:
|
@@ -59,6 +73,7 @@ files:
|
|
59
73
|
- lib/jquery-fileupload-rails.rb
|
60
74
|
- vendor/assets/images/loading.gif
|
61
75
|
- vendor/assets/images/progressbar.gif
|
76
|
+
- vendor/assets/javascripts/jquery-fileupload/basic.js
|
62
77
|
- vendor/assets/javascripts/jquery-fileupload/cors/jquery.postmessage-transport.js
|
63
78
|
- vendor/assets/javascripts/jquery-fileupload/cors/jquery.xdr-transport.js
|
64
79
|
- vendor/assets/javascripts/jquery-fileupload/index.js
|
@@ -67,11 +82,13 @@ files:
|
|
67
82
|
- vendor/assets/javascripts/jquery-fileupload/jquery.fileupload.js
|
68
83
|
- vendor/assets/javascripts/jquery-fileupload/jquery.iframe-transport.js
|
69
84
|
- vendor/assets/javascripts/jquery-fileupload/locale.js
|
85
|
+
- vendor/assets/javascripts/jquery-fileupload/vendor/canvas-to-blob.js
|
70
86
|
- vendor/assets/javascripts/jquery-fileupload/vendor/jquery.ui.widget.js
|
87
|
+
- vendor/assets/javascripts/jquery-fileupload/vendor/load-image.js
|
88
|
+
- vendor/assets/javascripts/jquery-fileupload/vendor/tmpl.js
|
71
89
|
- vendor/assets/stylesheets/jquery.fileupload-ui.css
|
72
90
|
- Rakefile
|
73
91
|
- README.md
|
74
|
-
has_rdoc: true
|
75
92
|
homepage: https://github.com/tors/jquery-fileupload-rails
|
76
93
|
licenses: []
|
77
94
|
post_install_message:
|
@@ -92,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
109
|
version: '0'
|
93
110
|
requirements: []
|
94
111
|
rubyforge_project: jquery-fileupload-rails
|
95
|
-
rubygems_version: 1.
|
112
|
+
rubygems_version: 1.8.21
|
96
113
|
signing_key:
|
97
114
|
specification_version: 3
|
98
115
|
summary: jQuery File Upload for Rails 3.1 Asset Pipeline
|