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