remotipart 0.3.3 → 0.3.4
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.rdoc +3 -1
- data/VERSION +1 -1
- data/lib/generators/templates/jquery.remotipart.js +80 -76
- data/remotipart.gemspec +1 -1
- metadata +3 -3
data/README.rdoc
CHANGED
@@ -17,15 +17,17 @@ This gem augments the native Rails jQuery remote form function enabling asynchro
|
|
17
17
|
+---------------------------------------------------------------------+
|
18
18
|
| Version of remotipart.js | is compatible with versions of rails.js* |
|
19
19
|
+---------------------------------------------------------------------+
|
20
|
-
| <= 0.3.1 |
|
20
|
+
| <= 0.3.1 | <= 498b35e24cdb14f2 |
|
21
21
|
| 0.3.2 | > 498b35e24cdb14f2, <= 7f2acc1811f62877 |
|
22
22
|
| 0.3.3 | > 7f2acc1811f62877, <= d2abd6f9df4e4a42 |
|
23
|
+
| 0.3.4 | > d2abd6f9df4e4a42 (i.e. latest) |
|
23
24
|
+---------------------------------------------------------------------+
|
24
25
|
|
25
26
|
*rails.js versions <em>(For a full list of Rails.js]versions and diffs, see {Rails jQuery UJS Changelog}[https://github.com/rails/jquery-ujs/blob/master/CHANGELOG.md])</em>:
|
26
27
|
* {498b35e24cdb14f2}[https://github.com/rails/jquery-ujs/raw/498b35e24cdb14f2d94486e8a1f4a1f661091426/src/rails.js]
|
27
28
|
* {7f2acc1811f62877}[https://github.com/rails/jquery-ujs/raw/7f2acc1811f62877611e16451530728b5e13dbe7/src/rails.js]
|
28
29
|
* {d2abd6f9df4e4a42}[https://github.com/rails/jquery-ujs/raw/d2abd6f9df4e4a426c17c218b7d5e05004c768d0/src/rails.js]
|
30
|
+
* {latest}[https://github.com/rails/jquery-ujs/raw/master/src/rails.js]
|
29
31
|
|
30
32
|
== Installation
|
31
33
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.4
|
@@ -1,80 +1,84 @@
|
|
1
|
-
(function
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
var input = $(this);
|
63
|
-
input.data('ujs:enable-with', input.val())
|
64
|
-
.val(input.attr('data-disable-with'))
|
65
|
-
.attr('disabled', 'disabled');
|
66
|
-
});
|
67
|
-
}
|
68
|
-
|
69
|
-
$('form').live('ajax:aborted:file.remotipart', function(){
|
70
|
-
var form = $(this), remote = form.attr('data-remote') != undefined;
|
71
|
-
|
72
|
-
if (remote) {
|
73
|
-
handleRemote(form);
|
74
|
-
return false;
|
75
|
-
} else {
|
76
|
-
disableFormElements(form);
|
1
|
+
(function($) {
|
2
|
+
|
3
|
+
var remotipart;
|
4
|
+
|
5
|
+
$.remotipart = remotipart = {
|
6
|
+
|
7
|
+
setup: function(form) {
|
8
|
+
form
|
9
|
+
// Append hidden input so we can tell from back-end when form has been submitted by remotipart
|
10
|
+
.append($('<input />', {
|
11
|
+
'id': "remotipart_submitted",
|
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
|
+
|
22
|
+
// Delete the beforeSend bindings, since we're about to re-submit via ajaxSubmit with the beforeSubmit
|
23
|
+
// hook that was just setup and triggered via the default `$.rails.handleRemote`
|
24
|
+
delete settings.beforeSend;
|
25
|
+
// form.js's `ajaxSubmit` will re-create this for us
|
26
|
+
delete settings.data;
|
27
|
+
|
28
|
+
// Manually set the default dataType if not defined, since the form.js's `ajaxSubmit` function
|
29
|
+
// does not actually submit an xhr request (which has its default dataType set by rails.js)
|
30
|
+
if (settings.dataType === undefined) settings.dataType = 'script';
|
31
|
+
|
32
|
+
// Allow remotipartSubmit to be cancelled if needed
|
33
|
+
if ($.rails.fire(form, 'ajax:remotipartSubmit', [xhr, settings])) {
|
34
|
+
|
35
|
+
// Setup request URL for js dataType (needed for some versions of IE)
|
36
|
+
if (settings.dataType == 'script') {
|
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);
|
46
|
+
|
47
|
+
// Cancel the default jquery-ujs remote call by returning false for `ajax:beforeSend`
|
48
|
+
return false;
|
49
|
+
}
|
50
|
+
})
|
51
|
+
|
52
|
+
// Keep track that we just set this particular form with Remotipart bindings
|
53
|
+
// Note: The `true` value will get over-written with the `settings.dataType` from the `ajax:beforeSend` handler
|
54
|
+
.data('remotipartSubmitted', true);
|
55
|
+
},
|
56
|
+
|
57
|
+
teardown: function(form) {
|
58
|
+
form
|
59
|
+
.unbind('ajax:beforeSend.remotipart')
|
60
|
+
.children('#remotipart_submitted').remove();
|
61
|
+
delete form.data.remotipartSubmitted;
|
77
62
|
}
|
63
|
+
};
|
64
|
+
|
65
|
+
$('form').live('ajax:aborted:file', function(){
|
66
|
+
var form = $(this);
|
67
|
+
|
68
|
+
// Only need to setup form and make form bindings once.
|
69
|
+
// If form has already been setup, just let bindings be executed.
|
70
|
+
if (form.data('remotipartSubmitted') === undefined) remotipart.setup(form);
|
71
|
+
|
72
|
+
// If browser does not support submit bubbling, then this live-binding will be called before direct
|
73
|
+
// bindings. Therefore, we should directly call any direct bindings before remotely submitting form.
|
74
|
+
if (!$.support.submitBubbles && 'callFormSubmitBindings' in $.rails && $.rails.callFormSubmitBindings(form) === false) return $.rails.stopEverything(e);
|
75
|
+
|
76
|
+
// Manually call jquery-ujs remote call so that it can setup form and settings as usual,
|
77
|
+
// and trigger the `ajax:beforeSend` callback to which remotipart binds functionality.
|
78
|
+
$.rails.handleRemote(form);
|
79
|
+
|
80
|
+
// Return false to prevent standard browser behavior (part of jquery-ujs api for `ajax:aborted:file`)
|
81
|
+
return false;
|
78
82
|
});
|
79
83
|
|
80
84
|
})(jQuery);
|
data/remotipart.gemspec
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: remotipart
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 4
|
10
|
+
version: 0.3.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Greg Leppert
|