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