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