FIX: clicking an attachment link works only once

This commit is contained in:
Régis Hanol 2015-02-09 17:49:59 +01:00
parent e36272cb68
commit b809e02c6c
2 changed files with 17 additions and 8 deletions

View File

@ -112,18 +112,17 @@ Discourse.ClickTrack = {
return false; 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 // Otherwise, use a custom URL with a redirect
if (Discourse.User.currentProp('external_links_in_new_tab')) { if (Discourse.User.currentProp('external_links_in_new_tab')) {
var win = window.open(trackingUrl, '_blank'); var win = window.open(trackingUrl, '_blank');
win.focus(); win.focus();
// restore href
setTimeout(function(){
$link.removeClass('no-href');
$link.attr('href', $link.data('href'));
$link.data('href', null);
},50);
} else { } else {
Discourse.URL.redirectTo(trackingUrl); Discourse.URL.redirectTo(trackingUrl);
} }

View File

@ -71,6 +71,16 @@ test("removes the href and put it as a data attribute", function() {
ok(Discourse.URL.redirectTo.calledOnce); 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) { var badgeClickCount = function(id, expected) {
track(generateClickEventOn('#' + id)); track(generateClickEventOn('#' + id));