From f6471b2d8117de8939b656c0b5e5222d448fbfef Mon Sep 17 00:00:00 2001
From: Evgeniy Sukhanov
Date: Wed, 15 Jun 2016 20:49:40 +0500
Subject: [PATCH 01/12] ready for jQuery 3
---
src/rails.js | 18 +++++++++---------
test/server.rb | 2 +-
2 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/src/rails.js b/src/rails.js
index 9e192a2e..1370a65c 100644
--- a/src/rails.js
+++ b/src/rails.js
@@ -416,15 +416,15 @@
});
});
- $document.delegate(rails.linkDisableSelector, 'ajax:complete', function() {
+ $document.on('ajax:complete', rails.linkDisableSelector, function() {
rails.enableElement($(this));
});
- $document.delegate(rails.buttonDisableSelector, 'ajax:complete', function() {
+ $document.on('ajax:complete', rails.buttonDisableSelector, function() {
rails.enableFormElement($(this));
});
- $document.delegate(rails.linkClickSelector, 'click.rails', function(e) {
+ $document.on('click.rails', rails.linkClickSelector, function(e) {
var link = $(this), method = link.data('method'), data = link.data('params'), metaClick = e.metaKey || e.ctrlKey;
if (!rails.allowAction(link)) return rails.stopEverything(e);
@@ -448,7 +448,7 @@
}
});
- $document.delegate(rails.buttonClickSelector, 'click.rails', function(e) {
+ $document.on('click.rails', rails.buttonClickSelector, function(e) {
var button = $(this);
if (!rails.allowAction(button) || !rails.isRemote(button)) return rails.stopEverything(e);
@@ -465,7 +465,7 @@
return false;
});
- $document.delegate(rails.inputChangeSelector, 'change.rails', function(e) {
+ $document.on('change.rails', rails.inputChangeSelector, function(e) {
var link = $(this);
if (!rails.allowAction(link) || !rails.isRemote(link)) return rails.stopEverything(e);
@@ -473,7 +473,7 @@
return false;
});
- $document.delegate(rails.formSubmitSelector, 'submit.rails', function(e) {
+ $document.on('submit.rails', rails.formSubmitSelector, function(e) {
var form = $(this),
remote = rails.isRemote(form),
blankRequiredInputs,
@@ -518,7 +518,7 @@
}
});
- $document.delegate(rails.formInputClickSelector, 'click.rails', function(event) {
+ $document.on('click.rails', rails.formInputClickSelector, function(event) {
var button = $(this);
if (!rails.allowAction(button)) return rails.stopEverything(event);
@@ -539,11 +539,11 @@
form.data('ujs:submit-button-formmethod', button.attr('formmethod'));
});
- $document.delegate(rails.formSubmitSelector, 'ajax:send.rails', function(event) {
+ $document.on('ajax:send.rails', rails.formSubmitSelector, function(event) {
if (this === event.target) rails.disableFormElements($(this));
});
- $document.delegate(rails.formSubmitSelector, 'ajax:complete.rails', function(event) {
+ $document.on('ajax:complete.rails', rails.formSubmitSelector, function(event) {
if (this === event.target) rails.enableFormElements($(this));
});
diff --git a/test/server.rb b/test/server.rb
index 85f11db2..db94368a 100644
--- a/test/server.rb
+++ b/test/server.rb
@@ -1,7 +1,7 @@
require 'sinatra'
require 'json'
-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 2.0.0 2.1.0].freeze
+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 2.0.0 2.1.0 3.0.0].freeze
use Rack::Static, :urls => ["/src"], :root => File.expand_path('..', settings.root)
From baccefdb5674d0d8964f3c93f5265a7d2db3a601 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?=
Date: Wed, 3 Aug 2016 04:59:25 -0300
Subject: [PATCH 02/12] Add package.json to release jquery-ujs in npm.
---
package.json | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
create mode 100644 package.json
diff --git a/package.json b/package.json
new file mode 100644
index 00000000..fcebfa56
--- /dev/null
+++ b/package.json
@@ -0,0 +1,29 @@
+{
+ "name": "jquery-ujs",
+ "version": "1.2.1",
+ "description": "Unobtrusive scripting adapter for jQuery",
+ "main": "src/rails.js",
+ "directories": {
+ "test": "test"
+ },
+ "scripts": {
+ "test": "echo \"See the wiki: https://github.com/rails/jquery-ujs/wiki/Running-Tests-and-Contributing\" && exit 1",
+ "postversion": "git push && git push --tags && npm publish"
+ },
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/rails/jquery-ujs.git"
+ },
+ "author": [
+ "Stephen St. Martin",
+ "Steve Schwartz"
+ ],
+ "license": "MIT",
+ "bugs": {
+ "url": "https://github.com/rails/jquery-ujs/issues"
+ },
+ "homepage": "https://github.com/rails/jquery-ujs#readme",
+ "dependencies": {
+ "jquery": ">=1.8.0"
+ }
+}
From 26c9c77fb6f769fbfd7d321319c5780be2f90872 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?=
Date: Wed, 3 Aug 2016 05:23:39 -0300
Subject: [PATCH 03/12] Add instructions about npm
---
README.md | 5 +++++
RELEASE.md | 23 +++++++++++++++++++++++
2 files changed, 28 insertions(+)
create mode 100644 RELEASE.md
diff --git a/README.md b/README.md
index a9fd2ab4..df6aee68 100644
--- a/README.md
+++ b/README.md
@@ -42,6 +42,11 @@ Require both `jquery` and `jquery_ujs` into your application.js manifest.
//= require jquery_ujs
```
+Installation using npm.
+------------
+
+Run `npm install --save jquery-ujs` to install the jquery-ujs package.
+
Installation using Bower
------------
diff --git a/RELEASE.md b/RELEASE.md
new file mode 100644
index 00000000..59316f77
--- /dev/null
+++ b/RELEASE.md
@@ -0,0 +1,23 @@
+## Releasing jquery-ujs
+
+### Releasing to npm
+
+Make sure npm's configuration `sign-git-tag` is set to true.
+
+```
+npm config set sign-git-tag true
+```
+
+Release it to npm using the [npm version command](https://docs.npmjs.com/cli/version). Like:
+
+```
+npm version patch
+```
+
+This will:
+
+* Bump a patch version
+* Commit the change
+* Generate the tag
+* Push the commit and the tag to the repository
+* Publish the package in https://www.npmjs.com
From 33ba167d25f4e3ff696d7fec39fea24935811b77 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?=
Date: Fri, 19 Aug 2016 13:20:32 -0300
Subject: [PATCH 04/12] Ignore Ruby files in the npm generated package
---
.npmignore | 4 ++++
package.json | 3 ---
2 files changed, 4 insertions(+), 3 deletions(-)
create mode 100644 .npmignore
diff --git a/.npmignore b/.npmignore
new file mode 100644
index 00000000..3af83847
--- /dev/null
+++ b/.npmignore
@@ -0,0 +1,4 @@
+script/
+test/
+Rakefile
+Gemfile*
diff --git a/package.json b/package.json
index fcebfa56..67ca7a12 100644
--- a/package.json
+++ b/package.json
@@ -3,9 +3,6 @@
"version": "1.2.1",
"description": "Unobtrusive scripting adapter for jQuery",
"main": "src/rails.js",
- "directories": {
- "test": "test"
- },
"scripts": {
"test": "echo \"See the wiki: https://github.com/rails/jquery-ujs/wiki/Running-Tests-and-Contributing\" && exit 1",
"postversion": "git push && git push --tags && npm publish"
From a4da3b4909b2ca081de3c6f99064403623bfe1fb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?=
Date: Fri, 19 Aug 2016 13:26:52 -0300
Subject: [PATCH 05/12] 1.2.2
---
package.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/package.json b/package.json
index 67ca7a12..08a5a245 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "jquery-ujs",
- "version": "1.2.1",
+ "version": "1.2.2",
"description": "Unobtrusive scripting adapter for jQuery",
"main": "src/rails.js",
"scripts": {
From 267b70d8a15514b084627aac6facd5bbdca8dd20 Mon Sep 17 00:00:00 2001
From: Sergey
Date: Fri, 30 Dec 2016 14:08:12 +0800
Subject: [PATCH 06/12] Allow to init Jquery UJS manually
---
src/rails.js | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
diff --git a/src/rails.js b/src/rails.js
index 1370a65c..e5f581fd 100644
--- a/src/rails.js
+++ b/src/rails.js
@@ -1,4 +1,4 @@
-(function($, undefined) {
+/* jshint node: true */
/**
* Unobtrusive scripting adapter for jQuery
@@ -10,10 +10,13 @@
*
*/
- // Cut down on the number of issues from people inadvertently including jquery_ujs twice
- // by detecting and raising an error when it happens.
+(function() {
'use strict';
+ var jqueryUjsInit = function($, undefined) {
+
+ // Cut down on the number of issues from people inadvertently including jquery_ujs twice
+ // by detecting and raising an error when it happens.
if ( $.rails !== undefined ) {
$.error('jquery-ujs has already been loaded!');
}
@@ -552,4 +555,11 @@
});
}
-})( jQuery );
+ };
+
+ if (window.jQuery) {
+ jqueryUjsInit(jQuery);
+ } else if (typeof exports === 'object' && typeof module === 'object') {
+ module.exports = jqueryUjsInit;
+ }
+})();
From 3bff9e049afcb38191c6eb470062b9e51f46e535 Mon Sep 17 00:00:00 2001
From: aki
Date: Fri, 14 Apr 2017 15:19:59 +0900
Subject: [PATCH 07/12] Use jQuery.fn.on instead of jQuery.fn.bind
---
src/rails.js | 4 +-
test/public/test/call-remote-callbacks.js | 114 +++++++++++-----------
test/public/test/call-remote.js | 18 ++--
test/public/test/data-confirm.js | 40 ++++----
test/public/test/data-disable-with.js | 44 ++++-----
test/public/test/data-disable.js | 38 ++++----
test/public/test/data-method.js | 4 +-
test/public/test/data-remote.js | 64 ++++++------
test/public/test/settings.js | 2 +-
test/views/layout.erb | 2 +-
10 files changed, 165 insertions(+), 165 deletions(-)
diff --git a/src/rails.js b/src/rails.js
index 1370a65c..7eee3906 100644
--- a/src/rails.js
+++ b/src/rails.js
@@ -372,7 +372,7 @@
element.html(replacement);
}
- element.bind('click.railsDisable', function(e) { // prevent further clicking
+ element.on('click.railsDisable', function(e) { // prevent further clicking
return rails.stopEverything(e);
});
element.data('ujs:disabled', true);
@@ -384,7 +384,7 @@
element.html(element.data('ujs:enable-with')); // set to old enabled state
element.removeData('ujs:enable-with'); // clean up cache
}
- element.unbind('click.railsDisable'); // enable element
+ element.off('click.railsDisable'); // enable element
element.removeData('ujs:disabled');
}
};
diff --git a/test/public/test/call-remote-callbacks.js b/test/public/test/call-remote-callbacks.js
index e7ee0dab..35926202 100644
--- a/test/public/test/call-remote-callbacks.js
+++ b/test/public/test/call-remote-callbacks.js
@@ -12,13 +12,13 @@ module('call-remote-callbacks', {
$(document).undelegate('form[data-remote]', 'ajax:send');
$(document).undelegate('form[data-remote]', 'ajax:complete');
$(document).undelegate('form[data-remote]', 'ajax:success');
- $(document).unbind('ajaxStop');
- $(document).unbind('iframe:loading');
+ $(document).off('ajaxStop');
+ $(document).off('iframe:loading');
}
});
function start_after_submit(form) {
- form.bind('ajax:complete', function() {
+ form.on('ajax:complete', function() {
ok(true, 'ajax:complete');
start();
});
@@ -43,7 +43,7 @@ asyncTest('modifying form fields with "ajax:before" sends modified data in reque
$('form[data-remote]')
.append($(''))
.append($(''))
- .bind('ajax:before', function() {
+ .on('ajax:before', function() {
var form = $(this);
form
.append($('',{name: 'other_user_name',value: 'jonathan'}))
@@ -53,7 +53,7 @@ asyncTest('modifying form fields with "ajax:before" sends modified data in reque
});
submit(function(form) {
- form.bind('ajax:success', function(e, data, status, xhr) {
+ form.on('ajax:success', function(e, data, status, xhr) {
equal(data.params.user_name, 'steve', 'modified field value should have been submitted');
equal(data.params.other_user_name, 'jonathan', 'added field value should have been submitted');
equal(data.params.removed_user_name, undefined, 'removed field value should be undefined');
@@ -63,13 +63,13 @@ asyncTest('modifying form fields with "ajax:before" sends modified data in reque
asyncTest('modifying data("type") with "ajax:before" requests new dataType in request', 2, function(){
$('form[data-remote]').data('type','html')
- .bind('ajax:before', function() {
+ .on('ajax:before', function() {
var form = $(this);
form.data('type','xml');
});
submit(function(form) {
- form.bind('ajax:beforeSend', function(e, xhr, settings) {
+ form.on('ajax:beforeSend', function(e, xhr, settings) {
equal(settings.dataType, 'xml', 'modified dataType should have been requested');
});
});
@@ -77,13 +77,13 @@ asyncTest('modifying data("type") with "ajax:before" requests new dataType in re
asyncTest('setting data("with-credentials",true) with "ajax:before" uses new setting in request', 2, function(){
$('form[data-remote]').data('with-credentials',false)
- .bind('ajax:before', function() {
+ .on('ajax:before', function() {
var form = $(this);
form.data('with-credentials',true);
});
submit(function(form) {
- form.bind('ajax:beforeSend', function(e, xhr, settings) {
+ form.on('ajax:beforeSend', function(e, xhr, settings) {
equal(settings.xhrFields && settings.xhrFields.withCredentials, true, 'setting modified in ajax:before should have forced withCredentials request');
});
});
@@ -91,37 +91,37 @@ asyncTest('setting data("with-credentials",true) with "ajax:before" uses new set
asyncTest('stopping the "ajax:beforeSend" event aborts the request', 1, function() {
submit(function(form) {
- form.bind('ajax:beforeSend', function() {
+ form.on('ajax:beforeSend', function() {
ok(true, 'aborting request in ajax:beforeSend');
return false;
});
- form.unbind('ajax:send').bind('ajax:send', function() {
+ form.off('ajax:send').on('ajax:send', function() {
ok(false, 'ajax:send should not run');
});
- form.unbind('ajax:complete').bind('ajax:complete', function() {
+ form.off('ajax:complete').on('ajax:complete', function() {
ok(false, 'ajax:complete should not run');
});
- form.bind('ajax:error', function(e, xhr, status, error) {
+ form.on('ajax:error', function(e, xhr, status, error) {
ok(false, 'ajax:error should not run');
});
- $(document).bind('ajaxStop', function() {
+ $(document).on('ajaxStop', function() {
start();
});
});
});
asyncTest('blank required form input field should abort request and trigger "ajax:aborted:required" event', 5, function() {
- $(document).bind('iframe:loading', function() {
+ $(document).on('iframe:loading', function() {
ok(false, 'form should not get submitted');
});
var form = $('form[data-remote]')
.append($(''))
.append($(''))
- .bind('ajax:beforeSend', function() {
+ .on('ajax:beforeSend', function() {
ok(false, 'ajax:beforeSend should not run');
})
- .bind('ajax:aborted:required', function(e,data){
+ .on('ajax:aborted:required', function(e,data){
ok(data.length == 2, 'ajax:aborted:required event is passed all blank required inputs (jQuery objects)');
ok(data.first().is('input[name="user_name"]') , 'ajax:aborted:required adds blank required input to data');
ok(data.last().is('textarea[name="user_bio"]'), 'ajax:aborted:required adds blank required textarea to data');
@@ -131,7 +131,7 @@ asyncTest('blank required form input field should abort request and trigger "aja
setTimeout(function() {
form.find('input[required],textarea[required]').val('Tyler');
- form.unbind('ajax:beforeSend');
+ form.off('ajax:beforeSend');
submit();
}, 13);
});
@@ -140,7 +140,7 @@ asyncTest('blank required form input for non-remote form should abort normal sub
var form = $('form[data-remote]')
.append($(''))
.removeAttr('data-remote')
- .bind('ujs:everythingStopped', function() {
+ .on('ujs:everythingStopped', function() {
ok(true, 'ujs:everythingStopped should run');
})
.trigger('submit');
@@ -153,10 +153,10 @@ asyncTest('blank required form input for non-remote form should abort normal sub
asyncTest('form should be submitted with blank required fields if handler is bound to "ajax:aborted:required" event that returns false', 1, function(){
var form = $('form[data-remote]')
.append($(''))
- .bind('ajax:beforeSend', function() {
+ .on('ajax:beforeSend', function() {
ok(true, 'ajax:beforeSend should run');
})
- .bind('ajax:aborted:required', function() {
+ .on('ajax:aborted:required', function() {
return false;
})
.trigger('submit');
@@ -170,10 +170,10 @@ asyncTest('disabled fields should not be included in blank required check', 2, f
var form = $('form[data-remote]')
.append($(''))
.append($(''))
- .bind('ajax:beforeSend', function() {
+ .on('ajax:beforeSend', function() {
ok(true, 'ajax:beforeSend should run');
})
- .bind('ajax:aborted:required', function() {
+ .on('ajax:aborted:required', function() {
ok(false, 'ajax:aborted:required should not run');
});
@@ -184,10 +184,10 @@ asyncTest('form should be submitted with blank required fields if it has the "no
var form = $('form[data-remote]')
.append($(''))
.attr("novalidate", "novalidate")
- .bind('ajax:beforeSend', function() {
+ .on('ajax:beforeSend', function() {
ok(true, 'ajax:beforeSend should run');
})
- .bind('ajax:aborted:required', function() {
+ .on('ajax:aborted:required', function() {
ok(false, 'ajax:aborted:required should not run');
});
@@ -199,10 +199,10 @@ asyncTest('form should be submitted with blank required fields if the button has
var form = $('form[data-remote]')
.append($(''))
.append(submit_button)
- .bind('ajax:beforeSend', function() {
+ .on('ajax:beforeSend', function() {
ok(true, 'ajax:beforeSend should run');
})
- .bind('ajax:aborted:required', function() {
+ .on('ajax:aborted:required', function() {
ok(false, 'ajax:aborted:required should not run');
});
@@ -210,7 +210,7 @@ asyncTest('form should be submitted with blank required fields if the button has
});
asyncTest('blank required form input for non-remote form with "novalidate" attribute should not abort normal submission', 1, function() {
- $(document).bind('iframe:loading', function() {
+ $(document).on('iframe:loading', function() {
ok(true, 'form should get submitted');
});
@@ -229,7 +229,7 @@ asyncTest('unchecked required checkbox should abort form submission', 1, functio
var form = $('form[data-remote]')
.append($(''))
.removeAttr('data-remote')
- .bind('ujs:everythingStopped', function() {
+ .on('ujs:everythingStopped', function() {
ok(true, 'ujs:everythingStopped should run');
})
.trigger('submit');
@@ -244,7 +244,7 @@ asyncTest('unchecked required radio should abort form submission', 1, function()
.append($(''))
.append($(''))
.removeAttr('data-remote')
- .bind('ujs:everythingStopped', function() {
+ .on('ujs:everythingStopped', function() {
ok(true, 'ujs:everythingStopped should run');
})
.trigger('submit');
@@ -255,7 +255,7 @@ asyncTest('unchecked required radio should abort form submission', 1, function()
});
asyncTest('required radio should only require one to be checked', 1, function() {
- $(document).bind('iframe:loading', function() {
+ $(document).on('iframe:loading', function() {
ok(true, 'form should get submitted');
});
@@ -263,7 +263,7 @@ asyncTest('required radio should only require one to be checked', 1, function()
.append($(''))
.append($(''))
.removeAttr('data-remote')
- .bind('ujs:everythingStopped', function() {
+ .on('ujs:everythingStopped', function() {
ok(false, 'ujs:everythingStopped should not run');
})
.find('#checkme').prop('checked', true)
@@ -276,7 +276,7 @@ asyncTest('required radio should only require one to be checked', 1, function()
});
asyncTest('required radio should only require one to be checked if not all radios are required', 1, function() {
- $(document).bind('iframe:loading', function() {
+ $(document).on('iframe:loading', function() {
ok(true, 'form should get submitted');
});
@@ -288,7 +288,7 @@ asyncTest('required radio should only require one to be checked if not all radio
// Only one needs to be required
.append($(''))
.removeAttr('data-remote')
- .bind('ujs:everythingStopped', function() {
+ .on('ujs:everythingStopped', function() {
ok(false, 'ujs:everythingStopped should not run');
})
.find('#checkme').prop('checked', true)
@@ -307,13 +307,13 @@ function skipIt() {
asyncTest('non-blank file form input field should abort remote request, but submit normally', 5, function() {
var form = $('form[data-remote]')
.append($(''))
- .bind('ajax:beforeSend', function() {
+ .on('ajax:beforeSend', function() {
ok(false, 'ajax:beforeSend should not run');
})
- .bind('iframe:loading', function() {
+ .on('iframe:loading', function() {
ok(true, 'form should get submitted');
})
- .bind('ajax:aborted:file', function(e,data) {
+ .on('ajax:aborted:file', function(e,data) {
ok(data.length == 1, 'ajax:aborted:file event is passed all non-blank file inputs (jQuery objects)');
ok(data.first().is('input[name="attachment"]') , 'ajax:aborted:file adds non-blank file input to data');
ok(true, 'ajax:aborted:file event should run');
@@ -322,7 +322,7 @@ function skipIt() {
setTimeout(function() {
form.find('input[type="file"]').val('');
- form.unbind('ajax:beforeSend');
+ form.off('ajax:beforeSend');
submit();
}, 13);
});
@@ -330,20 +330,20 @@ function skipIt() {
asyncTest('file form input field should not abort remote request if file form input does not have a name attribute', 5, function() {
var form = $('form[data-remote]')
.append($(''))
- .bind('ajax:beforeSend', function() {
+ .on('ajax:beforeSend', function() {
ok(true, 'ajax:beforeSend should run');
})
- .bind('iframe:loading', function() {
+ .on('iframe:loading', function() {
ok(true, 'form should get submitted');
})
- .bind('ajax:aborted:file', function(e,data) {
+ .on('ajax:aborted:file', function(e,data) {
ok(false, 'ajax:aborted:file should not run');
})
.trigger('submit');
setTimeout(function() {
form.find('input[type="file"]').val('');
- form.unbind('ajax:beforeSend');
+ form.off('ajax:beforeSend');
submit();
}, 13);
});
@@ -351,20 +351,20 @@ function skipIt() {
asyncTest('blank file input field should abort request entirely if handler bound to "ajax:aborted:file" event that returns false', 1, function() {
var form = $('form[data-remote]')
.append($(''))
- .bind('ajax:beforeSend', function() {
+ .on('ajax:beforeSend', function() {
ok(false, 'ajax:beforeSend should not run');
})
- .bind('iframe:loading', function() {
+ .on('iframe:loading', function() {
ok(false, 'form should not get submitted');
})
- .bind('ajax:aborted:file', function() {
+ .on('ajax:aborted:file', function() {
return false;
})
.trigger('submit');
setTimeout(function() {
form.find('input[type="file"]').val('');
- form.unbind('ajax:beforeSend');
+ form.off('ajax:beforeSend');
submit();
}, 13);
});
@@ -377,13 +377,13 @@ asyncTest('"ajax:beforeSend" can be observed and stopped with event delegation',
});
submit(function(form) {
- form.unbind('ajax:send').bind('ajax:send', function() {
+ form.off('ajax:send').on('ajax:send', function() {
ok(false, 'ajax:send should not run');
});
- form.unbind('ajax:complete').bind('ajax:complete', function() {
+ form.off('ajax:complete').on('ajax:complete', function() {
ok(false, 'ajax:complete should not run');
});
- $(document).bind('ajaxStop', function() {
+ $(document).on('ajaxStop', function() {
start();
});
});
@@ -391,19 +391,19 @@ asyncTest('"ajax:beforeSend" can be observed and stopped with event delegation',
asyncTest('"ajax:beforeSend", "ajax:send", "ajax:success" and "ajax:complete" are triggered', 9, function() {
submit(function(form) {
- form.bind('ajax:beforeSend', function(e, xhr, settings) {
+ form.on('ajax:beforeSend', function(e, xhr, settings) {
ok(xhr.setRequestHeader, 'first argument to "ajax:beforeSend" should be an XHR object');
equal(settings.url, '/echo', 'second argument to "ajax:beforeSend" should be a settings object');
});
- form.bind('ajax:send', function(e, xhr) {
+ form.on('ajax:send', function(e, xhr) {
ok(xhr.abort, 'first argument to "ajax:send" should be an XHR object');
});
- form.bind('ajax:success', function(e, data, status, xhr) {
+ form.on('ajax:success', function(e, data, status, xhr) {
ok(data.REQUEST_METHOD, 'first argument to ajax:success should be a data object');
equal(status, 'success', 'second argument to ajax:success should be a status string');
ok(xhr.getResponseHeader, 'third argument to "ajax:success" should be an XHR object');
});
- form.bind('ajax:complete', function(e, xhr, status) {
+ form.on('ajax:complete', function(e, xhr, status) {
ok(xhr.getResponseHeader, 'first argument to "ajax:complete" should be an XHR object');
equal(status, 'success', 'second argument to ajax:complete should be a status string');
});
@@ -414,9 +414,9 @@ if(window.phantom !== undefined) {
asyncTest('"ajax:beforeSend", "ajax:send", "ajax:error" and "ajax:complete" are triggered on error', 7, function() {
submit(function(form) {
form.attr('action', '/error');
- form.bind('ajax:beforeSend', function(arg) { ok(true, 'ajax:beforeSend') });
- form.bind('ajax:send', function(arg) { ok(true, 'ajax:send') });
- form.bind('ajax:error', function(e, xhr, status, error) {
+ form.on('ajax:beforeSend', function(arg) { ok(true, 'ajax:beforeSend') });
+ form.on('ajax:send', function(arg) { ok(true, 'ajax:send') });
+ form.on('ajax:error', function(e, xhr, status, error) {
ok(xhr.getResponseHeader, 'first argument to "ajax:error" should be an XHR object');
equal(status, 'error', 'second argument to ajax:error should be a status string');
// Firefox 8 returns "Forbidden " with trailing space
@@ -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]')
- .bind('ajax:send', function(e, xhr) {
+ .on('ajax:send', function(e, xhr) {
ok(true, 'event should fire');
equal(typeof(xhr.abort), 'function', 'event should pass jqXHR object');
xhr.abort();
diff --git a/test/public/test/call-remote.js b/test/public/test/call-remote.js
index 2a6e3a61..0d9214a0 100644
--- a/test/public/test/call-remote.js
+++ b/test/public/test/call-remote.js
@@ -11,8 +11,8 @@ module('call-remote');
function submit(fn) {
$('form')
- .bind('ajax:success', fn)
- .bind('ajax:complete', function() { start() })
+ .on('ajax:success', fn)
+ .on('ajax:complete', function() { start() })
.trigger('submit');
}
@@ -37,10 +37,10 @@ asyncTest('form method is read from submit button "formmethod" if submit is trig
buildForm({ method: 'post' });
$('#qunit-fixture').find('form').append(submitButton)
- .bind('ajax:success', function(e, data, status, xhr) {
+ .on('ajax:success', function(e, data, status, xhr) {
App.assertGetRequest(data);
})
- .bind('ajax:complete', function() { start() });
+ .on('ajax:complete', function() { start() });
submitButton.trigger('click');
});
@@ -74,10 +74,10 @@ asyncTest('form url is read from submit button "formaction" if submit is trigger
buildForm({ method: 'post', href: '/echo2' });
$('#qunit-fixture').find('form').append(submitButton)
- .bind('ajax:success', function(e, data, status, xhr) {
+ .on('ajax:success', function(e, data, status, xhr) {
App.assertRequestPath(data, '/echo');
})
- .bind('ajax:complete', function() { start() });
+ .on('ajax:complete', function() { start() });
submitButton.trigger('click');
});
@@ -113,7 +113,7 @@ asyncTest('allow empty form "action"', 1, function() {
buildForm({ action: '' });
$('#qunit-fixture').find('form')
- .bind('ajax:beforeSend', function(e, xhr, settings) {
+ .on('ajax:beforeSend', function(e, xhr, settings) {
// Get current location (the same way jQuery does)
try {
currentLocation = location.href;
@@ -155,7 +155,7 @@ asyncTest('intelligently guesses crossDomain behavior when target URL has a diff
$('#qunit-fixture').append('');
$('#qunit-fixture').find('form')
- .bind('ajax:beforeSend', function(e, xhr, settings) {
+ .on('ajax:beforeSend', function(e, xhr, settings) {
equal(settings.crossDomain, true, 'crossDomain should be set to true');
@@ -174,7 +174,7 @@ asyncTest('intelligently guesses crossDomain behavior when target URL consists o
$('#qunit-fixture').append('');
$('#qunit-fixture').find('form')
- .bind('ajax:beforeSend', function(e, xhr, settings) {
+ .on('ajax:beforeSend', function(e, xhr, settings) {
equal(settings.crossDomain, false, 'crossDomain should be set to false');
diff --git a/test/public/test/data-confirm.js b/test/public/test/data-confirm.js
index 8add713c..2e905d42 100644
--- a/test/public/test/data-confirm.js
+++ b/test/public/test/data-confirm.js
@@ -39,11 +39,11 @@ asyncTest('clicking on a link with data-confirm attribute. Confirm yes.', 6, fun
window.confirm = function(msg) { message = msg; return true };
$('a[data-confirm]')
- .bind('confirm:complete', function(e, data) {
+ .on('confirm:complete', function(e, data) {
App.assertCallbackInvoked('confirm:complete');
ok(data == true, 'confirm:complete passes in confirm answer (true)');
})
- .bind('ajax:success', function(e, data, status, xhr) {
+ .on('ajax:success', function(e, data, status, xhr) {
App.assertCallbackInvoked('ajax:success');
App.assertRequestPath(data, '/echo');
App.assertGetRequest(data);
@@ -60,11 +60,11 @@ asyncTest('clicking on a button with data-confirm attribute. Confirm yes.', 6, f
window.confirm = function(msg) { message = msg; return true };
$('button[data-confirm]')
- .bind('confirm:complete', function(e, data) {
+ .on('confirm:complete', function(e, data) {
App.assertCallbackInvoked('confirm:complete');
ok(data == true, 'confirm:complete passes in confirm answer (true)');
})
- .bind('ajax:success', function(e, data, status, xhr) {
+ .on('ajax:success', function(e, data, status, xhr) {
App.assertCallbackInvoked('ajax:success');
App.assertRequestPath(data, '/echo');
App.assertGetRequest(data);
@@ -81,11 +81,11 @@ asyncTest('clicking on a link with data-confirm attribute. Confirm No.', 3, func
window.confirm = function(msg) { message = msg; return false };
$('a[data-confirm]')
- .bind('confirm:complete', function(e, data) {
+ .on('confirm:complete', function(e, data) {
App.assertCallbackInvoked('confirm:complete');
ok(data == false, 'confirm:complete passes in confirm answer (false)');
})
- .bind('ajax:beforeSend', function(e, data, status, xhr) {
+ .on('ajax:beforeSend', function(e, data, status, xhr) {
App.assertCallbackNotInvoked('ajax:beforeSend');
})
.trigger('click');
@@ -102,11 +102,11 @@ asyncTest('clicking on a button with data-confirm attribute. Confirm No.', 3, fu
window.confirm = function(msg) { message = msg; return false };
$('button[data-confirm]')
- .bind('confirm:complete', function(e, data) {
+ .on('confirm:complete', function(e, data) {
App.assertCallbackInvoked('confirm:complete');
ok(data == false, 'confirm:complete passes in confirm answer (false)');
})
- .bind('ajax:beforeSend', function(e, data, status, xhr) {
+ .on('ajax:beforeSend', function(e, data, status, xhr) {
App.assertCallbackNotInvoked('ajax:beforeSend');
})
.trigger('click');
@@ -123,11 +123,11 @@ asyncTest('clicking on a button with data-confirm attribute. Confirm error.', 3,
window.confirm = function(msg) { message = msg; throw "some random error"; };
$('button[data-confirm]')
- .bind('confirm:complete', function(e, data) {
+ .on('confirm:complete', function(e, data) {
App.assertCallbackInvoked('confirm:complete');
ok(data == false, 'confirm:complete passes in confirm answer (false)');
})
- .bind('ajax:beforeSend', function(e, data, status, xhr) {
+ .on('ajax:beforeSend', function(e, data, status, xhr) {
App.assertCallbackNotInvoked('ajax:beforeSend');
})
.trigger('click');
@@ -144,11 +144,11 @@ asyncTest('clicking on a submit button with form and data-confirm attributes. Co
window.confirm = function(msg) { message = msg; return false };
$('input[type=submit][form]')
- .bind('confirm:complete', function(e, data) {
+ .on('confirm:complete', function(e, data) {
App.assertCallbackInvoked('confirm:complete');
ok(data == false, 'confirm:complete passes in confirm answer (false)');
})
- .bind('ajax:beforeSend', function(e, data, status, xhr) {
+ .on('ajax:beforeSend', function(e, data, status, xhr) {
App.assertCallbackNotInvoked('ajax:beforeSend');
})
.trigger('click');
@@ -166,11 +166,11 @@ asyncTest('binding to confirm event of a link and returning false', 1, function(
};
$('a[data-confirm]')
- .bind('confirm', function() {
+ .on('confirm', function() {
App.assertCallbackInvoked('confirm');
return false;
})
- .bind('confirm:complete', function() {
+ .on('confirm:complete', function() {
App.assertCallbackNotInvoked('confirm:complete');
})
.trigger('click');
@@ -187,11 +187,11 @@ asyncTest('binding to confirm event of a button and returning false', 1, functio
};
$('button[data-confirm]')
- .bind('confirm', function() {
+ .on('confirm', function() {
App.assertCallbackInvoked('confirm');
return false;
})
- .bind('confirm:complete', function() {
+ .on('confirm:complete', function() {
App.assertCallbackNotInvoked('confirm:complete');
})
.trigger('click');
@@ -209,11 +209,11 @@ asyncTest('binding to confirm:complete event of a link and returning false', 2,
};
$('a[data-confirm]')
- .bind('confirm:complete', function() {
+ .on('confirm:complete', function() {
App.assertCallbackInvoked('confirm:complete');
return false;
})
- .bind('ajax:beforeSend', function() {
+ .on('ajax:beforeSend', function() {
App.assertCallbackNotInvoked('ajax:beforeSend');
})
.trigger('click');
@@ -231,11 +231,11 @@ asyncTest('binding to confirm:complete event of a button and returning false', 2
};
$('button[data-confirm]')
- .bind('confirm:complete', function() {
+ .on('confirm:complete', function() {
App.assertCallbackInvoked('confirm:complete');
return false;
})
- .bind('ajax:beforeSend', function() {
+ .on('ajax:beforeSend', function() {
App.assertCallbackNotInvoked('ajax:beforeSend');
})
.trigger('click');
diff --git a/test/public/test/data-disable-with.js b/test/public/test/data-disable-with.js
index 0366f81e..1bb67426 100644
--- a/test/public/test/data-disable-with.js
+++ b/test/public/test/data-disable-with.js
@@ -40,7 +40,7 @@ module('data-disable-with', {
}));
},
teardown: function() {
- $(document).unbind('iframe:loaded');
+ $(document).off('iframe:loaded');
}
});
@@ -49,7 +49,7 @@ asyncTest('form input field with "data-disable-with" attribute', 7, function() {
App.checkEnabledState(input, 'john');
- form.bind('ajax:success', function(e, data) {
+ form.on('ajax:success', function(e, data) {
setTimeout(function() {
App.checkEnabledState(input, 'john');
equal(data.params.user_name, 'john');
@@ -67,7 +67,7 @@ asyncTest('blank form input field with "data-disable-with" attribute', 7, functi
input.val('');
App.checkEnabledState(input, '');
- form.bind('ajax:success', function(e, data) {
+ form.on('ajax:success', function(e, data) {
setTimeout(function() {
App.checkEnabledState(input, '');
equal(data.params.user_name, '');
@@ -85,7 +85,7 @@ asyncTest('form button with "data-disable-with" attribute', 6, function() {
App.checkEnabledState(button, 'Submit');
- form.bind('ajax:success', function(e, data) {
+ form.on('ajax:success', function(e, data) {
setTimeout(function() {
App.checkEnabledState(button, 'Submit');
start();
@@ -102,9 +102,9 @@ asyncTest('form input[type=submit][data-disable-with] disables', 6, function(){
App.checkEnabledState(input, 'Submit');
// WEEIRDD: attaching this handler makes the test work in IE7
- $(document).bind('iframe:loading', function(e, form) {});
+ $(document).on('iframe:loading', function(e, form) {});
- $(document).bind('iframe:loaded', function(e, data) {
+ $(document).on('iframe:loaded', function(e, data) {
setTimeout(function() {
App.checkDisabledState(input, 'submitting ...');
start();
@@ -138,7 +138,7 @@ test('form input[type=submit][data-disable-with] re-enables when `pageshow` even
asyncTest('form[data-remote] input[type=submit][data-disable-with] is replaced in ajax callback', 2, function(){
var form = $('form:not([data-remote])').attr('data-remote', 'true'), origFormContents = form.html();
- form.bind('ajax:success', function(){
+ form.on('ajax:success', function(){
form.html(origFormContents);
setTimeout(function(){
@@ -153,7 +153,7 @@ asyncTest('form[data-remote] input[data-disable-with] is replaced with disabled
var form = $('form:not([data-remote])').attr('data-remote', 'true'), input = form.find('input[type=submit]'),
newDisabledInput = input.clone().attr('disabled', 'disabled');
- form.bind('ajax:success', function(){
+ form.on('ajax:success', function(){
input.replaceWith(newDisabledInput);
setTimeout(function(){
@@ -168,9 +168,9 @@ asyncTest('form input[type=submit][data-disable-with] using "form" attribute dis
App.checkEnabledState(input, 'Form Attr Submit');
// WEEIRDD: attaching this handler makes the test work in IE7
- $(document).bind('iframe:loading', function(e, form) {});
+ $(document).on('iframe:loading', function(e, form) {});
- $(document).bind('iframe:loaded', function(e, data) {
+ $(document).on('iframe:loaded', function(e, data) {
setTimeout(function() {
App.checkDisabledState(input, 'form attr submitting');
start();
@@ -188,7 +188,7 @@ asyncTest('form[data-remote] textarea[data-disable-with] attribute', 3, function
var form = $('form[data-remote]'),
textarea = $('').appendTo(form);
- form.bind('ajax:success', function(e, data) {
+ form.on('ajax:success', function(e, data) {
setTimeout(function() {
equal(data.params.user_bio, 'born, lived, died.');
start();
@@ -227,10 +227,10 @@ asyncTest('a[data-remote][data-disable-with] disables and re-enables', 6, functi
App.checkEnabledState(link, 'Click me');
link
- .bind('ajax:beforeSend', function() {
+ .on('ajax:beforeSend', function() {
App.checkDisabledState(link, 'clicking...');
})
- .bind('ajax:complete', function() {
+ .on('ajax:complete', function() {
setTimeout( function() {
App.checkEnabledState(link, 'Click me');
start();
@@ -245,7 +245,7 @@ asyncTest('a[data-remote][data-disable-with] re-enables when `ajax:before` event
App.checkEnabledState(link, 'Click me');
link
- .bind('ajax:before', function() {
+ .on('ajax:before', function() {
App.checkDisabledState(link, 'clicking...');
return false;
})
@@ -263,7 +263,7 @@ asyncTest('a[data-remote][data-disable-with] re-enables when `ajax:beforeSend` e
App.checkEnabledState(link, 'Click me');
link
- .bind('ajax:beforeSend', function() {
+ .on('ajax:beforeSend', function() {
App.checkDisabledState(link, 'clicking...');
return false;
})
@@ -281,7 +281,7 @@ asyncTest('a[data-remote][data-disable-with] re-enables when `ajax:error` event
App.checkEnabledState(link, 'Click me');
link
- .bind('ajax:beforeSend', function() {
+ .on('ajax:beforeSend', function() {
App.checkDisabledState(link, 'clicking...');
})
.trigger('click');
@@ -300,7 +300,7 @@ asyncTest('form[data-remote] input|button|textarea[data-disable-with] does not d
submit = $('').appendTo(form);
form
- .bind('ajax:beforeSend', function() {
+ .on('ajax:beforeSend', function() {
return false;
})
.trigger('submit');
@@ -337,10 +337,10 @@ asyncTest('button[data-remote][data-disable-with] disables and re-enables', 6, f
App.checkEnabledState(button, 'Click me');
button
- .bind('ajax:send', function() {
+ .on('ajax:send', function() {
App.checkDisabledState(button, 'clicking...');
})
- .bind('ajax:complete', function() {
+ .on('ajax:complete', function() {
setTimeout( function() {
App.checkEnabledState(button, 'Click me');
start();
@@ -355,7 +355,7 @@ asyncTest('button[data-remote][data-disable-with] re-enables when `ajax:before`
App.checkEnabledState(button, 'Click me');
button
- .bind('ajax:before', function() {
+ .on('ajax:before', function() {
App.checkDisabledState(button, 'clicking...');
return false;
})
@@ -373,7 +373,7 @@ asyncTest('button[data-remote][data-disable-with] re-enables when `ajax:beforeSe
App.checkEnabledState(button, 'Click me');
button
- .bind('ajax:beforeSend', function() {
+ .on('ajax:beforeSend', function() {
App.checkDisabledState(button, 'clicking...');
return false;
})
@@ -391,7 +391,7 @@ asyncTest('button[data-remote][data-disable-with] re-enables when `ajax:error` e
App.checkEnabledState(button, 'Click me');
button
- .bind('ajax:send', function() {
+ .on('ajax:send', function() {
App.checkDisabledState(button, 'clicking...');
})
.trigger('click');
diff --git a/test/public/test/data-disable.js b/test/public/test/data-disable.js
index 3df1bb9c..ed30b0ec 100644
--- a/test/public/test/data-disable.js
+++ b/test/public/test/data-disable.js
@@ -30,7 +30,7 @@ module('data-disable', {
}));
},
teardown: function() {
- $(document).unbind('iframe:loaded');
+ $(document).off('iframe:loaded');
}
});
@@ -39,7 +39,7 @@ asyncTest('form input field with "data-disable" attribute', 7, function() {
App.checkEnabledState(input, 'john');
- form.bind('ajax:success', function(e, data) {
+ form.on('ajax:success', function(e, data) {
setTimeout(function() {
App.checkEnabledState(input, 'john');
equal(data.params.user_name, 'john');
@@ -57,7 +57,7 @@ asyncTest('form button with "data-disable" attribute', 7, function() {
App.checkEnabledState(button, 'Submit');
- form.bind('ajax:success', function(e, data) {
+ form.on('ajax:success', function(e, data) {
setTimeout(function() {
App.checkEnabledState(button, 'Submit');
start();
@@ -75,9 +75,9 @@ asyncTest('form input[type=submit][data-disable] disables', 6, function(){
App.checkEnabledState(input, 'Submit');
// WEEIRDD: attaching this handler makes the test work in IE7
- $(document).bind('iframe:loading', function(e, form) {});
+ $(document).on('iframe:loading', function(e, form) {});
- $(document).bind('iframe:loaded', function(e, data) {
+ $(document).on('iframe:loaded', function(e, data) {
setTimeout(function() {
App.checkDisabledState(input, 'Submit');
start();
@@ -93,7 +93,7 @@ asyncTest('form input[type=submit][data-disable] disables', 6, function(){
asyncTest('form[data-remote] input[type=submit][data-disable] is replaced in ajax callback', 2, function(){
var form = $('form:not([data-remote])').attr('data-remote', 'true'), origFormContents = form.html();
- form.bind('ajax:success', function(){
+ form.on('ajax:success', function(){
form.html(origFormContents);
setTimeout(function(){
@@ -108,7 +108,7 @@ asyncTest('form[data-remote] input[data-disable] is replaced with disabled field
var form = $('form:not([data-remote])').attr('data-remote', 'true'), input = form.find('input[type=submit]'),
newDisabledInput = input.clone().attr('disabled', 'disabled');
- form.bind('ajax:success', function(){
+ form.on('ajax:success', function(){
input.replaceWith(newDisabledInput);
setTimeout(function(){
@@ -122,7 +122,7 @@ asyncTest('form[data-remote] textarea[data-disable] attribute', 3, function() {
var form = $('form[data-remote]'),
textarea = $('').appendTo(form);
- form.bind('ajax:success', function(e, data) {
+ form.on('ajax:success', function(e, data) {
setTimeout(function() {
equal(data.params.user_bio, 'born, lived, died.');
start();
@@ -150,10 +150,10 @@ asyncTest('a[data-remote][data-disable] disables and re-enables', 6, function()
App.checkEnabledState(link, 'Click me');
link
- .bind('ajax:send', function() {
+ .on('ajax:send', function() {
App.checkDisabledState(link, 'Click me');
})
- .bind('ajax:complete', function() {
+ .on('ajax:complete', function() {
setTimeout( function() {
App.checkEnabledState(link, 'Click me');
start();
@@ -168,7 +168,7 @@ asyncTest('a[data-remote][data-disable] re-enables when `ajax:before` event is c
App.checkEnabledState(link, 'Click me');
link
- .bind('ajax:before', function() {
+ .on('ajax:before', function() {
App.checkDisabledState(link, 'Click me');
return false;
})
@@ -186,7 +186,7 @@ asyncTest('a[data-remote][data-disable] re-enables when `ajax:beforeSend` event
App.checkEnabledState(link, 'Click me');
link
- .bind('ajax:beforeSend', function() {
+ .on('ajax:beforeSend', function() {
App.checkDisabledState(link, 'Click me');
return false;
})
@@ -204,7 +204,7 @@ asyncTest('a[data-remote][data-disable] re-enables when `ajax:error` event is tr
App.checkEnabledState(link, 'Click me');
link
- .bind('ajax:send', function() {
+ .on('ajax:send', function() {
App.checkDisabledState(link, 'Click me');
})
.trigger('click');
@@ -223,7 +223,7 @@ asyncTest('form[data-remote] input|button|textarea[data-disable] does not disabl
submit = $('').appendTo(form);
form
- .bind('ajax:beforeSend', function() {
+ .on('ajax:beforeSend', function() {
return false;
})
.trigger('submit');
@@ -260,10 +260,10 @@ asyncTest('button[data-remote][data-disable] disables and re-enables', 6, functi
App.checkEnabledState(button, 'Click me');
button
- .bind('ajax:send', function() {
+ .on('ajax:send', function() {
App.checkDisabledState(button, 'Click me');
})
- .bind('ajax:complete', function() {
+ .on('ajax:complete', function() {
setTimeout( function() {
App.checkEnabledState(button, 'Click me');
start();
@@ -278,7 +278,7 @@ asyncTest('button[data-remote][data-disable] re-enables when `ajax:before` event
App.checkEnabledState(button, 'Click me');
button
- .bind('ajax:before', function() {
+ .on('ajax:before', function() {
App.checkDisabledState(button, 'Click me');
return false;
})
@@ -296,7 +296,7 @@ asyncTest('button[data-remote][data-disable] re-enables when `ajax:beforeSend` e
App.checkEnabledState(button, 'Click me');
button
- .bind('ajax:beforeSend', function() {
+ .on('ajax:beforeSend', function() {
App.checkDisabledState(button, 'Click me');
return false;
})
@@ -314,7 +314,7 @@ asyncTest('button[data-remote][data-disable] re-enables when `ajax:error` event
App.checkEnabledState(button, 'Click me');
button
- .bind('ajax:send', function() {
+ .on('ajax:send', function() {
App.checkDisabledState(button, 'Click me');
})
.trigger('click');
diff --git a/test/public/test/data-method.js b/test/public/test/data-method.js
index 57528377..32b90d70 100644
--- a/test/public/test/data-method.js
+++ b/test/public/test/data-method.js
@@ -7,12 +7,12 @@ module('data-method', {
}));
},
teardown: function() {
- $(document).unbind('iframe:loaded');
+ $(document).off('iframe:loaded');
}
});
function submit(fn, options) {
- $(document).bind('iframe:loaded', function(e, data) {
+ $(document).on('iframe:loaded', function(e, data) {
fn(data);
start();
});
diff --git a/test/public/test/data-remote.js b/test/public/test/data-remote.js
index e751c8e0..215d8217 100644
--- a/test/public/test/data-remote.js
+++ b/test/public/test/data-remote.js
@@ -39,7 +39,7 @@ asyncTest('ctrl-clicking on a link does not fire ajaxyness', 0, function() {
// follow links using `trigger('click')`, it only fires bindings.
link
.removeAttr('data-params')
- .bind('ajax:beforeSend', function() {
+ .on('ajax:beforeSend', function() {
ok(false, 'ajax should not be triggered');
});
@@ -62,7 +62,7 @@ asyncTest('ctrl-clicking on a link still fires ajax for non-GET links and for li
link
.removeAttr('data-params')
.attr('data-method', 'POST')
- .bind('ajax:beforeSend', function() {
+ .on('ajax:beforeSend', function() {
ok(true, 'ajax should be triggered');
})
.trigger(e);
@@ -80,23 +80,23 @@ asyncTest('ctrl-clicking on a link still fires ajax for non-GET links and for li
asyncTest('clicking on a link with data-remote attribute', 5, function() {
$('a[data-remote]')
- .bind('ajax:success', function(e, data, status, xhr) {
+ .on('ajax:success', function(e, data, status, xhr) {
App.assertCallbackInvoked('ajax:success');
App.assertRequestPath(data, '/echo');
equal(data.params.data1, 'value1', 'ajax arguments should have key data1 with right value');
equal(data.params.data2, 'value2', 'ajax arguments should have key data2 with right value');
App.assertGetRequest(data);
})
- .bind('ajax:complete', function() { start() })
+ .on('ajax:complete', function() { start() })
.trigger('click');
});
asyncTest('clicking on a link with disabled attribute', 0, function() {
$('a[disabled]')
- .bind("ajax:before", function(e, data, status, xhr) {
+ .on("ajax:before", function(e, data, status, xhr) {
App.assertCallbackNotInvoked('ajax:success')
})
- .bind('ajax:complete', function() { start() })
+ .on('ajax:complete', function() { start() })
.trigger('click')
setTimeout(function() {
@@ -106,14 +106,14 @@ asyncTest('clicking on a link with disabled attribute', 0, function() {
asyncTest('clicking on a button with data-remote attribute', 5, function() {
$('button[data-remote]')
- .bind('ajax:success', function(e, data, status, xhr) {
+ .on('ajax:success', function(e, data, status, xhr) {
App.assertCallbackInvoked('ajax:success');
App.assertRequestPath(data, '/echo');
equal(data.params.data1, 'value1', 'ajax arguments should have key data1 with right value');
equal(data.params.data2, 'value2', 'ajax arguments should have key data2 with right value');
App.assertGetRequest(data);
})
- .bind('ajax:complete', function() { start() })
+ .on('ajax:complete', function() { start() })
.trigger('click');
});
@@ -131,39 +131,39 @@ asyncTest('changing a select option with data-remote attribute', 5, function() {
);
$('select[data-remote]')
- .bind('ajax:success', function(e, data, status, xhr) {
+ .on('ajax:success', function(e, data, status, xhr) {
App.assertCallbackInvoked('ajax:success');
App.assertRequestPath(data, '/echo');
equal(data.params.user_data, 'optionValue2', 'ajax arguments should have key term with right value');
equal(data.params.data1, 'value1', 'ajax arguments should have key data1 with right value');
App.assertGetRequest(data);
})
- .bind('ajax:complete', function() { start() })
+ .on('ajax:complete', function() { start() })
.val('optionValue2')
.trigger('change');
});
asyncTest('submitting form with data-remote attribute', 4, function() {
$('form[data-remote]')
- .bind('ajax:success', function(e, data, status, xhr) {
+ .on('ajax:success', function(e, data, status, xhr) {
App.assertCallbackInvoked('ajax:success');
App.assertRequestPath(data, '/echo');
equal(data.params.user_name, 'john', 'ajax arguments should have key user_name with right value');
App.assertPostRequest(data);
})
- .bind('ajax:complete', function() { start() })
+ .on('ajax:complete', function() { start() })
.trigger('submit');
});
asyncTest('submitting form with data-remote attribute should include inputs in a fieldset only once', 3, function() {
$('form[data-remote]')
.append('')
- .bind('ajax:success', function(e, data, status, xhr) {
+ .on('ajax:success', function(e, data, status, xhr) {
App.assertCallbackInvoked('ajax:success');
equal(data.params.items.length, 1, 'ajax arguments should only have the item once')
App.assertPostRequest(data);
})
- .bind('ajax:complete', function() {
+ .on('ajax:complete', function() {
$('form[data-remote], fieldset').remove()
start()
})
@@ -175,27 +175,27 @@ asyncTest('submitting form with data-remote attribute submits input with matchin
.append($(''));
$('form[data-remote]')
- .bind('ajax:success', function(e, data, status, xhr) {
+ .on('ajax:success', function(e, data, status, xhr) {
App.assertCallbackInvoked('ajax:success');
App.assertRequestPath(data, '/echo');
equal(data.params.user_name, 'john', 'ajax arguments should have key user_name with right value');
equal(data.params.user_data, 'value1', 'ajax arguments should have key user_data with right value');
App.assertPostRequest(data);
})
- .bind('ajax:complete', function() { start() })
+ .on('ajax:complete', function() { start() })
.trigger('submit');
});
asyncTest('submitting form with data-remote attribute by clicking button with matching [form] attribute', 5, function() {
$('form[data-remote]')
- .bind('ajax:success', function(e, data, status, xhr) {
+ .on('ajax:success', function(e, data, status, xhr) {
App.assertCallbackInvoked('ajax:success');
App.assertRequestPath(data, '/echo');
equal(data.params.user_name, 'john', 'ajax arguments should have key user_name with right value');
equal(data.params.user_data, 'value2', 'ajax arguments should have key user_data with right value');
App.assertPostRequest(data);
})
- .bind('ajax:complete', function() { start() });
+ .on('ajax:complete', function() { start() });
$('', {
type: "submit",
@@ -222,16 +222,16 @@ asyncTest('form\'s submit bindings in browsers that don\'t support submit bubbli
form
.append($(''))
- .bind('submit', function(event){
+ .on('submit', function(event){
ok(event.type == 'submit', 'submit event handlers are called with submit event');
ok(true, 'binding handler is called');
directBindingCalled = true;
})
- .bind('ajax:beforeSend', function(){
+ .on('ajax:beforeSend', function(){
ok(true, 'form being submitted via ajax');
ok(directBindingCalled, 'binding handler already called');
})
- .bind('ajax:complete', function(){
+ .on('ajax:complete', function(){
start();
});
@@ -249,11 +249,11 @@ asyncTest('returning false in form\'s submit bindings in non-submit-bubbling bro
form
.append($(''))
- .bind('submit', function(){
+ .on('submit', function(){
ok(true, 'binding handler is called');
return false;
})
- .bind('ajax:beforeSend', function(){
+ .on('ajax:beforeSend', function(){
ok(false, 'form should not be submitted');
});
@@ -270,10 +270,10 @@ asyncTest('returning false in form\'s submit bindings in non-submit-bubbling bro
asyncTest('clicking on a link with falsy "data-remote" attribute does not fire ajaxyness', 0, function() {
$('a[data-remote]')
.attr('data-remote', 'false')
- .bind('ajax:beforeSend', function() {
+ .on('ajax:beforeSend', function() {
ok(false, 'ajax should not be triggered');
})
- .bind('click', function() {
+ .on('click', function() {
return false;
})
.trigger('click');
@@ -290,10 +290,10 @@ asyncTest('ctrl-clicking on a link with falsy "data-remote" attribute does not f
.removeAttr('data-params')
.attr('data-remote', 'false')
.attr('data-method', 'POST')
- .bind('ajax:beforeSend', function() {
+ .on('ajax:beforeSend', function() {
ok(false, 'ajax should not be triggered');
})
- .bind('click', function() {
+ .on('click', function() {
return false;
})
.trigger(e);
@@ -312,10 +312,10 @@ asyncTest('ctrl-clicking on a link with falsy "data-remote" attribute does not f
asyncTest('clicking on a button with falsy "data-remote" attribute', 0, function() {
$('button[data-remote]:first')
.attr('data-remote', 'false')
- .bind('ajax:beforeSend', function() {
+ .on('ajax:beforeSend', function() {
ok(false, 'ajax should not be triggered');
})
- .bind('click', function() {
+ .on('click', function() {
return false;
})
.trigger('click');
@@ -326,10 +326,10 @@ asyncTest('clicking on a button with falsy "data-remote" attribute', 0, function
asyncTest('submitting a form with falsy "data-remote" attribute', 0, function() {
$('form[data-remote]:first')
.attr('data-remote', 'false')
- .bind('ajax:beforeSend', function() {
+ .on('ajax:beforeSend', function() {
ok(false, 'ajax should not be triggered');
})
- .bind('submit', function() {
+ .on('submit', function() {
return false;
})
.trigger('submit');
@@ -351,7 +351,7 @@ asyncTest('changing a select option with falsy "data-remote" attribute', 0, func
);
$('select[data-remote=false]:first')
- .bind('ajax:beforeSend', function() {
+ .on('ajax:beforeSend', function() {
ok(false, 'ajax should not be triggered');
})
.val('optionValue2')
diff --git a/test/public/test/settings.js b/test/public/test/settings.js
index 6fbbdab3..e516e063 100644
--- a/test/public/test/settings.js
+++ b/test/public/test/settings.js
@@ -40,7 +40,7 @@ App.checkDisabledState = function(el, text) {
// hijacks normal form submit; lets it submit to an iframe to prevent
// navigating away from the test suite
-$(document).bind('submit', function(e) {
+$(document).on('submit', function(e) {
if (!e.isDefaultPrevented()) {
var form = $(e.target), action = form.attr('action'),
name = 'form-frame' + jQuery.guid++,
diff --git a/test/views/layout.erb b/test/views/layout.erb
index eb791b6a..8a743ce7 100644
--- a/test/views/layout.erb
+++ b/test/views/layout.erb
@@ -23,7 +23,7 @@
From 3dc8c21bb580b042b7fd8b21d24c6cc285a134dd Mon Sep 17 00:00:00 2001
From: aki
Date: Fri, 14 Apr 2017 15:25:20 +0900
Subject: [PATCH 08/12] Use jQuery.fn.on instead of jQuery.fn.delegate
---
test/public/test/call-remote-callbacks.js | 24 +++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/test/public/test/call-remote-callbacks.js b/test/public/test/call-remote-callbacks.js
index 35926202..7dd1d6ac 100644
--- a/test/public/test/call-remote-callbacks.js
+++ b/test/public/test/call-remote-callbacks.js
@@ -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');
}
@@ -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;
});
@@ -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');
@@ -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();
From fcd8a33409ec6814a4ecc868073f175cba85083c Mon Sep 17 00:00:00 2001
From: Justin Searls
Date: Fri, 4 Aug 2017 22:33:24 -0400
Subject: [PATCH 09/12] Add Rails 5.1 / webpacker instructions
I just had to figure this out on my own, so I figured throwing it in the readme wouldn't hurt, given that 5.1 / webpacker are now released
---
README.md | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/README.md b/README.md
index df6aee68..2e429bd1 100644
--- a/README.md
+++ b/README.md
@@ -47,6 +47,21 @@ Installation using npm.
Run `npm install --save jquery-ujs` to install the jquery-ujs package.
+Installation using Rails and Webpacker
+------------
+
+If you're using [webpacker](https://github.com/rails/webpacker) (introduced in [Rails 5.1](http://edgeguides.rubyonrails.org/5_1_release_notes.html#optional-webpack-support)) to manage JavaScript assets, then you can add the jquery-ujs npm package to your project using the [yarn](https://yarnpkg.com/en/) CLI.
+
+```
+$ yarn add jquery-ujs
+```
+
+Then, from any of your included files (e.g. `app/javascript/packs/application.js`, or from a JavaScript file imported by such a pack), you need only import the package for jquery-ujs to be initialized:
+
+```js
+import {} from 'jquery-ujs'
+```
+
Installation using Bower
------------
From fd0837325aa58890e9d75288a9649b8935aceafd Mon Sep 17 00:00:00 2001
From: Jamie Dyer
Date: Mon, 26 Mar 2018 10:39:08 +0100
Subject: [PATCH 10/12] Change jquery dependency to a peer dependency
---
package.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/package.json b/package.json
index 08a5a245..ca5c8bce 100644
--- a/package.json
+++ b/package.json
@@ -20,7 +20,7 @@
"url": "https://github.com/rails/jquery-ujs/issues"
},
"homepage": "https://github.com/rails/jquery-ujs#readme",
- "dependencies": {
+ "peerDependencies": {
"jquery": ">=1.8.0"
}
}
From 4bdd8724d41a4dc84aa3f9b29381adb47e6ee215 Mon Sep 17 00:00:00 2001
From: David Heinemeier Hansson
Date: Mon, 14 Jun 2021 15:19:02 +0200
Subject: [PATCH 11/12] Don't attach UJS form submission handlers to Turbo
forms
Allows for easier migration of apps written for UJS, such that new work can be done with Turbo forms that are marked with data-turbo=true.
---
src/rails.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/rails.js b/src/rails.js
index 93620134..0e27110d 100644
--- a/src/rails.js
+++ b/src/rails.js
@@ -36,10 +36,10 @@
inputChangeSelector: 'select[data-remote], input[data-remote], textarea[data-remote]',
// Form elements bound by jquery-ujs
- formSubmitSelector: 'form',
+ formSubmitSelector: 'form:not([data-turbo=true])',
// Form input elements bound by jquery-ujs
- formInputClickSelector: 'form input[type=submit], form input[type=image], form button[type=submit], form button:not([type]), input[type=submit][form], input[type=image][form], button[type=submit][form], button[form]:not([type])',
+ formInputClickSelector: 'form:not([data-turbo=true]) input[type=submit], form:not([data-turbo=true]) input[type=image], form:not([data-turbo=true]) button[type=submit], form:not([data-turbo=true]) button:not([type]), input[type=submit][form], input[type=image][form], button[type=submit][form], button[form]:not([type])',
// Form input elements disabled during form submission
disableSelector: 'input[data-disable-with]:enabled, button[data-disable-with]:enabled, textarea[data-disable-with]:enabled, input[data-disable]:enabled, button[data-disable]:enabled, textarea[data-disable]:enabled',
From 83b041ba72261f487b9264b9e94211e8107a1f18 Mon Sep 17 00:00:00 2001
From: David Heinemeier Hansson
Date: Tue, 15 Jun 2021 17:39:02 +0200
Subject: [PATCH 12/12] Bump version for Turbo compatibility
---
package.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/package.json b/package.json
index ca5c8bce..9299d5f5 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "jquery-ujs",
- "version": "1.2.2",
+ "version": "1.2.3",
"description": "Unobtrusive scripting adapter for jQuery",
"main": "src/rails.js",
"scripts": {