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
270 this.slice( i, i + 1 );
278 return this.eq( -1 );
282 return this.pushStack( slice.apply( this, arguments ),
283 "slice", slice.call(arguments).join(",") );
286 map: function( callback ) {
287 return this.pushStack( jQuery.map(this, function( elem, i ) {
288 return callback.call( elem, i, elem );
293 return this.prevObject || this.constructor(null);
296 // For internal use only.
297 // Behaves like an Array's method, not like a jQuery method.
303 // Give the init function the jQuery prototype for later instantiation
304 jQuery.fn.init.prototype = jQuery.fn;
306 jQuery.extend = jQuery.fn.extend = function() {
307 var options, name, src, copy, copyIsArray, clone,
308 target = arguments[0] || {},
310 length = arguments.length,
313 // Handle a deep copy situation
314 if ( typeof target === "boolean" ) {
316 target = arguments[1] || {};
317 // skip the boolean and the target
321 // Handle case when target is a string or something (possible in deep copy)
322 if ( typeof target !== "object" && !jQuery.isFunction(target) ) {
326 // extend jQuery itself if only one argument is passed
327 if ( length === i ) {
332 for ( ; i < length; i++ ) {
333 // Only deal with non-null/undefined values
334 if ( (options = arguments[ i ]) != null ) {
335 // Extend the base object
336 for ( name in options ) {
337 src = target[ name ];
338 copy = options[ name ];
340 // Prevent never-ending loop
341 if ( target === copy ) {
345 // Recurse if we're merging plain objects or arrays
346 if ( deep && copy && ( jQuery.isPlainObject(copy) || (copyIsArray = jQuery.isArray(copy)) ) ) {
349 clone = src && jQuery.isArray(src) ? src : [];
352 clone = src && jQuery.isPlainObject(src) ? src : {};
355 // Never move original objects, clone them
356 target[ name ] = jQuery.extend( deep, clone, copy );
358 // Don't bring in undefined values
359 } else if ( copy !== undefined ) {
360 target[ name ] = copy;
366 // Return the modified object
371 noConflict: function( deep ) {
372 if ( window.$ === jQuery ) {
376 if ( deep && window.jQuery === jQuery ) {
377 window.jQuery = _jQuery;
383 // Is the DOM ready to be used? Set to true once it occurs.
386 // A counter to track how many items to wait for before
387 // the ready event fires. See #6781
390 // Hold (or release) the ready event
391 holdReady: function( hold ) {
395 jQuery.ready( true );
399 // Handle when the DOM is ready
400 ready: function( wait ) {
401 // Either a released hold or an DOMready/load event and not yet ready
402 if ( (wait === true && !--jQuery.readyWait) || (wait !== true && !jQuery.isReady) ) {
403 // Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443).
404 if ( !document.body ) {
405 return setTimeout( jQuery.ready, 1 );
408 // Remember that the DOM is ready
409 jQuery.isReady = true;
411 // If a normal DOM Ready event fired, decrement, and wait if need be
412 if ( wait !== true && --jQuery.readyWait > 0 ) {
416 // If there are functions bound, to execute
417 readyList.fireWith( document, [ jQuery ] );
419 // Trigger any bound ready events
420 if ( jQuery.fn.trigger ) {
421 jQuery( document ).trigger( "ready" ).off( "ready" );
426 bindReady: function() {
431 readyList = jQuery.Callbacks( "once memory" );
433 // Catch cases where $(document).ready() is called after the
434 // browser event has already occurred.
435 if ( document.readyState === "complete" ) {
436 // Handle it asynchronously to allow scripts the opportunity to delay ready
437 return setTimeout( jQuery.ready, 1 );
440 // Mozilla, Opera and webkit nightlies currently support this event
441 if ( document.addEventListener ) {
442 // Use the handy event callback
443 document.addEventListener( "DOMContentLoaded", DOMContentLoaded, false );
445 // A fallback to window.onload, that will always work
446 window.addEventListener( "load", jQuery.ready, false );
448 // If IE event model is used
449 } else if ( document.attachEvent ) {
450 // ensure firing before onload,
451 // maybe late but safe also for iframes
452 document.attachEvent( "onreadystatechange", DOMContentLoaded );
454 // A fallback to window.onload, that will always work
455 window.attachEvent( "onload", jQuery.ready );
457 // If IE and not a frame
458 // continually check to see if the document is ready
459 var toplevel = false;
462 toplevel = window.frameElement == null;
465 if ( document.documentElement.doScroll && toplevel ) {
471 // See test/unit/core.js for details concerning isFunction.
472 // Since version 1.3, DOM methods and functions like alert
473 // aren't supported. They return false on IE (#2968).
474 isFunction: function( obj ) {
475 return jQuery.type(obj) === "function";
478 isArray: Array.isArray || function( obj ) {
479 return jQuery.type(obj) === "array";
482 // A crude way of determining if an object is a window
483 isWindow: function( obj ) {
484 return obj && typeof obj === "object" && "setInterval" in obj;
487 isNumeric: function( obj ) {
488 return !isNaN( parseFloat(obj) ) && isFinite( obj );
491 type: function( obj ) {
494 class2type[ toString.call(obj) ] || "object";
497 isPlainObject: function( obj ) {
498 // Must be an Object.
499 // Because of IE, we also have to check the presence of the constructor property.
500 // Make sure that DOM nodes and window objects don't pass through, as well
501 if ( !obj || jQuery.type(obj) !== "object" || obj.nodeType || jQuery.isWindow( obj ) ) {
506 // Not own constructor property must be Object
507 if ( obj.constructor &&
508 !hasOwn.call(obj, "constructor") &&
509 !hasOwn.call(obj.constructor.prototype, "isPrototypeOf") ) {
513 // IE8,9 Will throw exceptions on certain host objects #9897
517 // Own properties are enumerated firstly, so to speed up,
518 // if last one is own, then all properties are own.
521 for ( key in obj ) {}
523 return key === undefined || hasOwn.call( obj, key );
526 isEmptyObject: function( obj ) {
527 for ( var name in obj ) {
533 error: function( msg ) {
534 throw new Error( msg );
537 parseJSON: function( data ) {
538 if ( typeof data !== "string" || !data ) {
542 // Make sure leading/trailing whitespace is removed (IE can't handle it)
543 data = jQuery.trim( data );
545 // Attempt to parse using the native JSON parser first
546 if ( window.JSON && window.JSON.parse ) {
547 return window.JSON.parse( data );
550 // Make sure the incoming data is actual JSON
551 // Logic borrowed from http://json.org/json2.js
552 if ( rvalidchars.test( data.replace( rvalidescape, "@" )
553 .replace( rvalidtokens, "]" )
554 .replace( rvalidbraces, "")) ) {
556 return ( new Function( "return " + data ) )();
559 jQuery.error( "Invalid JSON: " + data );
562 // Cross-browser xml parsing
563 parseXML: function( data ) {
566 if ( window.DOMParser ) { // Standard
567 tmp = new DOMParser();
568 xml = tmp.parseFromString( data , "text/xml" );
570 xml = new ActiveXObject( "Microsoft.XMLDOM" );
577 if ( !xml || !xml.documentElement || xml.getElementsByTagName( "parsererror" ).length ) {
578 jQuery.error( "Invalid XML: " + data );
585 // Evaluates a script in a global context
586 // Workarounds based on findings by Jim Driscoll
587 // http://weblogs.java.net/blog/driscoll/archive/2009/09/08/eval-javascript-global-context
588 globalEval: function( data ) {
589 if ( data && rnotwhite.test( data ) ) {
590 // We use execScript on Internet Explorer
591 // We use an anonymous function so that context is window
592 // rather than jQuery in Firefox
593 ( window.execScript || function( data ) {
594 window[ "eval" ].call( window, data );
599 // Convert dashed to camelCase; used by the css and data modules
600 // Microsoft forgot to hump their vendor prefix (#9572)
601 camelCase: function( string ) {
602 return string.replace( rmsPrefix, "ms-" ).replace( rdashAlpha, fcamelCase );
605 nodeName: function( elem, name ) {
606 return elem.nodeName && elem.nodeName.toUpperCase() === name.toUpperCase();
609 // args is for internal usage only
610 each: function( object, callback, args ) {
612 length = object.length,
613 isObj = length === undefined || jQuery.isFunction( object );
617 for ( name in object ) {
618 if ( callback.apply( object[ name ], args ) === false ) {
623 for ( ; i < length; ) {
624 if ( callback.apply( object[ i++ ], args ) === false ) {
630 // A special, fast, case for the most common use of each
633 for ( name in object ) {
634 if ( callback.call( object[ name ], name, object[ name ] ) === false ) {
639 for ( ; i < length; ) {
640 if ( callback.call( object[ i ], i, object[ i++ ] ) === false ) {
650 // Use native String.trim function wherever possible
653 return text == null ?
658 // Otherwise use our own trimming functionality
660 return text == null ?
662 text.toString().replace( trimLeft, "" ).replace( trimRight, "" );
665 // results is for internal usage only
666 makeArray: function( array, results ) {
667 var ret = results || [];
669 if ( array != null ) {
670 // The window, strings (and functions) also have 'length'
671 // Tweaked logic slightly to handle Blackberry 4.7 RegExp issues #6930
672 var type = jQuery.type( array );
674 if ( array.length == null || type === "string" || type === "function" || type === "regexp" || jQuery.isWindow( array ) ) {
675 push.call( ret, array );
677 jQuery.merge( ret, array );
684 inArray: function( elem, array, i ) {
689 return indexOf.call( array, elem, i );
693 i = i ? i < 0 ? Math.max( 0, len + i ) : i : 0;
695 for ( ; i < len; i++ ) {
696 // Skip accessing in sparse arrays
697 if ( i in array && array[ i ] === elem ) {
706 merge: function( first, second ) {
707 var i = first.length,
710 if ( typeof second.length === "number" ) {
711 for ( var l = second.length; j < l; j++ ) {
712 first[ i++ ] = second[ j ];
716 while ( second[j] !== undefined ) {
717 first[ i++ ] = second[ j++ ];
726 grep: function( elems, callback, inv ) {
727 var ret = [], retVal;
730 // Go through the array, only saving the items
731 // that pass the validator function
732 for ( var i = 0, length = elems.length; i < length; i++ ) {
733 retVal = !!callback( elems[ i ], i );
734 if ( inv !== retVal ) {
735 ret.push( elems[ i ] );
742 // arg is for internal usage only
743 map: function( elems, callback, arg ) {
744 var value, key, ret = [],
746 length = elems.length,
747 // jquery objects are treated as arrays
748 isArray = elems instanceof jQuery || length !== undefined && typeof length === "number" && ( ( length > 0 && elems[ 0 ] && elems[ length -1 ] ) || length === 0 || jQuery.isArray( elems ) ) ;
750 // Go through the array, translating each of the items to their
752 for ( ; i < length; i++ ) {
753 value = callback( elems[ i ], i, arg );
755 if ( value != null ) {
756 ret[ ret.length ] = value;
760 // Go through every key on the object,
762 for ( key in elems ) {
763 value = callback( elems[ key ], key, arg );
765 if ( value != null ) {
766 ret[ ret.length ] = value;
771 // Flatten any nested arrays
772 return ret.concat.apply( [], ret );
775 // A global GUID counter for objects
778 // Bind a function to a context, optionally partially applying any
780 proxy: function( fn, context ) {
781 if ( typeof context === "string" ) {
782 var tmp = fn[ context ];
787 // Quick check to determine if target is callable, in the spec
788 // this throws a TypeError, but we will just return undefined.
789 if ( !jQuery.isFunction( fn ) ) {
794 var args = slice.call( arguments, 2 ),
796 return fn.apply( context, args.concat( slice.call( arguments ) ) );
799 // Set the guid of unique handler to the same of original handler, so it can be removed
800 proxy.guid = fn.guid = fn.guid || proxy.guid || jQuery.guid++;
805 // Mutifunctional method to get and set values to a collection
806 // The value/s can optionally be executed if it's a function
807 access: function( elems, key, value, exec, fn, pass ) {
808 var length = elems.length;
810 // Setting many attributes
811 if ( typeof key === "object" ) {
812 for ( var k in key ) {
813 jQuery.access( elems, k, key[k], exec, fn, value );
818 // Setting one attribute
819 if ( value !== undefined ) {
820 // Optionally, function values get executed if exec is true
821 exec = !pass && exec && jQuery.isFunction(value);
823 for ( var i = 0; i < length; i++ ) {
824 fn( elems[i], key, exec ? value.call( elems[i], i, fn( elems[i], key ) ) : value, pass );
830 // Getting an attribute
831 return length ? fn( elems[0], key ) : undefined;
835 return ( new Date() ).getTime();
838 // Use of jQuery.browser is frowned upon.
839 // More details: http://docs.jquery.com/Utilities/jQuery.browser
840 uaMatch: function( ua ) {
841 ua = ua.toLowerCase();
843 var match = rwebkit.exec( ua ) ||
846 ua.indexOf("compatible") < 0 && rmozilla.exec( ua ) ||
849 return { browser: match[1] || "", version: match[2] || "0" };
853 function jQuerySub( selector, context ) {
854 return new jQuerySub.fn.init( selector, context );
856 jQuery.extend( true, jQuerySub, this );
857 jQuerySub.superclass = this;
858 jQuerySub.fn = jQuerySub.prototype = this();
859 jQuerySub.fn.constructor = jQuerySub;
860 jQuerySub.sub = this.sub;
861 jQuerySub.fn.init = function init( selector, context ) {
862 if ( context && context instanceof jQuery && !(context instanceof jQuerySub) ) {
863 context = jQuerySub( context );
866 return jQuery.fn.init.call( this, selector, context, rootjQuerySub );
868 jQuerySub.fn.init.prototype = jQuerySub.fn;
869 var rootjQuerySub = jQuerySub(document);
876 // Populate the class2type map
877 jQuery.each("Boolean Number String Function Array Date RegExp Object".split(" "), function(i, name) {
878 class2type[ "[object " + name + "]" ] = name.toLowerCase();
881 browserMatch = jQuery.uaMatch( userAgent );
882 if ( browserMatch.browser ) {
883 jQuery.browser[ browserMatch.browser ] = true;
884 jQuery.browser.version = browserMatch.version;
887 // Deprecated, use jQuery.browser.webkit instead
888 if ( jQuery.browser.webkit ) {
889 jQuery.browser.safari = true;
892 // IE doesn't match non-breaking spaces with \s
893 if ( rnotwhite.test( "\xA0" ) ) {
894 trimLeft = /^[\s\xA0]+/;
895 trimRight = /[\s\xA0]+$/;
898 // All jQuery objects should point back to these
899 rootjQuery = jQuery(document);
901 // Cleanup functions for the document ready method
902 if ( document.addEventListener ) {
903 DOMContentLoaded = function() {
904 document.removeEventListener( "DOMContentLoaded", DOMContentLoaded, false );
908 } else if ( document.attachEvent ) {
909 DOMContentLoaded = function() {
910 // Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443).
911 if ( document.readyState === "complete" ) {
912 document.detachEvent( "onreadystatechange", DOMContentLoaded );
918 // The DOM ready check for Internet Explorer
919 function doScrollCheck() {
920 if ( jQuery.isReady ) {
925 // If IE is used, use the trick by Diego Perini
926 // http://javascript.nwbox.com/IEContentLoaded/
927 document.documentElement.doScroll("left");
929 setTimeout( doScrollCheck, 1 );
933 // and execute any waiting functions