jquery-fileupload-rails 0.3.5 → 0.4.0
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 +7 -1
- data/lib/jquery/fileupload/rails/middleware.rb +59 -0
- data/lib/jquery/fileupload/rails/upload.rb +1 -0
- data/lib/jquery/fileupload/rails/version.rb +1 -1
- data/vendor/assets/javascripts/jquery-fileupload/jquery.fileupload-fp.js +4 -1
- data/vendor/assets/javascripts/jquery-fileupload/jquery.fileupload.js +9 -9
- data/vendor/assets/javascripts/jquery-fileupload/jquery.iframe-transport.js +7 -0
- metadata +3 -2
data/README.md
CHANGED
@@ -7,7 +7,7 @@ jquery-fileupload-rails is a library that integrates jQuery File Upload for Rail
|
|
7
7
|
## Plugin versions
|
8
8
|
|
9
9
|
* jQuery File Upload User Interface Plugin 6.11
|
10
|
-
* jQuery File Upload Plugin 5.19.
|
10
|
+
* jQuery File Upload Plugin 5.19.3
|
11
11
|
* jQuery UI Widget 1.9.1+amd
|
12
12
|
|
13
13
|
## Installing Gem
|
@@ -48,6 +48,12 @@ Require the stylesheet file to app/assets/stylesheets/application.css
|
|
48
48
|
|
49
49
|
*= require jquery.fileupload-ui
|
50
50
|
|
51
|
+
## Using the middleware
|
52
|
+
|
53
|
+
The `jquery.iframe-transport` fallback transport has some special caveats regarding the response data type, http status, and character encodings. `jquery-fileupload-rails` includes a middleware that handles these inconsistencies seamlessly. If you decide to use it, create an initializer that adds the middleware to your application's middleware stack.
|
54
|
+
|
55
|
+
Rails.application.config.middleware.use JQuery::FileUpload::Rails::Middleware
|
56
|
+
|
51
57
|
## [Example app](https://github.com/tors/jquery-fileupload-rails-paperclip-example)
|
52
58
|
This app uses paperclip and twitter-bootstrap-rails
|
53
59
|
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module JQuery
|
2
|
+
module FileUpload
|
3
|
+
module Rails
|
4
|
+
class Middleware
|
5
|
+
def initialize(app)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
dup._call(env)
|
11
|
+
end
|
12
|
+
|
13
|
+
def _call(env)
|
14
|
+
@status, @headers, @response = @app.call(env)
|
15
|
+
@request = Rack::Request.new(env)
|
16
|
+
|
17
|
+
if iframe_transport?
|
18
|
+
@headers['Content-Type'] = 'text/html'
|
19
|
+
[@status, @headers, self]
|
20
|
+
else
|
21
|
+
[@status, @headers, @response]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def each(&block)
|
26
|
+
block.call(html_document_left) if iframe_transport?
|
27
|
+
@response.each(&block)
|
28
|
+
block.call(html_document_right) if iframe_transport?
|
29
|
+
end
|
30
|
+
|
31
|
+
def iframe_transport?
|
32
|
+
@request.params['X-Requested-With'] == 'IFrame'
|
33
|
+
end
|
34
|
+
|
35
|
+
def html_document_left
|
36
|
+
"<!DOCTYPE html><html><body><textarea #{metadata}>"
|
37
|
+
end
|
38
|
+
|
39
|
+
def html_document_right
|
40
|
+
"</textarea></body></html>"
|
41
|
+
end
|
42
|
+
|
43
|
+
def metadata
|
44
|
+
meta = {}
|
45
|
+
meta['data-status'] = @response.status if @response.respond_to? :status
|
46
|
+
meta['data-statusText'] = @response.status_message if @response.respond_to? :status_message
|
47
|
+
meta['data-type'] = @headers['Content-Type'] if @headers.has_key?('Content-Type')
|
48
|
+
meta.map {|key,value| "#{key}='#{value}'" }.join(' ')
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def method_missing(method, *args)
|
54
|
+
@response.send(method.intern, *args)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/*
|
2
|
-
* jQuery File Upload File Processing Plugin 1.2
|
2
|
+
* jQuery File Upload File Processing Plugin 1.2.1
|
3
3
|
* https://github.com/blueimp/jQuery-File-Upload
|
4
4
|
*
|
5
5
|
* Copyright 2012, Sebastian Tschan
|
@@ -86,6 +86,9 @@
|
|
86
86
|
loadImage(
|
87
87
|
file,
|
88
88
|
function (img) {
|
89
|
+
if (!img.src) {
|
90
|
+
return dfd.rejectWith(that, [data]);
|
91
|
+
}
|
89
92
|
data.img = img;
|
90
93
|
dfd.resolveWith(that, [data]);
|
91
94
|
}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/*
|
2
|
-
* jQuery File Upload Plugin 5.19.
|
2
|
+
* jQuery File Upload Plugin 5.19.3
|
3
3
|
* https://github.com/blueimp/jQuery-File-Upload
|
4
4
|
*
|
5
5
|
* Copyright 2010, Sebastian Tschan
|
@@ -644,18 +644,18 @@
|
|
644
644
|
_onSend: function (e, data) {
|
645
645
|
var that = this,
|
646
646
|
jqXHR,
|
647
|
+
aborted,
|
647
648
|
slot,
|
648
649
|
pipe,
|
649
650
|
options = that._getAJAXSettings(data),
|
650
|
-
send = function (
|
651
|
+
send = function () {
|
651
652
|
that._sending += 1;
|
652
653
|
// Set timer for bitrate progress calculation:
|
653
654
|
options._bitrateTimer = new that._BitrateTimer();
|
654
655
|
jqXHR = jqXHR || (
|
655
|
-
(
|
656
|
-
that.
|
657
|
-
|
658
|
-
that._getXHRPromise(false, options.context, args)
|
656
|
+
((aborted || that._trigger('send', e, options) === false) &&
|
657
|
+
that._getXHRPromise(false, options.context, aborted)) ||
|
658
|
+
that._chunkedUpload(options) || $.ajax(options)
|
659
659
|
).done(function (result, textStatus, jqXHR) {
|
660
660
|
that._onDone(result, textStatus, jqXHR, options);
|
661
661
|
}).fail(function (jqXHR, textStatus, errorThrown) {
|
@@ -705,12 +705,12 @@
|
|
705
705
|
// which is delegated to the jqXHR object of the current upload,
|
706
706
|
// and jqXHR callbacks mapped to the equivalent Promise methods:
|
707
707
|
pipe.abort = function () {
|
708
|
-
|
708
|
+
aborted = [undefined, 'abort', 'abort'];
|
709
709
|
if (!jqXHR) {
|
710
710
|
if (slot) {
|
711
|
-
slot.rejectWith(
|
711
|
+
slot.rejectWith(options.context, aborted);
|
712
712
|
}
|
713
|
-
return send(
|
713
|
+
return send();
|
714
714
|
}
|
715
715
|
return jqXHR.abort();
|
716
716
|
};
|
@@ -96,6 +96,13 @@
|
|
96
96
|
.val(field.value)
|
97
97
|
.appendTo(form);
|
98
98
|
});
|
99
|
+
// Add a hidden `X-Requested-With` field with the value `IFrame` to the
|
100
|
+
// form, to help server-side code to determine that the upload happened
|
101
|
+
// through this transport.
|
102
|
+
$('<input type="hidden" />')
|
103
|
+
.prop('name', 'X-Requested-With')
|
104
|
+
.val('IFrame')
|
105
|
+
.appendTo(form);
|
99
106
|
}
|
100
107
|
if (options.fileInput && options.fileInput.length &&
|
101
108
|
options.type === 'POST') {
|
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.4.0
|
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-12-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: railties
|
@@ -68,6 +68,7 @@ extensions: []
|
|
68
68
|
extra_rdoc_files: []
|
69
69
|
files:
|
70
70
|
- lib/jquery/fileupload/rails/engine.rb
|
71
|
+
- lib/jquery/fileupload/rails/middleware.rb
|
71
72
|
- lib/jquery/fileupload/rails/upload.rb
|
72
73
|
- lib/jquery/fileupload/rails/version.rb
|
73
74
|
- lib/jquery-fileupload-rails.rb
|