summaryrefslogtreecommitdiff
path: root/lib/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'lib/scripts')
-rw-r--r--lib/scripts/events.js55
1 files changed, 50 insertions, 5 deletions
diff --git a/lib/scripts/events.js b/lib/scripts/events.js
index 262e5ec2d..31a81f6da 100644
--- a/lib/scripts/events.js
+++ b/lib/scripts/events.js
@@ -67,26 +67,71 @@ fixEvent.stopPropagation = function() {
* 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/
+ * @author Dean Edwards
+ * @link http://dean.edwards.name/weblog/2006/06/again/
*/
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;
+ // kill the timer
+ if (_timer) {
+ clearInterval(_timer);
+ _timer = null;
+ }
- if (typeof window.oninit == 'function') {
+ if (typeof window.oninit == 'function') {
window.oninit();
}
};
/**
- * This is a pseudo Event that will be fired by the above function
+ * Run the fireoninit function as soon as possible after
+ * the DOM was loaded, using different methods for different
+ * Browsers
+ *
+ * @author Dean Edwards
+ * @link http://dean.edwards.name/weblog/2006/06/again/
+ */
+ // for Mozilla
+ if (document.addEventListener) {
+ document.addEventListener("DOMContentLoaded", window.fireoninit, null);
+ }
+
+ // for Internet Explorer (using conditional comments)
+ /*@cc_on @*/
+ /*@if (@_win32)
+ document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
+ var script = document.getElementById("__ie_onload");
+ script.onreadystatechange = function() {
+ if (this.readyState == "complete") {
+ window.fireoninit(); // call the onload handler
+ }
+ };
+ /*@end @*/
+
+ // for Safari
+ if (/WebKit/i.test(navigator.userAgent)) { // sniff
+ var _timer = setInterval(function() {
+ if (/loaded|complete/.test(document.readyState)) {
+ window.fireoninit(); // call the onload handler
+ }
+ }, 10);
+ }
+
+ // for other browsers
+ window.onload = window.fireoninit;
+
+
+/**
+ * This is a pseudo Event that will be fired by the fireoninit
+ * function above.
*
* Use addInitEvent to bind to this event!
*
- * @author Andreas Gohr
+ * @author Andreas Gohr <andi@splitbrain.org>
+ * @see fireoninit()
*/
window.oninit = function(){};