Allow plugins to delay the exeuction of the ready event. Delay the ready event by...
[jquery.git] / src / core.js
index 7fa20d4..2b00627 100644 (file)
@@ -1,4 +1,4 @@
-(function() {
+var jQuery = (function() {
 
 // Define a local copy of jQuery
 var jQuery = function( selector, context ) {
@@ -109,7 +109,7 @@ jQuery.fn = jQuery.prototype = {
                                                }
 
                                        } else {
-                                               ret = buildFragment( [ match[1] ], [ doc ] );
+                                               ret = jQuery.buildFragment( [ match[1] ], [ doc ] );
                                                selector = (ret.cacheable ? ret.fragment.cloneNode(true) : ret.fragment).childNodes;
                                        }
                                        
@@ -119,7 +119,9 @@ jQuery.fn = jQuery.prototype = {
                                } else {
                                        elem = document.getElementById( match[2] );
 
-                                       if ( elem ) {
+                                       // Check parentNode to catch when Blackberry 4.6 returns
+                                       // nodes that are no longer in the document #6963
+                                       if ( elem && elem.parentNode ) {
                                                // Handle the case where IE and Opera return items
                                                // by name instead of ID
                                                if ( elem.id !== match[2] ) {
@@ -358,11 +360,20 @@ jQuery.extend({
        
        // Is the DOM ready to be used? Set to true once it occurs.
        isReady: false,
+
+       // A counter to track how many items to wait for before
+       // the ready event fires. See #6781
+       readyWait: 1,
        
        // Handle when the DOM is ready
-       ready: function() {
+       ready: function( wait ) {
+               // A third-party is pushing the ready event forwards
+               if ( wait === true ) {
+                       jQuery.readyWait--;
+               }
+
                // Make sure that the DOM is not already loaded
-               if ( !jQuery.isReady ) {
+               if ( !jQuery.readyWait && !jQuery.isReady ) {
                        // Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443).
                        if ( !document.body ) {
                                return setTimeout( jQuery.ready, 13 );
@@ -371,6 +382,11 @@ jQuery.extend({
                        // Remember that the DOM is ready
                        jQuery.isReady = true;
 
+                       // If a normal DOM Ready event fired, decrement, and wait if need be
+                       if ( wait !== true && --jQuery.readyWait > 0 ) {
+                               return;
+                       }
+
                        // If there are functions bound, to execute
                        if ( readyList ) {
                                // Execute all of them
@@ -438,18 +454,24 @@ jQuery.extend({
        // Since version 1.3, DOM methods and functions like alert
        // aren't supported. They return false on IE (#2968).
        isFunction: function( obj ) {
-               return toString.call(obj) === "[object Function]";
+               return jQuery.type(obj) === "function";
+       },
+
+       isArray: Array.isArray || function( obj ) {
+               return jQuery.type(obj) === "array";
        },
 
-       isArray: function( obj ) {
-               return toString.call(obj) === "[object Array]";
+       type: function( obj ) {
+               return obj == null ?
+                       String( obj ) :
+                       toString.call(obj).slice(8, -1).toLowerCase();
        },
 
        isPlainObject: function( obj ) {
                // 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 || toString.call(obj) !== "[object Object]" || obj.nodeType || obj.setInterval ) {
+               if ( !obj || jQuery.type(obj) !== "object" || obj.nodeType || obj.setInterval ) {
                        return false;
                }
                
@@ -595,9 +617,9 @@ jQuery.extend({
                        // The extra typeof function check is to prevent crashes
                        // in Safari 2 (See: #3039)
                        // Tweaked logic slightly to handle Blackberry 4.7 RegExp issues #6930
-                       var type = toString.call(array);
+                       var type = jQuery.type(array);
 
-                       if ( array.length == null || type === "[object String]" || type === "[object Function]" || type === "[object RegExp]" || (typeof type !== "function" && array.setInterval) ) {
+                       if ( array.length == null || type === "string" || type === "function" || type === "regexp" || "setInterval" in array ) {
                                push.call( ret, array );
                        } else {
                                jQuery.merge( ret, array );
@@ -818,6 +840,6 @@ function doScrollCheck() {
 }
 
 // Expose jQuery to the global object
-window.jQuery = window.$ = jQuery;
+return (window.jQuery = window.$ = jQuery);
 
 })();