mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2026-08-08 11:38:42 +08:00
Handle rightside_button and button_hide_show for Knocket
This commit is contained in:
+32
-4
@@ -1,5 +1,33 @@
|
|||||||
//- Knocket live chat — https://trtc.io/solutions/knocket
|
//- Knocket live chat — https://trtc.io/solutions/knocket
|
||||||
//- Free-forever live chat widget. Renders only when theme.knocket.identifier is set.
|
script.
|
||||||
//- Get your own snippet/identifier at https://trtc.io/solutions/knocket
|
(() => {
|
||||||
if theme.knocket.identifier
|
const id = '#{theme.knocket.identifier}'
|
||||||
script(src=`https://trtc.io/knocket-sdk/sdk.js?identifier=${theme.knocket.identifier}` async)
|
if (!id) return
|
||||||
|
|
||||||
|
btf.getScript(`https://trtc.io/knocket-sdk/sdk.js?identifier=${id}`).then(() => {
|
||||||
|
const isChatBtn = !{theme.chat.rightside_button}
|
||||||
|
const isChatHideShow = !{theme.chat.button_hide_show}
|
||||||
|
|
||||||
|
const getWidget = () => document.querySelector('#knocket-widget, [id*="knocket"]')
|
||||||
|
|
||||||
|
if (isChatBtn) {
|
||||||
|
const hide = () => { const w = getWidget(); if (w) w.style.display = 'none' }
|
||||||
|
const show = () => { const w = getWidget(); if (w) w.style.display = '' }
|
||||||
|
|
||||||
|
hide()
|
||||||
|
|
||||||
|
window.chatBtnFn = () => {
|
||||||
|
const w = getWidget()
|
||||||
|
if (w && w.style.display === 'none') show()
|
||||||
|
else hide()
|
||||||
|
}
|
||||||
|
|
||||||
|
document.getElementById('chat-btn').style.display = 'block'
|
||||||
|
} else if (isChatHideShow) {
|
||||||
|
window.chatBtn = {
|
||||||
|
hide: () => { const w = getWidget(); if (w) w.style.display = 'none' },
|
||||||
|
show: () => { const w = getWidget(); if (w) w.style.display = '' }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})()
|
||||||
|
|||||||
Reference in New Issue
Block a user