Catch and redirect clicks on inline mentions

This commit is contained in:
silverpill 2022-05-12 22:27:34 +00:00
parent db16d94c0b
commit fd1b8ee0e8

View file

@ -270,9 +270,15 @@ export default class PostComponent extends Vue {
mounted() { mounted() {
const mentions = this.$refs.postContent.getElementsByClassName("mention") const mentions = this.$refs.postContent.getElementsByClassName("mention")
for (const mention of Array.from(mentions)) { for (const mentionElement of Array.from(mentions)) {
mention.setAttribute("target", "_blank") mentionElement.addEventListener("click", (event: Event) => {
mention.setAttribute("rel", "noreferrer") event.preventDefault()
const mention = this.post.mentions
.find((mention) => mention.url === mentionElement.getAttribute("href"))
if (mention) {
this.$router.push({ name: "profile", params: { profileId: mention.id } })
}
})
} }
} }