From: John Resig <jeresig@gmail.com>
Date: Wed, 12 Nov 2008 13:18:47 +0000 (+0000)
Subject: Landed the patch, by Diego, that 1) Removes browser sniffing from the ready code... 
X-Git-Url: http://git.asbjorn.it/?a=commitdiff_plain;h=3b1cf91fa44a02ed1377e9fe37b868a6e54762ea;p=jquery.git

Landed the patch, by Diego, that 1) Removes browser sniffing from the ready code and 2) Provides some form of fallback DOM Ready for Iframes in IE. Closes #2614.
---

diff --git a/src/event.js b/src/event.js
index d5ca6cd..f082e7e 100644
--- a/src/event.js
+++ b/src/event.js
@@ -526,21 +526,33 @@ function bindReady(){
 		// Use the handy event callback
 		document.addEventListener( "DOMContentLoaded", jQuery.ready, false );
 
-	// If IE is used and is not in a frame
-	// Continually check to see if the document is ready
-	if ( jQuery.browser.msie && window == top ) (function(){
-		if (jQuery.isReady) return;
-		try {
-			// If IE is used, use the trick by Diego Perini
-			// http://javascript.nwbox.com/IEContentLoaded/
-			document.documentElement.doScroll("left");
-		} catch( error ) {
-			setTimeout( arguments.callee, 0 );
-			return;
-		}
-		// and execute any waiting functions
-		jQuery.ready();
-	})();
+	// If IE event model is used
+	if ( document.attachEvent )
+		// ensure firing before onload,
+		// maybe late but safe also for iframes
+		document.attachEvent("onreadystatechange", function(e) {
+			if ( document.readyState == "complete" ) {
+				document.detachEvent("onreadystatechange", arguments.callee );
+				jQuery.ready();
+			}
+		});
+
+	// If IE and not an iframe
+	if ( document.documentElement.doScroll && !window.frameElement )
+		// continually check to see if the document is ready
+		(function(){
+			if (jQuery.isReady) return;
+			try {
+				// If IE is used, use the trick by Diego Perini
+				// http://javascript.nwbox.com/IEContentLoaded/
+				document.documentElement.doScroll("left");
+			} catch( error ) {
+				setTimeout( arguments.callee, 0 );
+				return;
+			}
+			// and execute any waiting functions
+			jQuery.ready();
+		})();
 
 	if ( jQuery.browser.opera )
 		document.addEventListener( "DOMContentLoaded", function () {