From 610dfb8881377598b7e63ab2c152d73aa1d3632f Mon Sep 17 00:00:00 2001 From: Steve Schwartz Date: Tue, 19 Feb 2013 00:28:38 -0500 Subject: [PATCH 001/123] Fixed bug where a[disable-with] got set to blank html when ajax returned error, due to enableElement being triggered twice. --- src/rails.js | 4 +--- test/public/test/data-disable.js | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/rails.js b/src/rails.js index 69db1843..a1661f31 100644 --- a/src/rails.js +++ b/src/rails.js @@ -276,9 +276,7 @@ enableElement: function(element) { if (element.data('ujs:enable-with') !== undefined) { element.html(element.data('ujs:enable-with')); // set to old enabled state - // this should be element.removeData('ujs:enable-with') - // but, there is currently a bug in jquery which makes hyphenated data attributes not get removed - element.data('ujs:enable-with', false); // clean up cache + element.removeData('ujs:enable-with'); // clean up cache } element.unbind('click.railsDisable'); // enable element } diff --git a/test/public/test/data-disable.js b/test/public/test/data-disable.js index 241c1583..6c973dfd 100644 --- a/test/public/test/data-disable.js +++ b/test/public/test/data-disable.js @@ -207,6 +207,23 @@ asyncTest('a[data-remote][data-disable-with] re-enables when `ajax:beforeSend` e }, 30); }); +asyncTest('a[data-remote][data-disable-with] re-enables when `ajax:error` event is triggered', 6, function() { + var link = $('a[data-disable-with]').attr('data-remote', true).attr('href', '/error'); + + checkEnabledState(link, 'Click me'); + + link + .bind('ajax:beforeSend', function() { + checkDisabledState(link, 'clicking...'); + }) + .trigger('click'); + + setTimeout(function() { + checkEnabledState(link, 'Click me'); + start(); + }, 30); +}); + asyncTest('form[data-remote] input|button|textarea[data-disable-with] does not disable when `ajax:beforeSend` event is cancelled', 8, function() { var form = $('form[data-remote]'), input = form.find('input:text'), From c30462003c41175acf7337536b036a47645cf742 Mon Sep 17 00:00:00 2001 From: ingeniarius Date: Wed, 20 Feb 2013 15:22:34 +0400 Subject: [PATCH 002/123] Supporting button[data-remote] as replacement of button_to helper --- src/rails.js | 16 ++++++++++++++++ test/public/test/data-remote.js | 31 +++++++++++++++++++++++++------ 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/src/rails.js b/src/rails.js index a1661f31..2cb26b53 100644 --- a/src/rails.js +++ b/src/rails.js @@ -23,6 +23,9 @@ // Link elements bound by jquery-ujs linkClickSelector: 'a[data-confirm], a[data-method], a[data-remote], a[data-disable-with]', + // Button elements boud jquery-ujs + buttonClickSelector: 'button[data-remote]', + // Select elements bound by jquery-ujs inputChangeSelector: 'select[data-remote], input[data-remote], textarea[data-remote]', @@ -100,6 +103,11 @@ url = element.data('url'); data = element.serialize(); if (element.data('params')) data = data + "&" + element.data('params'); + } else if (element.is(rails.buttonClickSelector)) { + method = element.data('method') || 'post'; + url = element.data('url'); + data = element.serialize(); + if (element.data('params')) data = data + "&" + element.data('params'); } else { method = element.data('method'); url = rails.href(element); @@ -315,6 +323,14 @@ } }); + $(document).delegate(rails.buttonClickSelector, 'click.rails', function(e) { + var button = $(this); + if (!rails.allowAction(button)) return rails.stopEverything(e); + + rails.handleRemote(button); + return false; + }); + $(document).delegate(rails.inputChangeSelector, 'change.rails', function(e) { var link = $(this); if (!rails.allowAction(link)) return rails.stopEverything(e); diff --git a/test/public/test/data-remote.js b/test/public/test/data-remote.js index d9c2f6d7..1ce113e9 100644 --- a/test/public/test/data-remote.js +++ b/test/public/test/data-remote.js @@ -7,6 +7,12 @@ module('data-remote', { 'data-params': 'data1=value1&data2=value2', text: 'my address' })) + .append($('