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 @@
{{#host}} - + {{#favicon}} {{/favicon}}{{host}} {{/host}} diff --git a/lib/oneboxer/templates/github_blob_onebox.hbrs b/lib/oneboxer/templates/github_blob_onebox.hbrs index d27d5eb633e..8899fd4eaa8 100644 --- a/lib/oneboxer/templates/github_blob_onebox.hbrs +++ b/lib/oneboxer/templates/github_blob_onebox.hbrs @@ -1,6 +1,6 @@
{{#host}} - + {{#favicon}} {{/favicon}}{{host}} {{/host}} diff --git a/lib/oneboxer/templates/github_commit_onebox.hbrs b/lib/oneboxer/templates/github_commit_onebox.hbrs index fce8c071870..6d8363b79ca 100644 --- a/lib/oneboxer/templates/github_commit_onebox.hbrs +++ b/lib/oneboxer/templates/github_commit_onebox.hbrs @@ -2,7 +2,7 @@ {{#host}}
diff --git a/lib/oneboxer/templates/oembed_onebox.hbrs b/lib/oneboxer/templates/oembed_onebox.hbrs index ac4da55f036..732cbd86ed6 100644 --- a/lib/oneboxer/templates/oembed_onebox.hbrs +++ b/lib/oneboxer/templates/oembed_onebox.hbrs @@ -2,7 +2,7 @@ {{#host}}
diff --git a/lib/oneboxer/templates/simple_onebox.hbrs b/lib/oneboxer/templates/simple_onebox.hbrs index 5eda1f98ff0..13983175d6b 100644 --- a/lib/oneboxer/templates/simple_onebox.hbrs +++ b/lib/oneboxer/templates/simple_onebox.hbrs @@ -2,7 +2,7 @@ {{#host}}
diff --git a/lib/oneboxer/templates/twitter_onebox.hbrs b/lib/oneboxer/templates/twitter_onebox.hbrs index e0c6b1c4c92..e53e550facb 100644 --- a/lib/oneboxer/templates/twitter_onebox.hbrs +++ b/lib/oneboxer/templates/twitter_onebox.hbrs @@ -2,7 +2,7 @@ {{#host}}
diff --git a/spec/components/oneboxer/amazon_onebox_spec.rb b/spec/components/oneboxer/amazon_onebox_spec.rb index af994534d23..161b7ae81cf 100644 --- a/spec/components/oneboxer/amazon_onebox_spec.rb +++ b/spec/components/oneboxer/amazon_onebox_spec.rb @@ -24,7 +24,7 @@ private
diff --git a/spec/components/oneboxer/android_app_store_onebox_spec.rb b/spec/components/oneboxer/android_app_store_onebox_spec.rb index f28eeab64ac..b7cd4458242 100644 --- a/spec/components/oneboxer/android_app_store_onebox_spec.rb +++ b/spec/components/oneboxer/android_app_store_onebox_spec.rb @@ -20,7 +20,7 @@ private
diff --git a/spec/components/oneboxer/apple_app_onebox_spec.rb b/spec/components/oneboxer/apple_app_onebox_spec.rb index 3e6a5c99637..a2812fc3ce4 100644 --- a/spec/components/oneboxer/apple_app_onebox_spec.rb +++ b/spec/components/oneboxer/apple_app_onebox_spec.rb @@ -20,7 +20,7 @@ private
diff --git a/spec/components/oneboxer/github_commit_onebox.rb b/spec/components/oneboxer/github_commit_onebox_spec.rb similarity index 95% rename from spec/components/oneboxer/github_commit_onebox.rb rename to spec/components/oneboxer/github_commit_onebox_spec.rb index ae1f01d7594..7d0c962c1bf 100644 --- a/spec/components/oneboxer/github_commit_onebox.rb +++ b/spec/components/oneboxer/github_commit_onebox_spec.rb @@ -24,7 +24,7 @@ private
diff --git a/spec/components/oneboxer/wikipedia_onebox_spec.rb b/spec/components/oneboxer/wikipedia_onebox_spec.rb index 443148dca12..e31d6e28c92 100644 --- a/spec/components/oneboxer/wikipedia_onebox_spec.rb +++ b/spec/components/oneboxer/wikipedia_onebox_spec.rb @@ -39,7 +39,7 @@ private