38 lines
1.1 KiB
Svelte
38 lines
1.1 KiB
Svelte
<script>
|
|
import { tick } from 'svelte';
|
|
|
|
export let pageId = null;
|
|
|
|
async function changePageId(pageId) {
|
|
if (typeof window !== 'undefined' && !window.commento) {
|
|
// init empty object so commento.js script extends this with global functions
|
|
window.commento = { };
|
|
const script = document.createElement('script')
|
|
// Replace this with the url to your commento instance's commento.js script
|
|
script.src = `https://commento.nemunai.re/js/commento.js`
|
|
script.defer = true
|
|
// Set default attributes for first load
|
|
script.setAttribute('data-auto-init', false)
|
|
script.setAttribute('data-page-id', pageId)
|
|
script.onload = () => {
|
|
// Tell commento.js to load the widget
|
|
window.commento.main()
|
|
}
|
|
document.getElementsByTagName('head')[0].appendChild(script)
|
|
} else if (typeof window !== 'undefined' && window.commento) {
|
|
await tick();
|
|
window.commento.reInit({
|
|
pageId: pageId,
|
|
})
|
|
}
|
|
}
|
|
|
|
$: {
|
|
if (pageId) {
|
|
changePageId(pageId);
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<div id="commento"></div>
|