|
1 | 1 | <template> |
| 2 | + <!-- eslint-disable-next-line vuejs-accessibility/click-events-have-key-events --> |
2 | 3 | <p |
| 4 | + v-safer-html="displayText" |
3 | 5 | dir="auto" |
4 | | - @timestamp-clicked="catchTimestampClick" |
5 | | - v-html="displayText" |
| 6 | + @click="catchTimestampClick" |
6 | 7 | /> |
7 | 8 | </template> |
8 | 9 |
|
9 | 10 | <script setup> |
10 | 11 | import { computed } from 'vue' |
11 | 12 | import { useRouter } from 'vue-router' |
12 | 13 |
|
| 14 | +import { vSaferHtml } from '../directives/vSaferHtml.js' |
| 15 | +
|
13 | 16 | const props = defineProps({ |
14 | 17 | inputHtml: { |
15 | 18 | type: String, |
@@ -40,15 +43,27 @@ const displayText = computed(() => props.inputHtml.replaceAll(/(?:(\d+):)?(\d+): |
40 | 43 | }).href |
41 | 44 |
|
42 | 45 | // Adding the URL lets the user open the video in a new window at this timestamp |
43 | | - return `<a tabindex="${props.linkTabIndex}" href="${url}" onclick="event.preventDefault();this.dispatchEvent(new CustomEvent('timestamp-clicked',{bubbles:true,detail:${time}}));window.scrollTo(0,0)">${timestamp}</a>` |
| 46 | + return `<a tabindex="${props.linkTabIndex}" href="${url}" data-time="${time}">${timestamp}</a>` |
44 | 47 | })) |
45 | 48 |
|
46 | 49 | const emit = defineEmits(['timestamp-event']) |
47 | 50 |
|
48 | 51 | /** |
49 | | - * @param {CustomEvent} event |
| 52 | + * @param {PointerEvent} event |
50 | 53 | */ |
51 | 54 | function catchTimestampClick(event) { |
52 | | - emit('timestamp-event', event.detail) |
| 55 | + /** @type {HTMLAnchorElement} */ |
| 56 | + const target = event.target |
| 57 | +
|
| 58 | + if (target.tagName === 'A' && target.dataset.time) { |
| 59 | + const timeSeconds = parseInt(target.dataset.time) |
| 60 | +
|
| 61 | + if (!isNaN(timeSeconds)) { |
| 62 | + event.preventDefault() |
| 63 | +
|
| 64 | + emit('timestamp-event', timeSeconds) |
| 65 | + window.scrollTo(0, 0) |
| 66 | + } |
| 67 | + } |
53 | 68 | } |
54 | 69 | </script> |
0 commit comments