From e39b3bdd35aa9a31637213bfb3c51e389a221269 Mon Sep 17 00:00:00 2001 From: negue Date: Sat, 11 Mar 2023 00:40:05 +0100 Subject: [PATCH] open the modal by click override --- website/client/src/directives/markdown.js | 18 ++++++++++++++++-- website/client/src/main.js | 8 +++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/website/client/src/directives/markdown.js b/website/client/src/directives/markdown.js index f4da7164f2..1d0abcf8f6 100644 --- a/website/client/src/directives/markdown.js +++ b/website/client/src/directives/markdown.js @@ -8,8 +8,22 @@ export default function markdown (el, { value, oldValue }) { } else { el.innerHTML = ''; } - // This is a hack, but it's one idea for how we might do things - el.innerHTML = el.innerHTML.replace('href="h', 'href="/external?link=h'); + + const allLinks = el.getElementsByTagName('a'); + + for (let i = 0; i < allLinks.length; i++) { + const link = allLinks[i]; + + // todo middleclick or ctrl+click to open it in a new tab + // todo? should a normal click leave the current page or also open it in a new tab? + // ... hopefully this wont create memory leaks + link.addEventListener('click', e => { + e.stopPropagation(); + e.preventDefault(); + + window.externalLink(link.href); + }); + } el.classList.add('markdown'); } diff --git a/website/client/src/main.js b/website/client/src/main.js index f3587c5c12..d52f73f0ee 100644 --- a/website/client/src/main.js +++ b/website/client/src/main.js @@ -33,9 +33,15 @@ setUpLogging(); setupAnalytics(); // just create queues for analytics, no scripts loaded at this time const store = getStore(); -export default new Vue({ +const vueInstance = new Vue({ el: '#app', router, store, render: h => h(AppComponent), }); + +export default vueInstance; + +window.externalLink = url => { + vueInstance.$root.$emit('bv::show::modal', 'external-link-modal', url); +};