Skip to content

Commit 3bff9e0

Browse files
committed
Use jQuery.fn.on instead of jQuery.fn.bind
1 parent a4da3b4 commit 3bff9e0

10 files changed

+165
-165
lines changed

src/rails.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@
372372
element.html(replacement);
373373
}
374374

375-
element.bind('click.railsDisable', function(e) { // prevent further clicking
375+
element.on('click.railsDisable', function(e) { // prevent further clicking
376376
return rails.stopEverything(e);
377377
});
378378
element.data('ujs:disabled', true);
@@ -384,7 +384,7 @@
384384
element.html(element.data('ujs:enable-with')); // set to old enabled state
385385
element.removeData('ujs:enable-with'); // clean up cache
386386
}
387-
element.unbind('click.railsDisable'); // enable element
387+
element.off('click.railsDisable'); // enable element
388388
element.removeData('ujs:disabled');
389389
}
390390
};

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

+57-57
Large diffs are not rendered by default.

test/public/test/call-remote.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ module('call-remote');
1111

1212
function submit(fn) {
1313
$('form')
14-
.bind('ajax:success', fn)
15-
.bind('ajax:complete', function() { start() })
14+
.on('ajax:success', fn)
15+
.on('ajax:complete', function() { start() })
1616
.trigger('submit');
1717
}
1818

