Skip to content

Commit 0bcf21a

Browse files
committed
Merge branch 'master' into data-disable
Conflicts: test/public/test/data-disable.js
2 parents d61894b + 4f8fc46 commit 0bcf21a

File tree

8 files changed

+43
-17
lines changed

8 files changed

+43
-17
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ source 'https://rubygems.org'
33
gem 'sinatra', '~> 1.0'
44
gem 'shotgun', :group => :reloadable
55
gem 'thin', :group => :reloadable
6+
gem 'rake'

Gemfile.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ GEM
44
daemons (1.1.0)
55
eventmachine (0.12.10)
66
rack (1.2.1)
7+
rake (10.1.1)
78
shotgun (0.8)
89
rack (>= 1.0)
910
sinatra (1.1.2)
@@ -19,6 +20,7 @@ PLATFORMS
1920
ruby
2021

2122
DEPENDENCIES
23+
rake
2224
shotgun
2325
sinatra (~> 1.0)
2426
thin

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Full [documentation is on the wiki][wiki], including the [list of published Ajax
1515
Requirements
1616
------------
1717

18-
- [jQuery 1.7.x or higher][jquery];
18+
- [jQuery 1.8.x or higher and less than 2.0][jquery];
1919
- HTML5 doctype (optional).
2020

2121
If you don't use HTML5, adding "data" attributes to your HTML4 or XHTML pages might make them fail [W3C markup validation][validator]. However, this shouldn't create any issues for web browsers or other user agents.

src/rails.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,11 @@
129129
if (settings.dataType === undefined) {
130130
xhr.setRequestHeader('accept', '*/*;q=0.5, ' + settings.accepts.script);
131131
}
132-
return rails.fire(element, 'ajax:beforeSend', [xhr, settings]);
132+
if (rails.fire(element, 'ajax:beforeSend', [xhr, settings])) {
133+
element.trigger('ajax:send', xhr);
134+
} else {
135+
return false;
136+
}
133137
},
134138
success: function(data, status, xhr) {
135139
element.trigger('ajax:success', [data, status, xhr]);
@@ -154,9 +158,7 @@
154158
// Only pass url to `ajax` options if not blank
155159
if (url) { options.url = url; }
156160

157-
var jqxhr = rails.ajax(options);
158-
element.trigger('ajax:send', jqxhr);
159-
return jqxhr;
161+
return rails.ajax(options);
160162
} else {
161163
return false;
162164
}
@@ -387,7 +389,7 @@
387389
button.closest('form').data('ujs:submit-button', data);
388390
});
389391

