Skip to content

A platform for community discussion. Free, open, simple.

FIX: Follow open in new tab site setting for bio links (#11418)

Bianca Nenciu812d047c60f6
diff --git a/app/assets/javascripts/discourse/app/components/html-with-links.js b/app/assets/javascripts/discourse/app/components/html-with-links.js
new file mode 100644
index 00000000000..d14b7dc7c73
--- /dev/null
+++ b/app/assets/javascripts/discourse/app/components/html-with-links.js
@@ -0,0 +1,23 @@
+import {
+ openLinkInNewTab,
+ shouldOpenInNewTab,
+} from "discourse/lib/click-track";
+import Component from "@ember/component";
+
+export default Component.extend({
+ didInsertElement() {
+ this._super(...arguments);
+ $(this.element).on("click.discourse-open-tab", "a", (event) => {
+ if (event.target && event.target.tagName === "A") {
+ if (shouldOpenInNewTab(event.target.href)) {
+ openLinkInNewTab(event.target);
+ }
+ }
+ });
+ },
+
+ willDestroyElement() {
+ this._super(...arguments);
+ $(this.element).off("click.discourse-open-tab", "a");
+ },
+});
diff --git a/app/assets/javascripts/discourse/app/templates/components/html-with-links.hbs b/app/assets/javascripts/discourse/app/templates/components/html-with-links.hbs
new file mode 100644
index 00000000000..889d9eeadc1
--- /dev/null
+++ b/app/assets/javascripts/discourse/app/templates/components/html-with-links.hbs
@@ -0,0 +1 @@
+{{yield}}
diff --git a/app/assets/javascripts/discourse/app/templates/components/user-card-contents.hbs b/app/assets/javascripts/discourse/app/templates/components/user-card-contents.hbs
index 28e08da19e2..80eb6ad2527 100644
--- a/app/assets/javascripts/discourse/app/templates/components/user-card-contents.hbs
+++ b/app/assets/javascripts/discourse/app/templates/components/user-card-contents.hbs
@@ -142,7 +142,11 @@
</div>
{{else}}
{{#if this.user.bio_excerpt}}
- <div class="bio">{{html-safe this.user.bio_excerpt}}</div>
+ <div class="bio">
+ {{#html-with-links}}
+ {{html-safe this.user.bio_excerpt}}
+ {{/html-with-links}}
+ </div>
{{/if}}
{{/if}}
</div>
diff --git a/app/assets/javascripts/discourse/app/templates/user.hbs b/app/assets/javascripts/discourse/app/templates/user.hbs
index 882963d8bec..5a3468539db 100644
--- a/app/assets/javascripts/discourse/app/templates/user.hbs
+++ b/app/assets/javascripts/discourse/app/templates/user.hbs
@@ -144,7 +144,9 @@
</div>
{{/if}}
{{#if isNotSuspendedOrIsStaff}}
- {{html-safe model.bio_cooked}}
+ {{#html-with-links}}
+ {{html-safe model.bio_cooked}}
+ {{/html-with-links}}
{{/if}}
</div>