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,13 +39,17 @@ 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 (tracking) {
|
||||||
|
|
||||||
|
destUrl = Discourse.getURL('/clicks/track?url=' + encodeURIComponent(href));
|
||||||
|
|
||||||
if (postId && !$link.data('ignore-post-id')) {
|
if (postId && !$link.data('ignore-post-id')) {
|
||||||
trackingUrl += "&post_id=" + encodeURI(postId);
|
destUrl += "&post_id=" + encodeURI(postId);
|
||||||
}
|
}
|
||||||
if (topicId) {
|
if (topicId) {
|
||||||
trackingUrl += "&topic_id=" + encodeURI(topicId);
|
destUrl += "&topic_id=" + encodeURI(topicId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update badge clicks unless it's our own
|
// Update badge clicks unless it's our own
|
||||||
|
@ -63,15 +67,16 @@ 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