FIX: Open links in external tabs. (#7444)

This commit is contained in:
Bianca Nenciu 2019-04-29 17:27:30 +03:00 committed by Penar Musaraj
parent ca9fd95a08
commit aef35faefc
2 changed files with 18 additions and 17 deletions

View File

@ -50,9 +50,7 @@ export default {
}
const $link = $(e.currentTarget);
if (!isValidLink($link)) {
return true;
}
const tracking = isValidLink($link);
if ($link.hasClass("attachment")) {
// Warn the user if they cannot download the file.
@ -81,7 +79,7 @@ export default {
const ownLink = userId && userId === Discourse.User.currentProp("id");
// Update badge clicks unless it's our own.
if (!ownLink) {
if (tracking && !ownLink) {
const $badge = $("span.badge", $link);
if ($badge.length === 1) {
const html = $badge.html();
@ -93,13 +91,15 @@ export default {
}
}
const trackPromise = ajax("/clicks/track", {
data: {
url: href,
post_id: postId,
topic_id: topicId
}
});
const trackPromise = tracking
? ajax("/clicks/track", {
data: {
url: href,
post_id: postId,
topic_id: topicId
}
})
: Ember.RSVP.resolve();
const isInternal = DiscourseURL.isInternal(href);
const openExternalInNewTab = Discourse.User.currentProp(

View File

@ -115,16 +115,15 @@ QUnit.test(
);
QUnit.test("does not track clicks on lightboxes", async assert => {
var clickEvent = generateClickEventOn(".lightbox");
assert.ok(track(clickEvent));
assert.notOk(track(generateClickEventOn(".lightbox")));
});
QUnit.test("does not track clicks when forcibly disabled", async assert => {
assert.ok(track(generateClickEventOn(".no-track-link")));
assert.notOk(track(generateClickEventOn(".no-track-link")));
});
QUnit.test("does not track clicks on back buttons", async assert => {
assert.ok(track(generateClickEventOn(".back")));
assert.notOk(track(generateClickEventOn(".back")));
});
QUnit.test("does not track right clicks inside quotes", async assert => {
@ -134,11 +133,13 @@ QUnit.test("does not track right clicks inside quotes", async assert => {
});
QUnit.test("does not track clicks links in quotes", async assert => {
assert.ok(track(generateClickEventOn(".quote a:last-child")));
Discourse.User.currentProp("external_links_in_new_tab", true);
assert.notOk(track(generateClickEventOn(".quote a:last-child")));
assert.ok(window.open.calledWith("https://google.com", "_blank"));
});
QUnit.test("does not track clicks on category badges", async assert => {
assert.ok(track(generateClickEventOn(".hashtag")));
assert.notOk(track(generateClickEventOn(".hashtag")));
});
QUnit.test("does not track clicks on mailto", async assert => {