`;
function initEngagently() {
engagently.Configuration({
communityId: 'nw9Ljb87d2',
defaultLanguage: 'de',
translations: {
de: {
interpolation: {
'messages': 'link'
},
messages: {
"log-in-to-comment": "Melden Sie sich bitte an um zu kommentieren ",
"discussion-preamble": welcomeMessageHTML
}
}
},
events: {
onSetup: function (data){
let loader_container = document.querySelector('.loader-container');
loader_container.classList.add('nw-hidden');
loader_container.setAttribute('data-setup', '1')
}
}
});
}
function renderEngagentlyDiscussion(event) {
if (event) event.preventDefault();
const template = document.querySelector('#egy-template');
const app = document.querySelector('#appEgy');
if (app.innerHTML.trim() === "") {
app.innerHTML = template.innerHTML;
}
if (!app.classList.contains('active')) {
// add to end of event loop (after event listener callback)
setTimeout(() => {
document.getElementById("closeEngagently").style.display = "flex";
document.querySelector('.loader-container').classList.remove('nw-hidden');
reinitEngagently();
app.classList.add('active');
document.getElementById('background-overlay').classList.remove('nw-hidden');
const htmlTag = document.querySelector('html');
htmlTag.style.overflowY = 'hidden';
}, 0)
}
}
// Button clicked
document.addEventListener('click', closeEngagentlyDrawer);
// Check if 'egy_cid' is present in the URL on page load for shared links
document.addEventListener('DOMContentLoaded', function () {
const params = new URLSearchParams(window.location.search);
if (params.has('egy_cid')) {
const app = document.querySelector('#appEgy');
app.classList.add('active');
document.getElementById("closeEngagently").style.display = "flex"
renderEngagentlyDiscussion();
}
var logged_in = '0' ;
if(localStorage.getItem("egy_open") && logged_in){
setTimeout(function (){renderEngagentlyDiscussion(event);}, 2000)
localStorage.removeItem('egy_open');
}
});
document.addEventListener("click", function(event) {
const app = document.querySelector('#logoutButton');
if (app && app.contains(event.target)) {
signOut();
}
});
async function signOut() {
await window.engagently?.signOut();
await window.engagently?.reinit({ token: null });
}
function closeEngagentlyDrawer(event){
const app = document.querySelector('#appEgy');
if (!app.contains(event.target) && app.classList.contains('active')) {
document.getElementById("closeEngagently").style.display = "none";
app.classList.remove('active');
document.getElementById('background-overlay').classList.add('nw-hidden');
}else if(event.target.id == 'closeEngagently' || event.target.id == 'userLoginButton'){
document.getElementById("closeEngagently").style.display = "none"
app.classList.remove('active');
document.getElementById('background-overlay').classList.add('nw-hidden');
}
const htmlTag = document.querySelector('html');
htmlTag.style.overflowY = '';
}
function userLogin(event){
window.scrollTo(0, 0);
localStorage.setItem('egy_open', 1);
const button = document.querySelector('#nw-login-button');
button.click();
}
function handleEngagentlyScroll() {
var close_button = document.querySelector('.drawer-header .close');
var engagently_div = document.getElementById('appEgy');
if (engagently_div.scrollTop > 100) {
close_button.classList.add('scrolled');
} else {
close_button.classList.remove('scrolled');
}
}
var engagently_div = document.getElementById('appEgy');
if (engagently_div) {
// Listen for the scroll event on the div
engagently_div.addEventListener('scroll', handleEngagentlyScroll);
}