From b809e02c6c43b92f618e9532b4c08e30f20fe4f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Mon, 9 Feb 2015 17:49:59 +0100 Subject: [PATCH] FIX: clicking an attachment link works only once --- .../javascripts/discourse/lib/click_track.js | 15 +++++++-------- test/javascripts/lib/click-track-test.js.es6 | 10 ++++++++++ 2 files changed, 17 insertions(+), 8 deletions(-) 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));