Skip to main content

Bug Tracker

Side navigation

Ticket #2614: event-ready.patch


File event-ready.patch, 1.7 KB (added by diego, July 16, 2008 10:20AM UTC)

Patch for event.js in trunk

--- event.js	2008-07-12 22:15:27.000000000 +0200
+++ event-patched.js	2008-07-15 18:44:02.000000000 +0200
@@ -528,21 +528,33 @@
 		// 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 () {

Download in other formats:

Original Format