Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change deprecated jQuery methods delegate/bind/unbind to on/off. #210

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ make sure you have a supported jquery-ujs (rails.js or jquery_ujs.js) version fr
if remotipart_submitted?
* from your javascript:

$(form).bind("ajax:success", function(){
$(form).on("ajax:success", function(){
if ( $(this).data('remotipartSubmitted') )
});
* If you want to be notified when the upload is complete (which can be either success or error)
Expand Down
6 changes: 3 additions & 3 deletions spec/dummy_app/app/assets/javascripts/comments.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
$(document)
.delegate('#new-comment-link, #new-comment-attachment-link', 'ajax:success', function(e, data, status, xhr){
.on('ajax:success', '#new-comment-link, #new-comment-attachment-link', function(e, data, status, xhr){
var $this = $(this),
$container = $('#new-comment-links'),
$responseText = $(xhr.responseText),
Expand All @@ -10,7 +10,7 @@ $(document)
e.preventDefault();
});
})
.delegate('form[data-remote]', 'ajax:aborted:required', function(){
.on('ajax:aborted:required', 'form[data-remote]', function(){
var $form = $(this),
errorDivId = 'ajax-validation-errors',
$errorDiv = $form.find('#' + errorDivId);
Expand All @@ -22,7 +22,7 @@ $(document)
text: 'You must fill in all required fields!'
}));
})
.delegate('form[data-remote]', 'ajax:error', function(e, xhr, status, statusText) {
.on('ajax:error', 'form[data-remote]', function(e, xhr, status, statusText) {
$('#comments').after('Error status code: ' + xhr.status + ', Error status message: ' + statusText);
});

38 changes: 19 additions & 19 deletions spec/features/comments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@

it "triggers ajax:remotipartSubmit event hook", js: true do
visit root_path
page.execute_script("$(document).delegate('form', 'ajax:remotipartSubmit', function() { $('#comments').after('remotipart!'); });")
page.execute_script("$(document).on('ajax:remotipartSubmit', 'form', function() { $('#comments').after('remotipart!'); });")

click_link 'New Comment with Attachment'

Expand All @@ -129,7 +129,7 @@

it "allows remotipart submission to be cancelable via event hook", js: true do
visit root_path
page.execute_script("$(document).delegate('form', 'ajax:remotipartSubmit', function() { $('#comments').after('remotipart!'); return false; });")
page.execute_script("$(document).on('ajax:remotipartSubmit', 'form', function() { $('#comments').after('remotipart!'); return false; });")

click_link 'New Comment with Attachment'

Expand All @@ -150,7 +150,7 @@

it "allows custom data-type on form", js: true do
visit root_path
page.execute_script("$(document).delegate('form', 'ajax:success', function(evt, data, status, xhr) { $('#comments').after(xhr.responseText); });")
page.execute_script("$(document).on('ajax:success', 'form', function(evt, data, status, xhr) { $('#comments').after(xhr.responseText); });")

click_link 'New Comment with Attachment'

Expand All @@ -169,7 +169,7 @@

it "allows users to use ajax response data safely", js: true do
visit root_path
page.execute_script("$(document).delegate('form', 'ajax:success', function(evt, data, status, xhr) { $('#comments').after(data); });")
page.execute_script("$(document).on('ajax:success', 'form', function(evt, data, status, xhr) { $('#comments').after(data); });")

click_link 'New Comment with Attachment'

Expand All @@ -188,7 +188,7 @@

it "escapes html response content properly", js: true do
visit root_path
page.execute_script("$(document).delegate('form', 'ajax:success', function(evt, data, status, xhr) { $('#comments').after(xhr.responseText); });")
page.execute_script("$(document).on('ajax:success', 'form', function(evt, data, status, xhr) { $('#comments').after(xhr.responseText); });")

click_link 'New Comment with Attachment'

Expand All @@ -212,7 +212,7 @@
click_link 'New Comment with Attachment'
# Needed to make test wait for above to finish
input = find('#comment_subject')
page.execute_script("$('#comment_subject').removeAttr('required');")
page.execute_script("$('#comment_subject').prop('required', false);")

file_path = File.join(fixture_path, 'qr.jpg')
fill_in 'comment_body', with: 'there'
Expand Down Expand Up @@ -244,7 +244,7 @@

it "does not submit via remotipart unless file is present", js: true do
visit root_path
page.execute_script("$(document).delegate('form', 'ajax:remotipartSubmit', function() { $('#comments').after('remotipart!'); });")
page.execute_script("$(document).on('ajax:remotipartSubmit', 'form', function() { $('#comments').after('remotipart!'); });")

click_link 'New Comment with Attachment'

Expand All @@ -262,9 +262,9 @@
# Needed to make test wait for above to finish
form = find('form')

page.execute_script("$('form').bind('ajax:beforeSend', function() { $('#comments').after('thebefore'); });")
page.execute_script("$(document).delegate('form', 'ajax:success', function() { $('#comments').after('success'); });")
page.execute_script("$(document).delegate('form', 'ajax:complete', function() { $('#comments').after('complete'); });")
page.execute_script("$('form').on('ajax:beforeSend', function() { $('#comments').after('thebefore'); });")
page.execute_script("$(document).on('ajax:success', 'form', function() { $('#comments').after('success'); });")
page.execute_script("$(document).on('ajax:complete', 'form', function() { $('#comments').after('complete'); });")

file_path = File.join(fixture_path, 'qr.jpg')
fill_in 'comment_subject', with: 'Hi'
Expand All @@ -286,9 +286,9 @@

page.execute_script("$('form').data('type', 'json');")

page.execute_script("$('form').bind('ajax:beforeSend', function() { $('#comments').after('thebefore'); });")
page.execute_script("$(document).delegate('form', 'ajax:success', function() { $('#comments').after('success'); });")
page.execute_script("$(document).delegate('form', 'ajax:complete', function() { $('#comments').after('complete'); });")
page.execute_script("$('form').on('ajax:beforeSend', function() { $('#comments').after('thebefore'); });")
page.execute_script("$(document).on('ajax:success', 'form', function() { $('#comments').after('success'); });")
page.execute_script("$(document).on('ajax:complete', 'form', function() { $('#comments').after('complete'); });")

file_path = File.join(fixture_path, 'qr.jpg')
fill_in 'comment_subject', with: 'Hi'
Expand All @@ -308,7 +308,7 @@
# Needed to make test wait for above to finish
form = find('form')

page.execute_script("$('form').bind('ajax:beforeSend', function() { $('#comments').after('<div class=\"ajax\">ajax!</div>'); });")
page.execute_script("$('form').on('ajax:beforeSend', function() { $('#comments').after('<div class=\"ajax\">ajax!</div>'); });")

file_path = File.join(fixture_path, 'qr.jpg')
fill_in 'comment_subject', with: 'Hi'
Expand All @@ -321,7 +321,7 @@

it "cleans up after itself when uploading files", js: true do
visit root_path
page.execute_script("$(document).delegate('form', 'ajax:remotipartSubmit', function(evt, xhr, data) { if ($(this).data('remotipartSubmitted')) { $('#comments').after('remotipart before!'); } });")
page.execute_script("$(document).on('ajax:remotipartSubmit', 'form', function(evt, xhr, data) { if ($(this).data('remotipartSubmitted')) { $('#comments').after('remotipart before!'); } });")

click_link 'New Comment with Attachment'
page.execute_script("$('form').attr('data-type', 'html');")
Expand All @@ -340,7 +340,7 @@

it "submits via remotipart when a file upload is present", js: true do
visit root_path
page.execute_script("$(document).delegate('form', 'ajax:remotipartSubmit', function(evt, xhr, data) { $('#comments').after('<div class=\"remotipart\">remotipart!</div>'); });")
page.execute_script("$(document).on('ajax:remotipartSubmit', 'form', function(evt, xhr, data) { $('#comments').after('<div class=\"remotipart\">remotipart!</div>'); });")

click_link 'New Comment with Attachment'
page.execute_script("$('form').attr('data-type', 'html');")
Expand All @@ -356,7 +356,7 @@

it "does not submit via remotipart when a file upload is not present", js: true do
visit root_path
page.execute_script("$(document).delegate('form', 'ajax:remotipartSubmit', function(evt, xhr, data) { $('#comments').after('<div class=\"remotipart\">remotipart!</div>'); });")
page.execute_script("$(document).on('ajax:remotipartSubmit', 'form', function(evt, xhr, data) { $('#comments').after('<div class=\"remotipart\">remotipart!</div>'); });")

click_link 'New Comment with Attachment'
page.execute_script("$('form').attr('data-type', 'html');")
Expand All @@ -375,7 +375,7 @@

button = find_button('Create Comment')
# clicking 'Create Comment' button causes capybara evaluation freeze until request ends, so perform check by JavaScript
page.execute_script("$('form').bind('ajax:remotipartComplete', function(data) { window.commitButtonDisabled = $('input[name=\"commit\"]').is(':disabled'); window.commitButtonValue = $('input[name=\"commit\"]').val(); });")
page.execute_script("$('form').on('ajax:remotipartComplete', function(data) { window.commitButtonDisabled = $('input[name=\"commit\"]').is(':disabled'); window.commitButtonValue = $('input[name=\"commit\"]').val(); });")

file_path = File.join(fixture_path, 'qr.jpg')
fill_in 'comment_subject', with: 'Hi'
Expand All @@ -395,7 +395,7 @@
click_link 'New Comment with Attachment'

form = find('form')
page.execute_script("$('form').bind('ajax:remotipartSubmit', function(e, xhr, settings) { $('#comments').after('<div class=\"params\">' + $.param(settings.data) + '</div>'); });")
page.execute_script("$('form').on('ajax:remotipartSubmit', function(e, xhr, settings) { $('#comments').after('<div class=\"params\">' + $.param(settings.data) + '</div>'); });")

file_path = File.join(fixture_path, 'qr.jpg')
fill_in 'comment_subject', with: 'Hi'
Expand Down
8 changes: 4 additions & 4 deletions vendor/assets/javascripts/jquery.iframe-transport.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// jQuery object, or a list of DOM elements containing one or more
// `<input type="file">` elements:

// $("#myform").submit(function() {
// $("#myform").on("submit", function() {
// $.ajax(this.action, {
// files: $(":file", this),
// iframe: true
Expand All @@ -31,7 +31,7 @@
// If you want to include other form fields in the form submission, include
// them in the `data` option, and set the `processData` option to `false`:

// $("#myform").submit(function() {
// $("#myform").on("submit", function() {
// $.ajax(this.action, {
// data: $(":text", this).serializeArray(),
// files: $(":file", this),
Expand Down Expand Up @@ -130,7 +130,7 @@
// (unsupported) conversion from "iframe" to the actual type.
options.dataTypes.shift();

// Use the data from the original AJAX options, as it doesn't seem to be
// Use the data from the original AJAX options, as it doesn't seem to be
// copied over since jQuery 1.7.
// See https://github.com/cmlenz/jquery-iframe-transport/issues/6
options.data = origOptions.data;
Expand Down Expand Up @@ -237,7 +237,7 @@
// aborted.
abort: function() {
if (iframe !== null) {
iframe.unbind("load").attr("src", "about:blank");
iframe.off("load").attr("src", "about:blank");
cleanUp();
}
}
Expand Down
2 changes: 1 addition & 1 deletion vendor/assets/javascripts/jquery.remotipart.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@

teardown: function(form) {
form
.unbind('ajax:beforeSend.remotipart')
.off('ajax:beforeSend.remotipart')
.removeData('remotipartSubmitted')
}
};
Expand Down