From ba7ebaf70be4cc91d0b4114f35e4afdf11151ae1 Mon Sep 17 00:00:00 2001 From: John Resig Date: Wed, 14 Jun 2006 20:05:06 +0000 Subject: [PATCH] Adding in the brand new, working, IE DOM Ready code. Plus I made it such that if you bind a ready() function after the DOM has loaded, it will fire the function instantly. --- event/event.js | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/event/event.js b/event/event.js index 70111c6..5511b35 100644 --- a/event/event.js +++ b/event/event.js @@ -41,8 +41,12 @@ $.fn.hover = function(f,g) { }); }; +$.$$isReady = false; +$.$$ready = []; + // Handle when the DOM is ready -$.ready = function(isFinal) { +$.ready = function() { + $.$$isReady = true; if ( $.$$ready ) { for ( var i = 0; i < $.$$ready.length; i++ ) { $.apply( document, $.$$ready[i] ); @@ -51,27 +55,28 @@ $.ready = function(isFinal) { } }; -// Based off of: -// http://linguiste.org/projects/behaviour-DOMContentLoaded/example.html - // If Mozilla is used if ( $.browser == "mozilla" ) { // Use the handy event callback document.addEventListener( "DOMContentLoaded", $.ready, null ); -// If IE is used +// If IE is used, use the excellent hack by Matthias Miller +// http://www.outofhanwell.com/blog/index.php?title=the_window_onload_problem_revisited } else if ( $.browser == "msie" ) { + + // Only works if you document.write() it + document.write('