diff --git a/src/rails.js b/src/rails.js index 309d74d6..0bf6749e 100644 --- a/src/rails.js +++ b/src/rails.js @@ -183,6 +183,19 @@ form.submit(); }, + // Follow the href after a delay. To be used instead of the default handler to give the DOM a chance to render any changes + followLink: function(link) { + var href = rails.href(link), + target = $.trim(link.attr("target")); + setTimeout(function() { + if (target) { + open(href, target); + } else { + location = href; + } + }, 0); + }, + /* Disables form elements: - Caches element value in 'ujs:enable-with' data store - Replaces element text with value of 'data-disable-with' attribute @@ -316,6 +329,9 @@ } else if (link.data('method')) { rails.handleMethod(link); return false; + } else { + rails.followLink(link); + return false; } }); diff --git a/test/public/test/call-remote.js b/test/public/test/call-remote.js index d78ce565..c508d874 100644 --- a/test/public/test/call-remote.js +++ b/test/public/test/call-remote.js @@ -96,7 +96,7 @@ asyncTest('allow empty form "action"', 1, function() { currentLocation.href = ""; currentLocation = currentLocation.href; } - currentLocation = currentLocation.replace(/\?$/, ''); + currentLocation = currentLocation.replace(/\??#?$/, ''); // Actual location (strip out settings.data that jQuery serializes and appends) // HACK: can no longer use settings.data below to see what was appended to URL, as of diff --git a/test/public/test/data-disable.js b/test/public/test/data-disable.js index ec858787..a9e6e3f8 100644 --- a/test/public/test/data-disable.js +++ b/test/public/test/data-disable.js @@ -18,7 +18,7 @@ module('data-disable', { $('#qunit-fixture').append($('', { text: 'Click me', - href: '/echo', + href: '#', 'data-disable-with': 'clicking...' })); },