Update version in release notes builder.
[jquery.git] / src / core.js
blob844eb159364f1e51970688884e99274af6f8c430
1 var
2         // A central reference to the root jQuery(document)
3         rootjQuery,
5         // The deferred used on DOM ready
6         readyList,
8         // Use the correct document accordingly with window argument (sandbox)
9         document = window.document,
10         location = window.location,
12         // Map over jQuery in case of overwrite
13         _jQuery = window.jQuery,
15         // Map over the $ in case of overwrite
16         _$ = window.$,
18         // [[Class]] -> type pairs
19         class2type = {},
21         // List of deleted data cache ids, so we can reuse them
22         core_deletedIds = [],
24         core_version = "@VERSION",
26         // Save a reference to some core methods
27         core_concat = core_deletedIds.concat,
28         core_push = core_deletedIds.push,
29         core_slice = core_deletedIds.slice,
30         core_indexOf = core_deletedIds.indexOf,
31         core_toString = class2type.toString,
32         core_hasOwn = class2type.hasOwnProperty,
33         core_trim = core_version.trim,
35         // Define a local copy of jQuery
36         jQuery = function( selector, context ) {
37                 // The jQuery object is actually just the init constructor 'enhanced'
38                 return new jQuery.fn.init( selector, context, rootjQuery );
39         },
41         // Used for matching numbers
42         core_pnum = /[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/.source,
44         // Used for splitting on whitespace
45         core_rnotwhite = /\S+/g,
47         // Make sure we trim BOM and NBSP (here's looking at you, Safari 5.0 and IE)
48         rtrim = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,
50         // A simple way to check for HTML strings
51         // Prioritize #id over <tag> to avoid XSS via location.hash (#9521)
52         // Strict HTML recognition (#11290: must start with <)
53         rquickExpr = /^(?:(<[\w\W]+>)[^>]*|#([\w-]*))$/,
55         // Match a standalone tag
56         rsingleTag = /^<(\w+)\s*\/?>(?:<\/\1>|)$/,
58         // JSON RegExp
59         rvalidchars = /^[\],:{}\s]*$/,
60         rvalidbraces = /(?:^|:|,)(?:\s*\[)+/g,
61         rvalidescape = /\\(?:["\\\/bfnrt]|u[\da-fA-F]{4})/g,
62         rvalidtokens = /"[^"\\\r\n]*"|true|false|null|-?(?:\d+\.|)\d+(?:[eE][+-]?\d+|)/g,
64         // Matches dashed string for camelizing
65         rmsPrefix = /^-ms-/,
66         rdashAlpha = /-([\da-z])/gi,
68         // Used by jQuery.camelCase as callback to replace()
69         fcamelCase = function( all, letter ) {
70                 return letter.toUpperCase();
71         },
73         // The ready event handler and self cleanup method
74         DOMContentLoaded = function() {
75                 if ( document.addEventListener ) {
76                         document.removeEventListener( "DOMContentLoaded", DOMContentLoaded, false );
77                         jQuery.ready();
78                 } else if ( document.readyState === "complete" ) {
79                         // we're here because readyState === "complete" in oldIE
80                         // which is good enough for us to call the dom ready!
81                         document.detachEvent( "onreadystatechange", DOMContentLoaded );
82                         jQuery.ready();
83                 }
84         };
86 jQuery.fn = jQuery.prototype = {
87         // The current version of jQuery being used
88         jquery: core_version,
90         constructor: jQuery,
91         init: function( selector, context, rootjQuery ) {
92                 var match, elem;
94                 // HANDLE: $(""), $(null), $(undefined), $(false)
95                 if ( !selector ) {
96                         return this;
97                 }
99                 // HANDLE: $(DOMElement)
100                 if ( selector.nodeType ) {
101                         this.context = this[0] = selector;
102                         this.length = 1;
103                         return this;
104                 }
106                 // Handle HTML strings
107                 if ( typeof selector === "string" ) {
108                         if ( selector.charAt(0) === "<" && selector.charAt( selector.length - 1 ) === ">" && selector.length >= 3 ) {
109                                 // Assume that strings that start and end with <> are HTML and skip the regex check
110                                 match = [ null, selector, null ];
112                         } else {
113                                 match = rquickExpr.exec( selector );
114                         }
116                         // Match html or make sure no context is specified for #id
117                         if ( match && (match[1] || !context) ) {
119                                 // HANDLE: $(html) -> $(array)
120                                 if ( match[1] ) {
121                                         context = context instanceof jQuery ? context[0] : context;
123                                         // scripts is true for back-compat
124                                         jQuery.merge( this, jQuery.parseHTML(
125                                                 match[1],
126                                                 context && context.nodeType ? context.ownerDocument || context : document,
127                                                 true
128                                         ) );
130                                         // HANDLE: $(html, props)
131                                         if ( rsingleTag.test( match[1] ) && jQuery.isPlainObject( context ) ) {
132                                                 for ( match in context ) {
133                                                         // Properties of context are called as methods if possible
134                                                         if ( jQuery.isFunction( this[ match ] ) ) {
135                                                                 this[ match ]( context[ match ] );
137                                                         // ...and otherwise set as attributes
138                                                         } else {
139                                                                 this.attr( match, context[ match ] );
140                                                         }
141                                                 }
142                                         }
144                                         return this;
146                                 // HANDLE: $(#id)
147                                 } else {
148                                         elem = document.getElementById( match[2] );
150                                         // Check parentNode to catch when Blackberry 4.6 returns
151                                         // nodes that are no longer in the document #6963
152                                         if ( elem && elem.parentNode ) {
153                                                 // Handle the case where IE and Opera return items
154                                                 // by name instead of ID
155                                                 if ( elem.id !== match[2] ) {
156                                                         return rootjQuery.find( selector );
157                                                 }
159                                                 // Otherwise, we inject the element directly into the jQuery object
160                                                 this.length = 1;
161                                                 this[0] = elem;
162                                         }
164                                         this.context = document;
165                                         this.selector = selector;
166                                         return this;
167                                 }
169                         // HANDLE: $(expr, $(...))
170                         } else if ( !context || context.jquery ) {
171                                 return ( context || rootjQuery ).find( selector );
173                         // HANDLE: $(expr, context)
174                         // (which is just equivalent to: $(context).find(expr)
175                         } else {
176                                 return this.constructor( context ).find( selector );
177                         }
179                 // HANDLE: $(function)
180                 // Shortcut for document ready
181                 } else if ( jQuery.isFunction( selector ) ) {
182                         return rootjQuery.ready( selector );
183                 }
185                 if ( selector.selector !== undefined ) {
186                         this.selector = selector.selector;
187                         this.context = selector.context;
188                 }
190                 return jQuery.makeArray( selector, this );
191         },
193         // Start with an empty selector
194         selector: "",
196         // The default length of a jQuery object is 0
197         length: 0,
199         // The number of elements contained in the matched element set
200         size: function() {
201                 return this.length;
202         },
204         toArray: function() {
205                 return core_slice.call( this );
206         },
208         // Get the Nth element in the matched element set OR
209         // Get the whole matched element set as a clean array
210         get: function( num ) {
211                 return num == null ?
213                         // Return a 'clean' array
214                         this.toArray() :
216                         // Return just the object
217                         ( num < 0 ? this[ this.length + num ] : this[ num ] );
218         },
220         // Take an array of elements and push it onto the stack
221         // (returning the new matched element set)
222         pushStack: function( elems ) {
224                 // Build a new jQuery matched element set
225                 var ret = jQuery.merge( this.constructor(), elems );
227                 // Add the old object onto the stack (as a reference)
228                 ret.prevObject = this;
229                 ret.context = this.context;
231                 // Return the newly-formed element set
232                 return ret;
233         },
235         // Execute a callback for every element in the matched set.
236         // (You can seed the arguments with an array of args, but this is
237         // only used internally.)
238         each: function( callback, args ) {
239                 return jQuery.each( this, callback, args );
240         },
242         ready: function( fn ) {
243                 // Add the callback
244                 jQuery.ready.promise().done( fn );
246                 return this;
247         },
249         slice: function() {
250                 return this.pushStack( core_slice.apply( this, arguments ) );
251         },
253         first: function() {
254                 return this.eq( 0 );
255         },
257         last: function() {
258                 return this.eq( -1 );
259         },
261         eq: function( i ) {
262                 var len = this.length,
263                         j = +i + ( i < 0 ? len : 0 );
264                 return this.pushStack( j >= 0 && j < len ? [ this[j] ] : [] );
265         },
267         map: function( callback ) {
268                 return this.pushStack( jQuery.map(this, function( elem, i ) {
269                         return callback.call( elem, i, elem );
270                 }));
271         },
273         end: function() {
274                 return this.prevObject || this.constructor(null);
275         },
277         // For internal use only.
278         // Behaves like an Array's method, not like a jQuery method.
279         push: core_push,
280         sort: [].sort,
281         splice: [].splice
284 // Give the init function the jQuery prototype for later instantiation
285 jQuery.fn.init.prototype = jQuery.fn;
287 jQuery.extend = jQuery.fn.extend = function() {
288         var options, name, src, copy, copyIsArray, clone,
289                 target = arguments[0] || {},
290                 i = 1,
291                 length = arguments.length,
292                 deep = false;
294         // Handle a deep copy situation
295         if ( typeof target === "boolean" ) {
296                 deep = target;
297                 target = arguments[1] || {};
298                 // skip the boolean and the target
299                 i = 2;
300         }
302         // Handle case when target is a string or something (possible in deep copy)
303         if ( typeof target !== "object" && !jQuery.isFunction(target) ) {
304                 target = {};
305         }
307         // extend jQuery itself if only one argument is passed
308         if ( length === i ) {
309                 target = this;
310                 --i;
311         }
313         for ( ; i < length; i++ ) {
314                 // Only deal with non-null/undefined values
315                 if ( (options = arguments[ i ]) != null ) {
316                         // Extend the base object
317                         for ( name in options ) {
318                                 src = target[ name ];
319                                 copy = options[ name ];
321                                 // Prevent never-ending loop
322                                 if ( target === copy ) {
323                                         continue;
324                                 }
326                                 // Recurse if we're merging plain objects or arrays
327                                 if ( deep && copy && ( jQuery.isPlainObject(copy) || (copyIsArray = jQuery.isArray(copy)) ) ) {
328                                         if ( copyIsArray ) {
329                                                 copyIsArray = false;
330                                                 clone = src && jQuery.isArray(src) ? src : [];
332                                         } else {
333                                                 clone = src && jQuery.isPlainObject(src) ? src : {};
334                                         }
336                                         // Never move original objects, clone them
337                                         target[ name ] = jQuery.extend( deep, clone, copy );
339                                 // Don't bring in undefined values
340                                 } else if ( copy !== undefined ) {
341                                         target[ name ] = copy;
342                                 }
343                         }
344                 }
345         }
347         // Return the modified object
348         return target;
351 jQuery.extend({
352         noConflict: function( deep ) {
353                 if ( window.$ === jQuery ) {
354                         window.$ = _$;
355                 }
357                 if ( deep && window.jQuery === jQuery ) {
358                         window.jQuery = _jQuery;
359                 }
361                 return jQuery;
362         },
364         // Is the DOM ready to be used? Set to true once it occurs.
365         isReady: false,
367         // A counter to track how many items to wait for before
368         // the ready event fires. See #6781
369         readyWait: 1,
371         // Hold (or release) the ready event
372         holdReady: function( hold ) {
373                 if ( hold ) {
374                         jQuery.readyWait++;
375                 } else {
376                         jQuery.ready( true );
377                 }
378         },
380         // Handle when the DOM is ready
381         ready: function( wait ) {
383                 // Abort if there are pending holds or we're already ready
384                 if ( wait === true ? --jQuery.readyWait : jQuery.isReady ) {
385                         return;
386                 }
388                 // Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443).
389                 if ( !document.body ) {
390                         return setTimeout( jQuery.ready );
391                 }
393                 // Remember that the DOM is ready
394                 jQuery.isReady = true;
396                 // If a normal DOM Ready event fired, decrement, and wait if need be
397                 if ( wait !== true && --jQuery.readyWait > 0 ) {
398                         return;
399                 }
401                 // If there are functions bound, to execute
402                 readyList.resolveWith( document, [ jQuery ] );
404                 // Trigger any bound ready events
405                 if ( jQuery.fn.trigger ) {
406                         jQuery( document ).trigger("ready").off("ready");
407                 }
408         },
410         // See test/unit/core.js for details concerning isFunction.
411         // Since version 1.3, DOM methods and functions like alert
412         // aren't supported. They return false on IE (#2968).
413         isFunction: function( obj ) {
414                 return jQuery.type(obj) === "function";
415         },
417         isArray: Array.isArray || function( obj ) {
418                 return jQuery.type(obj) === "array";
419         },
421         isWindow: function( obj ) {
422                 return obj != null && obj == obj.window;
423         },
425         isNumeric: function( obj ) {
426                 return !isNaN( parseFloat(obj) ) && isFinite( obj );
427         },
429         type: function( obj ) {
430                 return obj == null ?
431                         String( obj ) :
432                         class2type[ core_toString.call(obj) ] || "object";
433         },
435         isPlainObject: function( obj ) {
436                 // Must be an Object.
437                 // Because of IE, we also have to check the presence of the constructor property.
438                 // Make sure that DOM nodes and window objects don't pass through, as well
439                 if ( !obj || jQuery.type(obj) !== "object" || obj.nodeType || jQuery.isWindow( obj ) ) {
440                         return false;
441                 }
443                 try {
444                         // Not own constructor property must be Object
445                         if ( obj.constructor &&
446                                 !core_hasOwn.call(obj, "constructor") &&
447                                 !core_hasOwn.call(obj.constructor.prototype, "isPrototypeOf") ) {
448                                 return false;
449                         }
450                 } catch ( e ) {
451                         // IE8,9 Will throw exceptions on certain host objects #9897
452                         return false;
453                 }
455                 // Own properties are enumerated firstly, so to speed up,
456                 // if last one is own, then all properties are own.
458                 var key;
459                 for ( key in obj ) {}
461                 return key === undefined || core_hasOwn.call( obj, key );
462         },
464         isEmptyObject: function( obj ) {
465                 var name;
466                 for ( name in obj ) {
467                         return false;
468                 }
469                 return true;
470         },
472         error: function( msg ) {
473                 throw new Error( msg );
474         },
476         // data: string of html
477         // context (optional): If specified, the fragment will be created in this context, defaults to document
478         // keepScripts (optional): If true, will include scripts passed in the html string
479         parseHTML: function( data, context, keepScripts ) {
480                 if ( !data || typeof data !== "string" ) {
481                         return null;
482                 }
483                 if ( typeof context === "boolean" ) {
484                         keepScripts = context;
485                         context = false;
486                 }
487                 context = context || document;
489                 var parsed = rsingleTag.exec( data ),
490                         scripts = !keepScripts && [];
492                 // Single tag
493                 if ( parsed ) {
494                         return [ context.createElement( parsed[1] ) ];
495                 }
497                 parsed = context.createDocumentFragment();
498                 jQuery.clean( [ data ], context, parsed, scripts );
499                 if ( scripts ) {
500                         jQuery( scripts ).remove();
501                 }
502                 return jQuery.merge( [], parsed.childNodes );
503         },
505         parseJSON: function( data ) {
506                 // Attempt to parse using the native JSON parser first
507                 if ( window.JSON && window.JSON.parse ) {
508                         return window.JSON.parse( data );
509                 }
511                 if ( data === null ) {
512                         return data;
513                 }
515                 if ( typeof data === "string" ) {
517                         // Make sure leading/trailing whitespace is removed (IE can't handle it)
518                         data = jQuery.trim( data );
520                         if ( data ) {
521                                 // Make sure the incoming data is actual JSON
522                                 // Logic borrowed from http://json.org/json2.js
523                                 if ( rvalidchars.test( data.replace( rvalidescape, "@" )
524                                         .replace( rvalidtokens, "]" )
525                                         .replace( rvalidbraces, "")) ) {
527                                         return ( new Function( "return " + data ) )();
528                                 }
529                         }
530                 }
532                 jQuery.error( "Invalid JSON: " + data );
533         },
535         // Cross-browser xml parsing
536         parseXML: function( data ) {
537                 var xml, tmp;
538                 if ( !data || typeof data !== "string" ) {
539                         return null;
540                 }
541                 try {
542                         if ( window.DOMParser ) { // Standard
543                                 tmp = new DOMParser();
544                                 xml = tmp.parseFromString( data , "text/xml" );
545                         } else { // IE
546                                 xml = new ActiveXObject( "Microsoft.XMLDOM" );
547                                 xml.async = "false";
548                                 xml.loadXML( data );
549                         }
550                 } catch( e ) {
551                         xml = undefined;
552                 }
553                 if ( !xml || !xml.documentElement || xml.getElementsByTagName( "parsererror" ).length ) {
554                         jQuery.error( "Invalid XML: " + data );
555                 }
556                 return xml;
557         },
559         noop: function() {},
561         // Evaluates a script in a global context
562         // Workarounds based on findings by Jim Driscoll
563         // http://weblogs.java.net/blog/driscoll/archive/2009/09/08/eval-javascript-global-context
564         globalEval: function( data ) {
565                 if ( data && jQuery.trim( data ) ) {
566                         // We use execScript on Internet Explorer
567                         // We use an anonymous function so that context is window
568                         // rather than jQuery in Firefox
569                         ( window.execScript || function( data ) {
570                                 window[ "eval" ].call( window, data );
571                         } )( data );
572                 }
573         },
575         // Convert dashed to camelCase; used by the css and data modules
576         // Microsoft forgot to hump their vendor prefix (#9572)
577         camelCase: function( string ) {
578                 return string.replace( rmsPrefix, "ms-" ).replace( rdashAlpha, fcamelCase );
579         },
581         nodeName: function( elem, name ) {
582                 return elem.nodeName && elem.nodeName.toLowerCase() === name.toLowerCase();
583         },
585         // args is for internal usage only
586         each: function( obj, callback, args ) {
587                 var value,
588                         i = 0,
589                         length = obj.length,
590                         isArray = isArraylike( obj );
592                 if ( args ) {
593                         if ( isArray ) {
594                                 for ( ; i < length; i++ ) {
595                                         value = callback.apply( obj[ i ], args );
597                                         if ( value === false ) {
598                                                 break;
599                                         }
600                                 }
601                         } else {
602                                 for ( i in obj ) {
603                                         value = callback.apply( obj[ i ], args );
605                                         if ( value === false ) {
606                                                 break;
607                                         }
608                                 }
609                         }
611                 // A special, fast, case for the most common use of each
612                 } else {
613                         if ( isArray ) {
614                                 for ( ; i < length; i++ ) {
615                                         value = callback.call( obj[ i ], i, obj[ i ] );
617                                         if ( value === false ) {
618                                                 break;
619                                         }
620                                 }
621                         } else {
622                                 for ( i in obj ) {
623                                         value = callback.call( obj[ i ], i, obj[ i ] );
625                                         if ( value === false ) {
626                                                 break;
627                                         }
628                                 }
629                         }
630                 }
632                 return obj;
633         },
635         // Use native String.trim function wherever possible
636         trim: core_trim && !core_trim.call("\uFEFF\xA0") ?
637                 function( text ) {
638                         return text == null ?
639                                 "" :
640                                 core_trim.call( text );
641                 } :
643                 // Otherwise use our own trimming functionality
644                 function( text ) {
645                         return text == null ?
646                                 "" :
647                                 ( text + "" ).replace( rtrim, "" );
648                 },
650         // results is for internal usage only
651         makeArray: function( arr, results ) {
652                 var ret = results || [];
654                 if ( arr != null ) {
655                         if ( isArraylike( Object(arr) ) ) {
656                                 jQuery.merge( ret,
657                                         typeof arr === "string" ?
658                                         [ arr ] : arr
659                                 );
660                         } else {
661                                 core_push.call( ret, arr );
662                         }
663                 }
665                 return ret;
666         },
668         inArray: function( elem, arr, i ) {
669                 var len;
671                 if ( arr ) {
672                         if ( core_indexOf ) {
673                                 return core_indexOf.call( arr, elem, i );
674                         }
676                         len = arr.length;
677                         i = i ? i < 0 ? Math.max( 0, len + i ) : i : 0;
679                         for ( ; i < len; i++ ) {
680                                 // Skip accessing in sparse arrays
681                                 if ( i in arr && arr[ i ] === elem ) {
682                                         return i;
683                                 }
684                         }
685                 }
687                 return -1;
688         },
690         merge: function( first, second ) {
691                 var l = second.length,
692                         i = first.length,
693                         j = 0;
695                 if ( typeof l === "number" ) {
696                         for ( ; j < l; j++ ) {
697                                 first[ i++ ] = second[ j ];
698                         }
699                 } else {
700                         while ( second[j] !== undefined ) {
701                                 first[ i++ ] = second[ j++ ];
702                         }
703                 }
705                 first.length = i;
707                 return first;
708         },
710         grep: function( elems, callback, inv ) {
711                 var retVal,
712                         ret = [],
713                         i = 0,
714                         length = elems.length;
715                 inv = !!inv;
717                 // Go through the array, only saving the items
718                 // that pass the validator function
719                 for ( ; i < length; i++ ) {
720                         retVal = !!callback( elems[ i ], i );
721                         if ( inv !== retVal ) {
722                                 ret.push( elems[ i ] );
723                         }
724                 }
726                 return ret;
727         },
729         // arg is for internal usage only
730         map: function( elems, callback, arg ) {
731                 var value,
732                         i = 0,
733                         length = elems.length,
734                         isArray = isArraylike( elems ),
735                         ret = [];
737                 // Go through the array, translating each of the items to their
738                 if ( isArray ) {
739                         for ( ; i < length; i++ ) {
740                                 value = callback( elems[ i ], i, arg );
742                                 if ( value != null ) {
743                                         ret[ ret.length ] = value;
744                                 }
745                         }
747                 // Go through every key on the object,
748                 } else {
749                         for ( i in elems ) {
750                                 value = callback( elems[ i ], i, arg );
752                                 if ( value != null ) {
753                                         ret[ ret.length ] = value;
754                                 }
755                         }
756                 }
758                 // Flatten any nested arrays
759                 return core_concat.apply( [], ret );
760         },
762         // A global GUID counter for objects
763         guid: 1,
765         // Bind a function to a context, optionally partially applying any
766         // arguments.
767         proxy: function( fn, context ) {
768                 var tmp, args, proxy;
770                 if ( typeof context === "string" ) {
771                         tmp = fn[ context ];
772                         context = fn;
773                         fn = tmp;
774                 }
776                 // Quick check to determine if target is callable, in the spec
777                 // this throws a TypeError, but we will just return undefined.
778                 if ( !jQuery.isFunction( fn ) ) {
779                         return undefined;
780                 }
782                 // Simulated bind
783                 args = core_slice.call( arguments, 2 );
784                 proxy = function() {
785                         return fn.apply( context || this, args.concat( core_slice.call( arguments ) ) );
786                 };
788                 // Set the guid of unique handler to the same of original handler, so it can be removed
789                 proxy.guid = fn.guid = fn.guid || jQuery.guid++;
791                 return proxy;
792         },
794         // Multifunctional method to get and set values of a collection
795         // The value/s can optionally be executed if it's a function
796         access: function( elems, fn, key, value, chainable, emptyGet, raw ) {
797                 var i = 0,
798                         length = elems.length,
799                         bulk = key == null;
801                 // Sets many values
802                 if ( jQuery.type( key ) === "object" ) {
803                         chainable = true;
804                         for ( i in key ) {
805                                 jQuery.access( elems, fn, i, key[i], true, emptyGet, raw );
806                         }
808                 // Sets one value
809                 } else if ( value !== undefined ) {
810                         chainable = true;
812                         if ( !jQuery.isFunction( value ) ) {
813                                 raw = true;
814                         }
816                         if ( bulk ) {
817                                 // Bulk operations run against the entire set
818                                 if ( raw ) {
819                                         fn.call( elems, value );
820                                         fn = null;
822                                 // ...except when executing function values
823                                 } else {
824                                         bulk = fn;
825                                         fn = function( elem, key, value ) {
826                                                 return bulk.call( jQuery( elem ), value );
827                                         };
828                                 }
829                         }
831                         if ( fn ) {
832                                 for ( ; i < length; i++ ) {
833                                         fn( elems[i], key, raw ? value : value.call( elems[i], i, fn( elems[i], key ) ) );
834                                 }
835                         }
836                 }
838                 return chainable ?
839                         elems :
841                         // Gets
842                         bulk ?
843                                 fn.call( elems ) :
844                                 length ? fn( elems[0], key ) : emptyGet;
845         },
847         now: function() {
848                 return ( new Date() ).getTime();
849         }
852 jQuery.ready.promise = function( obj ) {
853         if ( !readyList ) {
855                 readyList = jQuery.Deferred();
857                 // Catch cases where $(document).ready() is called after the browser event has already occurred.
858                 // we once tried to use readyState "interactive" here, but it caused issues like the one
859                 // discovered by ChrisS here: http://bugs.jquery.com/ticket/12282#comment:15
860                 if ( document.readyState === "complete" ) {
861                         // Handle it asynchronously to allow scripts the opportunity to delay ready
862                         setTimeout( jQuery.ready );
864                 // Standards-based browsers support DOMContentLoaded
865                 } else if ( document.addEventListener ) {
866                         // Use the handy event callback
867                         document.addEventListener( "DOMContentLoaded", DOMContentLoaded, false );
869                         // A fallback to window.onload, that will always work
870                         window.addEventListener( "load", jQuery.ready, false );
872                 // If IE event model is used
873                 } else {
874                         // Ensure firing before onload, maybe late but safe also for iframes
875                         document.attachEvent( "onreadystatechange", DOMContentLoaded );
877                         // A fallback to window.onload, that will always work
878                         window.attachEvent( "onload", jQuery.ready );
880                         // If IE and not a frame
881                         // continually check to see if the document is ready
882                         var top = false;
884                         try {
885                                 top = window.frameElement == null && document.documentElement;
886                         } catch(e) {}
888                         if ( top && top.doScroll ) {
889                                 (function doScrollCheck() {
890                                         if ( !jQuery.isReady ) {
892                                                 try {
893                                                         // Use the trick by Diego Perini
894                                                         // http://javascript.nwbox.com/IEContentLoaded/
895                                                         top.doScroll("left");
896                                                 } catch(e) {
897                                                         return setTimeout( doScrollCheck, 50 );
898                                                 }
900                                                 // and execute any waiting functions
901                                                 jQuery.ready();
902                                         }
903                                 })();
904                         }
905                 }
906         }
907         return readyList.promise( obj );
910 // Populate the class2type map
911 jQuery.each("Boolean Number String Function Array Date RegExp Object Error".split(" "), function(i, name) {
912         class2type[ "[object " + name + "]" ] = name.toLowerCase();
915 function isArraylike( obj ) {
916         var length = obj.length,
917                 type = jQuery.type( obj );
919         if ( jQuery.isWindow( obj ) ) {
920                 return false;
921         }
923         if ( obj.nodeType === 1 && length ) {
924                 return true;
925         }
927         return type === "array" || type !== "function" &&
928                 ( length === 0 ||
929                 typeof length === "number" && length > 0 && ( length - 1 ) in obj );
932 // All jQuery objects should point back to these
933 rootjQuery = jQuery(document);