Ensured that arrays are not considered same as plain object on deep extending. Fixes...
[jquery.git] / src / core.js
1 var jQuery = (function() {
2
3 // Define a local copy of jQuery
4 var jQuery = function( selector, context ) {
5                 // The jQuery object is actually just the init constructor 'enhanced'
6                 return new jQuery.fn.init( selector, context );
7         },
8
9         // Map over jQuery in case of overwrite
10         _jQuery = window.jQuery,
11
12         // Map over the $ in case of overwrite
13         _$ = window.$,
14
15         // A central reference to the root jQuery(document)
16         rootjQuery,
17
18         // A simple way to check for HTML strings or ID strings
19         // (both of which we optimize for)
20         quickExpr = /^(?:[^<]*(<[\w\W]+>)[^>]*$|#([\w\-]+)$)/,
21
22         // Is it a simple selector
23         isSimple = /^.[^:#\[\.,]*$/,
24
25         // Check if a string has a non-whitespace character in it
26         rnotwhite = /\S/,
27         rwhite = /\s/,
28
29         // Used for trimming whitespace
30         trimLeft = /^\s+/,
31         trimRight = /\s+$/,
32
33         // Check for non-word characters
34         rnonword = /\W/,
35
36         // Match a standalone tag
37         rsingleTag = /^<(\w+)\s*\/?>(?:<\/\1>)?$/,
38
39         // JSON RegExp
40         rvalidchars = /^[\],:{}\s]*$/,
41         rvalidescape = /\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,
42         rvalidtokens = /"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,
43         rvalidbraces = /(?:^|:|,)(?:\s*\[)+/g,
44
45         // Useragent RegExp
46         rwebkit = /(webkit)[ \/]([\w.]+)/,
47         ropera = /(opera)(?:.*version)?[ \/]([\w.]+)/,
48         rmsie = /(msie) ([\w.]+)/,
49         rmozilla = /(mozilla)(?:.*? rv:([\w.]+))?/,
50
51         // Keep a UserAgent string for use with jQuery.browser
52         userAgent = navigator.userAgent,
53
54         // For matching the engine and version of the browser
55         browserMatch,
56         
57         // Has the ready events already been bound?
58         readyBound = false,
59         
60         // The functions to execute on DOM ready
61         readyList = [],
62
63         // The ready event handler
64         DOMContentLoaded,
65
66         // Save a reference to some core methods
67         toString = Object.prototype.toString,
68         hasOwn = Object.prototype.hasOwnProperty,
69         push = Array.prototype.push,
70         slice = Array.prototype.slice,
71         trim = String.prototype.trim,
72         indexOf = Array.prototype.indexOf;
73
74 jQuery.fn = jQuery.prototype = {
75         init: function( selector, context ) {
76                 var match, elem, ret, doc;
77
78                 // Handle $(""), $(null), or $(undefined)
79                 if ( !selector ) {
80                         return this;
81                 }
82
83                 // Handle $(DOMElement)
84                 if ( selector.nodeType ) {
85                         this.context = this[0] = selector;
86                         this.length = 1;
87                         return this;
88                 }
89                 
90                 // The body element only exists once, optimize finding it
91                 if ( selector === "body" && !context ) {
92                         this.context = document;
93                         this[0] = document.body;
94                         this.selector = "body";
95                         this.length = 1;
96                         return this;
97                 }
98
99                 // Handle HTML strings
100                 if ( typeof selector === "string" ) {
101                         // Are we dealing with HTML string or an ID?
102                         match = quickExpr.exec( selector );
103
104                         // Verify a match, and that no context was specified for #id
105                         if ( match && (match[1] || !context) ) {
106
107                                 // HANDLE: $(html) -> $(array)
108                                 if ( match[1] ) {
109                                         doc = (context ? context.ownerDocument || context : document);
110
111                                         // If a single string is passed in and it's a single tag
112                                         // just do a createElement and skip the rest
113                                         ret = rsingleTag.exec( selector );
114
115                                         if ( ret ) {
116                                                 if ( jQuery.isPlainObject( context ) ) {
117                                                         selector = [ document.createElement( ret[1] ) ];
118                                                         jQuery.fn.attr.call( selector, context, true );
119
120                                                 } else {
121                                                         selector = [ doc.createElement( ret[1] ) ];
122                                                 }
123
124                                         } else {
125                                                 ret = jQuery.buildFragment( [ match[1] ], [ doc ] );
126                                                 selector = (ret.cacheable ? ret.fragment.cloneNode(true) : ret.fragment).childNodes;
127                                         }
128                                         
129                                         return jQuery.merge( this, selector );
130                                         
131                                 // HANDLE: $("#id")
132                                 } else {
133                                         elem = document.getElementById( match[2] );
134
135                                         // Check parentNode to catch when Blackberry 4.6 returns
136                                         // nodes that are no longer in the document #6963
137                                         if ( elem && elem.parentNode ) {
138                                                 // Handle the case where IE and Opera return items
139                                                 // by name instead of ID
140                                                 if ( elem.id !== match[2] ) {
141                                                         return rootjQuery.find( selector );
142                                                 }
143
144                                                 // Otherwise, we inject the element directly into the jQuery object
145                                                 this.length = 1;
146                                                 this[0] = elem;
147                                         }
148
149                                         this.context = document;
150                                         this.selector = selector;
151                                         return this;
152                                 }
153
154                         // HANDLE: $("TAG")
155                         } else if ( !context && !rnonword.test( selector ) ) {
156                                 this.selector = selector;
157                                 this.context = document;
158                                 selector = document.getElementsByTagName( selector );
159                                 return jQuery.merge( this, selector );
160
161                         // HANDLE: $(expr, $(...))
162                         } else if ( !context || context.jquery ) {
163                                 return (context || rootjQuery).find( selector );
164
165                         // HANDLE: $(expr, context)
166                         // (which is just equivalent to: $(context).find(expr)
167                         } else {
168                                 return jQuery( context ).find( selector );
169                         }
170
171                 // HANDLE: $(function)
172                 // Shortcut for document ready
173                 } else if ( jQuery.isFunction( selector ) ) {
174                         return rootjQuery.ready( selector );
175                 }
176
177                 if (selector.selector !== undefined) {
178                         this.selector = selector.selector;
179                         this.context = selector.context;
180                 }
181
182                 return jQuery.makeArray( selector, this );
183         },
184
185         // Start with an empty selector
186         selector: "",
187
188         // The current version of jQuery being used
189         jquery: "@VERSION",
190
191         // The default length of a jQuery object is 0
192         length: 0,
193
194         // The number of elements contained in the matched element set
195         size: function() {
196                 return this.length;
197         },
198
199         toArray: function() {
200                 return slice.call( this, 0 );
201         },
202
203         // Get the Nth element in the matched element set OR
204         // Get the whole matched element set as a clean array
205         get: function( num ) {
206                 return num == null ?
207
208                         // Return a 'clean' array
209                         this.toArray() :
210
211                         // Return just the object
212                         ( num < 0 ? this.slice(num)[ 0 ] : this[ num ] );
213         },
214
215         // Take an array of elements and push it onto the stack
216         // (returning the new matched element set)
217         pushStack: function( elems, name, selector ) {
218                 // Build a new jQuery matched element set
219                 var ret = jQuery();
220
221                 if ( jQuery.isArray( elems ) ) {
222                         push.apply( ret, elems );
223                 
224                 } else {
225                         jQuery.merge( ret, elems );
226                 }
227
228                 // Add the old object onto the stack (as a reference)
229                 ret.prevObject = this;
230
231                 ret.context = this.context;
232
233                 if ( name === "find" ) {
234                         ret.selector = this.selector + (this.selector ? " " : "") + selector;
235                 } else if ( name ) {
236                         ret.selector = this.selector + "." + name + "(" + selector + ")";
237                 }
238
239                 // Return the newly-formed element set
240                 return ret;
241         },
242
243         // Execute a callback for every element in the matched set.
244         // (You can seed the arguments with an array of args, but this is
245         // only used internally.)
246         each: function( callback, args ) {
247                 return jQuery.each( this, callback, args );
248         },
249         
250         ready: function( fn ) {
251                 // Attach the listeners
252                 jQuery.bindReady();
253
254                 // If the DOM is already ready
255                 if ( jQuery.isReady ) {
256                         // Execute the function immediately
257                         fn.call( document, jQuery );
258
259                 // Otherwise, remember the function for later
260                 } else if ( readyList ) {
261                         // Add the function to the wait list
262                         readyList.push( fn );
263                 }
264
265                 return this;
266         },
267         
268         eq: function( i ) {
269                 return i === -1 ?
270                         this.slice( i ) :
271                         this.slice( i, +i + 1 );
272         },
273
274         first: function() {
275                 return this.eq( 0 );
276         },
277
278         last: function() {
279                 return this.eq( -1 );
280         },
281
282         slice: function() {
283                 return this.pushStack( slice.apply( this, arguments ),
284                         "slice", slice.call(arguments).join(",") );
285         },
286
287         map: function( callback ) {
288                 return this.pushStack( jQuery.map(this, function( elem, i ) {
289                         return callback.call( elem, i, elem );
290                 }));
291         },
292         
293         end: function() {
294                 return this.prevObject || jQuery(null);
295         },
296
297         // For internal use only.
298         // Behaves like an Array's method, not like a jQuery method.
299         push: push,
300         sort: [].sort,
301         splice: [].splice
302 };
303
304 // Give the init function the jQuery prototype for later instantiation
305 jQuery.fn.init.prototype = jQuery.fn;
306
307 jQuery.extend = jQuery.fn.extend = function() {
308         // copy reference to target object
309         var target = arguments[0] || {}, i = 1, length = arguments.length, deep = false, options, name, src, copy, copyIsArray;
310
311         // Handle a deep copy situation
312         if ( typeof target === "boolean" ) {
313                 deep = target;
314                 target = arguments[1] || {};
315                 // skip the boolean and the target
316                 i = 2;
317         }
318
319         // Handle case when target is a string or something (possible in deep copy)
320         if ( typeof target !== "object" && !jQuery.isFunction(target) ) {
321                 target = {};
322         }
323
324         // extend jQuery itself if only one argument is passed
325         if ( length === i ) {
326                 target = this;
327                 --i;
328         }
329
330         for ( ; i < length; i++ ) {
331                 // Only deal with non-null/undefined values
332                 if ( (options = arguments[ i ]) != null ) {
333                         // Extend the base object
334                         for ( name in options ) {
335                                 src = target[ name ];
336                                 copy = options[ name ];
337
338                                 // Prevent never-ending loop
339                                 if ( target === copy ) {
340                                         continue;
341                                 }
342
343                                 // Recurse if we're merging plain objects or arrays
344                                 if ( deep && copy && ( jQuery.isPlainObject(copy) || (copyIsArray = jQuery.isArray(copy)) ) ) {
345                                         if ( copyIsArray ) {
346                                                 copyIsArray = false;
347                                                 clone = src && jQuery.isArray(src) ? src : [];
348
349                                         } else {
350                                                 clone = src && jQuery.isPlainObject(src) ? src : {};
351                                         }
352
353                                         // Never move original objects, clone them
354                                         target[ name ] = jQuery.extend( deep, clone, copy );
355
356                                 // Don't bring in undefined values
357                                 } else if ( copy !== undefined ) {
358                                         target[ name ] = copy;
359                                 }
360                         }
361                 }
362         }
363
364         // Return the modified object
365         return target;
366 };
367
368 jQuery.extend({
369         noConflict: function( deep ) {
370                 window.$ = _$;
371
372                 if ( deep ) {
373                         window.jQuery = _jQuery;
374                 }
375
376                 return jQuery;
377         },
378         
379         // Is the DOM ready to be used? Set to true once it occurs.
380         isReady: false,
381
382         // A counter to track how many items to wait for before
383         // the ready event fires. See #6781
384         readyWait: 1,
385         
386         // Handle when the DOM is ready
387         ready: function( wait ) {
388                 // A third-party is pushing the ready event forwards
389                 if ( wait === true ) {
390                         jQuery.readyWait--;
391                 }
392
393                 // Make sure that the DOM is not already loaded
394                 if ( !jQuery.readyWait || (wait !== true && !jQuery.isReady) ) {
395                         // Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443).
396                         if ( !document.body ) {
397                                 return setTimeout( jQuery.ready, 13 );
398                         }
399
400                         // Remember that the DOM is ready
401                         jQuery.isReady = true;
402
403                         // If a normal DOM Ready event fired, decrement, and wait if need be
404                         if ( wait !== true && --jQuery.readyWait > 0 ) {
405                                 return;
406                         }
407
408                         // If there are functions bound, to execute
409                         if ( readyList ) {
410                                 // Execute all of them
411                                 var fn, i = 0;
412                                 while ( (fn = readyList[ i++ ]) ) {
413                                         fn.call( document, jQuery );
414                                 }
415
416                                 // Reset the list of functions
417                                 readyList = null;
418                         }
419
420                         // Trigger any bound ready events
421                         if ( jQuery.fn.triggerHandler ) {
422                                 jQuery( document ).triggerHandler( "ready" );
423                         }
424                 }
425         },
426         
427         bindReady: function() {
428                 if ( readyBound ) {
429                         return;
430                 }
431
432                 readyBound = true;
433
434                 // Catch cases where $(document).ready() is called after the
435                 // browser event has already occurred.
436                 if ( document.readyState === "complete" ) {
437                         return jQuery.ready();
438                 }
439
440                 // Mozilla, Opera and webkit nightlies currently support this event
441                 if ( document.addEventListener ) {
442                         // Use the handy event callback
443                         document.addEventListener( "DOMContentLoaded", DOMContentLoaded, false );
444                         
445                         // A fallback to window.onload, that will always work
446                         window.addEventListener( "load", jQuery.ready, false );
447
448                 // If IE event model is used
449                 } else if ( document.attachEvent ) {
450                         // ensure firing before onload,
451                         // maybe late but safe also for iframes
452                         document.attachEvent("onreadystatechange", DOMContentLoaded);
453                         
454                         // A fallback to window.onload, that will always work
455                         window.attachEvent( "onload", jQuery.ready );
456
457                         // If IE and not a frame
458                         // continually check to see if the document is ready
459                         var toplevel = false;
460
461                         try {
462                                 toplevel = window.frameElement == null;
463                         } catch(e) {}
464
465                         if ( document.documentElement.doScroll && toplevel ) {
466                                 doScrollCheck();
467                         }
468                 }
469         },
470
471         // See test/unit/core.js for details concerning isFunction.
472         // Since version 1.3, DOM methods and functions like alert
473         // aren't supported. They return false on IE (#2968).
474         isFunction: function( obj ) {
475                 return jQuery.type(obj) === "function";
476         },
477
478         isArray: Array.isArray || function( obj ) {
479                 return jQuery.type(obj) === "array";
480         },
481
482         // A crude way of determining if an object is a window
483         isWindow: function( obj ) {
484                 return obj && typeof obj === "object" && "setInterval" in obj;
485         },
486
487         type: function( obj ) {
488                 return obj == null ?
489                         String( obj ) :
490                         toString.call(obj).slice(8, -1).toLowerCase();
491         },
492
493         isPlainObject: function( obj ) {
494                 // Must be an Object.
495                 // Because of IE, we also have to check the presence of the constructor property.
496                 // Make sure that DOM nodes and window objects don't pass through, as well
497                 if ( !obj || jQuery.type(obj) !== "object" || obj.nodeType || jQuery.isWindow( obj ) ) {
498                         return false;
499                 }
500                 
501                 // Not own constructor property must be Object
502                 if ( obj.constructor &&
503                         !hasOwn.call(obj, "constructor") &&
504                         !hasOwn.call(obj.constructor.prototype, "isPrototypeOf") ) {
505                         return false;
506                 }
507                 
508                 // Own properties are enumerated firstly, so to speed up,
509                 // if last one is own, then all properties are own.
510         
511                 var key;
512                 for ( key in obj ) {}
513                 
514                 return key === undefined || hasOwn.call( obj, key );
515         },
516
517         isEmptyObject: function( obj ) {
518                 for ( var name in obj ) {
519                         return false;
520                 }
521                 return true;
522         },
523         
524         error: function( msg ) {
525                 throw msg;
526         },
527         
528         parseJSON: function( data ) {
529                 if ( typeof data !== "string" || !data ) {
530                         return null;
531                 }
532
533                 // Make sure leading/trailing whitespace is removed (IE can't handle it)
534                 data = jQuery.trim( data );
535                 
536                 // Make sure the incoming data is actual JSON
537                 // Logic borrowed from http://json.org/json2.js
538                 if ( rvalidchars.test(data.replace(rvalidescape, "@")
539                         .replace(rvalidtokens, "]")
540                         .replace(rvalidbraces, "")) ) {
541
542                         // Try to use the native JSON parser first
543                         return window.JSON && window.JSON.parse ?
544                                 window.JSON.parse( data ) :
545                                 (new Function("return " + data))();
546
547                 } else {
548                         jQuery.error( "Invalid JSON: " + data );
549                 }
550         },
551
552         noop: function() {},
553
554         // Evalulates a script in a global context
555         globalEval: function( data ) {
556                 if ( data && rnotwhite.test(data) ) {
557                         // Inspired by code by Andrea Giammarchi
558                         // http://webreflection.blogspot.com/2007/08/global-scope-evaluation-and-dom.html
559                         var head = document.getElementsByTagName("head")[0] || document.documentElement,
560                                 script = document.createElement("script");
561
562                         script.type = "text/javascript";
563
564                         if ( jQuery.support.scriptEval ) {
565                                 script.appendChild( document.createTextNode( data ) );
566                         } else {
567                                 script.text = data;
568                         }
569
570                         // Use insertBefore instead of appendChild to circumvent an IE6 bug.
571                         // This arises when a base node is used (#2709).
572                         head.insertBefore( script, head.firstChild );
573                         head.removeChild( script );
574                 }
575         },
576
577         nodeName: function( elem, name ) {
578                 return elem.nodeName && elem.nodeName.toUpperCase() === name.toUpperCase();
579         },
580
581         // args is for internal usage only
582         each: function( object, callback, args ) {
583                 var name, i = 0,
584                         length = object.length,
585                         isObj = length === undefined || jQuery.isFunction(object);
586
587                 if ( args ) {
588                         if ( isObj ) {
589                                 for ( name in object ) {
590                                         if ( callback.apply( object[ name ], args ) === false ) {
591                                                 break;
592                                         }
593                                 }
594                         } else {
595                                 for ( ; i < length; ) {
596                                         if ( callback.apply( object[ i++ ], args ) === false ) {
597                                                 break;
598                                         }
599                                 }
600                         }
601
602                 // A special, fast, case for the most common use of each
603                 } else {
604                         if ( isObj ) {
605                                 for ( name in object ) {
606                                         if ( callback.call( object[ name ], name, object[ name ] ) === false ) {
607                                                 break;
608                                         }
609                                 }
610                         } else {
611                                 for ( var value = object[0];
612                                         i < length && callback.call( value, i, value ) !== false; value = object[++i] ) {}
613                         }
614                 }
615
616                 return object;
617         },
618
619         // Use native String.trim function wherever possible
620         trim: trim ?
621                 function( text ) {
622                         return text == null ?
623                                 "" :
624                                 trim.call( text );
625                 } :
626
627                 // Otherwise use our own trimming functionality
628                 function( text ) {
629                         return text == null ?
630                                 "" :
631                                 text.toString().replace( trimLeft, "" ).replace( trimRight, "" );
632                 },
633
634         // results is for internal usage only
635         makeArray: function( array, results ) {
636                 var ret = results || [];
637
638                 if ( array != null ) {
639                         // The window, strings (and functions) also have 'length'
640                         // The extra typeof function check is to prevent crashes
641                         // in Safari 2 (See: #3039)
642                         // Tweaked logic slightly to handle Blackberry 4.7 RegExp issues #6930
643                         var type = jQuery.type(array);
644
645                         if ( array.length == null || type === "string" || type === "function" || type === "regexp" || jQuery.isWindow( array ) ) {
646                                 push.call( ret, array );
647                         } else {
648                                 jQuery.merge( ret, array );
649                         }
650                 }
651
652                 return ret;
653         },
654
655         inArray: function( elem, array ) {
656                 if ( array.indexOf ) {
657                         return array.indexOf( elem );
658                 }
659
660                 for ( var i = 0, length = array.length; i < length; i++ ) {
661                         if ( array[ i ] === elem ) {
662                                 return i;
663                         }
664                 }
665
666                 return -1;
667         },
668
669         merge: function( first, second ) {
670                 var i = first.length, j = 0;
671
672                 if ( typeof second.length === "number" ) {
673                         for ( var l = second.length; j < l; j++ ) {
674                                 first[ i++ ] = second[ j ];
675                         }
676                 
677                 } else {
678                         while ( second[j] !== undefined ) {
679                                 first[ i++ ] = second[ j++ ];
680                         }
681                 }
682
683                 first.length = i;
684
685                 return first;
686         },
687
688         grep: function( elems, callback, inv ) {
689                 var ret = [], retVal;
690                 inv = !!inv;
691
692                 // Go through the array, only saving the items
693                 // that pass the validator function
694                 for ( var i = 0, length = elems.length; i < length; i++ ) {
695                         retVal = !!callback( elems[ i ], i );
696                         if ( inv !== retVal ) {
697                                 ret.push( elems[ i ] );
698                         }
699                 }
700
701                 return ret;
702         },
703
704         // arg is for internal usage only
705         map: function( elems, callback, arg ) {
706                 var ret = [], value;
707
708                 // Go through the array, translating each of the items to their
709                 // new value (or values).
710                 for ( var i = 0, length = elems.length; i < length; i++ ) {
711                         value = callback( elems[ i ], i, arg );
712
713                         if ( value != null ) {
714                                 ret[ ret.length ] = value;
715                         }
716                 }
717
718                 return ret.concat.apply( [], ret );
719         },
720
721         // A global GUID counter for objects
722         guid: 1,
723
724         proxy: function( fn, proxy, thisObject ) {
725                 if ( arguments.length === 2 ) {
726                         if ( typeof proxy === "string" ) {
727                                 thisObject = fn;
728                                 fn = thisObject[ proxy ];
729                                 proxy = undefined;
730
731                         } else if ( proxy && !jQuery.isFunction( proxy ) ) {
732                                 thisObject = proxy;
733                                 proxy = undefined;
734                         }
735                 }
736
737                 if ( !proxy && fn ) {
738                         proxy = function() {
739                                 return fn.apply( thisObject || this, arguments );
740                         };
741                 }
742
743                 // Set the guid of unique handler to the same of original handler, so it can be removed
744                 if ( fn ) {
745                         proxy.guid = fn.guid = fn.guid || proxy.guid || jQuery.guid++;
746                 }
747
748                 // So proxy can be declared as an argument
749                 return proxy;
750         },
751
752         // Mutifunctional method to get and set values to a collection
753         // The value/s can be optionally by executed if its a function
754         access: function( elems, key, value, exec, fn, pass ) {
755                 var length = elems.length;
756         
757                 // Setting many attributes
758                 if ( typeof key === "object" ) {
759                         for ( var k in key ) {
760                                 jQuery.access( elems, k, key[k], exec, fn, value );
761                         }
762                         return elems;
763                 }
764         
765                 // Setting one attribute
766                 if ( value !== undefined ) {
767                         // Optionally, function values get executed if exec is true
768                         exec = !pass && exec && jQuery.isFunction(value);
769                 
770                         for ( var i = 0; i < length; i++ ) {
771                                 fn( elems[i], key, exec ? value.call( elems[i], i, fn( elems[i], key ) ) : value, pass );
772                         }
773                 
774                         return elems;
775                 }
776         
777                 // Getting an attribute
778                 return length ? fn( elems[0], key ) : undefined;
779         },
780
781         now: function() {
782                 return (new Date()).getTime();
783         },
784
785         // Use of jQuery.browser is frowned upon.
786         // More details: http://docs.jquery.com/Utilities/jQuery.browser
787         uaMatch: function( ua ) {
788                 ua = ua.toLowerCase();
789
790                 var match = rwebkit.exec( ua ) ||
791                         ropera.exec( ua ) ||
792                         rmsie.exec( ua ) ||
793                         ua.indexOf("compatible") < 0 && rmozilla.exec( ua ) ||
794                         [];
795
796                 return { browser: match[1] || "", version: match[2] || "0" };
797         },
798
799         browser: {}
800 });
801
802 browserMatch = jQuery.uaMatch( userAgent );
803 if ( browserMatch.browser ) {
804         jQuery.browser[ browserMatch.browser ] = true;
805         jQuery.browser.version = browserMatch.version;
806 }
807
808 // Deprecated, use jQuery.browser.webkit instead
809 if ( jQuery.browser.webkit ) {
810         jQuery.browser.safari = true;
811 }
812
813 if ( indexOf ) {
814         jQuery.inArray = function( elem, array ) {
815                 return indexOf.call( array, elem );
816         };
817 }
818
819 // Verify that \s matches non-breaking spaces
820 // (IE fails on this test)
821 if ( !rwhite.test( "\xA0" ) ) {
822         trimLeft = /^[\s\xA0]+/;
823         trimRight = /[\s\xA0]+$/;
824 }
825
826 // All jQuery objects should point back to these
827 rootjQuery = jQuery(document);
828
829 // Cleanup functions for the document ready method
830 if ( document.addEventListener ) {
831         DOMContentLoaded = function() {
832                 document.removeEventListener( "DOMContentLoaded", DOMContentLoaded, false );
833                 jQuery.ready();
834         };
835
836 } else if ( document.attachEvent ) {
837         DOMContentLoaded = function() {
838                 // Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443).
839                 if ( document.readyState === "complete" ) {
840                         document.detachEvent( "onreadystatechange", DOMContentLoaded );
841                         jQuery.ready();
842                 }
843         };
844 }
845
846 // The DOM ready check for Internet Explorer
847 function doScrollCheck() {
848         if ( jQuery.isReady ) {
849                 return;
850         }
851
852         try {
853                 // If IE is used, use the trick by Diego Perini
854                 // http://javascript.nwbox.com/IEContentLoaded/
855                 document.documentElement.doScroll("left");
856         } catch(e) {
857                 setTimeout( doScrollCheck, 1 );
858                 return;
859         }
860
861         // and execute any waiting functions
862         jQuery.ready();
863 }
864
865 // Expose jQuery to the global object
866 return (window.jQuery = window.$ = jQuery);
867
868 })();