remotipart 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +15 -10
- data/VERSION +1 -1
- data/lib/generators/templates/jquery.remotipart.js +70 -62
- data/remotipart.gemspec +2 -2
- metadata +4 -4
data/README.rdoc
CHANGED
@@ -14,21 +14,26 @@ This gem augments the native Rails jQuery remote form function enabling asynchro
|
|
14
14
|
|
15
15
|
== Version Compatibility
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
17
|
+
+---------------------------------------------------------------------+
|
18
|
+
| Version of remotipart.js | is compatible with versions of rails.js* |
|
19
|
+
+---------------------------------------------------------------------+
|
20
|
+
| <= 0.3.1 | <= 498b35e24cdb14f2 |
|
21
|
+
| 0.3.2 | > 498b35e24cdb14f2, <= 7f2acc1811f62877 |
|
22
|
+
| 0.3.3 | > 7f2acc1811f62877, <= d2abd6f9df4e4a42 |
|
23
|
+
+---------------------------------------------------------------------+
|
24
|
+
|
25
|
+
*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
|
+
* {498b35e24cdb14f2}[https://github.com/rails/jquery-ujs/raw/498b35e24cdb14f2d94486e8a1f4a1f661091426/src/rails.js]
|
27
|
+
* {7f2acc1811f62877}[https://github.com/rails/jquery-ujs/raw/7f2acc1811f62877611e16451530728b5e13dbe7/src/rails.js]
|
28
|
+
* {d2abd6f9df4e4a42}[https://github.com/rails/jquery-ujs/raw/d2abd6f9df4e4a426c17c218b7d5e05004c768d0/src/rails.js]
|
23
29
|
|
24
30
|
== Installation
|
25
31
|
|
26
|
-
<b>Prerequisite: Make sure you have a supported jquery-ujs (rails.js) version.</b>
|
27
|
-
|
28
|
-
<b>To be certain, replace public/javascripts/rails.js with {this version}[https://github.com/rails/jquery-ujs/raw/51272c68714748420d8c35984b3e2532ab14f748/src/rails.js] of rails.js. Alternatively, follow {these instructions}[https://github.com/formasfunction/remotipart/wiki/Getting-Remotipart-to-work-with-latest-jquery-ujs] to get Remotipart working with the latest jquery-ujs.</b>
|
32
|
+
<b>Prerequisite: Make sure you have a supported jquery-ujs (rails.js) version from the previous section.</b>
|
29
33
|
|
30
34
|
1. Install the Remotipart gem
|
31
|
-
|
35
|
+
|
36
|
+
* Add this line to your GEMFILE (add the correct version from previous section if needed)
|
32
37
|
|
33
38
|
gem 'remotipart'
|
34
39
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.3
|
@@ -1,72 +1,80 @@
|
|
1
1
|
(function ($) {
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
/**
|
9
|
-
* Handles execution of remote calls involving file uploads, firing overridable events along the way
|
10
|
-
*/
|
11
|
-
callRemotipart: function () {
|
12
|
-
var el = this,
|
13
|
-
url = el.attr('action'),
|
14
|
-
dataType = el.attr('data-type') || 'script';
|
2
|
+
// Triggers an event on an element and returns the event result
|
3
|
+
function fire(obj, name, data) {
|
4
|
+
var event = new $.Event(name);
|
5
|
+
obj.trigger(event, data);
|
6
|
+
return event.result !== false;
|
7
|
+
}
|
15
8
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
// we'll add a custom hidden input to keep track and let the server know this was still
|
21
|
-
// an AJAX form, we'll also make it easy to tell from our jQuery element object.
|
22
|
-
el
|
23
|
-
.append($('<input />', {
|
24
|
-
type: "hidden",
|
25
|
-
name: "remotipart_submitted",
|
26
|
-
value: true
|
27
|
-
}))
|
28
|
-
.data('remotipartSubmitted', dataType);
|
9
|
+
// Submits "remote" forms and links with ajax
|
10
|
+
function handleRemote(element) {
|
11
|
+
var method, url, data,
|
12
|
+
dataType = element.attr('data-type') || ($.ajaxSettings && $.ajaxSettings.dataType) || 'script';
|
29
13
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
beforeSend: function (xhr, settings) {
|
40
|
-
if (settings.dataType === undefined) {
|
41
|
-
xhr.setRequestHeader('accept', '*/*;q=0.5, ' + settings.accepts.script);
|
42
|
-
}
|
43
|
-
var proceed = fire(el, 'ajax:beforeSend', [xhr, settings, true]);
|
44
|
-
if (proceed) { el.trigger('ajax:loading', [xhr]); }
|
45
|
-
return proceed;
|
46
|
-
},
|
47
|
-
success: function (data, status, xhr) {
|
48
|
-
el.trigger('ajax:success', [data, status, xhr]);
|
49
|
-
},
|
50
|
-
complete: function (xhr) {
|
51
|
-
el.trigger('ajax:complete', xhr);
|
52
|
-
},
|
53
|
-
error: function (xhr, status, error) {
|
54
|
-
el.trigger('ajax:failure ajax:error', [xhr, status, error]);
|
55
|
-
}
|
56
|
-
});
|
57
|
-
}
|
14
|
+
// Since iframe-submitted form is submitted normal-style and cannot set custom headers,
|
15
|
+
// we'll add a custom hidden input to keep track and let the server know this was still
|
16
|
+
// an AJAX form.
|
17
|
+
element.append($('<input />', {
|
18
|
+
type: "hidden",
|
19
|
+
name: "remotipart_submitted",
|
20
|
+
value: true
|
21
|
+
}))
|
22
|
+
.data('remotipartSubmitted', dataType);
|
58
23
|
|
59
|
-
|
60
|
-
|
61
|
-
|
24
|
+
if (fire(element, 'ajax:before')) {
|
25
|
+
method = element.attr('method');
|
26
|
+
url = element.attr('action');
|
27
|
+
data = element.serializeArray();
|
28
|
+
// memoized value from clicked submit button
|
29
|
+
var button = element.data('ujs:submit-button');
|
30
|
+
if (button) {
|
31
|
+
data.push(button);
|
32
|
+
element.data('ujs:submit-button', null);
|
33
|
+
}
|
62
34
|
|
63
|
-
$('form[data-remote]').live('ajax:beforeSend', function (evt, xhr, settings, remotipart) {
|
64
35
|
|
65
|
-
|
66
|
-
|
36
|
+
if (dataType == 'script') {
|
37
|
+
url = url.split('?'); // split on GET params
|
38
|
+
if(url[0].substr(-3) != '.js') url[0] += '.js'; // force rails to respond to respond to the request with :format = js
|
39
|
+
url = url.join('?'); // join on GET params
|
40
|
+
}
|
41
|
+
element.ajaxSubmit({
|
42
|
+
url: url, type: method || 'GET', data: data, dataType: dataType,
|
43
|
+
// stopping the "ajax:beforeSend" event will cancel the ajax request
|
44
|
+
beforeSend: function(xhr, settings) {
|
45
|
+
return fire(element, 'ajax:beforeSend', [xhr, settings]);
|
46
|
+
},
|
47
|
+
success: function(data, status, xhr) {
|
48
|
+
element.trigger('ajax:success', [data, status, xhr]);
|
49
|
+
},
|
50
|
+
complete: function(xhr, status) {
|
51
|
+
element.trigger('ajax:complete', [xhr, status]);
|
52
|
+
},
|
53
|
+
error: function(xhr, status, error) {
|
54
|
+
element.trigger('ajax:error', [xhr, status, error]);
|
55
|
+
}
|
56
|
+
});
|
57
|
+
}
|
58
|
+
}
|
59
|
+
|
60
|
+
function disableFormElements(form) {
|
61
|
+
form.find('input[data-disable-with]').each(function() {
|
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);
|
67
74
|
return false;
|
75
|
+
} else {
|
76
|
+
disableFormElements(form);
|
68
77
|
}
|
69
|
-
|
70
|
-
return true;
|
71
78
|
});
|
79
|
+
|
72
80
|
})(jQuery);
|
data/remotipart.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{remotipart}
|
8
|
-
s.version = "0.3.
|
8
|
+
s.version = "0.3.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Greg Leppert", "Steve Schwartz"]
|
12
|
-
s.date = %q{2011-05-
|
12
|
+
s.date = %q{2011-05-02}
|
13
13
|
s.description = %q{Remotipart is a Ruby on Rails gem enabling remote multipart forms (AJAX style file uploads) with jQuery.
|
14
14
|
This gem augments the native Rails jQuery remote form function enabling asynchronous file uploads with little to no modification to your application.
|
15
15
|
It requires jQuery (http://jquery.com), the Rails jQuery driver (http://github.com/rails/jquery-ujs), and the jQuery Form plugin (http://jquery.malsup.com/form/).
|
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: 21
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 3
|
10
|
+
version: 0.3.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Greg Leppert
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2011-05-
|
19
|
+
date: 2011-05-02 00:00:00 -04:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|