Dirty hack to prevent some click event to default to href=#

This commit is contained in:
John Livingston 2024-04-03 15:06:18 +02:00
parent e5e6c6f953
commit 08fa8c28f4
No known key found for this signature in database
GPG Key ID: B17B5640CE66CDBC
1 changed files with 17 additions and 0 deletions

View File

@ -138,6 +138,23 @@ async function displayConverseJS (
converseRoot.classList.add('theme-peertube')
container.append(converseRoot)
converseRoot.addEventListener('click', ev => {
// For some reason, there are some buttons in ConverseJS that are not working properly.
// When clicked, it does not prevent the default, so it try to open href="#".
// We will catch such clicks in converse-root, and prevent default!
if (!ev.target) { return }
const a: HTMLAnchorElement | null = ('tagName' in ev.target) && ev.target.tagName === 'A'
? ev.target as HTMLAnchorElement
: (ev.target as HTMLElement).closest('a')
if (!a) { return }
if (a.getAttribute('href') !== '#') { return }
console.log('[peertube-plugin-livechat] intercepting a click on href=# in converse root, canceling the event.')
ev.preventDefault()
})
const authHeader = peertubeHelpers.getAuthHeader()
const response = await fetch(