mirror of
https://github.com/discourse/discourse.git
synced 2025-03-25 20:35:49 +08:00
FIX: Open links in external tabs. (#7444)
This commit is contained in:
parent
ca9fd95a08
commit
aef35faefc
@ -50,9 +50,7 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const $link = $(e.currentTarget);
|
const $link = $(e.currentTarget);
|
||||||
if (!isValidLink($link)) {
|
const tracking = isValidLink($link);
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($link.hasClass("attachment")) {
|
if ($link.hasClass("attachment")) {
|
||||||
// Warn the user if they cannot download the file.
|
// Warn the user if they cannot download the file.
|
||||||
@ -81,7 +79,7 @@ export default {
|
|||||||
const ownLink = userId && userId === Discourse.User.currentProp("id");
|
const ownLink = userId && userId === Discourse.User.currentProp("id");
|
||||||
|
|
||||||
// Update badge clicks unless it's our own.
|
// Update badge clicks unless it's our own.
|
||||||
if (!ownLink) {
|
if (tracking && !ownLink) {
|
||||||
const $badge = $("span.badge", $link);
|
const $badge = $("span.badge", $link);
|
||||||
if ($badge.length === 1) {
|
if ($badge.length === 1) {
|
||||||
const html = $badge.html();
|
const html = $badge.html();
|
||||||
@ -93,13 +91,15 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const trackPromise = ajax("/clicks/track", {
|
const trackPromise = tracking
|
||||||
data: {
|
? ajax("/clicks/track", {
|
||||||
url: href,
|
data: {
|
||||||
post_id: postId,
|
url: href,
|
||||||
topic_id: topicId
|
post_id: postId,
|
||||||
}
|
topic_id: topicId
|
||||||
});
|
}
|
||||||
|
})
|
||||||
|
: Ember.RSVP.resolve();
|
||||||
|
|
||||||
const isInternal = DiscourseURL.isInternal(href);
|
const isInternal = DiscourseURL.isInternal(href);
|
||||||
const openExternalInNewTab = Discourse.User.currentProp(
|
const openExternalInNewTab = Discourse.User.currentProp(
|
||||||
|
@ -115,16 +115,15 @@ QUnit.test(
|
|||||||
);
|
);
|
||||||
|
|
||||||
QUnit.test("does not track clicks on lightboxes", async assert => {
|
QUnit.test("does not track clicks on lightboxes", async assert => {
|
||||||
var clickEvent = generateClickEventOn(".lightbox");
|
assert.notOk(track(generateClickEventOn(".lightbox")));
|
||||||
assert.ok(track(clickEvent));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test("does not track clicks when forcibly disabled", async assert => {
|
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 => {
|
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 => {
|
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 => {
|
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 => {
|
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 => {
|
QUnit.test("does not track clicks on mailto", async assert => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user