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