FIX: Fix open quote links in new window. (#6477)

This commit is contained in:
Bianca Nenciu 2018-10-11 10:51:14 +03:00 committed by Régis Hanol
parent 09961fb425
commit 6275e745a7
2 changed files with 37 additions and 12 deletions

View File

@ -127,6 +127,17 @@ export default {
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 (isInternal && !$link.hasClass("attachment")) {
if (tracking) {
@ -140,21 +151,15 @@ export default {
dataType: "html"
});
}
DiscourseURL.routeTo(href);
if (openWindow) {
window.open(destUrl, "_blank").focus();
} else {
DiscourseURL.routeTo(href);
}
return false;
}
const modifierLeftClicked = (e.ctrlKey || e.metaKey) && e.which === 1;
const middleClicked = e.which === 2;
const openExternalInNewTab = Discourse.User.currentProp(
"external_links_in_new_tab"
);
if (
modifierLeftClicked ||
middleClicked ||
(!isInternal && openExternalInNewTab)
) {
if (openWindow) {
window.open(destUrl, "_blank").focus();
} else {
DiscourseURL.redirectTo(destUrl);

View File

@ -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 => {
track(generateClickEventOn(".quote a:last-child"));
assert.ok(DiscourseURL.redirectTo.calledWith("https://google.com"));