common keyboard javascript include
authorMischa POSLAWSKY <perl@shiar.org>
Tue, 3 Feb 2009 15:32:34 +0000 (15:32 +0000)
committerMischa POSLAWSKY <perl@shiar.org>
Tue, 21 Apr 2009 23:51:28 +0000 (23:51 +0000)
Move duplicated code to change key modes into one reusable place.

keys.js [new file with mode: 0644]
nethack.plp
vim.plp
vimperator.plp

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;
+       }
+}
+
index d6a37b136b4752830b29cf54b90a36501a60d153..3cedd6e3a182f63c8983fcdb40d6d94531b51954 100644 (file)
@@ -42,33 +42,7 @@ $header{content_type} = $ctype;
        print "\n<style> .no, .alias {opacity:.5} </style>"
                if $showkeys and $get{keys} eq 'ghost';
 :>
-
-<script><!--
-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;
-       }
-} // setmode
-//--></script>
+<script type="text/javascript" src="/keys.js"></script>
 
 <body id="nethack">
 
diff --git a/vim.plp b/vim.plp
index 505e34e70805b35608f56e398764a9f9822f6aa9..183a04a7b081f0c4ea9fdf38387f5c27dca16216 100644 (file)
--- a/vim.plp
+++ b/vim.plp
@@ -43,33 +43,7 @@ $header{content_type} = $ctype;
                if $showkeys and $get{keys} eq 'ghost';
 :>
 <link rel="vcs" type="git" href="git://dev.shiar.nl/sheet">
-
-<script><!--
-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;
-       }
-} // setmode
-//--></script>
+<script type="text/javascript" src="/keys.js"></script>
 
 <body id="vim">
 
index fe30db555d0261635c08bfeada8cf55ceaeb004d..14be32e4745fdf34dcbfc56f10270ae01b3d1956 100644 (file)
@@ -43,33 +43,7 @@ $header{content_type} = $ctype;
                if $showkeys and $get{keys} eq 'ghost';
 :>
 <link rel="vcs" type="git" href="git://dev.shiar.nl/sheet">
-
-<script><!--
-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;
-       }
-} // setmode
-//--></script>
+<script type="text/javascript" src="/keys.js"></script>
 
 <body id="vimperator">