FIX: links inside quotes not opening in new tab
This commit is contained in:
parent
aabac55edd
commit
2423b18839
|
@ -26,7 +26,7 @@ export default {
|
||||||
}
|
}
|
||||||
|
|
||||||
// don't track links in quotes or in elided part
|
// don't track links in quotes or in elided part
|
||||||
if ($link.parents('aside.quote,.elided').length) { return true; }
|
let tracking = $link.parents('aside.quote,.elided').length === 0;
|
||||||
|
|
||||||
let href = $link.attr('href') || $link.data('href');
|
let href = $link.attr('href') || $link.data('href');
|
||||||
|
|
||||||
|
@ -39,26 +39,31 @@ export default {
|
||||||
const userId = $link.data('user-id') || $article.data('user-id');
|
const userId = $link.data('user-id') || $article.data('user-id');
|
||||||
const ownLink = userId && (userId === Discourse.User.currentProp('id'));
|
const ownLink = userId && (userId === Discourse.User.currentProp('id'));
|
||||||
|
|
||||||
let trackingUrl = Discourse.getURL('/clicks/track?url=' + encodeURIComponent(href));
|
let destUrl = href;
|
||||||
|
|
||||||
if (postId && !$link.data('ignore-post-id')) {
|
if (tracking) {
|
||||||
trackingUrl += "&post_id=" + encodeURI(postId);
|
|
||||||
}
|
|
||||||
if (topicId) {
|
|
||||||
trackingUrl += "&topic_id=" + encodeURI(topicId);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update badge clicks unless it's our own
|
destUrl = Discourse.getURL('/clicks/track?url=' + encodeURIComponent(href));
|
||||||
if (!ownLink) {
|
|
||||||
const $badge = $('span.badge', $link);
|
if (postId && !$link.data('ignore-post-id')) {
|
||||||
if ($badge.length === 1) {
|
destUrl += "&post_id=" + encodeURI(postId);
|
||||||
// don't update counts in category badge nor in oneboxes (except when we force it)
|
}
|
||||||
if (isValidLink($link)) {
|
if (topicId) {
|
||||||
const html = $badge.html();
|
destUrl += "&topic_id=" + encodeURI(topicId);
|
||||||
const key = `${new Date().toLocaleDateString()}-${postId}-${href}`;
|
}
|
||||||
if (/^\d+$/.test(html) && !sessionStorage.getItem(key)) {
|
|
||||||
sessionStorage.setItem(key, true);
|
// Update badge clicks unless it's our own
|
||||||
$badge.html(parseInt(html, 10) + 1);
|
if (!ownLink) {
|
||||||
|
const $badge = $('span.badge', $link);
|
||||||
|
if ($badge.length === 1) {
|
||||||
|
// don't update counts in category badge nor in oneboxes (except when we force it)
|
||||||
|
if (isValidLink($link)) {
|
||||||
|
const html = $badge.html();
|
||||||
|
const key = `${new Date().toLocaleDateString()}-${postId}-${href}`;
|
||||||
|
if (/^\d+$/.test(html) && !sessionStorage.getItem(key)) {
|
||||||
|
sessionStorage.setItem(key, true);
|
||||||
|
$badge.html(parseInt(html, 10) + 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,12 +71,12 @@ export default {
|
||||||
|
|
||||||
// If they right clicked, change the destination href
|
// If they right clicked, change the destination href
|
||||||
if (e.which === 3) {
|
if (e.which === 3) {
|
||||||
$link.attr('href', Discourse.SiteSettings.track_external_right_clicks ? trackingUrl : href);
|
$link.attr('href', Discourse.SiteSettings.track_external_right_clicks ? destUrl : href);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if they want to open in a new tab, do an AJAX request
|
// if they want to open in a new tab, do an AJAX request
|
||||||
if (wantsNewWindow(e)) {
|
if (tracking && wantsNewWindow(e)) {
|
||||||
ajax("/clicks/track", {
|
ajax("/clicks/track", {
|
||||||
data: {
|
data: {
|
||||||
url: href,
|
url: href,
|
||||||
|
@ -109,7 +114,7 @@ export default {
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we're on the same site, use the router and track via AJAX
|
// If we're on the same site, use the router and track via AJAX
|
||||||
if (DiscourseURL.isInternal(href) && !$link.hasClass('attachment')) {
|
if (tracking && DiscourseURL.isInternal(href) && !$link.hasClass('attachment')) {
|
||||||
ajax("/clicks/track", {
|
ajax("/clicks/track", {
|
||||||
data: {
|
data: {
|
||||||
url: href,
|
url: href,
|
||||||
|
@ -125,9 +130,9 @@ export default {
|
||||||
|
|
||||||
// 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')) {
|
||||||
window.open(trackingUrl, '_blank').focus();
|
window.open(destUrl, '_blank').focus();
|
||||||
} else {
|
} else {
|
||||||
DiscourseURL.redirectTo(trackingUrl);
|
DiscourseURL.redirectTo(destUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Reference in New Issue