X-Git-Url: http://git.shiar.net/sheet.git/blobdiff_plain/114fe2a6b2b8dcfbe3c518f50a2d6b22495ffdd0..3f38a7192491a73a1527179cdd68218f023aed61:/keys.js?ds=inline diff --git a/keys.js b/keys.js index 5dc2e2d..cebd0ee 100644 --- a/keys.js +++ b/keys.js @@ -1,22 +1,36 @@ -function setmode(classname) { +var basetitle = document.title; + +function setmode(classname, restore) { + var tableref = document.getElementById('rows'); + if (!tableref) return; // 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'); + var rows = tableref.getElementsByTagName('TR'); for (var i = 0; i < rows.length; i++) { var el = rows[i]; el.style.display = el.className.match(showclass) ? 'block' : 'none'; } // update H2 to reflect the first part of a currently active (but hidden) row header - var h3s = document.getElementsByTagName('TH'); + var h3s = tableref.getElementsByTagName('TH'); for (var i = 0; i < h3s.length; i++) { if (h3s[i].parentNode.style.display != 'block') continue; var header = h3s[i].firstChild.data; document.getElementsByTagName('H2')[0].innerHTML = header; + document.title = basetitle + ': ' + 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), true); +} + var keyfocus = undefined; document.onkeypress = function(e) { var keylabels = document.getElementById('rows').getElementsByTagName('B');