jquery-fileupload-rails 0.3.1 → 0.3.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.
- data/README.md +9 -1
- data/lib/jquery/fileupload/rails/version.rb +1 -1
- data/vendor/assets/javascripts/jquery-fileupload/jquery.fileupload-ui.js +18 -5
- data/vendor/assets/javascripts/jquery-fileupload/jquery.fileupload.js +141 -41
- data/vendor/assets/javascripts/jquery-fileupload/jquery.iframe-transport.js +2 -1
- data/vendor/assets/javascripts/jquery-fileupload/vendor/canvas-to-blob.js +16 -6
- data/vendor/assets/javascripts/jquery-fileupload/vendor/jquery.ui.widget.js +1 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -4,7 +4,11 @@
|
|
4
4
|
|
5
5
|
jquery-fileupload-rails is a library that integrates jQuery File Upload for Rails 3.1 Asset Pipeline (Rails 3.2 supported).
|
6
6
|
|
7
|
-
|
7
|
+
## Plugin versions
|
8
|
+
|
9
|
+
* jQuery File Upload User Interface Plugin 6.9.4
|
10
|
+
* jQuery File Upload Plugin 5.16.1
|
11
|
+
* jQuery UI Widget 1.8.23+amd
|
8
12
|
|
9
13
|
## Installing Gem
|
10
14
|
|
@@ -44,6 +48,10 @@ Require the stylesheet file to app/assets/stylesheets/application.css
|
|
44
48
|
|
45
49
|
*= require jquery.fileupload-ui
|
46
50
|
|
51
|
+
## [Example app](https://github.com/tors/jquery-fileupload-rails-paperclip-example)
|
52
|
+
This app uses paperclip and twitter-bootstrap-rails
|
53
|
+
|
54
|
+
|
47
55
|
## Thanks
|
48
56
|
Thanks to [Sebastian Tschan](https://github.com/blueimp) for writing an awesome file upload plugin.
|
49
57
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/*
|
2
|
-
* jQuery File Upload User Interface Plugin 6.9.
|
2
|
+
* jQuery File Upload User Interface Plugin 6.9.4
|
3
3
|
* https://github.com/blueimp/jQuery-File-Upload
|
4
4
|
*
|
5
5
|
* Copyright 2010, Sebastian Tschan
|
@@ -89,7 +89,7 @@
|
|
89
89
|
files = data.files;
|
90
90
|
$(this).fileupload('process', data).done(function () {
|
91
91
|
that._adjustMaxNumberOfFiles(-files.length);
|
92
|
-
data.
|
92
|
+
data.maxNumberOfFilesAdjusted = true;
|
93
93
|
data.files.valid = data.isValidated = that._validate(files);
|
94
94
|
data.context = that._renderUpload(files).data('data', data);
|
95
95
|
options.filesContainer[
|
@@ -112,8 +112,9 @@
|
|
112
112
|
send: function (e, data) {
|
113
113
|
var that = $(this).data('fileupload');
|
114
114
|
if (!data.isValidated) {
|
115
|
-
if (!data.
|
115
|
+
if (!data.maxNumberOfFilesAdjusted) {
|
116
116
|
that._adjustMaxNumberOfFiles(-data.files.length);
|
117
|
+
data.maxNumberOfFilesAdjusted = true;
|
117
118
|
}
|
118
119
|
if (!that._validate(data.files)) {
|
119
120
|
return false;
|
@@ -163,6 +164,17 @@
|
|
163
164
|
);
|
164
165
|
});
|
165
166
|
} else {
|
167
|
+
if ($.isArray(data.result)) {
|
168
|
+
$.each(data.result, function (index, file) {
|
169
|
+
if (data.maxNumberOfFilesAdjusted && file.error) {
|
170
|
+
that._adjustMaxNumberOfFiles(1);
|
171
|
+
} else if (!data.maxNumberOfFilesAdjusted &&
|
172
|
+
!file.error) {
|
173
|
+
that._adjustMaxNumberOfFiles(-1);
|
174
|
+
}
|
175
|
+
});
|
176
|
+
data.maxNumberOfFilesAdjusted = true;
|
177
|
+
}
|
166
178
|
template = that._renderDownload(data.result)
|
167
179
|
.appendTo(that.options.filesContainer);
|
168
180
|
that._forceReflow(template);
|
@@ -178,7 +190,9 @@
|
|
178
190
|
fail: function (e, data) {
|
179
191
|
var that = $(this).data('fileupload'),
|
180
192
|
template;
|
181
|
-
|
193
|
+
if (data.maxNumberOfFilesAdjusted) {
|
194
|
+
that._adjustMaxNumberOfFiles(data.files.length);
|
195
|
+
}
|
182
196
|
if (data.context) {
|
183
197
|
data.context.each(function (index) {
|
184
198
|
if (data.errorThrown !== 'abort') {
|
@@ -209,7 +223,6 @@
|
|
209
223
|
}
|
210
224
|
});
|
211
225
|
} else if (data.errorThrown !== 'abort') {
|
212
|
-
that._adjustMaxNumberOfFiles(-data.files.length);
|
213
226
|
data.context = that._renderUpload(data.files)
|
214
227
|
.appendTo(that.options.filesContainer)
|
215
228
|
.data('data', data);
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/*
|
2
|
-
* jQuery File Upload Plugin 5.
|
2
|
+
* jQuery File Upload Plugin 5.16.1
|
3
3
|
* https://github.com/blueimp/jQuery-File-Upload
|
4
4
|
*
|
5
5
|
* Copyright 2010, Sebastian Tschan
|
@@ -447,6 +447,9 @@
|
|
447
447
|
if (options.type !== 'POST' && options.type !== 'PUT') {
|
448
448
|
options.type = 'POST';
|
449
449
|
}
|
450
|
+
if (!options.formAcceptCharset) {
|
451
|
+
options.formAcceptCharset = options.form.attr('accept-charset');
|
452
|
+
}
|
450
453
|
},
|
451
454
|
|
452
455
|
_getAJAXSettings: function (data) {
|
@@ -663,9 +666,15 @@
|
|
663
666
|
options.limitConcurrentUploads > that._sending) {
|
664
667
|
// Start the next queued upload,
|
665
668
|
// that has not been aborted:
|
666
|
-
var nextSlot = that._slots.shift()
|
669
|
+
var nextSlot = that._slots.shift(),
|
670
|
+
isPending;
|
667
671
|
while (nextSlot) {
|
668
|
-
|
672
|
+
// jQuery 1.6 doesn't provide .state(),
|
673
|
+
// while jQuery 1.8+ removed .isRejected():
|
674
|
+
isPending = nextSlot.state ?
|
675
|
+
nextSlot.state() === 'pending' :
|
676
|
+
!nextSlot.isRejected();
|
677
|
+
if (isPending) {
|
669
678
|
nextSlot.resolve();
|
670
679
|
break;
|
671
680
|
}
|
@@ -693,7 +702,7 @@
|
|
693
702
|
var args = [undefined, 'abort', 'abort'];
|
694
703
|
if (!jqXHR) {
|
695
704
|
if (slot) {
|
696
|
-
slot.rejectWith(args);
|
705
|
+
slot.rejectWith(pipe, args);
|
697
706
|
}
|
698
707
|
return send(false, args);
|
699
708
|
}
|
@@ -748,14 +757,6 @@
|
|
748
757
|
return result;
|
749
758
|
},
|
750
759
|
|
751
|
-
// File Normalization for Gecko 1.9.1 (Firefox 3.5) support:
|
752
|
-
_normalizeFile: function (index, file) {
|
753
|
-
if (file.name === undefined && file.size === undefined) {
|
754
|
-
file.name = file.fileName;
|
755
|
-
file.size = file.fileSize;
|
756
|
-
}
|
757
|
-
},
|
758
|
-
|
759
760
|
_replaceFileInput: function (input) {
|
760
761
|
var inputClone = input.clone(true);
|
761
762
|
$('<form></form>').append(inputClone)[0].reset();
|
@@ -780,21 +781,90 @@
|
|
780
781
|
}
|
781
782
|
},
|
782
783
|
|
784
|
+
_handleFileTreeEntry: function (entry, path) {
|
785
|
+
var that = this,
|
786
|
+
dfd = $.Deferred(),
|
787
|
+
errorHandler = function () {
|
788
|
+
dfd.reject();
|
789
|
+
},
|
790
|
+
dirReader;
|
791
|
+
path = path || '';
|
792
|
+
if (entry.isFile) {
|
793
|
+
entry.file(function (file) {
|
794
|
+
file.relativePath = path;
|
795
|
+
dfd.resolve(file);
|
796
|
+
}, errorHandler);
|
797
|
+
} else if (entry.isDirectory) {
|
798
|
+
dirReader = entry.createReader();
|
799
|
+
dirReader.readEntries(function (entries) {
|
800
|
+
that._handleFileTreeEntries(
|
801
|
+
entries,
|
802
|
+
path + entry.name + '/'
|
803
|
+
).done(function (files) {
|
804
|
+
dfd.resolve(files);
|
805
|
+
}).fail(errorHandler);
|
806
|
+
}, errorHandler);
|
807
|
+
} else {
|
808
|
+
errorHandler();
|
809
|
+
}
|
810
|
+
return dfd.promise();
|
811
|
+
},
|
812
|
+
|
813
|
+
_handleFileTreeEntries: function (entries, path) {
|
814
|
+
var that = this;
|
815
|
+
return $.when.apply(
|
816
|
+
$,
|
817
|
+
$.map(entries, function (entry) {
|
818
|
+
return that._handleFileTreeEntry(entry, path);
|
819
|
+
})
|
820
|
+
).pipe(function () {
|
821
|
+
return Array.prototype.concat.apply(
|
822
|
+
[],
|
823
|
+
arguments
|
824
|
+
);
|
825
|
+
});
|
826
|
+
},
|
827
|
+
|
828
|
+
_getDroppedFiles: function (dataTransfer) {
|
829
|
+
dataTransfer = dataTransfer || {};
|
830
|
+
var items = dataTransfer.items;
|
831
|
+
if (items && items.length && (items[0].webkitGetAsEntry ||
|
832
|
+
items[0].getAsEntry)) {
|
833
|
+
return this._handleFileTreeEntries(
|
834
|
+
$.map(items, function (item) {
|
835
|
+
if (item.webkitGetAsEntry) {
|
836
|
+
return item.webkitGetAsEntry();
|
837
|
+
}
|
838
|
+
return item.getAsEntry();
|
839
|
+
})
|
840
|
+
);
|
841
|
+
}
|
842
|
+
return $.Deferred().resolve(
|
843
|
+
$.makeArray(dataTransfer.files)
|
844
|
+
).promise();
|
845
|
+
},
|
846
|
+
|
783
847
|
_getFileInputFiles: function (fileInput) {
|
784
848
|
fileInput = $(fileInput);
|
785
|
-
var
|
849
|
+
var entries = fileInput.prop('webkitEntries') ||
|
850
|
+
fileInput.prop('entries'),
|
851
|
+
files,
|
786
852
|
value;
|
853
|
+
if (entries) {
|
854
|
+
return this._handleFileTreeEntries(entries);
|
855
|
+
}
|
856
|
+
files = $.makeArray(fileInput.prop('files'));
|
787
857
|
if (!files.length) {
|
788
858
|
value = fileInput.prop('value');
|
789
859
|
if (!value) {
|
790
|
-
return [];
|
860
|
+
return $.Deferred().reject([]).promise();
|
791
861
|
}
|
792
862
|
// If the files property is not available, the browser does not
|
793
863
|
// support the File API and we add a pseudo File object with
|
794
864
|
// the input value as name with path information removed:
|
795
865
|
files = [{name: value.replace(/^.*\\/, '')}];
|
796
866
|
}
|
797
|
-
return files;
|
867
|
+
return $.Deferred().resolve(files).promise();
|
798
868
|
},
|
799
869
|
|
800
870
|
_onChange: function (e) {
|
@@ -803,14 +873,15 @@
|
|
803
873
|
fileInput: $(e.target),
|
804
874
|
form: $(e.target.form)
|
805
875
|
};
|
806
|
-
|
807
|
-
|
808
|
-
that.
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
876
|
+
that._getFileInputFiles(data.fileInput).always(function (files) {
|
877
|
+
data.files = files;
|
878
|
+
if (that.options.replaceFileInput) {
|
879
|
+
that._replaceFileInput(data.fileInput);
|
880
|
+
}
|
881
|
+
if (that._trigger('change', e, data) !== false) {
|
882
|
+
that._onAdd(e, data);
|
883
|
+
}
|
884
|
+
});
|
814
885
|
},
|
815
886
|
|
816
887
|
_onPaste: function (e) {
|
@@ -831,19 +902,16 @@
|
|
831
902
|
},
|
832
903
|
|
833
904
|
_onDrop: function (e) {
|
905
|
+
e.preventDefault();
|
834
906
|
var that = e.data.fileupload,
|
835
907
|
dataTransfer = e.dataTransfer = e.originalEvent.dataTransfer,
|
836
|
-
data = {
|
837
|
-
|
838
|
-
|
839
|
-
|
840
|
-
)
|
841
|
-
}
|
842
|
-
|
843
|
-
that._onAdd(e, data) === false) {
|
844
|
-
return false;
|
845
|
-
}
|
846
|
-
e.preventDefault();
|
908
|
+
data = {};
|
909
|
+
that._getDroppedFiles(dataTransfer).always(function (files) {
|
910
|
+
data.files = files;
|
911
|
+
if (that._trigger('drop', e, data) !== false) {
|
912
|
+
that._onAdd(e, data);
|
913
|
+
}
|
914
|
+
});
|
847
915
|
},
|
848
916
|
|
849
917
|
_onDragOver: function (e) {
|
@@ -937,29 +1005,61 @@
|
|
937
1005
|
// must have a files property and can contain additional options:
|
938
1006
|
// .fileupload('add', {files: filesList});
|
939
1007
|
add: function (data) {
|
1008
|
+
var that = this;
|
940
1009
|
if (!data || this.options.disabled) {
|
941
1010
|
return;
|
942
1011
|
}
|
943
1012
|
if (data.fileInput && !data.files) {
|
944
|
-
|
1013
|
+
this._getFileInputFiles(data.fileInput).always(function (files) {
|
1014
|
+
data.files = files;
|
1015
|
+
that._onAdd(null, data);
|
1016
|
+
});
|
945
1017
|
} else {
|
946
|
-
data.files = $.
|
1018
|
+
data.files = $.makeArray(data.files);
|
1019
|
+
this._onAdd(null, data);
|
947
1020
|
}
|
948
|
-
this._onAdd(null, data);
|
949
1021
|
},
|
950
1022
|
|
951
1023
|
// This method is exposed to the widget API and allows sending files
|
952
1024
|
// using the fileupload API. The data parameter accepts an object which
|
953
|
-
// must have a files property and can contain additional options:
|
1025
|
+
// must have a files or fileInput property and can contain additional options:
|
954
1026
|
// .fileupload('send', {files: filesList});
|
955
1027
|
// The method returns a Promise object for the file upload call.
|
956
1028
|
send: function (data) {
|
957
1029
|
if (data && !this.options.disabled) {
|
958
1030
|
if (data.fileInput && !data.files) {
|
959
|
-
|
960
|
-
|
961
|
-
|
1031
|
+
var that = this,
|
1032
|
+
dfd = $.Deferred(),
|
1033
|
+
promise = dfd.promise(),
|
1034
|
+
jqXHR,
|
1035
|
+
aborted;
|
1036
|
+
promise.abort = function () {
|
1037
|
+
aborted = true;
|
1038
|
+
if (jqXHR) {
|
1039
|
+
return jqXHR.abort();
|
1040
|
+
}
|
1041
|
+
dfd.reject(null, 'abort', 'abort');
|
1042
|
+
return promise;
|
1043
|
+
};
|
1044
|
+
this._getFileInputFiles(data.fileInput).always(
|
1045
|
+
function (files) {
|
1046
|
+
if (aborted) {
|
1047
|
+
return;
|
1048
|
+
}
|
1049
|
+
data.files = files;
|
1050
|
+
jqXHR = that._onSend(null, data).then(
|
1051
|
+
function (result, textStatus, jqXHR) {
|
1052
|
+
dfd.resolve(result, textStatus, jqXHR);
|
1053
|
+
},
|
1054
|
+
function (jqXHR, textStatus, errorThrown) {
|
1055
|
+
dfd.reject(jqXHR, textStatus, errorThrown);
|
1056
|
+
}
|
1057
|
+
);
|
1058
|
+
}
|
1059
|
+
);
|
1060
|
+
return this._enhancePromise(promise);
|
962
1061
|
}
|
1062
|
+
data.files = $.makeArray(data.files);
|
963
1063
|
if (data.files.length) {
|
964
1064
|
return this._onSend(null, data);
|
965
1065
|
}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/*
|
2
|
-
* jQuery Iframe Transport Plugin 1.
|
2
|
+
* jQuery Iframe Transport Plugin 1.5
|
3
3
|
* https://github.com/blueimp/jQuery-File-Upload
|
4
4
|
*
|
5
5
|
* Copyright 2011, Sebastian Tschan
|
@@ -42,6 +42,7 @@
|
|
42
42
|
return {
|
43
43
|
send: function (_, completeCallback) {
|
44
44
|
form = $('<form style="display:none;"></form>');
|
45
|
+
form.attr('accept-charset', options.formAcceptCharset);
|
45
46
|
// javascript:false as initial iframe src
|
46
47
|
// prevents warning popups on HTTPS in IE6.
|
47
48
|
// IE versions below IE8 cannot set the name property of
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/*
|
2
|
-
* JavaScript Canvas to Blob 2.0.
|
2
|
+
* JavaScript Canvas to Blob 2.0.2
|
3
3
|
* https://github.com/blueimp/JavaScript-Canvas-to-Blob
|
4
4
|
*
|
5
5
|
* Copyright 2012, Sebastian Tschan
|
@@ -13,16 +13,23 @@
|
|
13
13
|
*/
|
14
14
|
|
15
15
|
/*jslint nomen: true, regexp: true */
|
16
|
-
/*global window, atob, ArrayBuffer, Uint8Array, define */
|
16
|
+
/*global window, atob, Blob, ArrayBuffer, Uint8Array, define */
|
17
17
|
|
18
18
|
(function (window) {
|
19
19
|
'use strict';
|
20
20
|
var CanvasPrototype = window.HTMLCanvasElement &&
|
21
21
|
window.HTMLCanvasElement.prototype,
|
22
|
+
hasBlobConstructor = function () {
|
23
|
+
try {
|
24
|
+
return !!new Blob();
|
25
|
+
} catch (e) {
|
26
|
+
return false;
|
27
|
+
}
|
28
|
+
}(),
|
22
29
|
BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder ||
|
23
30
|
window.MozBlobBuilder || window.MSBlobBuilder,
|
24
|
-
dataURLtoBlob = BlobBuilder && window.atob &&
|
25
|
-
window.Uint8Array && function (dataURI) {
|
31
|
+
dataURLtoBlob = (hasBlobConstructor || BlobBuilder) && window.atob &&
|
32
|
+
window.ArrayBuffer && window.Uint8Array && function (dataURI) {
|
26
33
|
var byteString,
|
27
34
|
arrayBuffer,
|
28
35
|
intArray,
|
@@ -42,11 +49,14 @@
|
|
42
49
|
for (i = 0; i < byteString.length; i += 1) {
|
43
50
|
intArray[i] = byteString.charCodeAt(i);
|
44
51
|
}
|
52
|
+
// Separate out the mime component:
|
53
|
+
mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0];
|
45
54
|
// Write the ArrayBuffer to a blob:
|
55
|
+
if (hasBlobConstructor) {
|
56
|
+
return new Blob([arrayBuffer], {type: mimeString});
|
57
|
+
}
|
46
58
|
bb = new BlobBuilder();
|
47
59
|
bb.append(arrayBuffer);
|
48
|
-
// Separate out the mime component:
|
49
|
-
mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0];
|
50
60
|
return bb.getBlob(mimeString);
|
51
61
|
};
|
52
62
|
if (window.HTMLCanvasElement && !CanvasPrototype.toBlob) {
|
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.3.
|
4
|
+
version: 0.3.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-08-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: railties
|