remotipart 0.4.2 → 1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.rdoc +8 -1
- data/README.rdoc +55 -33
- data/lib/generators/remotipart/install/install_generator.rb +4 -4
- data/lib/remotipart/middleware.rb +33 -0
- data/lib/remotipart/rails/engine.rb +5 -0
- data/lib/remotipart/rails/railtie.rb +6 -1
- data/lib/remotipart/rails/version.rb +2 -2
- data/lib/remotipart/render_overrides.rb +15 -0
- data/lib/remotipart/request_helper.rb +1 -0
- data/lib/remotipart/view_helper.rb +3 -7
- data/lib/remotipart.rb +2 -0
- data/remotipart.gemspec +4 -2
- data/vendor/assets/javascripts/jquery.iframe-transport.js +233 -0
- data/vendor/assets/javascripts/jquery.remotipart.js +25 -40
- metadata +6 -5
- data/vendor/assets/javascripts/jquery.form.js +0 -911
@@ -1,3 +1,6 @@
|
|
1
|
+
//= require jquery.iframe-transport.js
|
2
|
+
//= require_self
|
3
|
+
|
1
4
|
(function($) {
|
2
5
|
|
3
6
|
var remotipart;
|
@@ -6,47 +9,34 @@
|
|
6
9
|
|
7
10
|
setup: function(form) {
|
8
11
|
form
|
9
|
-
//
|
10
|
-
|
11
|
-
|
12
|
-
type: "hidden",
|
13
|
-
name: "remotipart_submitted",
|
14
|
-
value: true
|
15
|
-
}))
|
16
|
-
|
17
|
-
// Allow setup part of $.rails.handleRemot to setup remote settings before canceling default remote handler
|
18
|
-
.bind('ajax:beforeSend.remotipart', function(e, xhr, origSettings){
|
19
|
-
// Shallow copy
|
20
|
-
var settings = $.extend({}, origSettings);
|
21
|
-
|
12
|
+
// Allow setup part of $.rails.handleRemote to setup remote settings before canceling default remote handler
|
13
|
+
// This is required in order to change the remote settings using the form details
|
14
|
+
.one('ajax:beforeSend.remotipart', function(e, xhr, settings){
|
22
15
|
// Delete the beforeSend bindings, since we're about to re-submit via ajaxSubmit with the beforeSubmit
|
23
16
|
// hook that was just setup and triggered via the default `$.rails.handleRemote`
|
17
|
+
// delete settings.beforeSend;
|
24
18
|
delete settings.beforeSend;
|
25
|
-
// form.js's `ajaxSubmit` will re-create this for us
|
26
|
-
delete settings.data;
|
27
19
|
|
28
|
-
|
29
|
-
|
30
|
-
|
20
|
+
settings.iframe = true;
|
21
|
+
settings.files = $($.rails.fileInputSelector, form);
|
22
|
+
settings.data = form.serializeArray();
|
23
|
+
settings.processData = false;
|
24
|
+
|
25
|
+
// Modify some settings to integrate JS request with rails helpers and middleware
|
26
|
+
if (settings.dataType === undefined) { settings.dataType = 'script *'; }
|
27
|
+
settings.data.push({name: 'remotipart_submitted', value: true});
|
31
28
|
|
32
29
|
// Allow remotipartSubmit to be cancelled if needed
|
33
30
|
if ($.rails.fire(form, 'ajax:remotipartSubmit', [xhr, settings])) {
|
31
|
+
// Second verse, same as the first
|
32
|
+
$.rails.ajax(settings);
|
33
|
+
}
|
34
34
|
|
35
|
-
|
36
|
-
|
37
|
-
settings.url = settings.url.split('?'); // split on GET params
|
38
|
-
if (settings.url[0].substr(-3) != '.js') settings.url[0] += '.js'; // force rails to respond to respond to the request with :format = js
|
39
|
-
settings.url = settings.url.join('?'); // join on GET params
|
40
|
-
}
|
41
|
-
|
42
|
-
// Update remotipartSubmitted data with dataType, in case needed in other scripts
|
43
|
-
form.data('remotipartSubmitted', settings.dataType);
|
44
|
-
// And finally, Use form.js's `ajaxSubmit` to do remote file uploading via iframe method
|
45
|
-
form.ajaxSubmit(settings);
|
35
|
+
//Run cleanup
|
36
|
+
remotipart.teardown(form);
|
46
37
|
|
47
|
-
|
48
|
-
|
49
|
-
}
|
38
|
+
// Cancel the jQuery UJS request
|
39
|
+
return false;
|
50
40
|
})
|
51
41
|
|
52
42
|
// Keep track that we just set this particular form with Remotipart bindings
|
@@ -57,27 +47,22 @@
|
|
57
47
|
teardown: function(form) {
|
58
48
|
form
|
59
49
|
.unbind('ajax:beforeSend.remotipart')
|
60
|
-
.
|
61
|
-
delete form.data.remotipartSubmitted;
|
50
|
+
.removeData('remotipartSubmitted')
|
62
51
|
}
|
63
52
|
};
|
64
53
|
|
65
54
|
$('form').live('ajax:aborted:file', function(){
|
66
55
|
var form = $(this);
|
67
56
|
|
68
|
-
|
69
|
-
// If form has already been setup, just let bindings be executed.
|
70
|
-
if (form.data('remotipartSubmitted') === undefined) remotipart.setup(form);
|
57
|
+
remotipart.setup(form);
|
71
58
|
|
72
59
|
// If browser does not support submit bubbling, then this live-binding will be called before direct
|
73
60
|
// bindings. Therefore, we should directly call any direct bindings before remotely submitting form.
|
74
|
-
if (!$.support.submitBubbles &&
|
61
|
+
if (!$.support.submitBubbles && $.rails.callFormSubmitBindings(form) === false) return $.rails.stopEverything(e);
|
75
62
|
|
76
63
|
// Manually call jquery-ujs remote call so that it can setup form and settings as usual,
|
77
64
|
// and trigger the `ajax:beforeSend` callback to which remotipart binds functionality.
|
78
65
|
$.rails.handleRemote(form);
|
79
|
-
|
80
|
-
// Return false to prevent standard browser behavior (part of jquery-ujs api for `ajax:aborted:file`)
|
81
66
|
return false;
|
82
67
|
});
|
83
68
|
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: remotipart
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
|
+
- 1
|
7
8
|
- 0
|
8
|
-
|
9
|
-
- 2
|
10
|
-
version: 0.4.2
|
9
|
+
version: "1.0"
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Greg Leppert
|
@@ -54,16 +53,18 @@ files:
|
|
54
53
|
- VERSION_COMPATIBILITY.rdoc
|
55
54
|
- lib/generators/remotipart/install/install_generator.rb
|
56
55
|
- lib/remotipart.rb
|
56
|
+
- lib/remotipart/middleware.rb
|
57
57
|
- lib/remotipart/rails.rb
|
58
58
|
- lib/remotipart/rails/engine.rb
|
59
59
|
- lib/remotipart/rails/railtie.rb
|
60
60
|
- lib/remotipart/rails/version.rb
|
61
|
+
- lib/remotipart/render_overrides.rb
|
61
62
|
- lib/remotipart/request_helper.rb
|
62
63
|
- lib/remotipart/view_helper.rb
|
63
64
|
- remotipart.gemspec
|
64
65
|
- test/helper.rb
|
65
66
|
- test/test_remotipart.rb
|
66
|
-
- vendor/assets/javascripts/jquery.
|
67
|
+
- vendor/assets/javascripts/jquery.iframe-transport.js
|
67
68
|
- vendor/assets/javascripts/jquery.remotipart.js
|
68
69
|
has_rdoc: true
|
69
70
|
homepage: http://www.alfajango.com/blog/remotipart-rails-gem/
|