Delay the result of the readyState check to give scripts the opportunity to delay...
[jquery.git] / src / core.js
index ab325ee..f6a07eb 100644 (file)
@@ -17,7 +17,7 @@ var jQuery = function( selector, context ) {
 
        // A simple way to check for HTML strings or ID strings
        // (both of which we optimize for)
-       quickExpr = /^(?:[^<]*(<[\w\W]+>)[^>]*$|#([\w-]+)$)/,
+       quickExpr = /^(?:[^<]*(<[\w\W]+>)[^>]*$|#([\w\-]+)$)/,
 
        // Is it a simple selector
        isSimple = /^.[^:#\[\.,]*$/,
@@ -429,7 +429,8 @@ jQuery.extend({
                // Catch cases where $(document).ready() is called after the
                // browser event has already occurred.
                if ( document.readyState === "complete" ) {
-                       return jQuery.ready();
+                       // Handle it asynchronously to allow scripts the opportunity to delay ready
+                       return setTimeout( jQuery.ready, 13 );
                }
 
                // Mozilla, Opera and webkit nightlies currently support this event
@@ -474,6 +475,11 @@ jQuery.extend({
                return jQuery.type(obj) === "array";
        },
 
+       // A crude way of determining if an object is a window
+       isWindow: function( obj ) {
+               return obj && typeof obj === "object" && "setInterval" in obj;
+       },
+
        type: function( obj ) {
                return obj == null ?
                        String( obj ) :
@@ -484,7 +490,7 @@ jQuery.extend({
                // Must be an Object.
                // Because of IE, we also have to check the presence of the constructor property.
                // Make sure that DOM nodes and window objects don't pass through, as well
-               if ( !obj || jQuery.type(obj) !== "object" || obj.nodeType || obj.setInterval ) {
+               if ( !obj || jQuery.type(obj) !== "object" || obj.nodeType || jQuery.isWindow( obj ) ) {
                        return false;
                }
                
@@ -632,7 +638,7 @@ jQuery.extend({
                        // Tweaked logic slightly to handle Blackberry 4.7 RegExp issues #6930
                        var type = jQuery.type(array);
 
-                       if ( array.length == null || type === "string" || type === "function" || type === "regexp" || "setInterval" in array ) {
+                       if ( array.length == null || type === "string" || type === "function" || type === "regexp" || jQuery.isWindow( array ) ) {
                                push.call( ret, array );
                        } else {
                                jQuery.merge( ret, array );