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