2 // A central reference to the root jQuery(document)
5 // The deferred used on DOM ready
8 // Use the correct document accordingly with window argument (sandbox)
9 document = window.document,
10 location = window.location,
12 // Map over jQuery in case of overwrite
13 _jQuery = window.jQuery,
15 // Map over the $ in case of overwrite
18 // [[Class]] -> type pairs
21 // List of deleted data cache ids, so we can reuse them
24 core_version = "@VERSION",
26 // Save a reference to some core methods
27 core_concat = core_deletedIds.concat,
28 core_push = core_deletedIds.push,
29 core_slice = core_deletedIds.slice,
30 core_indexOf = core_deletedIds.indexOf,
31 core_toString = class2type.toString,
32 core_hasOwn = class2type.hasOwnProperty,
33 core_trim = core_version.trim,
35 // Define a local copy of jQuery
36 jQuery = function( selector, context ) {
37 // The jQuery object is actually just the init constructor 'enhanced'
38 return new jQuery.fn.init( selector, context, rootjQuery );
41 // Used for matching numbers
42 core_pnum = /[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/.source,
44 // Used for splitting on whitespace
45 core_rnotwhite = /\S+/g,
47 // Make sure we trim BOM and NBSP (here's looking at you, Safari 5.0 and IE)
48 rtrim = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,
50 // A simple way to check for HTML strings
51 // Prioritize #id over <tag> to avoid XSS via location.hash (#9521)
52 // Strict HTML recognition (#11290: must start with <)
53 rquickExpr = /^(?:(<[\w\W]+>)[^>]*|#([\w-]*))$/,
55 // Match a standalone tag
56 rsingleTag = /^<(\w+)\s*\/?>(?:<\/\1>|)$/,
59 rvalidchars = /^[\],:{}\s]*$/,
60 rvalidbraces = /(?:^|:|,)(?:\s*\[)+/g,
61 rvalidescape = /\\(?:["\\\/bfnrt]|u[\da-fA-F]{4})/g,
62 rvalidtokens = /"[^"\\\r\n]*"|true|false|null|-?(?:\d+\.|)\d+(?:[eE][+-]?\d+|)/g,
64 // Matches dashed string for camelizing
66 rdashAlpha = /-([\da-z])/gi,
68 // Used by jQuery.camelCase as callback to replace()
69 fcamelCase = function( all, letter ) {
70 return letter.toUpperCase();
73 // The ready event handler and self cleanup method
74 DOMContentLoaded = function() {
75 if ( document.addEventListener ) {
76 document.removeEventListener( "DOMContentLoaded", DOMContentLoaded, false );
78 } else if ( document.readyState === "complete" ) {
79 // we're here because readyState === "complete" in oldIE
80 // which is good enough for us to call the dom ready!
81 document.detachEvent( "onreadystatechange", DOMContentLoaded );
86 jQuery.fn = jQuery.prototype = {
87 // The current version of jQuery being used
91 init: function( selector, context, rootjQuery ) {
94 // HANDLE: $(""), $(null), $(undefined), $(false)
99 // HANDLE: $(DOMElement)
100 if ( selector.nodeType ) {
101 this.context = this[0] = selector;
106 // Handle HTML strings
107 if ( typeof selector === "string" ) {
108 if ( selector.charAt(0) === "<" && selector.charAt( selector.length - 1 ) === ">" && selector.length >= 3 ) {
109 // Assume that strings that start and end with <> are HTML and skip the regex check
110 match = [ null, selector, null ];
113 match = rquickExpr.exec( selector );
116 // Match html or make sure no context is specified for #id
117 if ( match && (match[1] || !context) ) {
119 // HANDLE: $(html) -> $(array)
121 context = context instanceof jQuery ? context[0] : context;
123 // scripts is true for back-compat
124 jQuery.merge( this, jQuery.parseHTML(
126 context && context.nodeType ? context.ownerDocument || context : document,
130 // HANDLE: $(html, props)
131 if ( rsingleTag.test( match[1] ) && jQuery.isPlainObject( context ) ) {
132 for ( match in context ) {
133 // Properties of context are called as methods if possible
134 if ( jQuery.isFunction( this[ match ] ) ) {
135 this[ match ]( context[ match ] );
137 // ...and otherwise set as attributes
139 this.attr( match, context[ match ] );
148 elem = document.getElementById( match[2] );
150 // Check parentNode to catch when Blackberry 4.6 returns
151 // nodes that are no longer in the document #6963
152 if ( elem && elem.parentNode ) {
153 // Handle the case where IE and Opera return items
154 // by name instead of ID
155 if ( elem.id !== match[2] ) {
156 return rootjQuery.find( selector );
159 // Otherwise, we inject the element directly into the jQuery object
164 this.context = document;
165 this.selector = selector;
169 // HANDLE: $(expr, $(...))
170 } else if ( !context || context.jquery ) {
171 return ( context || rootjQuery ).find( selector );
173 // HANDLE: $(expr, context)
174 // (which is just equivalent to: $(context).find(expr)
176 return this.constructor( context ).find( selector );
179 // HANDLE: $(function)
180 // Shortcut for document ready
181 } else if ( jQuery.isFunction( selector ) ) {
182 return rootjQuery.ready( selector );
185 if ( selector.selector !== undefined ) {
186 this.selector = selector.selector;
187 this.context = selector.context;
190 return jQuery.makeArray( selector, this );
193 // Start with an empty selector
196 // The default length of a jQuery object is 0
199 // The number of elements contained in the matched element set
204 toArray: function() {
205 return core_slice.call( this );
208 // Get the Nth element in the matched element set OR
209 // Get the whole matched element set as a clean array
210 get: function( num ) {
213 // Return a 'clean' array
216 // Return just the object
217 ( num < 0 ? this[ this.length + num ] : this[ num ] );
220 // Take an array of elements and push it onto the stack
221 // (returning the new matched element set)
222 pushStack: function( elems ) {
224 // Build a new jQuery matched element set
225 var ret = jQuery.merge( this.constructor(), elems );
227 // Add the old object onto the stack (as a reference)
228 ret.prevObject = this;
229 ret.context = this.context;
231 // Return the newly-formed element set
235 // Execute a callback for every element in the matched set.
236 // (You can seed the arguments with an array of args, but this is
237 // only used internally.)
238 each: function( callback, args ) {
239 return jQuery.each( this, callback, args );
242 ready: function( fn ) {
244 jQuery.ready.promise().done( fn );
250 return this.pushStack( core_slice.apply( this, arguments ) );
258 return this.eq( -1 );
262 var len = this.length,
263 j = +i + ( i < 0 ? len : 0 );
264 return this.pushStack( j >= 0 && j < len ? [ this[j] ] : [] );
267 map: function( callback ) {
268 return this.pushStack( jQuery.map(this, function( elem, i ) {
269 return callback.call( elem, i, elem );
274 return this.prevObject || this.constructor(null);
277 // For internal use only.
278 // Behaves like an Array's method, not like a jQuery method.
284 // Give the init function the jQuery prototype for later instantiation
285 jQuery.fn.init.prototype = jQuery.fn;
287 jQuery.extend = jQuery.fn.extend = function() {
288 var options, name, src, copy, copyIsArray, clone,
289 target = arguments[0] || {},
291 length = arguments.length,
294 // Handle a deep copy situation
295 if ( typeof target === "boolean" ) {
297 target = arguments[1] || {};
298 // skip the boolean and the target
302 // Handle case when target is a string or something (possible in deep copy)
303 if ( typeof target !== "object" && !jQuery.isFunction(target) ) {
307 // extend jQuery itself if only one argument is passed
308 if ( length === i ) {
313 for ( ; i < length; i++ ) {
314 // Only deal with non-null/undefined values
315 if ( (options = arguments[ i ]) != null ) {
316 // Extend the base object
317 for ( name in options ) {
318 src = target[ name ];
319 copy = options[ name ];
321 // Prevent never-ending loop
322 if ( target === copy ) {
326 // Recurse if we're merging plain objects or arrays
327 if ( deep && copy && ( jQuery.isPlainObject(copy) || (copyIsArray = jQuery.isArray(copy)) ) ) {
330 clone = src && jQuery.isArray(src) ? src : [];
333 clone = src && jQuery.isPlainObject(src) ? src : {};
336 // Never move original objects, clone them
337 target[ name ] = jQuery.extend( deep, clone, copy );
339 // Don't bring in undefined values
340 } else if ( copy !== undefined ) {
341 target[ name ] = copy;
347 // Return the modified object
352 noConflict: function( deep ) {
353 if ( window.$ === jQuery ) {
357 if ( deep && window.jQuery === jQuery ) {
358 window.jQuery = _jQuery;
364 // Is the DOM ready to be used? Set to true once it occurs.
367 // A counter to track how many items to wait for before
368 // the ready event fires. See #6781
371 // Hold (or release) the ready event
372 holdReady: function( hold ) {
376 jQuery.ready( true );
380 // Handle when the DOM is ready
381 ready: function( wait ) {
383 // Abort if there are pending holds or we're already ready
384 if ( wait === true ? --jQuery.readyWait : jQuery.isReady ) {
388 // Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443).
389 if ( !document.body ) {
390 return setTimeout( jQuery.ready );
393 // Remember that the DOM is ready
394 jQuery.isReady = true;
396 // If a normal DOM Ready event fired, decrement, and wait if need be
397 if ( wait !== true && --jQuery.readyWait > 0 ) {
401 // If there are functions bound, to execute
402 readyList.resolveWith( document, [ jQuery ] );
404 // Trigger any bound ready events
405 if ( jQuery.fn.trigger ) {
406 jQuery( document ).trigger("ready").off("ready");
410 // See test/unit/core.js for details concerning isFunction.
411 // Since version 1.3, DOM methods and functions like alert
412 // aren't supported. They return false on IE (#2968).
413 isFunction: function( obj ) {
414 return jQuery.type(obj) === "function";
417 isArray: Array.isArray || function( obj ) {
418 return jQuery.type(obj) === "array";
421 isWindow: function( obj ) {
422 return obj != null && obj == obj.window;
425 isNumeric: function( obj ) {
426 return !isNaN( parseFloat(obj) ) && isFinite( obj );
429 type: function( obj ) {
432 class2type[ core_toString.call(obj) ] || "object";
435 isPlainObject: function( obj ) {
436 // Must be an Object.
437 // Because of IE, we also have to check the presence of the constructor property.
438 // Make sure that DOM nodes and window objects don't pass through, as well
439 if ( !obj || jQuery.type(obj) !== "object" || obj.nodeType || jQuery.isWindow( obj ) ) {
444 // Not own constructor property must be Object
445 if ( obj.constructor &&
446 !core_hasOwn.call(obj, "constructor") &&
447 !core_hasOwn.call(obj.constructor.prototype, "isPrototypeOf") ) {
451 // IE8,9 Will throw exceptions on certain host objects #9897
455 // Own properties are enumerated firstly, so to speed up,
456 // if last one is own, then all properties are own.
459 for ( key in obj ) {}
461 return key === undefined || core_hasOwn.call( obj, key );
464 isEmptyObject: function( obj ) {
466 for ( name in obj ) {
472 error: function( msg ) {
473 throw new Error( msg );
476 // data: string of html
477 // context (optional): If specified, the fragment will be created in this context, defaults to document
478 // keepScripts (optional): If true, will include scripts passed in the html string
479 parseHTML: function( data, context, keepScripts ) {
480 if ( !data || typeof data !== "string" ) {
483 if ( typeof context === "boolean" ) {
484 keepScripts = context;
487 context = context || document;
489 var parsed = rsingleTag.exec( data ),
490 scripts = !keepScripts && [];
494 return [ context.createElement( parsed[1] ) ];
497 parsed = context.createDocumentFragment();
498 jQuery.clean( [ data ], context, parsed, scripts );
500 jQuery( scripts ).remove();
502 return jQuery.merge( [], parsed.childNodes );
505 parseJSON: function( data ) {
506 // Attempt to parse using the native JSON parser first
507 if ( window.JSON && window.JSON.parse ) {
508 return window.JSON.parse( data );
511 if ( data === null ) {
515 if ( typeof data === "string" ) {
517 // Make sure leading/trailing whitespace is removed (IE can't handle it)
518 data = jQuery.trim( data );
521 // Make sure the incoming data is actual JSON
522 // Logic borrowed from http://json.org/json2.js
523 if ( rvalidchars.test( data.replace( rvalidescape, "@" )
524 .replace( rvalidtokens, "]" )
525 .replace( rvalidbraces, "")) ) {
527 return ( new Function( "return " + data ) )();
532 jQuery.error( "Invalid JSON: " + data );
535 // Cross-browser xml parsing
536 parseXML: function( data ) {
538 if ( !data || typeof data !== "string" ) {
542 if ( window.DOMParser ) { // Standard
543 tmp = new DOMParser();
544 xml = tmp.parseFromString( data , "text/xml" );
546 xml = new ActiveXObject( "Microsoft.XMLDOM" );
553 if ( !xml || !xml.documentElement || xml.getElementsByTagName( "parsererror" ).length ) {
554 jQuery.error( "Invalid XML: " + data );
561 // Evaluates a script in a global context
562 // Workarounds based on findings by Jim Driscoll
563 // http://weblogs.java.net/blog/driscoll/archive/2009/09/08/eval-javascript-global-context
564 globalEval: function( data ) {
565 if ( data && jQuery.trim( data ) ) {
566 // We use execScript on Internet Explorer
567 // We use an anonymous function so that context is window
568 // rather than jQuery in Firefox
569 ( window.execScript || function( data ) {
570 window[ "eval" ].call( window, data );
575 // Convert dashed to camelCase; used by the css and data modules
576 // Microsoft forgot to hump their vendor prefix (#9572)
577 camelCase: function( string ) {
578 return string.replace( rmsPrefix, "ms-" ).replace( rdashAlpha, fcamelCase );
581 nodeName: function( elem, name ) {
582 return elem.nodeName && elem.nodeName.toLowerCase() === name.toLowerCase();
585 // args is for internal usage only
586 each: function( obj, callback, args ) {
590 isArray = isArraylike( obj );
594 for ( ; i < length; i++ ) {
595 value = callback.apply( obj[ i ], args );
597 if ( value === false ) {
603 value = callback.apply( obj[ i ], args );
605 if ( value === false ) {
611 // A special, fast, case for the most common use of each
614 for ( ; i < length; i++ ) {
615 value = callback.call( obj[ i ], i, obj[ i ] );
617 if ( value === false ) {
623 value = callback.call( obj[ i ], i, obj[ i ] );
625 if ( value === false ) {
635 // Use native String.trim function wherever possible
636 trim: core_trim && !core_trim.call("\uFEFF\xA0") ?
638 return text == null ?
640 core_trim.call( text );
643 // Otherwise use our own trimming functionality
645 return text == null ?
647 ( text + "" ).replace( rtrim, "" );
650 // results is for internal usage only
651 makeArray: function( arr, results ) {
652 var ret = results || [];
655 if ( isArraylike( Object(arr) ) ) {
657 typeof arr === "string" ?
661 core_push.call( ret, arr );
668 inArray: function( elem, arr, i ) {
672 if ( core_indexOf ) {
673 return core_indexOf.call( arr, elem, i );
677 i = i ? i < 0 ? Math.max( 0, len + i ) : i : 0;
679 for ( ; i < len; i++ ) {
680 // Skip accessing in sparse arrays
681 if ( i in arr && arr[ i ] === elem ) {
690 merge: function( first, second ) {
691 var l = second.length,
695 if ( typeof l === "number" ) {
696 for ( ; j < l; j++ ) {
697 first[ i++ ] = second[ j ];
700 while ( second[j] !== undefined ) {
701 first[ i++ ] = second[ j++ ];
710 grep: function( elems, callback, inv ) {
714 length = elems.length;
717 // Go through the array, only saving the items
718 // that pass the validator function
719 for ( ; i < length; i++ ) {
720 retVal = !!callback( elems[ i ], i );
721 if ( inv !== retVal ) {
722 ret.push( elems[ i ] );
729 // arg is for internal usage only
730 map: function( elems, callback, arg ) {
733 length = elems.length,
734 isArray = isArraylike( elems ),
737 // Go through the array, translating each of the items to their
739 for ( ; i < length; i++ ) {
740 value = callback( elems[ i ], i, arg );
742 if ( value != null ) {
743 ret[ ret.length ] = value;
747 // Go through every key on the object,
750 value = callback( elems[ i ], i, arg );
752 if ( value != null ) {
753 ret[ ret.length ] = value;
758 // Flatten any nested arrays
759 return core_concat.apply( [], ret );
762 // A global GUID counter for objects
765 // Bind a function to a context, optionally partially applying any
767 proxy: function( fn, context ) {
768 var tmp, args, proxy;
770 if ( typeof context === "string" ) {
776 // Quick check to determine if target is callable, in the spec
777 // this throws a TypeError, but we will just return undefined.
778 if ( !jQuery.isFunction( fn ) ) {
783 args = core_slice.call( arguments, 2 );
785 return fn.apply( context || this, args.concat( core_slice.call( arguments ) ) );
788 // Set the guid of unique handler to the same of original handler, so it can be removed
789 proxy.guid = fn.guid = fn.guid || jQuery.guid++;
794 // Multifunctional method to get and set values of a collection
795 // The value/s can optionally be executed if it's a function
796 access: function( elems, fn, key, value, chainable, emptyGet, raw ) {
798 length = elems.length,
802 if ( jQuery.type( key ) === "object" ) {
805 jQuery.access( elems, fn, i, key[i], true, emptyGet, raw );
809 } else if ( value !== undefined ) {
812 if ( !jQuery.isFunction( value ) ) {
817 // Bulk operations run against the entire set
819 fn.call( elems, value );
822 // ...except when executing function values
825 fn = function( elem, key, value ) {
826 return bulk.call( jQuery( elem ), value );
832 for ( ; i < length; i++ ) {
833 fn( elems[i], key, raw ? value : value.call( elems[i], i, fn( elems[i], key ) ) );
844 length ? fn( elems[0], key ) : emptyGet;
848 return ( new Date() ).getTime();
852 jQuery.ready.promise = function( obj ) {
855 readyList = jQuery.Deferred();
857 // Catch cases where $(document).ready() is called after the browser event has already occurred.
858 // we once tried to use readyState "interactive" here, but it caused issues like the one
859 // discovered by ChrisS here: http://bugs.jquery.com/ticket/12282#comment:15
860 if ( document.readyState === "complete" ) {
861 // Handle it asynchronously to allow scripts the opportunity to delay ready
862 setTimeout( jQuery.ready );
864 // Standards-based browsers support DOMContentLoaded
865 } else if ( document.addEventListener ) {
866 // Use the handy event callback
867 document.addEventListener( "DOMContentLoaded", DOMContentLoaded, false );
869 // A fallback to window.onload, that will always work
870 window.addEventListener( "load", jQuery.ready, false );
872 // If IE event model is used
874 // Ensure firing before onload, maybe late but safe also for iframes
875 document.attachEvent( "onreadystatechange", DOMContentLoaded );
877 // A fallback to window.onload, that will always work
878 window.attachEvent( "onload", jQuery.ready );
880 // If IE and not a frame
881 // continually check to see if the document is ready
885 top = window.frameElement == null && document.documentElement;
888 if ( top && top.doScroll ) {
889 (function doScrollCheck() {
890 if ( !jQuery.isReady ) {
893 // Use the trick by Diego Perini
894 // http://javascript.nwbox.com/IEContentLoaded/
895 top.doScroll("left");
897 return setTimeout( doScrollCheck, 50 );
900 // and execute any waiting functions
907 return readyList.promise( obj );
910 // Populate the class2type map
911 jQuery.each("Boolean Number String Function Array Date RegExp Object Error".split(" "), function(i, name) {
912 class2type[ "[object " + name + "]" ] = name.toLowerCase();
915 function isArraylike( obj ) {
916 var length = obj.length,
917 type = jQuery.type( obj );
919 if ( jQuery.isWindow( obj ) ) {
923 if ( obj.nodeType === 1 && length ) {
927 return type === "array" || type !== "function" &&
929 typeof length === "number" && length > 0 && ( length - 1 ) in obj );
932 // All jQuery objects should point back to these
933 rootjQuery = jQuery(document);