X-Git-Url: https://git.rvb.name/esp-clock.git/blobdiff_plain/e1b7c70070cda97937a405a2c9e48d190b4391ef..018c87cf62ac447add9510fe2cafd21ef1e75040:/data/web/script.js diff --git a/data/web/script.js b/data/web/script.js index 67c213f..c40f7e1 100644 --- a/data/web/script.js +++ b/data/web/script.js @@ -1,61 +1,26 @@ -(function (window, document) { - - // 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') - }; - } - - function toggleClass(element, className) { - var classes = element.className.split(/\s+/); - var length = classes.length; - var i = 0; - - for (; i < length; i++) { - if (classes[i] === className) { - classes.splice(i, 1); - break; - } - } - // The className is not found - if (length === classes.length) { - classes.push(className); - } +var pages +var parameters = {} +var daynames = ['Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб', 'Вс'] - element.className = classes.join(' '); +function toggleMenu(e) { + active = (document.getElementById('menuLink').className.indexOf('active') !== -1) + if (active || e.target.id == 'menuLink' || e.target.id == 'menuBtn') { + elements = [ document.getElementById('layout'), document.getElementById('menu'), document.getElementById('menuLink') ] + for (const element of elements) { + if (!active) { + element.classList.add('active') + } else { + element.classList.remove('active') + } } - - function toggleAll() { - var active = 'active'; - var elements = getElements(); - - toggleClass(elements.layout, active); - toggleClass(elements.menu, active); - toggleClass(elements.menuLink, active); + if (e.target.id == 'menuLink' || e.target.id == 'menuBtn') { + e.preventDefault() } - - function handleEvent(e) { - var elements = getElements(); - - if (e.target.id === elements.menuLink.id) { - toggleAll(); - e.preventDefault(); - } else if (elements.menu.className.indexOf('active') !== -1) { - toggleAll(); - } - } - - document.addEventListener('click', handleEvent); - -}(this, this.document)); + e.stopPropagation() + } +} -var pages -var parameters = {} -var daynames = ['Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб', 'Вс'] +document.getElementById('layout').addEventListener('click', toggleMenu) function encode(r){ r = String(r) @@ -271,7 +236,7 @@ function ElementHTML(element) { return '
' + '' - + '
👁
' + + '
' case 'input': var pattern = "" if (element.pattern) { @@ -288,7 +253,7 @@ function ElementHTML(element) { return '
' + '' - + '
📶
' + + '
' + '