FIX: Fix open quote links in new window. (#6477)
This commit is contained in:
parent
09961fb425
commit
6275e745a7
|
@ -127,6 +127,17 @@ export default {
|
||||||
|
|
||||||
const isInternal = DiscourseURL.isInternal(href);
|
const isInternal = DiscourseURL.isInternal(href);
|
||||||
|
|
||||||
|
const modifierLeftClicked = (e.ctrlKey || e.metaKey) && e.which === 1;
|
||||||
|
const middleClicked = e.which === 2;
|
||||||
|
const openExternalInNewTab = Discourse.User.currentProp(
|
||||||
|
"external_links_in_new_tab"
|
||||||
|
);
|
||||||
|
|
||||||
|
const openWindow =
|
||||||
|
modifierLeftClicked ||
|
||||||
|
middleClicked ||
|
||||||
|
(!isInternal && openExternalInNewTab);
|
||||||
|
|
||||||
// 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 (isInternal && !$link.hasClass("attachment")) {
|
if (isInternal && !$link.hasClass("attachment")) {
|
||||||
if (tracking) {
|
if (tracking) {
|
||||||
|
@ -140,21 +151,15 @@ export default {
|
||||||
dataType: "html"
|
dataType: "html"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
DiscourseURL.routeTo(href);
|
if (openWindow) {
|
||||||
|
window.open(destUrl, "_blank").focus();
|
||||||
|
} else {
|
||||||
|
DiscourseURL.routeTo(href);
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const modifierLeftClicked = (e.ctrlKey || e.metaKey) && e.which === 1;
|
if (openWindow) {
|
||||||
const middleClicked = 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);
|
||||||
|
|
|
@ -81,6 +81,26 @@ QUnit.test("does not track clicks to internal links in quotes", assert => {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
QUnit.test("can open links inside quotes in new window", assert => {
|
||||||
|
sandbox.stub(DiscourseURL, "routeTo");
|
||||||
|
sandbox.stub(DiscourseURL, "origin").returns("http://discuss.domain.com");
|
||||||
|
|
||||||
|
track(
|
||||||
|
$.Event("click", {
|
||||||
|
currentTarget: fixture(".quote a:first-child")[0],
|
||||||
|
ctrlKey: true,
|
||||||
|
which: 1
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.ok(
|
||||||
|
window.open.calledWith(
|
||||||
|
"https://discuss.domain.com/t/welcome-to-meta-discourse-org/1/30",
|
||||||
|
"_blank"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
QUnit.test("does not track clicks to external links in quotes", assert => {
|
QUnit.test("does not track clicks to external links in quotes", assert => {
|
||||||
track(generateClickEventOn(".quote a:last-child"));
|
track(generateClickEventOn(".quote a:last-child"));
|
||||||
assert.ok(DiscourseURL.redirectTo.calledWith("https://google.com"));
|
assert.ok(DiscourseURL.redirectTo.calledWith("https://google.com"));
|
||||||
|
|
Loading…
Reference in New Issue