Skip to main content

Bug Tracker

Side navigation

Ticket #4982: ready.patch
File ready.patch, 3.8 KB (added by andr3a, July 28, 2009 10:29AM UTC)

ready carousel revisited ( more linear proposal )

Index: event.js
===================================================================
--- event.js	(revision 6518)
+++ event.js	(working copy)
@@ -396,8 +396,6 @@
 
 	special: {
 		ready: {
-			// Make sure the ready event is setup
-			setup: bindReady,
 			teardown: function() {}
 		},
 
@@ -613,20 +611,7 @@
 	},
 
 	ready: function( fn ) {
-		// Attach the listeners
-		bindReady();
-
-		// If the DOM is already ready
-		if ( jQuery.isReady ) {
-			// Execute the function immediately
-			fn.call( document, jQuery );
-
-		// Otherwise, remember the function for later
-		} else {
-			// Add the function to the wait list
-			jQuery.readyList.push( fn );
-		}
-
+		jQuery.isReady ? fn.call( document, jQuery ) : jQuery.readyList.push( fn );
 		return this;
 	},
 
@@ -686,63 +671,55 @@
 	readyList: [],
 	// Handle when the DOM is ready
 	ready: function() {
-		// Make sure that the DOM is not already loaded
-		if ( !jQuery.isReady ) {
-			// Remember that the DOM is ready
-			jQuery.isReady = true;
+		// Make sure that the DOM is already loaded
+		if ( jQuery.isReady ) {
+			// Execute every callback in the queue
+			while(jQuery.readyList.length)
+				jQuery.readyList.shift().call(document, jQuery);
 
-			// If there are functions bound, to execute
-			if ( jQuery.readyList ) {
-				// Execute all of them
-				var fn, i = 0;
-				while ( (fn = jQuery.readyList[ i++ ]) ) {
-					fn.call( document, jQuery );
-				}
-
-				// Reset the list of functions
-				jQuery.readyList = null;
-			}
-
+		} else {
+			// Set isReady as true
+			jQuery.isReady = true;
+			// Execute every callback in the queue
+			jQuery.ready();
 			// Trigger any bound ready events
 			jQuery( document ).triggerHandler( "ready" );
 		}
 	}
 });
 
-var readyBound = false;
+(function(){ // anonymous bindReady
 
-function bindReady() {
-	if ( readyBound ) return;
-	readyBound = true;
-
 	// Catch cases where $(document).ready() is called after the
 	// browser event has already occurred.
 	if ( document.readyState === "complete" ) {
 		return jQuery.ready();
 	}
 
+	var c, fn; // Callbacks alias for "use strict" compatibility
+	
 	// Mozilla, Opera and webkit nightlies currently support this event
 	if ( document.addEventListener ) {
 		// Use the handy event callback
-		document.addEventListener( "DOMContentLoaded", function() {
-			document.removeEventListener( "DOMContentLoaded", arguments.callee, false );
+		document.addEventListener( "DOMContentLoaded", c = function() {
+			document.removeEventListener( "DOMContentLoaded", c, false );
 			jQuery.ready();
 		}, false );
 
-	// If IE event model is used
+		// If IE event model is used
 	} else if ( document.attachEvent ) {
 		// ensure firing before onload,
 		// maybe late but safe also for iframes
-		document.attachEvent("onreadystatechange", function() {
+		document.attachEvent("onreadystatechange", c = function() {
 			if ( document.readyState === "complete" ) {
-				document.detachEvent( "onreadystatechange", arguments.callee );
+				document.detachEvent( "onreadystatechange", c );
 				jQuery.ready();
 			}
 		});
 
 		// If IE and not an iframe
 		// continually check to see if the document is ready
-		if ( document.documentElement.doScroll && window === window.top ) (function() {
+		if ( document.documentElement.doScroll && window === window.top ) (fn = function() {
 			if ( jQuery.isReady ) {
 				return;
 			}
@@ -752,7 +729,7 @@
 				// http://javascript.nwbox.com/IEContentLoaded/
 				document.documentElement.doScroll("left");
 			} catch( error ) {
-				setTimeout( arguments.callee, 0 );
+				setTimeout( fn, 0 );
 				return;
 			}
 
@@ -763,7 +740,7 @@
 
 	// A fallback to window.onload, that will always work
 	jQuery.event.add( window, "load", jQuery.ready );
-}
+})();
 
 jQuery.each( ("blur,focus,load,resize,scroll,unload,click,dblclick," +
 	"mousedown,mouseup,mousemove,mouseover,mouseout,mouseenter,mouseleave," +

Download in other formats:

Original Format