Last active
December 28, 2021 02:30
-
-
Save neodigm/a94e11ee11357b9eeaaf116880b9fb8c to your computer and use it in GitHub Desktop.
A11y | Is keyboard navigation
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
// Change display attributes if the page is being navigated via kb | |
// I think this was an IEFE back in the day | |
// Useage: | |
/* | |
body:not([data-is-kb]) .h-vs__hidden, | |
body[data-is-kb="false"] .h-vs__hidden{ visibility: hidden; } | |
*/ | |
"isKeyb": function( _bMode ){ // User navigation mode state | |
if( typeof _bMode !== "undefined" ){ | |
if(_bKeyb !== _bMode){ | |
_bKeyb = _bMode; | |
document.body.dataset.isKb = _bKeyb; | |
} | |
} | |
return _bKeyb; | |
} | |
window.addEventListener("click", function() {oTopmenu.isKeyb(false)}); // mouse state | |
window.addEventListener("keyup", function(e) { if(e.keyCode==9) oTopmenu.isKeyb(true); }); // kb state |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment