Permalink
Browse files

Merge branch 'master' of https://github.com/nulogy/jquery-ujs into nu…

…logy-master
  • Loading branch information...
JangoSteve committed Nov 25, 2011
2 parents f38dba1 + 7e0ea5c commit 69fe8962c3b5e42a02f8e39005e465817828b5fd
Showing with 58 additions and 2 deletions.
  1. +6 −2 src/rails.js
  2. +52 −0 test/public/test/data-disable.js
View
@@ -151,7 +151,9 @@
// Only pass url to `ajax` options if not blank
if (url) { options.url = url; }
- rails.ajax(options);
+ return rails.ajax(options);
+ } else {
+ return false;
}
},
@@ -299,7 +301,9 @@
if (link.data('remote') !== undefined) {
if ( (e.metaKey || e.ctrlKey) && (!method || method === 'GET') && !data ) { return true; }
- rails.handleRemote(link);
+ if(rails.handleRemote(link) === false) {
+ rails.enableElement($(this));
+ }
return false;
} else if (link.data('method')) {
rails.handleMethod(link);
@@ -180,3 +180,55 @@ asyncTest('remote link with "data-disable-with" attribute disables and re-enable
})
.trigger('click');
});
+
+asyncTest('remote link with "data-disable-with" attribute disables and re-enables when ajax:before event is cancelled', 6, function() {
+ var link = $('a[data-disable-with]').attr('data-remote', true);
+
+ function checkEnabledLink() {
+ ok(!link.data('ujs:enable-with'), 'link should not be disabled');
+ equal(link.html(), 'Click me', 'link should have value given to it');
+ }
+ checkEnabledLink();
+
+ function checkDisabledLink() {
+ ok(link.data('ujs:enable-with'), 'link should be disabled');
+ equal(link.html(), 'clicking...');
+ }
+
+ link
+ .bind('ajax:before', function() {
+ checkDisabledLink();
+ return false;
+ })
+ .trigger('click');
+ setTimeout(function() {
+ checkEnabledLink();
+ start();
+ }, 30);
+});
+
+asyncTest('remote link with "data-disable-with" attribute disables and re-enables when ajax:beforeSend event is cancelled', 6, function() {
+ var link = $('a[data-disable-with]').attr('data-remote', true);
+
+ function checkEnabledLink() {
+ ok(!link.data('ujs:enable-with'), 'link should not be disabled');
+ equal(link.html(), 'Click me', 'link should have value given to it');
+ }
+ checkEnabledLink();
+
+ function checkDisabledLink() {
+ ok(link.data('ujs:enable-with'), 'link should be disabled');
+ equal(link.html(), 'clicking...');
+ }
+
+ link
+ .bind('ajax:beforeSend', function() {
+ checkDisabledLink();
+ return false;
+ })
+ .trigger('click');
+ setTimeout(function() {
+ checkEnabledLink();
+ start();
+ }, 30);
+});

0 comments on commit 69fe896

Please sign in to comment.