improved, possibly faster getelementsbyclass by willu
authorJoey Hess <joey@kodama.kitenet.net>
Fri, 25 Jul 2008 05:43:37 +0000 (01:43 -0400)
committerJoey Hess <joey@kodama.kitenet.net>
Fri, 25 Jul 2008 05:43:37 +0000 (01:43 -0400)
IkiWiki/Plugin/toggle.pm
doc/bugs/toggle_fails_on_Safari.mdwn

index ef30fe6b6ddce2349820da08401c2ccf376845a8..cd9617e259d5433f561faabb4719abc7756c8d75 100644 (file)
@@ -39,18 +39,22 @@ function toggle(s) {
                style.display = "none";
 }
 
-function getElementsByClass(c) {
+function getElementsByClass(cls, node, tag) {
+       if (document.getElementsByClass)
+               return document.getElementsByClass(cls, node, tag);
+       if (! node) node = document;
+       if (! tag) tag = '*';
        var ret = new Array();
-       var pattern = new RegExp("(^|\\s)"+c+"(\\s|$)");
-       var els = document.getElementsByTagName('*');
-       for (i = 0, j = 0; i < els.length; i++) {
+       var pattern = new RegExp("(^|\\s)"+cls+"(\\s|$)");
+       var els = node.getElementsByTagName(tag);
+       for (i = 0; i < els.length; i++) {
                if ( pattern.test(els[i].className) ) {
-                       ret[j] = els[i];
-                       j++;
+                       ret.push(els[i]);
                }
        }
        return ret;
 }
+
 //-->
 </script>
 EOF
index 5ba14d257969bbc94dfaf207bdd54aa6a6b754ea..25f62e0888e424f47fcc8c019c1776f50a7dd24b 100644 (file)
@@ -53,3 +53,6 @@ Looking at the Safari Web Inspector, it believes there is a parse error on line
 >> they're filled in with useful defaults.
 
 >> I don't know if it is worth making this change, but it is there if you want it.
+
+>>> Well, it seems to work. Although god only knows about IE. Suppose I
+>>> might as well.. --[[Joey]]