Skip to content

Commit

Permalink
Use jQuery.fn.on instead of jQuery.fn.delegate
Browse files Browse the repository at this point in the history
  • Loading branch information
aki77 committed Apr 14, 2017
1 parent 3bff9e0 commit 3dc8c21
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions test/public/test/call-remote-callbacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ module('call-remote-callbacks', {
}));
},
teardown: function() {
$(document).undelegate('form[data-remote]', 'ajax:beforeSend');
$(document).undelegate('form[data-remote]', 'ajax:before');
$(document).undelegate('form[data-remote]', 'ajax:send');
$(document).undelegate('form[data-remote]', 'ajax:complete');
$(document).undelegate('form[data-remote]', 'ajax:success');
$(document).off('ajax:beforeSend', 'form[data-remote]');
$(document).off('ajax:before', 'form[data-remote]');
$(document).off('ajax:send', 'form[data-remote]');
$(document).off('ajax:complete', 'form[data-remote]');
$(document).off('ajax:success', 'form[data-remote]');
$(document).off('ajaxStop');
$(document).off('iframe:loading');
}
Expand Down Expand Up @@ -371,7 +371,7 @@ function skipIt() {
}

asyncTest('"ajax:beforeSend" can be observed and stopped with event delegation', 1, function() {
$(document).delegate('form[data-remote]', 'ajax:beforeSend', function() {
$(document).on('ajax:beforeSend', 'form[data-remote]', function() {
ok(true, 'ajax:beforeSend observed with event delegation');
return false;
});
Expand Down Expand Up @@ -429,18 +429,18 @@ if(window.phantom !== undefined) {
}

// IF THIS TEST IS FAILING, TRY INCREASING THE TIMEOUT AT THE BOTTOM TO > 100
asyncTest('binding to ajax callbacks via .delegate() triggers handlers properly', 4, function() {
asyncTest('binding to ajax callbacks via .on() triggers handlers properly', 4, function() {
$(document)
.delegate('form[data-remote]', 'ajax:beforeSend', function() {
.on('ajax:beforeSend', 'form[data-remote]', function() {
ok(true, 'ajax:beforeSend handler is triggered');
})
.delegate('form[data-remote]', 'ajax:send', function() {
.on('ajax:send', 'form[data-remote]', function() {
ok(true, 'ajax:send handler is triggered');
})
.delegate('form[data-remote]', 'ajax:complete', function() {
.on('ajax:complete', 'form[data-remote]', function() {
ok(true, 'ajax:complete handler is triggered');
})
.delegate('form[data-remote]', 'ajax:success', function() {
.on('ajax:success', 'form[data-remote]', function() {
ok(true, 'ajax:success handler is triggered');
});
$('form[data-remote]').trigger('submit');
Expand All @@ -452,7 +452,7 @@ asyncTest('binding to ajax callbacks via .delegate() triggers handlers properly'

asyncTest('binding to ajax:send event to call jquery methods on ajax object', 2, function() {
$('form[data-remote]')
.on('ajax:send', function(e, xhr) {
.bind('ajax:send', function(e, xhr) {
ok(true, 'event should fire');
equal(typeof(xhr.abort), 'function', 'event should pass jqXHR object');
xhr.abort();
Expand Down

0 comments on commit 3dc8c21

Please sign in to comment.