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 );
9 // Map over jQuery in case of overwrite
10 _jQuery = window.jQuery,
12 // Map over the $ in case of overwrite
15 // A central reference to the root jQuery(document)
18 // A simple way to check for HTML strings or ID strings
19 // Prioritize #id over <tag> to avoid XSS via location.hash (#9521)
20 quickExpr = /^(?:[^#<]*(<[\w\W]+>)[^>]*$|#([\w\-]*)$)/,
22 // Check if a string has a non-whitespace character in it
25 // Used for trimming whitespace
32 // Match a standalone tag
33 rsingleTag = /^<(\w+)\s*\/?>(?:<\/\1>)?$/,
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,
42 rwebkit = /(webkit)[ \/]([\w.]+)/,
43 ropera = /(opera)(?:.*version)?[ \/]([\w.]+)/,
44 rmsie = /(msie) ([\w.]+)/,
45 rmozilla = /(mozilla)(?:.*? rv:([\w.]+))?/,
47 // Matches dashed string for camelizing
48 rdashAlpha = /-([a-z]|[0-9])/ig,
51 // Used by jQuery.camelCase as callback to replace()
52 fcamelCase = function( all, letter ) {
53 return ( letter + "" ).toUpperCase();
56 // Keep a UserAgent string for use with jQuery.browser
57 userAgent = navigator.userAgent,
59 // For matching the engine and version of the browser
62 // The deferred used on DOM ready
65 // The ready event handler
68 // Save a reference to some core methods
69 toString = Object.prototype.toString,
70 hasOwn = Object.prototype.hasOwnProperty,
71 push = Array.prototype.push,
72 slice = Array.prototype.slice,
73 trim = String.prototype.trim,
74 indexOf = Array.prototype.indexOf,
76 // [[Class]] -> type pairs
79 jQuery.fn = jQuery.prototype = {
81 init: function( selector, context, rootjQuery ) {
82 var match, elem, ret, doc;
84 // Handle $(""), $(null), or $(undefined)
89 // Handle $(DOMElement)
90 if ( selector.nodeType ) {
91 this.context = this[0] = selector;
96 // The body element only exists once, optimize finding it
97 if ( selector === "body" && !context && document.body ) {
98 this.context = document;
99 this[0] = document.body;
100 this.selector = selector;
105 // Handle HTML strings
106 if ( typeof selector === "string" ) {
107 // Are we dealing with HTML string or an ID?
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 = quickExpr.exec( selector );
116 // Verify a match, and that no context was specified for #id
117 if ( match && (match[1] || !context) ) {
119 // HANDLE: $(html) -> $(array)
121 context = context instanceof jQuery ? context[0] : context;
122 doc = ( context ? context.ownerDocument || context : document );
124 // If a single string is passed in and it's a single tag
125 // just do a createElement and skip the rest
126 ret = rsingleTag.exec( selector );
129 if ( jQuery.isPlainObject( context ) ) {
130 selector = [ document.createElement( ret[1] ) ];
131 jQuery.fn.attr.call( selector, context, true );
134 selector = [ doc.createElement( ret[1] ) ];
138 ret = jQuery.buildFragment( [ match[1] ], [ doc ] );
139 selector = ( ret.cacheable ? jQuery.clone(ret.fragment) : ret.fragment ).childNodes;
142 return jQuery.merge( this, selector );
146 elem = document.getElementById( match[2] );
148 // Check parentNode to catch when Blackberry 4.6 returns
149 // nodes that are no longer in the document #6963
150 if ( elem && elem.parentNode ) {
151 // Handle the case where IE and Opera return items
152 // by name instead of ID
153 if ( elem.id !== match[2] ) {
154 return rootjQuery.find( selector );
157 // Otherwise, we inject the element directly into the jQuery object
162 this.context = document;
163 this.selector = selector;
167 // HANDLE: $(expr, $(...))
168 } else if ( !context || context.jquery ) {
169 return ( context || rootjQuery ).find( selector );
171 // HANDLE: $(expr, context)
172 // (which is just equivalent to: $(context).find(expr)
174 return this.constructor( context ).find( selector );
177 // HANDLE: $(function)
178 // Shortcut for document ready
179 } else if ( jQuery.isFunction( selector ) ) {
180 return rootjQuery.ready( selector );
183 if ( selector.selector !== undefined ) {
184 this.selector = selector.selector;
185 this.context = selector.context;
188 return jQuery.makeArray( selector, this );
191 // Start with an empty selector
194 // The current version of jQuery being used
197 // The default length of a jQuery object is 0
200 // The number of elements contained in the matched element set
205 toArray: function() {
206 return slice.call( this, 0 );
209 // Get the Nth element in the matched element set OR
210 // Get the whole matched element set as a clean array
211 get: function( num ) {
214 // Return a 'clean' array
217 // Return just the object
218 ( num < 0 ? this[ this.length + num ] : this[ num ] );
221 // Take an array of elements and push it onto the stack
222 // (returning the new matched element set)
223 pushStack: function( elems, name, selector ) {
224 // Build a new jQuery matched element set
225 var ret = this.constructor();
227 if ( jQuery.isArray( elems ) ) {
228 push.apply( ret, elems );
231 jQuery.merge( ret, elems );
234 // Add the old object onto the stack (as a reference)
235 ret.prevObject = this;
237 ret.context = this.context;
239 if ( name === "find" ) {
240 ret.selector = this.selector + ( this.selector ? " " : "" ) + selector;
242 ret.selector = this.selector + "." + name + "(" + selector + ")";
245 // Return the newly-formed element set
249 // Execute a callback for every element in the matched set.
250 // (You can seed the arguments with an array of args, but this is
251 // only used internally.)
252 each: function( callback, args ) {
253 return jQuery.each( this, callback, args );
256 ready: function( fn ) {
257 // Attach the listeners
269 this.slice( i, +i + 1 );
277 return this.eq( -1 );
281 return this.pushStack( slice.apply( this, arguments ),
282 "slice", slice.call(arguments).join(",") );
285 map: function( callback ) {
286 return this.pushStack( jQuery.map(this, function( elem, i ) {
287 return callback.call( elem, i, elem );
292 return this.prevObject || this.constructor(null);
295 // For internal use only.
296 // Behaves like an Array's method, not like a jQuery method.
302 // Give the init function the jQuery prototype for later instantiation
303 jQuery.fn.init.prototype = jQuery.fn;
305 jQuery.extend = jQuery.fn.extend = function() {
306 var options, name, src, copy, copyIsArray, clone,
307 target = arguments[0] || {},
309 length = arguments.length,
312 // Handle a deep copy situation
313 if ( typeof target === "boolean" ) {
315 target = arguments[1] || {};
316 // skip the boolean and the target
320 // Handle case when target is a string or something (possible in deep copy)
321 if ( typeof target !== "object" && !jQuery.isFunction(target) ) {
325 // extend jQuery itself if only one argument is passed
326 if ( length === i ) {
331 for ( ; i < length; i++ ) {
332 // Only deal with non-null/undefined values
333 if ( (options = arguments[ i ]) != null ) {
334 // Extend the base object
335 for ( name in options ) {
336 src = target[ name ];
337 copy = options[ name ];
339 // Prevent never-ending loop
340 if ( target === copy ) {
344 // Recurse if we're merging plain objects or arrays
345 if ( deep && copy && ( jQuery.isPlainObject(copy) || (copyIsArray = jQuery.isArray(copy)) ) ) {
348 clone = src && jQuery.isArray(src) ? src : [];
351 clone = src && jQuery.isPlainObject(src) ? src : {};
354 // Never move original objects, clone them
355 target[ name ] = jQuery.extend( deep, clone, copy );
357 // Don't bring in undefined values
358 } else if ( copy !== undefined ) {
359 target[ name ] = copy;
365 // Return the modified object
370 noConflict: function( deep ) {
371 if ( window.$ === jQuery ) {
375 if ( deep && window.jQuery === jQuery ) {
376 window.jQuery = _jQuery;
382 // Is the DOM ready to be used? Set to true once it occurs.
385 // A counter to track how many items to wait for before
386 // the ready event fires. See #6781
389 // Hold (or release) the ready event
390 holdReady: function( hold ) {
394 jQuery.ready( true );
398 // Handle when the DOM is ready
399 ready: function( wait ) {
400 // Either a released hold or an DOMready/load event and not yet ready
401 if ( (wait === true && !--jQuery.readyWait) || (wait !== true && !jQuery.isReady) ) {
402 // Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443).
403 if ( !document.body ) {
404 return setTimeout( jQuery.ready, 1 );
407 // Remember that the DOM is ready
408 jQuery.isReady = true;
410 // If a normal DOM Ready event fired, decrement, and wait if need be
411 if ( wait !== true && --jQuery.readyWait > 0 ) {
415 // If there are functions bound, to execute
416 readyList.fireWith( document, [ jQuery ] );
418 // Trigger any bound ready events
419 if ( jQuery.fn.trigger ) {
420 jQuery( document ).trigger( "ready" ).unbind( "ready" );
425 bindReady: function() {
430 readyList = jQuery.Callbacks( "once memory" );
432 // Catch cases where $(document).ready() is called after the
433 // browser event has already occurred.
434 if ( document.readyState === "complete" ) {
435 // Handle it asynchronously to allow scripts the opportunity to delay ready
436 return setTimeout( jQuery.ready, 1 );
439 // Mozilla, Opera and webkit nightlies currently support this event
440 if ( document.addEventListener ) {
441 // Use the handy event callback
442 document.addEventListener( "DOMContentLoaded", DOMContentLoaded, false );
444 // A fallback to window.onload, that will always work
445 window.addEventListener( "load", jQuery.ready, false );
447 // If IE event model is used
448 } else if ( document.attachEvent ) {
449 // ensure firing before onload,
450 // maybe late but safe also for iframes
451 document.attachEvent( "onreadystatechange", DOMContentLoaded );
453 // A fallback to window.onload, that will always work
454 window.attachEvent( "onload", jQuery.ready );
456 // If IE and not a frame
457 // continually check to see if the document is ready
458 var toplevel = false;
461 toplevel = window.frameElement == null;
464 if ( document.documentElement.doScroll && toplevel ) {
470 // See test/unit/core.js for details concerning isFunction.
471 // Since version 1.3, DOM methods and functions like alert
472 // aren't supported. They return false on IE (#2968).
473 isFunction: function( obj ) {
474 return jQuery.type(obj) === "function";
477 isArray: Array.isArray || function( obj ) {
478 return jQuery.type(obj) === "array";
481 // A crude way of determining if an object is a window
482 isWindow: function( obj ) {
483 return obj && typeof obj === "object" && "setInterval" in obj;
486 isNumeric: function( obj ) {
487 return obj != null && rdigit.test( obj ) && !isNaN( obj );
490 type: function( obj ) {
493 class2type[ toString.call(obj) ] || "object";
496 isPlainObject: function( obj ) {
497 // Must be an Object.
498 // Because of IE, we also have to check the presence of the constructor property.
499 // Make sure that DOM nodes and window objects don't pass through, as well
500 if ( !obj || jQuery.type(obj) !== "object" || obj.nodeType || jQuery.isWindow( obj ) ) {
505 // Not own constructor property must be Object
506 if ( obj.constructor &&
507 !hasOwn.call(obj, "constructor") &&
508 !hasOwn.call(obj.constructor.prototype, "isPrototypeOf") ) {
512 // IE8,9 Will throw exceptions on certain host objects #9897
516 // Own properties are enumerated firstly, so to speed up,
517 // if last one is own, then all properties are own.
520 for ( key in obj ) {}
522 return key === undefined || hasOwn.call( obj, key );
525 isEmptyObject: function( obj ) {
526 for ( var name in obj ) {
532 error: function( msg ) {
536 parseJSON: function( data ) {
537 if ( typeof data !== "string" || !data ) {
541 // Make sure leading/trailing whitespace is removed (IE can't handle it)
542 data = jQuery.trim( data );
544 // Attempt to parse using the native JSON parser first
545 if ( window.JSON && window.JSON.parse ) {
546 return window.JSON.parse( data );
549 // Make sure the incoming data is actual JSON
550 // Logic borrowed from http://json.org/json2.js
551 if ( rvalidchars.test( data.replace( rvalidescape, "@" )
552 .replace( rvalidtokens, "]" )
553 .replace( rvalidbraces, "")) ) {
555 return ( new Function( "return " + data ) )();
558 jQuery.error( "Invalid JSON: " + data );
561 // Cross-browser xml parsing
562 parseXML: function( data ) {
565 if ( window.DOMParser ) { // Standard
566 tmp = new DOMParser();
567 xml = tmp.parseFromString( data , "text/xml" );
569 xml = new ActiveXObject( "Microsoft.XMLDOM" );
576 if ( !xml || !xml.documentElement || xml.getElementsByTagName( "parsererror" ).length ) {
577 jQuery.error( "Invalid XML: " + data );
584 // Evaluates a script in a global context
585 // Workarounds based on findings by Jim Driscoll
586 // http://weblogs.java.net/blog/driscoll/archive/2009/09/08/eval-javascript-global-context
587 globalEval: function( data ) {
588 if ( data && rnotwhite.test( data ) ) {
589 // We use execScript on Internet Explorer
590 // We use an anonymous function so that context is window
591 // rather than jQuery in Firefox
592 ( window.execScript || function( data ) {
593 window[ "eval" ].call( window, data );
598 // Convert dashed to camelCase; used by the css and data modules
599 // Microsoft forgot to hump their vendor prefix (#9572)
600 camelCase: function( string ) {
601 return string.replace( rmsPrefix, "ms-" ).replace( rdashAlpha, fcamelCase );
604 nodeName: function( elem, name ) {
605 return elem.nodeName && elem.nodeName.toUpperCase() === name.toUpperCase();
608 // args is for internal usage only
609 each: function( object, callback, args ) {
611 length = object.length,
612 isObj = length === undefined || jQuery.isFunction( object );
616 for ( name in object ) {
617 if ( callback.apply( object[ name ], args ) === false ) {
622 for ( ; i < length; ) {
623 if ( callback.apply( object[ i++ ], args ) === false ) {
629 // A special, fast, case for the most common use of each
632 for ( name in object ) {
633 if ( callback.call( object[ name ], name, object[ name ] ) === false ) {
638 for ( ; i < length; ) {
639 if ( callback.call( object[ i ], i, object[ i++ ] ) === false ) {
649 // Use native String.trim function wherever possible
652 return text == null ?
657 // Otherwise use our own trimming functionality
659 return text == null ?
661 text.toString().replace( trimLeft, "" ).replace( trimRight, "" );
664 // results is for internal usage only
665 makeArray: function( array, results ) {
666 var ret = results || [];
668 if ( array != null ) {
669 // The window, strings (and functions) also have 'length'
670 // The extra typeof function check is to prevent crashes
671 // in Safari 2 (See: #3039)
672 // Tweaked logic slightly to handle Blackberry 4.7 RegExp issues #6930
673 var type = jQuery.type( array );
675 if ( array.length == null || type === "string" || type === "function" || type === "regexp" || jQuery.isWindow( array ) ) {
676 push.call( ret, array );
678 jQuery.merge( ret, array );
685 inArray: function( elem, array, i ) {
690 return indexOf.call( array, elem, i );
694 i = i ? i < 0 ? Math.max( 0, len + i ) : i : 0;
696 for ( ; i < len; i++ ) {
697 // Skip accessing in sparse arrays
698 if ( i in array && array[ i ] === elem ) {
707 merge: function( first, second ) {
708 var i = first.length,
711 if ( typeof second.length === "number" ) {
712 for ( var l = second.length; j < l; j++ ) {
713 first[ i++ ] = second[ j ];
717 while ( second[j] !== undefined ) {
718 first[ i++ ] = second[ j++ ];
727 grep: function( elems, callback, inv ) {
728 var ret = [], retVal;
731 // Go through the array, only saving the items
732 // that pass the validator function
733 for ( var i = 0, length = elems.length; i < length; i++ ) {
734 retVal = !!callback( elems[ i ], i );
735 if ( inv !== retVal ) {
736 ret.push( elems[ i ] );
743 // arg is for internal usage only
744 map: function( elems, callback, arg ) {
745 var value, key, ret = [],
747 length = elems.length,
748 // jquery objects are treated as arrays
749 isArray = elems instanceof jQuery || length !== undefined && typeof length === "number" && ( ( length > 0 && elems[ 0 ] && elems[ length -1 ] ) || length === 0 || jQuery.isArray( elems ) ) ;
751 // Go through the array, translating each of the items to their
753 for ( ; i < length; i++ ) {
754 value = callback( elems[ i ], i, arg );
756 if ( value != null ) {
757 ret[ ret.length ] = value;
761 // Go through every key on the object,
763 for ( key in elems ) {
764 value = callback( elems[ key ], key, arg );
766 if ( value != null ) {
767 ret[ ret.length ] = value;
772 // Flatten any nested arrays
773 return ret.concat.apply( [], ret );
776 // A global GUID counter for objects
779 // Bind a function to a context, optionally partially applying any
781 proxy: function( fn, context ) {
782 if ( typeof context === "string" ) {
783 var tmp = fn[ context ];
788 // Quick check to determine if target is callable, in the spec
789 // this throws a TypeError, but we will just return undefined.
790 if ( !jQuery.isFunction( fn ) ) {
795 var args = slice.call( arguments, 2 ),
797 return fn.apply( context, args.concat( slice.call( arguments ) ) );
800 // Set the guid of unique handler to the same of original handler, so it can be removed
801 proxy.guid = fn.guid = fn.guid || proxy.guid || jQuery.guid++;
806 // Mutifunctional method to get and set values to a collection
807 // The value/s can optionally be executed if it's a function
808 access: function( elems, key, value, exec, fn, pass ) {
809 var length = elems.length;
811 // Setting many attributes
812 if ( typeof key === "object" ) {
813 for ( var k in key ) {
814 jQuery.access( elems, k, key[k], exec, fn, value );
819 // Setting one attribute
820 if ( value !== undefined ) {
821 // Optionally, function values get executed if exec is true
822 exec = !pass && exec && jQuery.isFunction(value);
824 for ( var i = 0; i < length; i++ ) {
825 fn( elems[i], key, exec ? value.call( elems[i], i, fn( elems[i], key ) ) : value, pass );
831 // Getting an attribute
832 return length ? fn( elems[0], key ) : undefined;
836 return ( new Date() ).getTime();
839 // Use of jQuery.browser is frowned upon.
840 // More details: http://docs.jquery.com/Utilities/jQuery.browser
841 uaMatch: function( ua ) {
842 ua = ua.toLowerCase();
844 var match = rwebkit.exec( ua ) ||
847 ua.indexOf("compatible") < 0 && rmozilla.exec( ua ) ||
850 return { browser: match[1] || "", version: match[2] || "0" };
854 function jQuerySub( selector, context ) {
855 return new jQuerySub.fn.init( selector, context );
857 jQuery.extend( true, jQuerySub, this );
858 jQuerySub.superclass = this;
859 jQuerySub.fn = jQuerySub.prototype = this();
860 jQuerySub.fn.constructor = jQuerySub;
861 jQuerySub.sub = this.sub;
862 jQuerySub.fn.init = function init( selector, context ) {
863 if ( context && context instanceof jQuery && !(context instanceof jQuerySub) ) {
864 context = jQuerySub( context );
867 return jQuery.fn.init.call( this, selector, context, rootjQuerySub );
869 jQuerySub.fn.init.prototype = jQuerySub.fn;
870 var rootjQuerySub = jQuerySub(document);
877 // Populate the class2type map
878 jQuery.each("Boolean Number String Function Array Date RegExp Object".split(" "), function(i, name) {
879 class2type[ "[object " + name + "]" ] = name.toLowerCase();
882 browserMatch = jQuery.uaMatch( userAgent );
883 if ( browserMatch.browser ) {
884 jQuery.browser[ browserMatch.browser ] = true;
885 jQuery.browser.version = browserMatch.version;
888 // Deprecated, use jQuery.browser.webkit instead
889 if ( jQuery.browser.webkit ) {
890 jQuery.browser.safari = true;
893 // IE doesn't match non-breaking spaces with \s
894 if ( rnotwhite.test( "\xA0" ) ) {
895 trimLeft = /^[\s\xA0]+/;
896 trimRight = /[\s\xA0]+$/;
899 // All jQuery objects should point back to these
900 rootjQuery = jQuery(document);
902 // Cleanup functions for the document ready method
903 if ( document.addEventListener ) {
904 DOMContentLoaded = function() {
905 document.removeEventListener( "DOMContentLoaded", DOMContentLoaded, false );
909 } else if ( document.attachEvent ) {
910 DOMContentLoaded = function() {
911 // Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443).
912 if ( document.readyState === "complete" ) {
913 document.detachEvent( "onreadystatechange", DOMContentLoaded );
919 // The DOM ready check for Internet Explorer
920 function doScrollCheck() {
921 if ( jQuery.isReady ) {
926 // If IE is used, use the trick by Diego Perini
927 // http://javascript.nwbox.com/IEContentLoaded/
928 document.documentElement.doScroll("left");
930 setTimeout( doScrollCheck, 1 );
934 // and execute any waiting functions
938 // Expose jQuery as an AMD module, but only for AMD loaders that
939 // understand the issues with loading multiple versions of jQuery
940 // in a page that all might call define(). The loader will indicate
941 // they have special allowances for multiple jQuery versions by
942 // specifying define.amd.jQuery = true. Register as a named module,
943 // since jQuery can be concatenated with other files that may use define,
944 // but not use a proper concatenation script that understands anonymous
945 // AMD modules. A named AMD is safest and most robust way to register.
946 // Lowercase jquery is used because AMD module names are derived from
947 // file names, and jQuery is normally delivered in a lowercase file name.
948 if ( typeof define === "function" && define.amd && define.amd.jQuery ) {
949 define( "jquery", [], function () { return jQuery; } );