Skip to content

Instantly share code, notes, and snippets.

@Shimilbi
Last active January 17, 2024 11:44
Show Gist options
  • Save Shimilbi/4653c81a9b1609fb4883aeabb95f7c30 to your computer and use it in GitHub Desktop.
Save Shimilbi/4653c81a9b1609fb4883aeabb95f7c30 to your computer and use it in GitHub Desktop.
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