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