Last active
January 17, 2024 11:44
-
-
Save Shimilbi/4653c81a9b1609fb4883aeabb95f7c30 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function toggleDetails (element, setOpen) { | |
const attr = document.createAttribute('open') | |
if (setOpen===undefined) { | |
if (element.hasAttribute('open')) | |
element.removeAttribute('open') | |
else { | |
element.setAttributeNode(attr, 'true') | |
} | |
} | |
if (setOpen) | |
element.setAttributeNode(attr, 'true') | |
if (!setOpen) | |
element.removeAttribute('open') | |
} | |
function setModalMenu (doOpen) { | |
if(doOpen) { | |
toggleDetails(leftNodes, true) | |
document.body.style.overflowY='hidden' | |
// Navigates through menu | |
let i = 0 | |
let leftNodesArr = Array.from(leftNodes.children) | |
let max = parseInt(leftNodesArr.length)-1 | |
document.addEventListener('keyup', function(e) { | |
if (e.key === 'ArrowDown') | |
i = i==max ? 0 : i+1 | |
else if (e.key === 'ArrowUp') | |
i = i==0 ? max : i-1 | |
leftNodesArr[i].focus() | |
}) | |
} | |
else if (!doOpen) { | |
toggleDetails(leftNodes, false) | |
document.body.style.overflowY='scroll' | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment