Přeskočit na hlavní obsah

Rozdílné zobrazení widgetu po kliknutí na odkaz

Javascript


var _msgokType = "popup";
var _msgokConfig =
{
"recipient":"mujucet",
"src":"templates/mujucet",
"type": _msgokType,
"classes": ["msgokWidget--fix-to-right", "msgokWidget--size-text"],
"title": "Online pomoc"
};

var e = document.createElement("script");
e.src = "https://cdn.msgok.net/client/v10.js";
e.async = true;
e.defer = true;
e.addEventListener("load",function(){
const linksWithPayload = document.querySelectorAll('a[data-msgokpayload]');
if (linksWithPayload.length > 0) {
linksWithPayload.forEach(link => {
link.addEventListener('click', function(event) {
event.preventDefault();

if (window.msgokWidget) {
// Select all div elements with the class 'msgokWidget--popup'
const popupElements = document.querySelectorAll('div.msgokWidget--' + _msgokType);

// Loop through the selected elements and remove each one
popupElements.forEach(function(element) {
element.remove();
});
}

const payload = link.getAttribute('data-msgokpayload');
_msgokConfig.payload = payload;
const w = window.msgokWidget.create(null, _msgokConfig);
w.show();
w.open();
});
});
}
});
document.getElementsByTagName("head")[0].appendChild(e);