Migrate to prototype.
authorJan Schneider <jan@horde.org>
Sat, 26 Jun 2010 13:30:00 +0000 (15:30 +0200)
committerJan Schneider <jan@horde.org>
Sat, 26 Jun 2010 13:30:00 +0000 (15:30 +0200)
wicked/js/toc.js

index 8533b8c..4419dff 100644 (file)
@@ -1,35 +1,16 @@
 /**
- * Javascript code for making the ToC collapsible.
+ * Javascript code for making the TOC collapsible.
  *
  * See the enclosed file COPYING for license information (GPL). If you
  * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
  */
 
-addEvent(window, 'load', wicked_toc);
-function wicked_toc()
-{
-    var toc = document.getElementById('toc');
-    var ol, h2;
-    for (var i = 0; i < toc.childNodes.length; ++i) {
-        var tagName = toc.childNodes[i].tagName.toUpperCase();
-        if (tagName == 'OL') {
-            ol = toc.childNodes[i];
-        } else if (tagName == 'H2') {
-            h2 = toc.childNodes[i];
-        }
-    }
-
+document.observe('dom:loaded', function() {
+    var h2 = $('toc').down('h2'),
+        ol = $('toc').down('ol');
     if (!ol) {
         return;
     }
-
-    h2.style.cursor = 'pointer';
-
-    addEvent(h2, 'click', function() {
-        if (ol.style.display != 'none') {
-            ol.style.display = 'none';
-        } else {
-            ol.style.display = '';
-        }
-    });
-}
+    h2.setStyle({ cursor: 'pointer' });
+    h2.observe('click', ol.toggle.bind(ol));
+});