Create jQuery.holdReady(true/false) method to encapsulate jQuery.readyWait++ / jQuery...
[jquery.git] / src / core.js
blobb81fa7644c98aa7683000896362f7ce7c8f1a211
1 var jQuery = (function() {
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         },
9         // Map over jQuery in case of overwrite
10         _jQuery = window.jQuery,
12         // Map over the $ in case of overwrite
13         _$ = window.$,
15         // A central reference to the root jQuery(document)
16         rootjQuery,
18         // A simple way to check for HTML strings or ID strings
19         // (both of which we optimize for)
20         quickExpr = /^(?:[^<]*(<[\w\W]+>)[^>]*$|#([\w\-]*)$)/,
22         // Check if a string has a non-whitespace character in it
23         rnotwhite = /\S/,
25         // Used for trimming whitespace
26         trimLeft = /^\s+/,
27         trimRight = /\s+$/,
29         // Check for digits
30         rdigit = /\d/,
32         // Match a standalone tag
33         rsingleTag = /^<(\w+)\s*\/?>(?:<\/\1>)?$/,
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,
41         // Useragent RegExp
42         rwebkit = /(webkit)[ \/]([\w.]+)/,
43         ropera = /(opera)(?:.*version)?[ \/]([\w.]+)/,
44         rmsie = /(msie) ([\w.]+)/,
45         rmozilla = /(mozilla)(?:.*? rv:([\w.]+))?/,
47         // Keep a UserAgent string for use with jQuery.browser
48         userAgent = navigator.userAgent,
50         // For matching the engine and version of the browser
51         browserMatch,
53         // The deferred used on DOM ready
54         readyList,
56         // The ready event handler
57         DOMContentLoaded,
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,
67         // [[Class]] -> type pairs
68         class2type = {};
70 jQuery.fn = jQuery.prototype = {
71         constructor: jQuery,
72         init: function( selector, context, rootjQuery ) {
73                 var match, elem, ret, doc;
75                 // Handle $(""), $(null), or $(undefined)
76                 if ( !selector ) {
77                         return this;
78                 }
80                 // Handle $(DOMElement)
81                 if ( selector.nodeType ) {
82                         this.context = this[0] = selector;
83                         this.length = 1;
84                         return this;
85                 }
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                 }
96                 // Handle HTML strings
97                 if ( typeof selector === "string" ) {
98                         // Are we dealing with HTML string or an ID?
99                         if ( selector.length > 1024 ) {
100                                 // Assume very large strings are HTML and skip the regex check
101                                 match = [ null, selector, null ];
102                         } else {
103                                 match = quickExpr.exec( selector );
104                         }
106                         // Verify a match, and that no context was specified for #id
107                         if ( match && (match[1] || !context) ) {
109                                 // HANDLE: $(html) -> $(array)
110                                 if ( match[1] ) {
111                                         context = context instanceof jQuery ? context[0] : context;
112                                         doc = (context ? context.ownerDocument || context : document);
114                                         // If a single string is passed in and it's a single tag
115                                         // just do a createElement and skip the rest
116                                         ret = rsingleTag.exec( selector );
118                                         if ( ret ) {
119                                                 if ( jQuery.isPlainObject( context ) ) {
120                                                         selector = [ document.createElement( ret[1] ) ];
121                                                         jQuery.fn.attr.call( selector, context, true );
123                                                 } else {
124                                                         selector = [ doc.createElement( ret[1] ) ];
125                                                 }
127                                         } else {
128                                                 ret = jQuery.buildFragment( [ match[1] ], [ doc ] );
129                                                 selector = (ret.cacheable ? jQuery.clone(ret.fragment) : ret.fragment).childNodes;
130                                         }
132                                         return jQuery.merge( this, selector );
134                                 // HANDLE: $("#id")
135                                 } else {
136                                         elem = document.getElementById( match[2] );
138                                         // Check parentNode to catch when Blackberry 4.6 returns
139                                         // nodes that are no longer in the document #6963
140                                         if ( elem && elem.parentNode ) {
141                                                 // Handle the case where IE and Opera return items
142                                                 // by name instead of ID
143                                                 if ( elem.id !== match[2] ) {
144                                                         return rootjQuery.find( selector );
145                                                 }
147                                                 // Otherwise, we inject the element directly into the jQuery object
148                                                 this.length = 1;
149                                                 this[0] = elem;
150                                         }
152                                         this.context = document;
153                                         this.selector = selector;
154                                         return this;
155                                 }
157                         // HANDLE: $(expr, $(...))
158                         } else if ( !context || context.jquery ) {
159                                 return (context || rootjQuery).find( selector );
161                         // HANDLE: $(expr, context)
162                         // (which is just equivalent to: $(context).find(expr)
163                         } else {
164                                 return this.constructor( context ).find( selector );
165                         }
167                 // HANDLE: $(function)
168                 // Shortcut for document ready
169                 } else if ( jQuery.isFunction( selector ) ) {
170                         return rootjQuery.ready( selector );
171                 }
173                 if (selector.selector !== undefined) {
174                         this.selector = selector.selector;
175                         this.context = selector.context;
176                 }
178                 return jQuery.makeArray( selector, this );
179         },
181         // Start with an empty selector
182         selector: "",
184         // The current version of jQuery being used
185         jquery: "@VERSION",
187         // The default length of a jQuery object is 0
188         length: 0,
190         // The number of elements contained in the matched element set
191         size: function() {
192                 return this.length;
193         },
195         toArray: function() {
196                 return slice.call( this, 0 );
197         },
199         // Get the Nth element in the matched element set OR
200         // Get the whole matched element set as a clean array
201         get: function( num ) {
202                 return num == null ?
204                         // Return a 'clean' array
205                         this.toArray() :
207                         // Return just the object
208                         ( num < 0 ? this[ this.length + num ] : this[ num ] );
209         },
211         // Take an array of elements and push it onto the stack
212         // (returning the new matched element set)
213         pushStack: function( elems, name, selector ) {
214                 // Build a new jQuery matched element set
215                 var ret = this.constructor();
217                 if ( jQuery.isArray( elems ) ) {
218                         push.apply( ret, elems );
220                 } else {
221                         jQuery.merge( ret, elems );
222                 }
224                 // Add the old object onto the stack (as a reference)
225                 ret.prevObject = this;
227                 ret.context = this.context;
229                 if ( name === "find" ) {
230                         ret.selector = this.selector + (this.selector ? " " : "") + selector;
231                 } else if ( name ) {
232                         ret.selector = this.selector + "." + name + "(" + selector + ")";
233                 }
235                 // Return the newly-formed element set
236                 return ret;
237         },
239         // Execute a callback for every element in the matched set.
240         // (You can seed the arguments with an array of args, but this is
241         // only used internally.)
242         each: function( callback, args ) {
243                 return jQuery.each( this, callback, args );
244         },
246         ready: function( fn ) {
247                 // Attach the listeners
248                 jQuery.bindReady();
250                 // Add the callback
251                 readyList.done( fn );
253                 return this;
254         },
256         eq: function( i ) {
257                 return i === -1 ?
258                         this.slice( i ) :
259                         this.slice( i, +i + 1 );
260         },
262         first: function() {
263                 return this.eq( 0 );
264         },
266         last: function() {
267                 return this.eq( -1 );
268         },
270         slice: function() {
271                 return this.pushStack( slice.apply( this, arguments ),
272                         "slice", slice.call(arguments).join(",") );
273         },
275         map: function( callback ) {
276                 return this.pushStack( jQuery.map(this, function( elem, i ) {
277                         return callback.call( elem, i, elem );
278                 }));
279         },
281         end: function() {
282                 return this.prevObject || this.constructor(null);
283         },
285         // For internal use only.
286         // Behaves like an Array's method, not like a jQuery method.
287         push: push,
288         sort: [].sort,
289         splice: [].splice
292 // Give the init function the jQuery prototype for later instantiation
293 jQuery.fn.init.prototype = jQuery.fn;
295 jQuery.extend = jQuery.fn.extend = function() {
296         var options, name, src, copy, copyIsArray, clone,
297                 target = arguments[0] || {},
298                 i = 1,
299                 length = arguments.length,
300                 deep = false;
302         // Handle a deep copy situation
303         if ( typeof target === "boolean" ) {
304                 deep = target;
305                 target = arguments[1] || {};
306                 // skip the boolean and the target
307                 i = 2;
308         }
310         // Handle case when target is a string or something (possible in deep copy)
311         if ( typeof target !== "object" && !jQuery.isFunction(target) ) {
312                 target = {};
313         }
315         // extend jQuery itself if only one argument is passed
316         if ( length === i ) {
317                 target = this;
318                 --i;
319         }
321         for ( ; i < length; i++ ) {
322                 // Only deal with non-null/undefined values
323                 if ( (options = arguments[ i ]) != null ) {
324                         // Extend the base object
325                         for ( name in options ) {
326                                 src = target[ name ];
327                                 copy = options[ name ];
329                                 // Prevent never-ending loop
330                                 if ( target === copy ) {
331                                         continue;
332                                 }
334                                 // Recurse if we're merging plain objects or arrays
335                                 if ( deep && copy && ( jQuery.isPlainObject(copy) || (copyIsArray = jQuery.isArray(copy)) ) ) {
336                                         if ( copyIsArray ) {
337                                                 copyIsArray = false;
338                                                 clone = src && jQuery.isArray(src) ? src : [];
340                                         } else {
341                                                 clone = src && jQuery.isPlainObject(src) ? src : {};
342                                         }
344                                         // Never move original objects, clone them
345                                         target[ name ] = jQuery.extend( deep, clone, copy );
347                                 // Don't bring in undefined values
348                                 } else if ( copy !== undefined ) {
349                                         target[ name ] = copy;
350                                 }
351                         }
352                 }
353         }
355         // Return the modified object
356         return target;
359 jQuery.extend({
360         noConflict: function( deep ) {
361                 window.$ = _$;
363                 if ( deep ) {
364                         window.jQuery = _jQuery;
365                 }
367                 return jQuery;
368         },
370         // Is the DOM ready to be used? Set to true once it occurs.
371         isReady: false,
373         // A counter to track how many items to wait for before
374         // the ready event fires. See #6781
375         readyWait: 1,
377         // Hold (or release) the ready event
378         holdReady: function( hold ) {
379                 if ( hold ) {
380                         jQuery.readyWait++;
381                 } else {
382                         jQuery.ready( true );
383                 }
384         },
386         // Handle when the DOM is ready
387         ready: function( wait ) {
388                 // Either a released hold or an DOMready/load event and not yet ready
389                 if ( (wait === true && !--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, 1 );
393                         }
395                         // Remember that the DOM is ready
396                         jQuery.isReady = true;
398                         // If a normal DOM Ready event fired, decrement, and wait if need be
399                         if ( wait !== true && --jQuery.readyWait > 0 ) {
400                                 return;
401                         }
403                         // If there are functions bound, to execute
404                         readyList.resolveWith( document, [ jQuery ] );
406                         // Trigger any bound ready events
407                         if ( jQuery.fn.trigger ) {
408                                 jQuery( document ).trigger( "ready" ).unbind( "ready" );
409                         }
410                 }
411         },
413         bindReady: function() {
414                 if ( readyList ) {
415                         return;
416                 }
418                 readyList = jQuery._Deferred();
420                 // Catch cases where $(document).ready() is called after the
421                 // browser event has already occurred.
422                 if ( document.readyState === "complete" ) {
423                         // Handle it asynchronously to allow scripts the opportunity to delay ready
424                         return setTimeout( jQuery.ready, 1 );
425                 }
427                 // Mozilla, Opera and webkit nightlies currently support this event
428                 if ( document.addEventListener ) {
429                         // Use the handy event callback
430                         document.addEventListener( "DOMContentLoaded", DOMContentLoaded, false );
432                         // A fallback to window.onload, that will always work
433                         window.addEventListener( "load", jQuery.ready, false );
435                 // If IE event model is used
436                 } else if ( document.attachEvent ) {
437                         // ensure firing before onload,
438                         // maybe late but safe also for iframes
439                         document.attachEvent("onreadystatechange", DOMContentLoaded);
441                         // A fallback to window.onload, that will always work
442                         window.attachEvent( "onload", jQuery.ready );
444                         // If IE and not a frame
445                         // continually check to see if the document is ready
446                         var toplevel = false;
448                         try {
449                                 toplevel = window.frameElement == null;
450                         } catch(e) {}
452                         if ( document.documentElement.doScroll && toplevel ) {
453                                 doScrollCheck();
454                         }
455                 }
456         },
458         // See test/unit/core.js for details concerning isFunction.
459         // Since version 1.3, DOM methods and functions like alert
460         // aren't supported. They return false on IE (#2968).
461         isFunction: function( obj ) {
462                 return jQuery.type(obj) === "function";
463         },
465         isArray: Array.isArray || function( obj ) {
466                 return jQuery.type(obj) === "array";
467         },
469         // A crude way of determining if an object is a window
470         isWindow: function( obj ) {
471                 return obj && typeof obj === "object" && "setInterval" in obj;
472         },
474         isNaN: function( obj ) {
475                 return obj == null || !rdigit.test( obj ) || isNaN( obj );
476         },
478         type: function( obj ) {
479                 return obj == null ?
480                         String( obj ) :
481                         class2type[ toString.call(obj) ] || "object";
482         },
484         isPlainObject: function( obj ) {
485                 // Must be an Object.
486                 // Because of IE, we also have to check the presence of the constructor property.
487                 // Make sure that DOM nodes and window objects don't pass through, as well
488                 if ( !obj || jQuery.type(obj) !== "object" || obj.nodeType || jQuery.isWindow( obj ) ) {
489                         return false;
490                 }
492                 // Not own constructor property must be Object
493                 if ( obj.constructor &&
494                         !hasOwn.call(obj, "constructor") &&
495                         !hasOwn.call(obj.constructor.prototype, "isPrototypeOf") ) {
496                         return false;
497                 }
499                 // Own properties are enumerated firstly, so to speed up,
500                 // if last one is own, then all properties are own.
502                 var key;
503                 for ( key in obj ) {}
505                 return key === undefined || hasOwn.call( obj, key );
506         },
508         isEmptyObject: function( obj ) {
509                 for ( var name in obj ) {
510                         return false;
511                 }
512                 return true;
513         },
515         error: function( msg ) {
516                 throw msg;
517         },
519         parseJSON: function( data ) {
520                 if ( typeof data !== "string" || !data ) {
521                         return null;
522                 }
524                 // Make sure leading/trailing whitespace is removed (IE can't handle it)
525                 data = jQuery.trim( data );
527                 // Attempt to parse using the native JSON parser first
528                 if ( window.JSON && window.JSON.parse ) {
529                         return window.JSON.parse( data );
530                 }
532                 // Make sure the incoming data is actual JSON
533                 // Logic borrowed from http://json.org/json2.js
534                 if ( rvalidchars.test( data.replace( rvalidescape, "@" )
535                         .replace( rvalidtokens, "]" )
536                         .replace( rvalidbraces, "")) ) {
538                         return (new Function( "return " + data ))();
540                 }
541                 jQuery.error( "Invalid JSON: " + data );
542         },
544         // Cross-browser xml parsing
545         // (xml & tmp used internally)
546         parseXML: function( data , xml , tmp ) {
548                 if ( window.DOMParser ) { // Standard
549                         tmp = new DOMParser();
550                         xml = tmp.parseFromString( data , "text/xml" );
551                 } else { // IE
552                         xml = new ActiveXObject( "Microsoft.XMLDOM" );
553                         xml.async = "false";
554                         xml.loadXML( data );
555                 }
557                 tmp = xml.documentElement;
559                 if ( ! tmp || ! tmp.nodeName || tmp.nodeName === "parsererror" ) {
560                         jQuery.error( "Invalid XML: " + data );
561                 }
563                 return xml;
564         },
566         noop: function() {},
568         // Evalulates a script in a global context
569         globalEval: function( data ) {
570                 if ( data && rnotwhite.test(data) ) {
571                         // Inspired by code by Andrea Giammarchi
572                         // http://webreflection.blogspot.com/2007/08/global-scope-evaluation-and-dom.html
573                         var head = document.head || document.getElementsByTagName( "head" )[0] || document.documentElement,
574                                 script = document.createElement( "script" );
576                         if ( jQuery.support.scriptEval() ) {
577                                 script.appendChild( document.createTextNode( data ) );
578                         } else {
579                                 script.text = data;
580                         }
582                         // Use insertBefore instead of appendChild to circumvent an IE6 bug.
583                         // This arises when a base node is used (#2709).
584                         head.insertBefore( script, head.firstChild );
585                         head.removeChild( script );
586                 }
587         },
589         nodeName: function( elem, name ) {
590                 return elem.nodeName && elem.nodeName.toUpperCase() === name.toUpperCase();
591         },
593         // args is for internal usage only
594         each: function( object, callback, args ) {
595                 var name, i = 0,
596                         length = object.length,
597                         isObj = length === undefined || jQuery.isFunction(object);
599                 if ( args ) {
600                         if ( isObj ) {
601                                 for ( name in object ) {
602                                         if ( callback.apply( object[ name ], args ) === false ) {
603                                                 break;
604                                         }
605                                 }
606                         } else {
607                                 for ( ; i < length; ) {
608                                         if ( callback.apply( object[ i++ ], args ) === false ) {
609                                                 break;
610                                         }
611                                 }
612                         }
614                 // A special, fast, case for the most common use of each
615                 } else {
616                         if ( isObj ) {
617                                 for ( name in object ) {
618                                         if ( callback.call( object[ name ], name, object[ name ] ) === false ) {
619                                                 break;
620                                         }
621                                 }
622                         } else {
623                                 for ( var value = object[0];
624                                         i < length && callback.call( value, i, value ) !== false; value = object[++i] ) {}
625                         }
626                 }
628                 return object;
629         },
631         // Use native String.trim function wherever possible
632         trim: trim ?
633                 function( text ) {
634                         return text == null ?
635                                 "" :
636                                 trim.call( text );
637                 } :
639                 // Otherwise use our own trimming functionality
640                 function( text ) {
641                         return text == null ?
642                                 "" :
643                                 text.toString().replace( trimLeft, "" ).replace( trimRight, "" );
644                 },
646         // results is for internal usage only
647         makeArray: function( array, results ) {
648                 var ret = results || [];
650                 if ( array != null ) {
651                         // The window, strings (and functions) also have 'length'
652                         // The extra typeof function check is to prevent crashes
653                         // in Safari 2 (See: #3039)
654                         // Tweaked logic slightly to handle Blackberry 4.7 RegExp issues #6930
655                         var type = jQuery.type(array);
657                         if ( array.length == null || type === "string" || type === "function" || type === "regexp" || jQuery.isWindow( array ) ) {
658                                 push.call( ret, array );
659                         } else {
660                                 jQuery.merge( ret, array );
661                         }
662                 }
664                 return ret;
665         },
667         inArray: function( elem, array ) {
668                 if ( array.indexOf ) {
669                         return array.indexOf( elem );
670                 }
672                 for ( var i = 0, length = array.length; i < length; i++ ) {
673                         if ( array[ i ] === elem ) {
674                                 return i;
675                         }
676                 }
678                 return -1;
679         },
681         merge: function( first, second ) {
682                 var i = first.length,
683                         j = 0;
685                 if ( typeof second.length === "number" ) {
686                         for ( var l = second.length; j < l; j++ ) {
687                                 first[ i++ ] = second[ j ];
688                         }
690                 } else {
691                         while ( second[j] !== undefined ) {
692                                 first[ i++ ] = second[ j++ ];
693                         }
694                 }
696                 first.length = i;
698                 return first;
699         },
701         grep: function( elems, callback, inv ) {
702                 var ret = [], retVal;
703                 inv = !!inv;
705                 // Go through the array, only saving the items
706                 // that pass the validator function
707                 for ( var i = 0, length = elems.length; i < length; i++ ) {
708                         retVal = !!callback( elems[ i ], i );
709                         if ( inv !== retVal ) {
710                                 ret.push( elems[ i ] );
711                         }
712                 }
714                 return ret;
715         },
717         // arg is for internal usage only
718         map: function( elems, callback, arg ) {
719                 var ret = [], value;
721                 // Go through the array, translating each of the items to their
722                 // new value (or values).
723                 for ( var i = 0, length = elems.length; i < length; i++ ) {
724                         value = callback( elems[ i ], i, arg );
726                         if ( value != null ) {
727                                 ret[ ret.length ] = value;
728                         }
729                 }
731                 // Flatten any nested arrays
732                 return ret.concat.apply( [], ret );
733         },
735         // A global GUID counter for objects
736         guid: 1,
738         proxy: function( fn, proxy, thisObject ) {
739                 if ( arguments.length === 2 ) {
740                         if ( typeof proxy === "string" ) {
741                                 thisObject = fn;
742                                 fn = thisObject[ proxy ];
743                                 proxy = undefined;
745                         } else if ( proxy && !jQuery.isFunction( proxy ) ) {
746                                 thisObject = proxy;
747                                 proxy = undefined;
748                         }
749                 }
751                 if ( !proxy && fn ) {
752                         proxy = function() {
753                                 return fn.apply( thisObject || this, arguments );
754                         };
755                 }
757                 // Set the guid of unique handler to the same of original handler, so it can be removed
758                 if ( fn ) {
759                         proxy.guid = fn.guid = fn.guid || proxy.guid || jQuery.guid++;
760                 }
762                 // So proxy can be declared as an argument
763                 return proxy;
764         },
766         // Mutifunctional method to get and set values to a collection
767         // The value/s can be optionally by executed if its a function
768         access: function( elems, key, value, exec, fn, pass ) {
769                 var length = elems.length;
771                 // Setting many attributes
772                 if ( typeof key === "object" ) {
773                         for ( var k in key ) {
774                                 jQuery.access( elems, k, key[k], exec, fn, value );
775                         }
776                         return elems;
777                 }
779                 // Setting one attribute
780                 if ( value !== undefined ) {
781                         // Optionally, function values get executed if exec is true
782                         exec = !pass && exec && jQuery.isFunction(value);
784                         for ( var i = 0; i < length; i++ ) {
785                                 fn( elems[i], key, exec ? value.call( elems[i], i, fn( elems[i], key ) ) : value, pass );
786                         }
788                         return elems;
789                 }
791                 // Getting an attribute
792                 return length ? fn( elems[0], key ) : undefined;
793         },
795         now: function() {
796                 return (new Date()).getTime();
797         },
799         // Use of jQuery.browser is frowned upon.
800         // More details: http://docs.jquery.com/Utilities/jQuery.browser
801         uaMatch: function( ua ) {
802                 ua = ua.toLowerCase();
804                 var match = rwebkit.exec( ua ) ||
805                         ropera.exec( ua ) ||
806                         rmsie.exec( ua ) ||
807                         ua.indexOf("compatible") < 0 && rmozilla.exec( ua ) ||
808                         [];
810                 return { browser: match[1] || "", version: match[2] || "0" };
811         },
813         sub: function() {
814                 function jQuerySubclass( selector, context ) {
815                         return new jQuerySubclass.fn.init( selector, context );
816                 }
817                 jQuery.extend( true, jQuerySubclass, this );
818                 jQuerySubclass.superclass = this;
819                 jQuerySubclass.fn = jQuerySubclass.prototype = this();
820                 jQuerySubclass.fn.constructor = jQuerySubclass;
821                 jQuerySubclass.subclass = this.subclass;
822                 jQuerySubclass.fn.init = function init( selector, context ) {
823                         if ( context && context instanceof jQuery && !(context instanceof jQuerySubclass) ) {
824                                 context = jQuerySubclass(context);
825                         }
827                         return jQuery.fn.init.call( this, selector, context, rootjQuerySubclass );
828                 };
829                 jQuerySubclass.fn.init.prototype = jQuerySubclass.fn;
830                 var rootjQuerySubclass = jQuerySubclass(document);
831                 return jQuerySubclass;
832         },
834         browser: {}
837 // Populate the class2type map
838 jQuery.each("Boolean Number String Function Array Date RegExp Object".split(" "), function(i, name) {
839         class2type[ "[object " + name + "]" ] = name.toLowerCase();
842 browserMatch = jQuery.uaMatch( userAgent );
843 if ( browserMatch.browser ) {
844         jQuery.browser[ browserMatch.browser ] = true;
845         jQuery.browser.version = browserMatch.version;
848 // Deprecated, use jQuery.browser.webkit instead
849 if ( jQuery.browser.webkit ) {
850         jQuery.browser.safari = true;
853 if ( indexOf ) {
854         jQuery.inArray = function( elem, array ) {
855                 return indexOf.call( array, elem );
856         };
859 // IE doesn't match non-breaking spaces with \s
860 if ( rnotwhite.test( "\xA0" ) ) {
861         trimLeft = /^[\s\xA0]+/;
862         trimRight = /[\s\xA0]+$/;
865 // All jQuery objects should point back to these
866 rootjQuery = jQuery(document);
868 // Cleanup functions for the document ready method
869 if ( document.addEventListener ) {
870         DOMContentLoaded = function() {
871                 document.removeEventListener( "DOMContentLoaded", DOMContentLoaded, false );
872                 jQuery.ready();
873         };
875 } else if ( document.attachEvent ) {
876         DOMContentLoaded = function() {
877                 // Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443).
878                 if ( document.readyState === "complete" ) {
879                         document.detachEvent( "onreadystatechange", DOMContentLoaded );
880                         jQuery.ready();
881                 }
882         };
885 // The DOM ready check for Internet Explorer
886 function doScrollCheck() {
887         if ( jQuery.isReady ) {
888                 return;
889         }
891         try {
892                 // If IE is used, use the trick by Diego Perini
893                 // http://javascript.nwbox.com/IEContentLoaded/
894                 document.documentElement.doScroll("left");
895         } catch(e) {
896                 setTimeout( doScrollCheck, 1 );
897                 return;
898         }
900         // and execute any waiting functions
901         jQuery.ready();
904 // Expose jQuery to the global object
905 return jQuery;
907 })();