From 00540a38be97858e71163f53dddf8dee53185b1d Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sat, 10 Dec 2005 20:37:09 +0100 Subject: unobstrusive JS for TOC, better onload handling This path adds more unobstrusive JavaScript for the TOC handling. It also loads JavaScript initialiezers as soon as the DOM is parsed for Mozilla-based Browsers as described at http://dean.edwards.name/weblog/2005/09/busted/ - a IE solution was not chosen yet. darcs-hash:20051210193709-7ad00-771461e56d9661caf9ca733a6d617f009e24d0b7.gz --- lib/scripts/events.js | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) (limited to 'lib/scripts/events.js') diff --git a/lib/scripts/events.js b/lib/scripts/events.js index f6360219d..fb65b1bd7 100644 --- a/lib/scripts/events.js +++ b/lib/scripts/events.js @@ -59,4 +59,54 @@ fixEvent.preventDefault = function() { }; fixEvent.stopPropagation = function() { this.cancelBubble = true; -}; \ No newline at end of file +}; + + +/** + * Pseudo event handler to be fired after the DOM was parsed or + * on window load at last. + * + * @author based upon some code by Dean Edwards + * @author Andreas Gohr + * @see http://dean.edwards.name/weblog/2005/09/busted/ + */ +window.fireoninit = function() { + // quit if this function has already been called + if (arguments.callee.done) return; + // flag this function so we don't do the same thing twice + arguments.callee.done = true; + + if (typeof window.oninit == 'function') { + window.oninit(); + } +} + +/** + * This is a pseudo Event that will be fired by the above function + * + * Use addInitEvent to bind to this event! + * + * @author Andreas Gohr + */ +window.oninit = function() { +} + +/** + * Bind a function to the window.init pseudo event + * + * @author Simon Willison + * @see http://simon.incutio.com/archive/2004/05/26/addLoadEvent + */ +function addInitEvent(func) { + var oldoninit = window.oninit; + if (typeof window.oninit != 'function') { + window.oninit = func; + } else { + window.oninit = function() { + oldoninit(); + func(); + }; + } +} + + -- cgit v1.2.3