Merge branch 'master' of github.com:jquery/jquery
[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                         // Handle it asynchronously to allow scripts the opportunity to delay ready
441                         return setTimeout( jQuery.ready, 13 );
442                 }
443
444                 // Mozilla, Opera and webkit nightlies currently support this event
445                 if ( document.addEventListener ) {
446                         // Use the handy event callback
447                         document.addEventListener( "DOMContentLoaded", DOMContentLoaded, false );
448                         
449                         // A fallback to window.onload, that will always work
450                         window.addEventListener( "load", jQuery.ready, false );
451
452                 // If IE event model is used
453                 } else if ( document.attachEvent ) {
454                         // ensure firing before onload,
455                         // maybe late but safe also for iframes
456                         document.attachEvent("onreadystatechange", DOMContentLoaded);
457                         
458                         // A fallback to window.onload, that will always work
459                         window.attachEvent( "onload", jQuery.ready );
460
461                         // If IE and not a frame
462                         // continually check to see if the document is ready
463                         var toplevel = false;
464
465                         try {
466                                 toplevel = window.frameElement == null;
467                         } catch(e) {}
468
469                         if ( document.documentElement.doScroll && toplevel ) {
470                                 doScrollCheck();
471                         }
472                 }
473         },
474
475         // See test/unit/core.js for details concerning isFunction.
476         // Since version 1.3, DOM methods and functions like alert
477         // aren't supported. They return false on IE (#2968).
478         isFunction: function( obj ) {
479                 return jQuery.type(obj) === "function";
480         },
481
482         isArray: Array.isArray || function( obj ) {
483                 return jQuery.type(obj) === "array";
484         },
485
486         // A crude way of determining if an object is a window
487         isWindow: function( obj ) {
488                 return obj && typeof obj === "object" && "setInterval" in obj;
489         },
490
491         type: function( obj ) {
492                 return obj == null ?
493                         String( obj ) :
494                         class2type[ toString.call(obj) ] || "object";
495         },
496
497         isPlainObject: function( obj ) {
498                 // Must be an Object.
499                 // Because of IE, we also have to check the presence of the constructor property.
500                 // Make sure that DOM nodes and window objects don't pass through, as well
501                 if ( !obj || jQuery.type(obj) !== "object" || obj.nodeType || jQuery.isWindow( obj ) ) {
502                         return false;
503                 }
504                 
505                 // Not own constructor property must be Object
506                 if ( obj.constructor &&
507                         !hasOwn.call(obj, "constructor") &&
508                         !hasOwn.call(obj.constructor.prototype, "isPrototypeOf") ) {
509                         return false;
510                 }
511                 
512                 // Own properties are enumerated firstly, so to speed up,
513                 // if last one is own, then all properties are own.
514         
515                 var key;
516                 for ( key in obj ) {}
517                 
518                 return key === undefined || hasOwn.call( obj, key );
519         },
520
521         isEmptyObject: function( obj ) {
522                 for ( var name in obj ) {
523                         return false;
524                 }
525                 return true;
526         },
527         
528         error: function( msg ) {
529                 throw msg;
530         },
531         
532         parseJSON: function( data ) {
533                 if ( typeof data !== "string" || !data ) {
534                         return null;
535                 }
536
537                 // Make sure leading/trailing whitespace is removed (IE can't handle it)
538                 data = jQuery.trim( data );
539                 
540                 // Make sure the incoming data is actual JSON
541                 // Logic borrowed from http://json.org/json2.js
542                 if ( rvalidchars.test(data.replace(rvalidescape, "@")
543                         .replace(rvalidtokens, "]")
544                         .replace(rvalidbraces, "")) ) {
545
546                         // Try to use the native JSON parser first
547                         return window.JSON && window.JSON.parse ?
548                                 window.JSON.parse( data ) :
549                                 (new Function("return " + data))();
550
551                 } else {
552                         jQuery.error( "Invalid JSON: " + data );
553                 }
554         },
555
556         noop: function() {},
557
558         // Evalulates a script in a global context
559         globalEval: function( data ) {
560                 if ( data && rnotwhite.test(data) ) {
561                         // Inspired by code by Andrea Giammarchi
562                         // http://webreflection.blogspot.com/2007/08/global-scope-evaluation-and-dom.html
563                         var head = document.getElementsByTagName("head")[0] || document.documentElement,
564                                 script = document.createElement("script");
565
566                         script.type = "text/javascript";
567
568                         if ( jQuery.support.scriptEval ) {
569                                 script.appendChild( document.createTextNode( data ) );
570                         } else {
571                                 script.text = data;
572                         }
573
574                         // Use insertBefore instead of appendChild to circumvent an IE6 bug.
575                         // This arises when a base node is used (#2709).
576                         head.insertBefore( script, head.firstChild );
577                         head.removeChild( script );
578                 }
579         },
580
581         nodeName: function( elem, name ) {
582                 return elem.nodeName && elem.nodeName.toUpperCase() === name.toUpperCase();
583         },
584
585         // args is for internal usage only
586         each: function( object, callback, args ) {
587                 var name, i = 0,
588                         length = object.length,
589                         isObj = length === undefined || jQuery.isFunction(object);
590
591                 if ( args ) {
592                         if ( isObj ) {
593                                 for ( name in object ) {
594                                         if ( callback.apply( object[ name ], args ) === false ) {
595                                                 break;
596                                         }
597                                 }
598                         } else {
599                                 for ( ; i < length; ) {
600                                         if ( callback.apply( object[ i++ ], args ) === false ) {
601                                                 break;
602                                         }
603                                 }
604                         }
605
606                 // A special, fast, case for the most common use of each
607                 } else {
608                         if ( isObj ) {
609                                 for ( name in object ) {
610                                         if ( callback.call( object[ name ], name, object[ name ] ) === false ) {
611                                                 break;
612                                         }
613                                 }
614                         } else {
615                                 for ( var value = object[0];
616                                         i < length && callback.call( value, i, value ) !== false; value = object[++i] ) {}
617                         }
618                 }
619
620                 return object;
621         },
622
623         // Use native String.trim function wherever possible
624         trim: trim ?
625                 function( text ) {
626                         return text == null ?
627                                 "" :
628                                 trim.call( text );
629                 } :
630
631                 // Otherwise use our own trimming functionality
632                 function( text ) {
633                         return text == null ?
634                                 "" :
635                                 text.toString().replace( trimLeft, "" ).replace( trimRight, "" );
636                 },
637
638         // results is for internal usage only
639         makeArray: function( array, results ) {
640                 var ret = results || [];
641
642                 if ( array != null ) {
643                         // The window, strings (and functions) also have 'length'
644                         // The extra typeof function check is to prevent crashes
645                         // in Safari 2 (See: #3039)
646                         // Tweaked logic slightly to handle Blackberry 4.7 RegExp issues #6930
647                         var type = jQuery.type(array);
648
649                         if ( array.length == null || type === "string" || type === "function" || type === "regexp" || jQuery.isWindow( array ) ) {
650                                 push.call( ret, array );
651                         } else {
652                                 jQuery.merge( ret, array );
653                         }
654                 }
655
656                 return ret;
657         },
658
659         inArray: function( elem, array ) {
660                 if ( array.indexOf ) {
661                         return array.indexOf( elem );
662                 }
663
664                 for ( var i = 0, length = array.length; i < length; i++ ) {
665                         if ( array[ i ] === elem ) {
666                                 return i;
667                         }
668                 }
669
670                 return -1;
671         },
672
673         merge: function( first, second ) {
674                 var i = first.length, j = 0;
675
676                 if ( typeof second.length === "number" ) {
677                         for ( var l = second.length; j < l; j++ ) {
678                                 first[ i++ ] = second[ j ];
679                         }
680                 
681                 } else {
682                         while ( second[j] !== undefined ) {
683                                 first[ i++ ] = second[ j++ ];
684                         }
685                 }
686
687                 first.length = i;
688
689                 return first;
690         },
691
692         grep: function( elems, callback, inv ) {
693                 var ret = [], retVal;
694                 inv = !!inv;
695
696                 // Go through the array, only saving the items
697                 // that pass the validator function
698                 for ( var i = 0, length = elems.length; i < length; i++ ) {
699                         retVal = !!callback( elems[ i ], i );
700                         if ( inv !== retVal ) {
701                                 ret.push( elems[ i ] );
702                         }
703                 }
704
705                 return ret;
706         },
707
708         // arg is for internal usage only
709         map: function( elems, callback, arg ) {
710                 var ret = [], value;
711
712                 // Go through the array, translating each of the items to their
713                 // new value (or values).
714                 for ( var i = 0, length = elems.length; i < length; i++ ) {
715                         value = callback( elems[ i ], i, arg );
716
717                         if ( value != null ) {
718                                 ret[ ret.length ] = value;
719                         }
720                 }
721
722                 return ret.concat.apply( [], ret );
723         },
724
725         // A global GUID counter for objects
726         guid: 1,
727
728         proxy: function( fn, proxy, thisObject ) {
729                 if ( arguments.length === 2 ) {
730                         if ( typeof proxy === "string" ) {
731                                 thisObject = fn;
732                                 fn = thisObject[ proxy ];
733                                 proxy = undefined;
734
735                         } else if ( proxy && !jQuery.isFunction( proxy ) ) {
736                                 thisObject = proxy;
737                                 proxy = undefined;
738                         }
739                 }
740
741                 if ( !proxy && fn ) {
742                         proxy = function() {
743                                 return fn.apply( thisObject || this, arguments );
744                         };
745                 }
746
747                 // Set the guid of unique handler to the same of original handler, so it can be removed
748                 if ( fn ) {
749                         proxy.guid = fn.guid = fn.guid || proxy.guid || jQuery.guid++;
750                 }
751
752                 // So proxy can be declared as an argument
753                 return proxy;
754         },
755
756         // Mutifunctional method to get and set values to a collection
757         // The value/s can be optionally by executed if its a function
758         access: function( elems, key, value, exec, fn, pass ) {
759                 var length = elems.length;
760         
761                 // Setting many attributes
762                 if ( typeof key === "object" ) {
763                         for ( var k in key ) {
764                                 jQuery.access( elems, k, key[k], exec, fn, value );
765                         }
766                         return elems;
767                 }
768         
769                 // Setting one attribute
770                 if ( value !== undefined ) {
771                         // Optionally, function values get executed if exec is true
772                         exec = !pass && exec && jQuery.isFunction(value);
773                 
774                         for ( var i = 0; i < length; i++ ) {
775                                 fn( elems[i], key, exec ? value.call( elems[i], i, fn( elems[i], key ) ) : value, pass );
776                         }
777                 
778                         return elems;
779                 }
780         
781                 // Getting an attribute
782                 return length ? fn( elems[0], key ) : undefined;
783         },
784
785         now: function() {
786                 return (new Date()).getTime();
787         },
788
789         // Use of jQuery.browser is frowned upon.
790         // More details: http://docs.jquery.com/Utilities/jQuery.browser
791         uaMatch: function( ua ) {
792                 ua = ua.toLowerCase();
793
794                 var match = rwebkit.exec( ua ) ||
795                         ropera.exec( ua ) ||
796                         rmsie.exec( ua ) ||
797                         ua.indexOf("compatible") < 0 && rmozilla.exec( ua ) ||
798                         [];
799
800                 return { browser: match[1] || "", version: match[2] || "0" };
801         },
802
803         browser: {}
804 });
805
806 // Populate the class2type map
807 jQuery.each("Boolean Number String Function Array Date RegExp Object".split(" "), function(i, name) {
808         class2type[ "[object " + name + "]" ] = name.toLowerCase();
809 });
810
811 browserMatch = jQuery.uaMatch( userAgent );
812 if ( browserMatch.browser ) {
813         jQuery.browser[ browserMatch.browser ] = true;
814         jQuery.browser.version = browserMatch.version;
815 }
816
817 // Deprecated, use jQuery.browser.webkit instead
818 if ( jQuery.browser.webkit ) {
819         jQuery.browser.safari = true;
820 }
821
822 if ( indexOf ) {
823         jQuery.inArray = function( elem, array ) {
824                 return indexOf.call( array, elem );
825         };
826 }
827
828 // Verify that \s matches non-breaking spaces
829 // (IE fails on this test)
830 if ( !rwhite.test( "\xA0" ) ) {
831         trimLeft = /^[\s\xA0]+/;
832         trimRight = /[\s\xA0]+$/;
833 }
834
835 // All jQuery objects should point back to these
836 rootjQuery = jQuery(document);
837
838 // Cleanup functions for the document ready method
839 if ( document.addEventListener ) {
840         DOMContentLoaded = function() {
841                 document.removeEventListener( "DOMContentLoaded", DOMContentLoaded, false );
842                 jQuery.ready();
843         };
844
845 } else if ( document.attachEvent ) {
846         DOMContentLoaded = function() {
847                 // Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443).
848                 if ( document.readyState === "complete" ) {
849                         document.detachEvent( "onreadystatechange", DOMContentLoaded );
850                         jQuery.ready();
851                 }
852         };
853 }
854
855 // The DOM ready check for Internet Explorer
856 function doScrollCheck() {
857         if ( jQuery.isReady ) {
858                 return;
859         }
860
861         try {
862                 // If IE is used, use the trick by Diego Perini
863                 // http://javascript.nwbox.com/IEContentLoaded/
864                 document.documentElement.doScroll("left");
865         } catch(e) {
866                 setTimeout( doScrollCheck, 1 );
867                 return;
868         }
869
870         // and execute any waiting functions
871         jQuery.ready();
872 }
873
874 // Expose jQuery to the global object
875 return (window.jQuery = window.$ = jQuery);
876
877 })();