diff --git a/app/assets/javascripts/discourse/lib/click_track.js b/app/assets/javascripts/discourse/lib/click_track.js index 09a360474f0..f53d0e1ed0d 100644 --- a/app/assets/javascripts/discourse/lib/click_track.js +++ b/app/assets/javascripts/discourse/lib/click_track.js @@ -112,18 +112,17 @@ Discourse.ClickTrack = { return false; } + // restore href + setTimeout(function() { + $link.removeClass('no-href'); + $link.attr('href', $link.data('href')); + $link.data('href', null); + }, 50); + // Otherwise, use a custom URL with a redirect if (Discourse.User.currentProp('external_links_in_new_tab')) { var win = window.open(trackingUrl, '_blank'); win.focus(); - - // restore href - setTimeout(function(){ - $link.removeClass('no-href'); - $link.attr('href', $link.data('href')); - $link.data('href', null); - },50); - } else { Discourse.URL.redirectTo(trackingUrl); } diff --git a/test/javascripts/lib/click-track-test.js.es6 b/test/javascripts/lib/click-track-test.js.es6 index 82f7348bd2f..dff00e93689 100644 --- a/test/javascripts/lib/click-track-test.js.es6 +++ b/test/javascripts/lib/click-track-test.js.es6 @@ -71,6 +71,16 @@ test("removes the href and put it as a data attribute", function() { ok(Discourse.URL.redirectTo.calledOnce); }); +asyncTest("restores the href after a while", function() { + expect(1); + + track(generateClickEventOn('a')); + + setTimeout(function() { + start(); + equal(fixture('a').attr('href'), "http://www.google.com"); + }, 75); +}); var badgeClickCount = function(id, expected) { track(generateClickEventOn('#' + id));