common keyboard javascript include
[sheet.git] / keys.js
diff --git a/keys.js b/keys.js
new file mode 100644 (file)
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;
+       }
+}
+