From de7011fef55911cb157624996430848fff02a5d4 Mon Sep 17 00:00:00 2001
From: Quin Hoxie
Date: Tue, 9 Feb 2010 23:31:38 -0800
Subject: [PATCH 01/12] Throw exception if no url is provided in the remote
call
---
src/rails.js | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/rails.js b/src/rails.js
index d9285c93..e122e6dd 100644
--- a/src/rails.js
+++ b/src/rails.js
@@ -27,8 +27,9 @@ jQuery(function ($) {
method = el.attr('method') || el.attr('data-method') || 'GET',
url = el.attr('action') || el.attr('href');
- // TODO: should let the developer know no url was found
- if (url !== undefined) {
+ if (url === undefined) {
+ throw "No URL specified for remote call (action or href must be present).";
+ } else {
if (el.triggerAndReturn('ajax:before')) {
$.ajax({
url: url,
From 2e8f578825fe388f357722241ba65519f1dc44a9 Mon Sep 17 00:00:00 2001
From: Quin Hoxie
Date: Tue, 9 Feb 2010 23:32:16 -0800
Subject: [PATCH 02/12] Utilize dataType option to manage Accept header
---
src/rails.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/rails.js b/src/rails.js
index e122e6dd..204508e6 100644
--- a/src/rails.js
+++ b/src/rails.js
@@ -34,9 +34,9 @@ jQuery(function ($) {
$.ajax({
url: url,
data: data,
+ dataType: 'script',
type: method.toUpperCase(),
beforeSend: function (xhr) {
- xhr.setRequestHeader("Accept", "text/javascript");
el.trigger('ajax:loading', xhr);
},
success: function (data, status, xhr) {
From 5ae3f93d66bde731876840b68481525719ec3625 Mon Sep 17 00:00:00 2001
From: Quin Hoxie
Date: Wed, 10 Feb 2010 00:04:05 -0800
Subject: [PATCH 03/12] Better symmetry in negation of data-remote selector
---
src/rails.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/rails.js b/src/rails.js
index 204508e6..edc3659d 100644
--- a/src/rails.js
+++ b/src/rails.js
@@ -82,7 +82,7 @@ jQuery(function ($) {
e.preventDefault();
});
- $('a[data-method][data-remote!=true]').live('click',function(e){
+ $('a[data-method]:not([data-remote="true"])').live('click',function(e){
var link = $(this),
href = link.attr('href'),
method = link.attr('data-method'),
From 0999420167a48769383f2025f68b528fa2eae1ee Mon Sep 17 00:00:00 2001
From: Quin Hoxie
Date: Wed, 10 Feb 2010 00:06:14 -0800
Subject: [PATCH 04/12] Treat data-remote as a boolean attribute in selectors
---
src/rails.js | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/rails.js b/src/rails.js
index edc3659d..d4cd8116 100644
--- a/src/rails.js
+++ b/src/rails.js
@@ -72,17 +72,17 @@ jQuery(function ($) {
/**
* remote handlers
*/
- $('form[data-remote="true"]').live('submit', function (e) {
+ $('form[data-remote]').live('submit', function (e) {
$(this).callRemote();
e.preventDefault();
});
- $('a[data-remote="true"],input[data-remote="true"]').live('click', function (e) {
+ $('a[data-remote],input[data-remote]').live('click', function (e) {
$(this).callRemote();
e.preventDefault();
});
- $('a[data-method]:not([data-remote="true"])').live('click',function(e){
+ $('a[data-method]:not([data-remote])').live('click',function(e){
var link = $(this),
href = link.attr('href'),
method = link.attr('data-method'),
@@ -102,7 +102,7 @@ jQuery(function ($) {
/**
* disable_with handlers
*/
- $('form[data-remote="true"]').live('ajax:before', function () {
+ $('form[data-remote]').live('ajax:before', function () {
$(this).children('input[data-disable-with]').each(function () {
var input = $(this);
input.data('enable_with', input.val())
@@ -111,7 +111,7 @@ jQuery(function ($) {
});
});
- $('form[data-remote="true"]').live('ajax:after', function () {
+ $('form[data-remote]').live('ajax:after', function () {
$(this).children('input[data-disable-with]').each(function () {
var input = $(this);
input.removeAttr('disabled')
From 16363f7cf44ce9aaca138ee1d07d5443f3439342 Mon Sep 17 00:00:00 2001
From: Quin Hoxie
Date: Wed, 10 Feb 2010 00:20:37 -0800
Subject: [PATCH 05/12] Simplify metadata inputs to strings and a single call
to append()
---
src/rails.js | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/src/rails.js b/src/rails.js
index d4cd8116..f09c2c94 100644
--- a/src/rails.js
+++ b/src/rails.js
@@ -87,13 +87,12 @@ jQuery(function ($) {
href = link.attr('href'),
method = link.attr('data-method'),
form = $('