diff --git a/app/assets/javascripts/discourse/components/click_track.js b/app/assets/javascripts/discourse/components/click_track.js index f68943f3c11..d03b38555c2 100644 --- a/app/assets/javascripts/discourse/components/click_track.js +++ b/app/assets/javascripts/discourse/components/click_track.js @@ -14,38 +14,39 @@ Discourse.ClickTrack = { @param {jQuery.Event} e The click event that occurred **/ trackClick: function(e) { - var $a, $article, $badge, count, destination, href, ownLink, postId, topicId, trackingUrl, userId; - $a = $(e.currentTarget); - if ($a.hasClass('lightbox')) { - return; - } + var $link = $(e.currentTarget); + if ($link.hasClass('lightbox')) return true; + e.preventDefault(); // We don't track clicks on quote back buttons - if ($a.hasClass('back') || $a.hasClass('quote-other-topic')) return true; + if ($link.hasClass('back') || $link.hasClass('quote-other-topic')) return true; + + // We don't track clicks in oneboxes + // except when we force it with the "track-link" class + if ($link.closest('.onebox-result') && !$link.hasClass('track-link')) return true; // Remove the href, put it as a data attribute - if (!$a.data('href')) { - $a.addClass('no-href'); - $a.data('href', $a.attr('href')); - $a.attr('href', null); + if (!$link.data('href')) { + $link.addClass('no-href'); + $link.data('href', $link.attr('href')); + $link.attr('href', null); // Don't route to this URL - $a.data('auto-route', true); + $link.data('auto-route', true); } - href = $a.data('href'); - $article = $a.closest('article'); - postId = $article.data('post-id'); - topicId = $('#topic').data('topic-id'); - userId = $a.data('user-id'); - if (!userId) { - userId = $article.data('user-id'); - } - ownLink = userId && (userId === Discourse.get('currentUser.id')); + var href = $link.data('href'), + $article = $link.closest('article'), + postId = $article.data('post-id'), + topicId = $('#topic').data('topic-id'), + userId = $link.data('user-id'); + + if (!userId) userId = $article.data('user-id'); + var ownLink = userId && (userId === Discourse.get('currentUser.id')); // Build a Redirect URL - trackingUrl = Discourse.getURL("/clicks/track?url=" + encodeURIComponent(href)); - if (postId && (!$a.data('ignore-post-id'))) { + var trackingUrl = Discourse.getURL("/clicks/track?url=" + encodeURIComponent(href)); + if (postId && (!$link.data('ignore-post-id'))) { trackingUrl += "&post_id=" + encodeURI(postId); } if (topicId) { @@ -54,23 +55,21 @@ Discourse.ClickTrack = { // Update badge clicks unless it's our own if (!ownLink) { - $badge = $('span.badge', $a); + var $badge = $('span.badge', $link); if ($badge.length === 1) { - count = parseInt($badge.html(), 10); - $badge.html(count + 1); + $badge.html(parseInt($badge.html(), 10) + 1); } } // If they right clicked, change the destination href if (e.which === 3) { - destination = Discourse.SiteSettings.track_external_right_clicks ? trackingUrl : href; - $a.attr('href', destination); + var destination = Discourse.SiteSettings.track_external_right_clicks ? trackingUrl : href; + $link.attr('href', destination); return true; } // if they want to open in a new tab, do an AJAX request if (e.metaKey || e.ctrlKey || e.which === 2) { - Discourse.ajax(Discourse.getURL("/clicks/track"), { data: { url: href, @@ -101,8 +100,7 @@ Discourse.ClickTrack = { if (Discourse.get('currentUser.external_links_in_new_tab')) { var win = window.open(trackingUrl, '_blank'); win.focus(); - } - else { + } else { window.location = trackingUrl; } diff --git a/lib/oneboxer/templates/discourse_post_onebox.hbrs b/lib/oneboxer/templates/discourse_post_onebox.hbrs deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/lib/oneboxer/templates/gist_onebox.hbrs b/lib/oneboxer/templates/gist_onebox.hbrs index 4717c38e59e..a63cb8000a6 100644 --- a/lib/oneboxer/templates/gist_onebox.hbrs +++ b/lib/oneboxer/templates/gist_onebox.hbrs @@ -1,6 +1,6 @@