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