From: Mischa POSLAWSKY Date: Tue, 3 Feb 2009 15:32:34 +0000 (+0000) Subject: common keyboard javascript include X-Git-Tag: v1.3~199 X-Git-Url: http://git.shiar.nl/sheet.git/commitdiff_plain/d4937c088ffb429c8b3fdf1b3d35b8cbc78d1290?hp=d1a47ecf1b72f55598b2728f82f6b4edb9ebcfa9 common keyboard javascript include Move duplicated code to change key modes into one reusable place. --- diff --git a/keys.js b/keys.js new file mode 100644 index 0000000..d891b52 --- /dev/null +++ b/keys.js @@ -0,0 +1,25 @@ +function setmode(classname) { + // set style for each #rows>li>ul>li to display:none unless it matches classname + var showclass = classname ? ' '+classname+'(?!\\w)' : '^$'; + var parentskip = /^keys/; + var row = document.getElementById('rows').firstChild; + do { + if (row.tagName == 'LI' && row.firstChild.tagName == 'UL' + && !row.firstChild.className.match(parentskip)) { + var el = row.firstChild.firstChild; + if (el) do { + if (el.tagName == 'LI') { + el.style.display = el.className.match(showclass) ? 'block' : 'none'; + } + } while (el = el.nextSibling); + } + } while (row = row.nextSibling); + + // update H2 to reflect the first part of a currently active (but hidden) H3 + var h3s = document.getElementsByTagName('H3'); + for (var i = 0; i < h3s.length; i++) { + if (h3s[i].parentNode.style.display != 'block') continue; + document.getElementsByTagName('H2')[0].innerHTML = h3s[i].firstChild.data; + } +} + diff --git a/nethack.plp b/nethack.plp index d6a37b1..3cedd6e 100644 --- a/nethack.plp +++ b/nethack.plp @@ -42,33 +42,7 @@ $header{content_type} = $ctype; print "\n" if $showkeys and $get{keys} eq 'ghost'; :> - - + diff --git a/vim.plp b/vim.plp index 505e34e..183a04a 100644 --- a/vim.plp +++ b/vim.plp @@ -43,33 +43,7 @@ $header{content_type} = $ctype; if $showkeys and $get{keys} eq 'ghost'; :> - - + diff --git a/vimperator.plp b/vimperator.plp index fe30db5..14be32e 100644 --- a/vimperator.plp +++ b/vimperator.plp @@ -43,33 +43,7 @@ $header{content_type} = $ctype; if $showkeys and $get{keys} eq 'ghost'; :> - - +