summaryrefslogtreecommitdiff
path: root/underlays/javascript/ikiwiki.js
blob: 29de7ec6f6f6237f1fc4ef5237b16d18d2a96ea4 (plain)
  1. // ikiwiki's javascript utility function library
  2. var hooks = new Array;
  3. window.onload = run_hooks_onload;
  4. function run_hooks_onload() {
  5. run_hooks("onload");
  6. }
  7. function run_hooks(name) {
  8. for (var i = 0; i < hooks.length; i++) {
  9. if (hooks[i].name == name) {
  10. hooks[i].call();
  11. }
  12. }
  13. }
  14. function hook(name, call) {
  15. var h={name: name, call: call};
  16. hooks.push(h);
  17. }
  18. function getElementsByClass(cls, node, tag) {
  19. if (document.getElementsByClass)
  20. return document.getElementsByClass(cls, node, tag);
  21. if (! node) node = document;
  22. if (! tag) tag = '*';
  23. var ret = new Array();
  24. var pattern = new RegExp("(^|\\s)"+cls+"(\\s|$)");
  25. var els = node.getElementsByTagName(tag);
  26. for (i = 0; i < els.length; i++) {
  27. if ( pattern.test(els[i].className) ) {
  28. ret.push(els[i]);
  29. }
  30. }
  31. return ret;
  32. }