mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: never open internal links in a new tab when user prefers opening external links in a new tab
This commit is contained in:
parent
97e19a7d02
commit
4e7244d8d9
@ -113,8 +113,10 @@ export default {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isInternal = DiscourseURL.isInternal(href);
|
||||||
|
|
||||||
// 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 (tracking && DiscourseURL.isInternal(href) && !$link.hasClass('attachment')) {
|
if (tracking && isInternal && !$link.hasClass('attachment')) {
|
||||||
ajax("/clicks/track", {
|
ajax("/clicks/track", {
|
||||||
data: {
|
data: {
|
||||||
url: href,
|
url: href,
|
||||||
@ -128,9 +130,11 @@ export default {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, use a custom URL with a redirect
|
const modifierLeftClicked = (e.ctrlKey || e.metaKey) && e.which === 1;
|
||||||
// consider CTRL+mouse-left-click / CMD+mouse-left-click or mouse-middle-click as well
|
const middleClicked = e.which === 2;
|
||||||
if (Discourse.User.currentProp('external_links_in_new_tab') || ((e.ctrlKey || e.metaKey) && (e.which === 1)) || (e.which === 2)) {
|
const openExternalInNewTab = Discourse.User.currentProp('external_links_in_new_tab');
|
||||||
|
|
||||||
|
if (modifierLeftClicked || middleClicked || (!isInternal && openExternalInNewTab)) {
|
||||||
window.open(destUrl, '_blank').focus();
|
window.open(destUrl, '_blank').focus();
|
||||||
} else {
|
} else {
|
||||||
DiscourseURL.redirectTo(destUrl);
|
DiscourseURL.redirectTo(destUrl);
|
||||||
|
Loading…
Reference in New Issue
Block a user