Fix button cloning method.

This commit is contained in:
John Livingston 2024-04-11 15:14:50 +02:00
parent 1689657aa7
commit eee07da1e3
No known key found for this signature in database
GPG Key ID: B17B5640CE66CDBC
3 changed files with 22 additions and 4 deletions

View File

@ -40,10 +40,9 @@
} }
} }
.peertube-plugin-livechat-buttons-open { .peertube-plugin-livechat-buttons-cloned {
// So that buttons will be behind chatbox (buttons are then cloned by our custom muc-head template): // Hidding buttons when cloned by the ConverseJS mini-muc-head plugin.
position: fixed; display: none;
right: 0;
} }
[peertube-plugin-livechat-state="initializing"] { [peertube-plugin-livechat-state="initializing"] {

View File

@ -20,6 +20,10 @@ function getPeertubeButtons () {
) )
if (!buttonsContainer) { return html`` } if (!buttonsContainer) { return html`` }
// We must remove this class, in case it is already here.
// Otherwise, the trick with offsetParent (see the forEach loop) will not work.
buttonsContainer.classList.remove('peertube-plugin-livechat-buttons-cloned')
const buttons = [] const buttons = []
buttonsContainer.childNodes.forEach(button => { buttonsContainer.childNodes.forEach(button => {
try { try {
@ -39,6 +43,10 @@ function getPeertubeButtons () {
return html`` return html``
} }
// Hidding original buttons:
console.log('[peertube-plugin-livechat] Adding class peertube-plugin-livechat-buttons-cloned')
buttonsContainer.classList.add('peertube-plugin-livechat-buttons-cloned')
return html` return html`
${repeat(buttons, (node) => html` ${repeat(buttons, (node) => html`
<a <a

View File

@ -21,5 +21,16 @@ export const livechatMiniMucHeadPlugin = {
buttons = buttons.filter(b => b.name !== 'toggle-topic') buttons = buttons.filter(b => b.name !== 'toggle-topic')
return buttons return buttons
}) })
const restoreClonedButtons = (): void => {
console.log('[peertube-plugin-livechat] Removing class peertube-plugin-livechat-buttons-cloned')
document.querySelectorAll(
'.peertube-plugin-livechat-buttons-cloned'
).forEach(el => el.classList.remove('peertube-plugin-livechat-buttons-cloned'))
}
// muc-head can hide buttons that are cloned, so we restore them on disconnection and chatbox closing.
_converse.api.listen.on('disconnected', restoreClonedButtons)
_converse.api.listen.on('chatBoxClosed', restoreClonedButtons)
} }
} }