From e4a7c6505a32ed30e872bfab2b8cbf411e7a9b13 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Sun, 18 Jun 2017 09:53:54 +0200 Subject: [PATCH] keys: mode switches in page location hash Maintain location history (reflecting current mode in url), and refresh on reload to support browser navigation. --- TODO | 1 + keys.js | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) 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; -- 2.30.0