From: Mischa POSLAWSKY Date: Sun, 18 Jun 2017 07:53:54 +0000 (+0200) Subject: keys: mode switches in page location hash X-Git-Tag: v1.11~38 X-Git-Url: http://git.shiar.nl/sheet.git/commitdiff_plain/e4a7c6505a32ed30e872bfab2b8cbf411e7a9b13?ds=sidebyside keys: mode switches in page location hash Maintain location history (reflecting current mode in url), and refresh on reload to support browser navigation. --- diff --git a/TODO b/TODO index 6d2f341..4f44428 100644 --- a/TODO +++ b/TODO @@ -20,3 +20,4 @@ - footer style option to top position/button? - top-left header (logo to root)? conflicts with Esc key positioning +- /browser history diff --git a/keys.js b/keys.js index dba04a1..e1b7038 100644 --- a/keys.js +++ b/keys.js @@ -1,4 +1,4 @@ -function setmode(classname) { +function setmode(classname, restore) { // set style for each #rows>li>ul>li to display:none unless it matches classname var showclass = classname ? '^mode '+classname+'(?!\\w)' : '^(?!mode)'; var rows = document.getElementById('rows').getElementsByTagName('TR'); @@ -13,12 +13,17 @@ function setmode(classname) { if (h3s[i].parentNode.style.display != 'block') continue; var header = h3s[i].firstChild.data; document.getElementsByTagName('H2')[0].innerHTML = header; + if (restore) break; + history.pushState(null, header, classname ? '#'+classname : '#'); break; } } +window.addEventListener('hashchange', function(e) { + setmode(location.hash.slice(1), true); +}); if (location.hash) { - setmode(location.hash.slice(1)); + setmode(location.hash.slice(1), true); } var keyfocus = undefined;