From de7011fef55911cb157624996430848fff02a5d4 Mon Sep 17 00:00:00 2001 From: Quin Hoxie Date: Tue, 9 Feb 2010 23:31:38 -0800 Subject: [PATCH 1/7] Throw exception if no url is provided in the remote call --- src/rails.js | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/rails.js b/src/rails.js index d9285c9..e122e6d 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, -- 1.6.3.3 From 2e8f578825fe388f357722241ba65519f1dc44a9 Mon Sep 17 00:00:00 2001 From: Quin Hoxie Date: Tue, 9 Feb 2010 23:32:16 -0800 Subject: [PATCH 2/7] Utilize dataType option to manage Accept header --- src/rails.js | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/src/rails.js b/src/rails.js index e122e6d..204508e 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) { -- 1.6.3.3 From 5ae3f93d66bde731876840b68481525719ec3625 Mon Sep 17 00:00:00 2001 From: Quin Hoxie Date: Wed, 10 Feb 2010 00:04:05 -0800 Subject: [PATCH 3/7] Better symmetry in negation of data-remote selector --- src/rails.js | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/src/rails.js b/src/rails.js index 204508e..edc3659 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'), -- 1.6.3.3 From 0999420167a48769383f2025f68b528fa2eae1ee Mon Sep 17 00:00:00 2001 From: Quin Hoxie Date: Wed, 10 Feb 2010 00:06:14 -0800 Subject: [PATCH 4/7] Treat data-remote as a boolean attribute in selectors --- src/rails.js | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/rails.js b/src/rails.js index edc3659..d4cd811 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') -- 1.6.3.3 From 16363f7cf44ce9aaca138ee1d07d5443f3439342 Mon Sep 17 00:00:00 2001 From: Quin Hoxie Date: Wed, 10 Feb 2010 00:20:37 -0800 Subject: [PATCH 5/7] Simplify metadata inputs to strings and a single call to append() --- src/rails.js | 9 ++++----- 1 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/rails.js b/src/rails.js index d4cd811..f09c2c9 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 = $('
'), - input = $(''), - csrf_input = $(''); + input = '', + csrf_input = ''; form.hide() - .append(input) - .append(csrf_input) - .appendTo('body'); // redundant? + .append(input + csrf_input) + .appendTo('body'); e.preventDefault(); form.submit(); -- 1.6.3.3 From b17c7bb3a1a1a73c8eb2e0a7f0804ffb23190285 Mon Sep 17 00:00:00 2001 From: Quin Hoxie Date: Wed, 10 Feb 2010 00:22:20 -0800 Subject: [PATCH 6/7] Only create csrf input if the data is provided --- src/rails.js | 9 ++++++--- 1 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/rails.js b/src/rails.js index f09c2c9..6b09b8c 100644 --- a/src/rails.js +++ b/src/rails.js @@ -87,11 +87,14 @@ jQuery(function ($) { href = link.attr('href'), method = link.attr('data-method'), form = $(''), - input = '', - csrf_input = ''; + metadata_input = ''; + + if (csrf_param != null && csrf_token != null) { + metadata_input += ''; + } form.hide() - .append(input + csrf_input) + .append(metadata_input) .appendTo('body'); e.preventDefault(); -- 1.6.3.3 From be329c5d37dfb5acafe994fa52ed39bb87317c7c Mon Sep 17 00:00:00 2001 From: Quin Hoxie Date: Wed, 10 Feb 2010 00:25:43 -0800 Subject: [PATCH 7/7] Whitespace consistency --- src/rails.js | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/src/rails.js b/src/rails.js index 6b09b8c..d03c462 100644 --- a/src/rails.js +++ b/src/rails.js @@ -82,7 +82,7 @@ jQuery(function ($) { e.preventDefault(); }); - $('a[data-method]:not([data-remote])').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'), -- 1.6.3.3