Skip to content

Commit

Permalink
Sanitize links in Text windows (WIP) #45
Browse files Browse the repository at this point in the history
  • Loading branch information
Lev Z Király authored and Lev Z Király committed Oct 2, 2023
1 parent 754b876 commit 4c245ff
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 36 deletions.
23 changes: 22 additions & 1 deletion components/Text.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div v-html="htmlContents" class="vv-text"></div>
<div v-html="htmlContents" class="vv-text" :id="domId"></div>
</template>

<script setup lang="ts">
Expand All @@ -8,6 +8,8 @@
const htmlContents: Ref<string | undefined> = ref("")
const props = defineProps(['params'])
const domId = 'id-' + Math.floor(Math.random() * 1000000)
const GetText = async () => {
const { $api } = useNuxtApp()
const id = String(props.params.id)
Expand All @@ -19,7 +21,26 @@
}
}
const SanitizeLinks = () => {
document.querySelectorAll(`#${domId} .aVicText`)
.forEach(a => {
let targetType = a.getAttribute('data-target-type'),
textId = a.getAttribute('data-text-id')
console.log('Link', targetType, textId)
if (targetType == 'external-link') {
return
}
a.addEventListener("click", e => {
e.preventDefault()
console.log(`You clicked a link, target-type: ${targetType}, text-id: ${textId}`)
}, false)
})
}
htmlContents.value = await GetText()
onMounted(() => {
SanitizeLinks()
})
</script>

<style>
Expand Down
35 changes: 0 additions & 35 deletions components/WindowManager.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,44 +71,9 @@
WMStore.RegisterClientSize(document.documentElement.clientWidth, document.documentElement.clientHeight)
}
const getDBSnippet = (params: string): void => {
// TODO: create a method in a "legacy vicav" helper plugin that returns a { windowTypeId, windowName, windowParams } object
// based on the getDBSnippet parameter
console.log('getDBSnippet: ', params)
let splitPoint = params.indexOf(":")
let sHead = params.substring(0, splitPoint)
let sTail = params.substring(splitPoint + 1)
let sh = sTail.split("/")
let snippetID = sh[0].trim()
let secLabel = ""
if (!!sh[1]) {
secLabel = sh[1].trim()
secLabel = secLabel.replace(/_/g, " ")
}
let sid = null;
let dict = null;
switch (sHead) {
case "dictID":
let st5 = sTail.split(",");
sid = st5[0];
dict = st5[1];
WMStore.Open('DictEntry', sid + ': ' + dict, { dict, sid })
console.log ('getDBSnippet: dictID,', { dict, sid })
break;
case "text":
WMStore.Open('Text', secLabel, { id: snippetID })
break;
default:
console.warn("getDBSnippet: sHead type unknown [" + sHead + "]")
break;
}
}
onMounted(() =>{
RegisterClientSize()
window.addEventListener('resize', RegisterClientSize, true)
window.getDBSnippet = getDBSnippet
})
</script>

Expand Down

0 comments on commit 4c245ff

Please sign in to comment.