@@ -37,10 +37,10 @@ asyncTest('form method is read from submit button "formmethod" if submit is trig
3737
buildForm({ method: 'post' });
3838

3939
$('#qunit-fixture').find('form').append(submitButton)
40-
.bind('ajax:success', function(e, data, status, xhr) {
40+
.on('ajax:success', function(e, data, status, xhr) {
4141
App.assertGetRequest(data);
4242
})
43-
.bind('ajax:complete', function() { start() });
43+
.on('ajax:complete', function() { start() });
4444

4545
submitButton.trigger('click');
4646
});
@@ -74,10 +74,10 @@ asyncTest('form url is read from submit button "formaction" if submit is trigger
7474
buildForm({ method: 'post', href: '/echo2' });
7575

7676
$('#qunit-fixture').find('form').append(submitButton)
77-
.bind('ajax:success', function(e, data, status, xhr) {
77+
.on('ajax:success', function(e, data, status, xhr) {
7878
App.assertRequestPath(data, '/echo');
7979
})
80-
.bind('ajax:complete', function() { start() });
80+
.on('ajax:complete', function() { start() });
8181

8282
submitButton.trigger('click');
8383
});
@@ -113,7 +113,7 @@ asyncTest('allow empty form "action"', 1, function() {
113113
buildForm({ action: '' });
114114

115115
$('#qunit-fixture').find('form')
116-
.bind('ajax:beforeSend', function(e, xhr, settings) {
116+
.on('ajax:beforeSend', function(e, xhr, settings) {
117117
// Get current location (the same way jQuery does)
118118
try {
119119
currentLocation = location.href;
@@ -155,7 +155,7 @@ asyncTest('intelligently guesses crossDomain behavior when target URL has a diff
155155
$('#qunit-fixture').append('<meta name="csrf-token" content="cf50faa3fe97702ca1ae" />');
156156

157157
$('#qunit-fixture').find('form')
158-
.bind('ajax:beforeSend', function(e, xhr, settings) {
158+
.on('ajax:beforeSend', function(e, xhr, settings) {
159159

160160
equal(settings.crossDomain, true, 'crossDomain should be set to true');
161161

@@ -174,7 +174,7 @@ asyncTest('intelligently guesses crossDomain behavior when target URL consists o
174174
$('#qunit-fixture').append('<meta name="csrf-token" content="cf50faa3fe97702ca1ae" />');
175175

176176
$('#qunit-fixture').find('form')
177-
.bind('ajax:beforeSend', function(e, xhr, settings) {
177+
.on('ajax:beforeSend', function(e, xhr, settings) {
178178

179179
equal(settings.crossDomain, false, 'crossDomain should be set to false');
180180

test/public/test/data-confirm.js

+20-20
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ asyncTest('clicking on a link with data-confirm attribute. Confirm yes.', 6, fun
3939
window.confirm = function(msg) { message = msg; return true };
4040

4141
$('a[data-confirm]')
42-
.bind('confirm:complete', function(e, data) {
42+
.on('confirm:complete', function(e, data) {
4343
App.assertCallbackInvoked('confirm:complete');
4444
ok(data == true, 'confirm:complete passes in confirm answer (true)');
4545
})
46-
.bind('ajax:success', function(e, data, status, xhr) {
46+
.on('ajax:success', function(e, data, status, xhr) {
4747
App.assertCallbackInvoked('ajax:success');
4848
App.assertRequestPath(data, '/echo');
4949
App.assertGetRequest(data);
@@ -60,11 +60,11 @@ asyncTest('clicking on a button with data-confirm attribute. Confirm yes.', 6, f
6060
window.confirm = function(msg) { message = msg; return true };
6161

6262
$('button[data-confirm]')
63-
.bind('confirm:complete', function(e, data) {
63+
.on('confirm:complete', function(e, data) {
6464
App.assertCallbackInvoked('confirm:complete');
6565
ok(data == true, 'confirm:complete passes in confirm answer (true)');
6666
})
67-
.bind('ajax:success', function(e, data, status, xhr) {
67+
.on('ajax:success', function(e, data, status, xhr) {
6868
App.assertCallbackInvoked('ajax:success');
6969
App.assertRequestPath(data, '/echo');
7070
App.assertGetRequest(data);
@@ -81,11 +81,11 @@ asyncTest('clicking on a link with data-confirm attribute. Confirm No.', 3, func
8181
window.confirm = function(msg) { message = msg; return false };
8282

8383
$('a[data-confirm]')
84-
.bind('confirm:complete', function(e, data) {
84+
.on('confirm:complete', function(e, data) {
8585
App.assertCallbackInvoked('confirm:complete');
8686
ok(data == false, 'confirm:complete passes in confirm answer (false)');
8787
})
88-
.bind('ajax:beforeSend', function(e, data, status, xhr) {
88+
.on('ajax:beforeSend', function(e, data, status, xhr) {
8989
App.assertCallbackNotInvoked('ajax:beforeSend');
9090
})
9191
.trigger('click');
@@ -102,11 +102,11 @@ asyncTest('clicking on a button with data-confirm attribute. Confirm No.', 3, fu
102102
window.confirm = function(msg) { message = msg; return false };
103103

104104
$('button[data-confirm]')
105-
.bind('confirm:complete', function(e, data) {
105+
.on('confirm:complete', function(e, data) {
106106
App.assertCallbackInvoked('confirm:complete');
107107
ok(data == false, 'confirm:complete passes in confirm answer (false)');
108108
})
109-
.bind('ajax:beforeSend', function(e, data, status, xhr) {
109+
.on('ajax:beforeSend', function(e, data, status, xhr) {
110110
App.assertCallbackNotInvoked('ajax:beforeSend');
111111
})
112112
.trigger('click');
@@ -123,11 +123,11 @@ asyncTest('clicking on a button with data-confirm attribute. Confirm error.', 3,
123123
window.confirm = function(msg) { message = msg; throw "some random error"; };
124124

125125
$('button[data-confirm]')
126-
.bind('confirm:complete', function(e, data) {
126+
.on('confirm:complete', function(e, data) {
127127
App.assertCallbackInvoked('confirm:complete');
128128
ok(data == false, 'confirm:complete passes in confirm answer (false)');
129129
})
130-
.bind('ajax:beforeSend', function(e, data, status, xhr) {
130+
.on('ajax:beforeSend', function(e, data, status, xhr) {
131131
App.assertCallbackNotInvoked('ajax:beforeSend');
132132
})
133133
.trigger('click');
@@ -144,11 +144,11 @@ asyncTest('clicking on a submit button with form and data-confirm attributes. Co
144144
window.confirm = function(msg) { message = msg; return false };
145145

146146
$('input[type=submit][form]')
147-
.bind('confirm:complete', function(e, data) {
147+
.on('confirm:complete', function(e, data) {
148148
App.assertCallbackInvoked('confirm:complete');
149149
ok(data == false, 'confirm:complete passes in confirm answer (false)');
150150
})
151-
.bind('ajax:beforeSend', function(e, data, status, xhr) {
151+
.on('ajax:beforeSend', function(e, data, status, xhr) {
152152
App.assertCallbackNotInvoked('ajax:beforeSend');
153153
})
154154
.trigger('click');
@@ -166,11 +166,11 @@ asyncTest('binding to confirm event of a link and returning false', 1, function(
166166
};
167167

168168
$('a[data-confirm]')
169-
.bind('confirm', function() {
169+
.on('confirm', function() {
170170
App.assertCallbackInvoked('confirm');
171171
return false;
172172
})
173-
.bind('confirm:complete', function() {
173+
.on('confirm:complete', function() {
174174
App.assertCallbackNotInvoked('confirm:complete');
175175
})
176176
.trigger('click');
@@ -187,11 +187,11 @@ asyncTest('binding to confirm event of a button and returning false', 1, functio
187187
};
188188

189189
$('button[data-confirm]')
190-
.bind('confirm', function() {
190+
.on('confirm', function() {
191191
App.assertCallbackInvoked('confirm');
192192
return false;
193193
})
194-
.bind('confirm:complete', function() {
194+
.on('confirm:complete', function() {
195195
App.assertCallbackNotInvoked('confirm:complete');
196196
})
197197
.trigger('click');
@@ -209,11 +209,11 @@ asyncTest('binding to confirm:complete event of a link and returning false', 2,
209209
};
210210

211211
$('a[data-confirm]')
212-
.bind('confirm:complete', function() {
212+
.on('confirm:complete', function() {
213213
App.assertCallbackInvoked('confirm:complete');
214214
return false;
215215
})
216-
.bind('ajax:beforeSend', function() {
216+
.on('ajax:beforeSend', function() {
217217
App.assertCallbackNotInvoked('ajax:beforeSend');
218218
})
219219
.trigger('click');
@@ -231,11 +231,11 @@ asyncTest('binding to confirm:complete event of a button and returning false', 2
231231
};
232232

233233
$('button[data-confirm]')
234-
.bind('confirm:complete', function() {
234+
.on('confirm:complete', function() {
235235
App.assertCallbackInvoked('confirm:complete');
236236
return false;
237237
})
238-
.bind('ajax:beforeSend', function() {
238+
.on('ajax:beforeSend', function() {
239239
App.assertCallbackNotInvoked('ajax:beforeSend');
240240
})
241241
.trigger('click');

test/public/test/data-disable-with.js

+22-22
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ module('data-disable-with', {
4040
}));
4141
},
4242
teardown: function() {
43-
$(document).unbind('iframe:loaded');
43+
$(document).off('iframe:loaded');
4444
}
4545
});
4646

@@ -49,7 +49,7 @@ asyncTest('form input field with "data-disable-with" attribute', 7, function() {
4949

5050
App.checkEnabledState(input, 'john');
5151

52-
form.bind('ajax:success', function(e, data) {
52+
form.on('ajax:success', function(e, data) {
5353
setTimeout(function() {
5454
App.checkEnabledState(input, 'john');
5555
equal(data.params.user_name, 'john');
@@ -67,7 +67,7 @@ asyncTest('blank form input field with "data-disable-with" attribute', 7, functi
6767
input.val('');
6868
App.checkEnabledState(input, '');
6969

70-
form.bind('ajax:success', function(e, data) {
70+
form.on('ajax:success', function(e, data) {
7171
setTimeout(function() {
7272
App.checkEnabledState(input, '');
7373
equal(data.params.user_name, '');
@@ -85,7 +85,7 @@ asyncTest('form button with "data-disable-with" attribute', 6, function() {
8585

8686
App.checkEnabledState(button, 'Submit');
8787

88-
form.bind('ajax:success', function(e, data) {
88+
form.on('ajax:success', function(e, data) {
8989
setTimeout(function() {
9090
App.checkEnabledState(button, 'Submit');
9191
start();
@@ -102,9 +102,9 @@ asyncTest('form input[type=submit][data-disable-with] disables', 6, function(){
102102
App.checkEnabledState(input, 'Submit');
103103

104104
// WEEIRDD: attaching this handler makes the test work in IE7
105-
$(document).bind('iframe:loading', function(e, form) {});
105+
$(document).on('iframe:loading', function(e, form) {});
106106

107-
$(document).bind('iframe:loaded', function(e, data) {
107+
$(document).on('iframe:loaded', function(e, data) {
108108
setTimeout(function() {
109109
App.checkDisabledState(input, 'submitting ...');
110110
start();
@@ -138,7 +138,7 @@ test('form input[type=submit][data-disable-with] re-enables when `pageshow` even
138138
asyncTest('form[data-remote] input[type=submit][data-disable-with] is replaced in ajax callback', 2, function(){
139139
var form = $('form:not([data-remote])').attr('data-remote', 'true'), origFormContents = form.html();
140140

141-
form.bind('ajax:success', function(){
141+
form.on('ajax:success', function(){
142142
form.html(origFormContents);
143143

144144
setTimeout(function(){
@@ -153,7 +153,7 @@ asyncTest('form[data-remote] input[data-disable-with] is replaced with disabled
153153
var form = $('form:not([data-remote])').attr('data-remote', 'true'), input = form.find('input[type=submit]'),
154154
newDisabledInput = input.clone().attr('disabled', 'disabled');
155155

156-
form.bind('ajax:success', function(){
156+
form.on('ajax:success', function(){
157157
input.replaceWith(newDisabledInput);
158158

159159
setTimeout(function(){
@@ -168,9 +168,9 @@ asyncTest('form input[type=submit][data-disable-with] using "form" attribute dis
168168
App.checkEnabledState(input, 'Form Attr Submit');
169169

170170
// WEEIRDD: attaching this handler makes the test work in IE7
171-
$(document).bind('iframe:loading', function(e, form) {});
171+
$(document).on('iframe:loading', function(e, form) {});
172172

173-
$(document).bind('iframe:loaded', function(e, data) {
173+
$(document).on('iframe:loaded', function(e, data) {
174174
setTimeout(function() {
175175
App.checkDisabledState(input, 'form attr submitting');
176176
start();
@@ -188,7 +188,7 @@ asyncTest('form[data-remote] textarea[data-disable-with] attribute', 3, function
188188
var form = $('form[data-remote]'),
189189
textarea = $('<textarea data-disable-with="processing ..." name="user_bio">born, lived, died.</textarea>').appendTo(form);
190190

191-
form.bind('ajax:success', function(e, data) {
191+
form.on('ajax:success', function(e, data) {
192192
setTimeout(function() {
193193
equal(data.params.user_bio, 'born, lived, died.');
194194
start();
@@ -227,10 +227,10 @@ asyncTest('a[data-remote][data-disable-with] disables and re-enables', 6, functi
227227
App.checkEnabledState(link, 'Click me');
228228

229229
link
230-
.bind('ajax:beforeSend', function() {
230+
.on('ajax:beforeSend', function() {
231231
App.checkDisabledState(link, 'clicking...');
232232
})
233-
.bind('ajax:complete', function() {
233+
.on('ajax:complete', function() {
234234
setTimeout( function() {
235235
App.checkEnabledState(link, 'Click me');
236236
start();
@@ -245,7 +245,7 @@ asyncTest('a[data-remote][data-disable-with] re-enables when `ajax:before` event
245245
App.checkEnabledState(link, 'Click me');
246246

247247
link
248-
.bind('ajax:before', function() {
248+
.on('ajax:before', function() {
249249
App.checkDisabledState(link, 'clicking...');
250250
return false;
251251
})
@@ -263,7 +263,7 @@ asyncTest('a[data-remote][data-disable-with] re-enables when `ajax:beforeSend` e
263263
App.checkEnabledState(link, 'Click me');
264264

265265
link
266-
.bind('ajax:beforeSend', function() {
266+
.on('ajax:beforeSend', function() {
267267
App.checkDisabledState(link, 'clicking...');
268268
return false;
269269
})
@@ -281,7 +281,7 @@ asyncTest('a[data-remote][data-disable-with] re-enables when `ajax:error` event
281281
App.checkEnabledState(link, 'Click me');
282282

283283
link
284-
.bind('ajax:beforeSend', function() {
284+
.on('ajax:beforeSend', function() {
285285
App.checkDisabledState(link, 'clicking...');
286286
})
287287
.trigger('click');
@@ -300,7 +300,7 @@ asyncTest('form[data-remote] input|button|textarea[data-disable-with] does not d
300300
submit = $('<input type="submit" data-disable-with="submitting ..." name="submit2" value="Submit" />').appendTo(form);
301301

302302
form
303-
.bind('ajax:beforeSend', function() {
303+
.on('ajax:beforeSend', function() {
304304
return false;
305305
})
306306
.trigger('submit');
@@ -337,10 +337,10 @@ asyncTest('button[data-remote][data-disable-with] disables and re-enables', 6, f
337337
App.checkEnabledState(button, 'Click me');
338338

339339
button
340-
.bind('ajax:send', function() {
340+
.on('ajax:send', function() {
341341
App.checkDisabledState(button, 'clicking...');
342342
})
343-
.bind('ajax:complete', function() {
343+
.on('ajax:complete', function() {
344344
setTimeout( function() {
345345
App.checkEnabledState(button, 'Click me');
346346
start();
@@ -355,7 +355,7 @@ asyncTest('button[data-remote][data-disable-with] re-enables when `ajax:before`
355355
App.checkEnabledState(button, 'Click me');
356356

357357
button
358-
.bind('ajax:before', function() {
358+
.on('ajax:before', function() {
359359
App.checkDisabledState(button, 'clicking...');
360360
return false;
361361
})
@@ -373,7 +373,7 @@ asyncTest('button[data-remote][data-disable-with] re-enables when `ajax:beforeSe
373373
App.checkEnabledState(button, 'Click me');
374374

375375
button
376-
.bind('ajax:beforeSend', function() {
376+
.on('ajax:beforeSend', function() {
377377
App.checkDisabledState(button, 'clicking...');
378378
return false;
379379
})
@@ -391,7 +391,7 @@ asyncTest('button[data-remote][data-disable-with] re-enables when `ajax:error` e
391391
App.checkEnabledState(button, 'Click me');
392392

393393
button
394-
.bind('ajax:send', function() {
394+
.on('ajax:send', function() {
395395
App.checkDisabledState(button, 'clicking...');
396396
})
397397
.trigger('click');

0 commit comments

Comments
 (0)