2018-12-03 18:49:32 +00:00
|
|
|
document.addEventListener('DOMContentLoaded', function (event) {
|
|
|
|
const menuWrappers = Array.from(document.querySelectorAll('.menu-wrapper'));
|
2019-02-19 15:40:29 +00:00
|
|
|
const rightMenus = Array.from(document.querySelectorAll('nav.jsRightMenu'));
|
2019-05-14 16:19:30 +00:00
|
|
|
const viewsContainer = Array.from(document.querySelectorAll('.views-container'));
|
2018-12-03 18:49:32 +00:00
|
|
|
|
2019-06-05 11:26:10 +00:00
|
|
|
//- View change event
|
|
|
|
// window.addEventListener('navigate', (event) => {
|
|
|
|
// });
|
2019-05-20 13:06:07 +00:00
|
|
|
|
2019-05-14 16:19:30 +00:00
|
|
|
//- Toggle sub-menus
|
2018-12-03 18:49:32 +00:00
|
|
|
menuWrappers.forEach(menuWrapper => {
|
|
|
|
const menu = menuWrapper.querySelector('.menu');
|
|
|
|
menu.addEventListener('click', e => {
|
|
|
|
menuWrapper.classList.toggle('is-closed');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-05-14 16:19:30 +00:00
|
|
|
//- Open/close menu on the right
|
2019-02-19 15:40:29 +00:00
|
|
|
rightMenus.forEach(rightMenu => {
|
|
|
|
const btnRightMenu = rightMenu.querySelector("li.jsOffsiteToggle");
|
2019-05-13 16:50:34 +00:00
|
|
|
|
2019-02-19 15:40:29 +00:00
|
|
|
btnRightMenu.addEventListener('click', e => {
|
2019-05-14 16:19:30 +00:00
|
|
|
rightMenus.forEach(rM => rM.classList.toggle('offsite-is-closed'));
|
|
|
|
viewsContainer.forEach(vC => vC.classList.toggle('sidebar-is-closed'));
|
2019-02-19 15:40:29 +00:00
|
|
|
})
|
2019-05-13 16:50:34 +00:00
|
|
|
});
|
|
|
|
|
2019-06-05 11:26:10 +00:00
|
|
|
//- Watch every sib-forms & update data-src of linked sib-display
|
|
|
|
document.querySelectorAll('sib-form[data-src], sib-form[bind-resource]').forEach(function(el) {
|
|
|
|
el.addEventListener("save", function() {
|
|
|
|
let dataSrc = el.getAttribute('data-src');
|
|
|
|
document.querySelectorAll('sib-display[data-src="'+dataSrc+'"]').forEach(function(e) {
|
|
|
|
e.setAttribute('data-src', dataSrc);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-06-05 11:26:58 +00:00
|
|
|
//- Header login hide/show
|
|
|
|
if(document.querySelector('sib-auth').getUser() !== null) {
|
|
|
|
document.querySelector('button[role="log in"]').style.display = 'none';
|
|
|
|
//- Token expired, hack for ask relogin
|
|
|
|
if(new Date(document.querySelector('sib-auth').getUser().expires_at*1000) <= new Date()) {
|
|
|
|
document.querySelector('button[role="log in"]').style.display = '';
|
|
|
|
document.querySelector('button[role="log in"]').style.color = 'red';
|
|
|
|
document.querySelector('button[role="log in"]').innerHTML = 'Re-login';
|
|
|
|
}
|
|
|
|
}
|
2019-06-05 11:26:10 +00:00
|
|
|
|
2019-05-13 16:50:34 +00:00
|
|
|
});
|