K |
|
Zeile 1: |
Zeile 1: |
- | /* Jedes JavaScript hier wird für alle Benutzer für jede Seite geladen. */ | + | // <syntax type="javascript"> |
| | | |
- | /** | + | /** |
| Toggles the display of elements on a page | | Toggles the display of elements on a page |
| Author/contact: Austin Che http://openwetware.org/wiki/User:Austin | | Author/contact: Austin Che http://openwetware.org/wiki/User:Austin |
- | */
| + | */ |
- |
| + | |
| // indexed array of toggler ids to array of associated toggle operations | | // indexed array of toggler ids to array of associated toggle operations |
| // each operation is a two element array, the first being the type, the second a class name or array of elements | | // each operation is a two element array, the first being the type, the second a class name or array of elements |
Zeile 11: |
Zeile 11: |
| var togglers = new Array(); | | var togglers = new Array(); |
| var allClasses = new Object(); // associative map of class names to page elements | | var allClasses = new Object(); // associative map of class names to page elements |
- |
| + | |
| function toggler(id) | | function toggler(id) |
| { | | { |
Zeile 17: |
Zeile 17: |
| if (!toBeToggled) | | if (!toBeToggled) |
| return; | | return; |
- |
| + | |
| // if some element is in list more than once, it will be toggled multiple times | | // if some element is in list more than once, it will be toggled multiple times |
| for (var i = 0; i < toBeToggled.length; i++) | | for (var i = 0; i < toBeToggled.length; i++) |
Zeile 37: |
Zeile 37: |
| if (!toggles || !toggles.length) | | if (!toggles || !toggles.length) |
| continue; | | continue; |
- |
| + | |
| var op = toBeToggled[i][0]; // what the operation will be | | var op = toBeToggled[i][0]; // what the operation will be |
- |
| + | |
| switch (op) | | switch (op) |
| { | | { |
Zeile 63: |
Zeile 63: |
| } | | } |
| } | | } |
- |
| + | |
| function createTogglerLink(toggler, id) | | function createTogglerLink(toggler, id) |
| { | | { |
Zeile 75: |
Zeile 75: |
| toggler.insertBefore(toggle, toggler.firstChild); | | toggler.insertBefore(toggle, toggler.firstChild); |
| } | | } |
- |
| + | |
| function toggleInit() | | function toggleInit() |
| { | | { |
| var togglerElems = new Array(); | | var togglerElems = new Array(); |
| var toggleGroup = new Array(); | | var toggleGroup = new Array(); |
- |
| + | |
| // make list of all document classes | | // make list of all document classes |
| var elems = document.getElementsByTagName("*"); | | var elems = document.getElementsByTagName("*"); |
Zeile 89: |
Zeile 89: |
| if (!elem.className) | | if (!elem.className) |
| continue; | | continue; |
- |
| + | |
| elem._toggle_original_display = elem.style.display; | | elem._toggle_original_display = elem.style.display; |
| var togglerID = -1; | | var togglerID = -1; |
Zeile 99: |
Zeile 99: |
| allClasses[elemClass] = new Array(); | | allClasses[elemClass] = new Array(); |
| allClasses[elemClass].push(elem); | | allClasses[elemClass].push(elem); |
- |
| + | |
| // all the special classes begin with _toggle | | // all the special classes begin with _toggle |
| if (elemClass.substring(0, 7) != "_toggle") | | if (elemClass.substring(0, 7) != "_toggle") |
| continue; | | continue; |
- |
| + | |
| if (elemClass == "_togglegroup") | | if (elemClass == "_togglegroup") |
| toggleGroup = new Array(); | | toggleGroup = new Array(); |
Zeile 127: |
Zeile 127: |
| togglerElems[togglerID] = elem; | | togglerElems[togglerID] = elem; |
| } | | } |
- |
| + | |
| // all classes are of form _toggler_op-CLASS | | // all classes are of form _toggler_op-CLASS |
| // figure out what class we're toggling | | // figure out what class we're toggling |
Zeile 140: |
Zeile 140: |
| hyphen = elemClass.length; | | hyphen = elemClass.length; |
| } | | } |
- |
| + | |
| var op = elemClass.substring(8, hyphen); | | var op = elemClass.substring(8, hyphen); |
| togglers[togglerID].push(new Array(op, toBeToggled)); | | togglers[togglerID].push(new Array(op, toBeToggled)); |
Zeile 146: |
Zeile 146: |
| } | | } |
| } | | } |
- |
| + | |
| // add javascript links to all toggler elements | | // add javascript links to all toggler elements |
| for (var i = 0; i < togglerElems.length; i++) | | for (var i = 0; i < togglerElems.length; i++) |
| createTogglerLink(togglerElems[i], i); | | createTogglerLink(togglerElems[i], i); |
| } | | } |
- |
| + | |
| addOnloadHook(toggleInit); | | addOnloadHook(toggleInit); |
- |
| + | |
- | // | + | // </syntax> |