390-
$document.delegate(rails.formSubmitSelector, 'ajax:beforeSend.rails', function(event) {
392+
$document.delegate(rails.formSubmitSelector, 'ajax:send.rails', function(event) {
391393
if (this == event.target) rails.disableFormElements($(this));
392394
});
393395

test/public/test/call-remote-callbacks.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module('call-remote-callbacks', {
99
teardown: function() {
1010
$(document).undelegate('form[data-remote]', 'ajax:beforeSend');
1111
$(document).undelegate('form[data-remote]', 'ajax:before');
12+
$(document).undelegate('form[data-remote]', 'ajax:send');
1213
$(document).undelegate('form[data-remote]', 'ajax:complete');
1314
$(document).undelegate('form[data-remote]', 'ajax:success');
1415
$(document).unbind('ajaxStop');
@@ -97,6 +98,9 @@ asyncTest('stopping the "ajax:beforeSend" event aborts the request', 1, function
9798
ok(true, 'aborting request in ajax:beforeSend');
9899
return false;
99100
});
101+
form.unbind('ajax:send').bind('ajax:send', function() {
102+
ok(false, 'ajax:send should not run');
103+
});
100104
form.unbind('ajax:complete').bind('ajax:complete', function() {
101105
ok(false, 'ajax:complete should not run');
102106
});
@@ -315,6 +319,9 @@ asyncTest('"ajax:beforeSend" can be observed and stopped with event delegation',
315319
});
316320

317321
submit(function(form) {
322+
form.unbind('ajax:send').bind('ajax:send', function() {
323+
ok(false, 'ajax:send should not run');
324+
});
318325
form.unbind('ajax:complete').bind('ajax:complete', function() {
319326
ok(false, 'ajax:complete should not run');
320327
});
@@ -324,12 +331,15 @@ asyncTest('"ajax:beforeSend" can be observed and stopped with event delegation',
324331
});
325332
});
326333

327-
asyncTest('"ajax:beforeSend", "ajax:success" and "ajax:complete" are triggered', 8, function() {
334+
asyncTest('"ajax:beforeSend", "ajax:send", "ajax:success" and "ajax:complete" are triggered', 9, function() {
328335
submit(function(form) {
329336
form.bind('ajax:beforeSend', function(e, xhr, settings) {
330337
ok(xhr.setRequestHeader, 'first argument to "ajax:beforeSend" should be an XHR object');
331338
equal(settings.url, '/echo', 'second argument to "ajax:beforeSend" should be a settings object');
332339
});
340+
form.bind('ajax:send', function(e, xhr) {
341+
ok(xhr.abort, 'first argument to "ajax:send" should be an XHR object');
342+
});
333343
form.bind('ajax:success', function(e, data, status, xhr) {
334344
ok(data.REQUEST_METHOD, 'first argument to ajax:success should be a data object');
335345
equal(status, 'success', 'second argument to ajax:success should be a status string');
@@ -342,10 +352,11 @@ asyncTest('"ajax:beforeSend", "ajax:success" and "ajax:complete" are triggered',
342352
});
343353
});
344354

345-
asyncTest('"ajax:beforeSend", "ajax:error" and "ajax:complete" are triggered on error', 6, function() {
355+
asyncTest('"ajax:beforeSend", "ajax:send", "ajax:error" and "ajax:complete" are triggered on error', 7, function() {
346356
submit(function(form) {
347357
form.attr('action', '/error');
348358
form.bind('ajax:beforeSend', function(arg) { ok(true, 'ajax:beforeSend') });
359+
form.bind('ajax:send', function(arg) { ok(true, 'ajax:send') });
349360
form.bind('ajax:error', function(e, xhr, status, error) {
350361
ok(xhr.getResponseHeader, 'first argument to "ajax:error" should be an XHR object');
351362
equal(status, 'error', 'second argument to ajax:error should be a status string');
@@ -358,11 +369,14 @@ asyncTest('"ajax:beforeSend", "ajax:error" and "ajax:complete" are triggered on
358369
});
359370

360371
// IF THIS TEST IS FAILING, TRY INCREASING THE TIMEOUT AT THE BOTTOM TO > 100
361-
asyncTest('binding to ajax callbacks via .delegate() triggers handlers properly', 3, function() {
372+
asyncTest('binding to ajax callbacks via .delegate() triggers handlers properly', 4, function() {
362373
$(document)
363374
.delegate('form[data-remote]', 'ajax:beforeSend', function() {
364375
ok(true, 'ajax:beforeSend handler is triggered');
365376
})
377+
.delegate('form[data-remote]', 'ajax:send', function() {
378+
ok(true, 'ajax:send handler is triggered');
379+
})
366380
.delegate('form[data-remote]', 'ajax:complete', function() {
367381
ok(true, 'ajax:complete handler is triggered');
368382
})

test/public/test/data-disable.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ asyncTest('a[data-remote][data-disable] disables and re-enables', 6, function()
141141
App.checkEnabledState(link, 'Click me');
142142

143143
link
144-
.bind('ajax:beforeSend', function() {
144+
.bind('ajax:send', function() {
145145
App.checkDisabledState(link, 'Click me');
146146
})
147147
.bind('ajax:complete', function() {
@@ -195,7 +195,7 @@ asyncTest('a[data-remote][data-disable] re-enables when `ajax:error` event is tr
195195
App.checkEnabledState(link, 'Click me');
196196

197197
link
198-
.bind('ajax:beforeSend', function() {
198+
.bind('ajax:send', function() {
199199
App.checkDisabledState(link, 'Click me');
200200
})
201201
.trigger('click');

test/server.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require 'sinatra'
22
require 'json'
33

4-
JQUERY_VERSIONS = %w[ 1.7 1.7.1 1.7.2 1.8.0 1.8.1 1.8.2 1.8.3 1.9.0 1.9.1 1.10.0 1.10.1 ].freeze
4+
JQUERY_VERSIONS = %w[ 1.8.0 1.8.1 1.8.2 1.8.3 1.9.0 1.9.1 1.10.0 1.10.1 1.10.2 1.11.0 ].freeze
55

66
use Rack::Static, :urls => ["/src"], :root => File.expand_path('..', settings.root)
77

@@ -48,7 +48,7 @@ def jquery_versions
4848
end
4949

5050
get '/' do
51-
params[:version] ||= '1.10.1'
51+
params[:version] ||= '1.11.0'
5252
params[:cdn] ||= 'jquery'
5353
erb :index
5454
end

test/views/layout.erb

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,18 @@
55
<link href="/vendor/qunit.css" media="screen" rel="stylesheet" type="text/css" media="screen, projection" />
66
<style>
77
#jquery-cdn, #jquery-version {
8-
color: #8699A4; text-align: right; font-family: sans-serif; line-height: 1;
9-
margin-top: -1.8em; padding: 0 2em .8em 0;
8+
padding: 0 2em .8em 0;
9+
text-align: right;
10+
font-family: sans-serif;
11+
line-height: 1;
12+
color: #8699A4;
13+
background-color: #0d3349;
14+
}
15+
16+
#jquery-cdn a, #jquery-version a {
17+
color: white;
18+
text-decoration: underline;
1019
}
11-
#jquery-cdn { margin-right: 550px; }
12-
#jquery-cdn a, #jquery-version a { color: white; text-decoration: underline; }
1320
</style>
1421

1522
<%= script_tag jquery_src %>

0 commit comments

Comments
 (0)