2020-04-27 17:42:40 +00:00
|
|
|
(function (window, document) {
|
|
|
|
|
2021-01-20 19:35:15 +00:00
|
|
|
// we fetch the elements each time because docusaurus removes the previous
|
|
|
|
// element references on page navigation
|
|
|
|
function getElements() {
|
|
|
|
return {
|
|
|
|
layout: document.getElementById('layout'),
|
|
|
|
menu: document.getElementById('menu'),
|
|
|
|
menuLink: document.getElementById('menuLink')
|
|
|
|
};
|
|
|
|
}
|
2020-04-27 17:42:40 +00:00
|
|
|
|
|
|
|
function toggleClass(element, className) {
|
2021-01-20 19:35:15 +00:00
|
|
|
var classes = element.className.split(/\s+/);
|
|
|
|
var length = classes.length;
|
|
|
|
var i = 0;
|
2020-04-27 17:42:40 +00:00
|
|
|
|
2020-05-16 03:53:27 +00:00
|
|
|
for (; i < length; i++) {
|
2020-05-16 18:09:14 +00:00
|
|
|
if (classes[i] === className) {
|
|
|
|
classes.splice(i, 1);
|
|
|
|
break;
|
|
|
|
}
|
2020-04-27 17:42:40 +00:00
|
|
|
}
|
|
|
|
// The className is not found
|
|
|
|
if (length === classes.length) {
|
|
|
|
classes.push(className);
|
|
|
|
}
|
|
|
|
|
|
|
|
element.className = classes.join(' ');
|
|
|
|
}
|
|
|
|
|
2021-01-20 19:35:15 +00:00
|
|
|
function toggleAll() {
|
2020-04-27 17:42:40 +00:00
|
|
|
var active = 'active';
|
2021-01-20 19:35:15 +00:00
|
|
|
var elements = getElements();
|
2020-04-27 17:42:40 +00:00
|
|
|
|
2021-01-20 19:35:15 +00:00
|
|
|
toggleClass(elements.layout, active);
|
|
|
|
toggleClass(elements.menu, active);
|
|
|
|
toggleClass(elements.menuLink, active);
|
2020-04-27 17:42:40 +00:00
|
|
|
}
|
2020-05-16 03:53:27 +00:00
|
|
|
|
|
|
|
function handleEvent(e) {
|
2021-01-20 19:35:15 +00:00
|
|
|
var elements = getElements();
|
2020-05-16 03:53:27 +00:00
|
|
|
|
2021-01-20 19:35:15 +00:00
|
|
|
if (e.target.id === elements.menuLink.id) {
|
|
|
|
toggleAll();
|
|
|
|
e.preventDefault();
|
|
|
|
} else if (elements.menu.className.indexOf('active') !== -1) {
|
|
|
|
toggleAll();
|
2020-04-27 17:42:40 +00:00
|
|
|
}
|
2020-05-16 03:53:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
document.addEventListener('click', handleEvent);
|
2020-04-27 17:42:40 +00:00
|
|
|
|
|
|
|
}(this, this.document));
|