2 * jQuery JavaScript Library v1.6.4
5 * Copyright 2011, John Resig
6 * Dual licensed under the MIT or GPL Version 2 licenses.
7 * http://jquery.org/license
10 * http://sizzlejs.com/
11 * Copyright 2011, The Dojo Foundation
12 * Released under the MIT, BSD, and GPL Licenses.
14 * Date: Mon Sep 12 18:54:48 2011 -0400
16 (function( window, undefined ) {
18 // Use the correct document accordingly with window argument (sandbox)
19 var document = window.document,
20 navigator = window.navigator,
21 location = window.location;
22 var jQuery = (function() {
24 // Define a local copy of jQuery
25 var jQuery = function( selector, context ) {
26 // The jQuery object is actually just the init constructor 'enhanced'
27 return new jQuery.fn.init( selector, context, rootjQuery );
30 // Map over jQuery in case of overwrite
31 _jQuery = window.jQuery,
33 // Map over the $ in case of overwrite
36 // A central reference to the root jQuery(document)
39 // A simple way to check for HTML strings or ID strings
40 // Prioritize #id over <tag> to avoid XSS via location.hash (#9521)
41 quickExpr = /^(?:[^#<]*(<[\w\W]+>)[^>]*$|#([\w\-]*)$)/,
43 // Check if a string has a non-whitespace character in it
46 // Used for trimming whitespace
53 // Match a standalone tag
54 rsingleTag = /^<(\w+)\s*\/?>(?:<\/\1>)?$/,
57 rvalidchars = /^[\],:{}\s]*$/,
58 rvalidescape = /\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,
59 rvalidtokens = /"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,
60 rvalidbraces = /(?:^|:|,)(?:\s*\[)+/g,
63 rwebkit = /(webkit)[ \/]([\w.]+)/,
64 ropera = /(opera)(?:.*version)?[ \/]([\w.]+)/,
65 rmsie = /(msie) ([\w.]+)/,
66 rmozilla = /(mozilla)(?:.*? rv:([\w.]+))?/,
68 // Matches dashed string for camelizing
69 rdashAlpha = /-([a-z]|[0-9])/ig,
72 // Used by jQuery.camelCase as callback to replace()
73 fcamelCase = function( all, letter ) {
74 return ( letter + "" ).toUpperCase();
77 // Keep a UserAgent string for use with jQuery.browser
78 userAgent = navigator.userAgent,
80 // For matching the engine and version of the browser
83 // The deferred used on DOM ready
86 // The ready event handler
89 // Save a reference to some core methods
90 toString = Object.prototype.toString,
91 hasOwn = Object.prototype.hasOwnProperty,
92 push = Array.prototype.push,
93 slice = Array.prototype.slice,
94 trim = String.prototype.trim,
95 indexOf = Array.prototype.indexOf,
97 // [[Class]] -> type pairs
100 jQuery.fn = jQuery.prototype = {
102 init: function( selector, context, rootjQuery ) {
103 var match, elem, ret, doc;
105 // Handle $(""), $(null), or $(undefined)
110 // Handle $(DOMElement)
111 if ( selector.nodeType ) {
112 this.context = this[0] = selector;
117 // The body element only exists once, optimize finding it
118 if ( selector === "body" && !context && document.body ) {
119 this.context = document;
120 this[0] = document.body;
121 this.selector = selector;
126 // Handle HTML strings
127 if ( typeof selector === "string" ) {
128 // Are we dealing with HTML string or an ID?
129 if ( selector.charAt(0) === "<" && selector.charAt( selector.length - 1 ) === ">" && selector.length >= 3 ) {
130 // Assume that strings that start and end with <> are HTML and skip the regex check
131 match = [ null, selector, null ];
134 match = quickExpr.exec( selector );
137 // Verify a match, and that no context was specified for #id
138 if ( match && (match[1] || !context) ) {
140 // HANDLE: $(html) -> $(array)
142 context = context instanceof jQuery ? context[0] : context;
143 doc = (context ? context.ownerDocument || context : document);
145 // If a single string is passed in and it's a single tag
146 // just do a createElement and skip the rest
147 ret = rsingleTag.exec( selector );
150 if ( jQuery.isPlainObject( context ) ) {
151 selector = [ document.createElement( ret[1] ) ];
152 jQuery.fn.attr.call( selector, context, true );
155 selector = [ doc.createElement( ret[1] ) ];
159 ret = jQuery.buildFragment( [ match[1] ], [ doc ] );
160 selector = (ret.cacheable ? jQuery.clone(ret.fragment) : ret.fragment).childNodes;
163 return jQuery.merge( this, selector );
167 elem = document.getElementById( match[2] );
169 // Check parentNode to catch when Blackberry 4.6 returns
170 // nodes that are no longer in the document #6963
171 if ( elem && elem.parentNode ) {
172 // Handle the case where IE and Opera return items
173 // by name instead of ID
174 if ( elem.id !== match[2] ) {
175 return rootjQuery.find( selector );
178 // Otherwise, we inject the element directly into the jQuery object
183 this.context = document;
184 this.selector = selector;
188 // HANDLE: $(expr, $(...))
189 } else if ( !context || context.jquery ) {
190 return (context || rootjQuery).find( selector );
192 // HANDLE: $(expr, context)
193 // (which is just equivalent to: $(context).find(expr)
195 return this.constructor( context ).find( selector );
198 // HANDLE: $(function)
199 // Shortcut for document ready
200 } else if ( jQuery.isFunction( selector ) ) {
201 return rootjQuery.ready( selector );
204 if (selector.selector !== undefined) {
205 this.selector = selector.selector;
206 this.context = selector.context;
209 return jQuery.makeArray( selector, this );
212 // Start with an empty selector
215 // The current version of jQuery being used
218 // The default length of a jQuery object is 0
221 // The number of elements contained in the matched element set
226 toArray: function() {
227 return slice.call( this, 0 );
230 // Get the Nth element in the matched element set OR
231 // Get the whole matched element set as a clean array
232 get: function( num ) {
235 // Return a 'clean' array
238 // Return just the object
239 ( num < 0 ? this[ this.length + num ] : this[ num ] );
242 // Take an array of elements and push it onto the stack
243 // (returning the new matched element set)
244 pushStack: function( elems, name, selector ) {
245 // Build a new jQuery matched element set
246 var ret = this.constructor();
248 if ( jQuery.isArray( elems ) ) {
249 push.apply( ret, elems );
252 jQuery.merge( ret, elems );
255 // Add the old object onto the stack (as a reference)
256 ret.prevObject = this;
258 ret.context = this.context;
260 if ( name === "find" ) {
261 ret.selector = this.selector + (this.selector ? " " : "") + selector;
263 ret.selector = this.selector + "." + name + "(" + selector + ")";
266 // Return the newly-formed element set
270 // Execute a callback for every element in the matched set.
271 // (You can seed the arguments with an array of args, but this is
272 // only used internally.)
273 each: function( callback, args ) {
274 return jQuery.each( this, callback, args );
277 ready: function( fn ) {
278 // Attach the listeners
282 readyList.done( fn );
290 this.slice( i, +i + 1 );
298 return this.eq( -1 );
302 return this.pushStack( slice.apply( this, arguments ),
303 "slice", slice.call(arguments).join(",") );
306 map: function( callback ) {
307 return this.pushStack( jQuery.map(this, function( elem, i ) {
308 return callback.call( elem, i, elem );
313 return this.prevObject || this.constructor(null);
316 // For internal use only.
317 // Behaves like an Array's method, not like a jQuery method.
323 // Give the init function the jQuery prototype for later instantiation
324 jQuery.fn.init.prototype = jQuery.fn;
326 jQuery.extend = jQuery.fn.extend = function() {
327 var options, name, src, copy, copyIsArray, clone,
328 target = arguments[0] || {},
330 length = arguments.length,
333 // Handle a deep copy situation
334 if ( typeof target === "boolean" ) {
336 target = arguments[1] || {};
337 // skip the boolean and the target
341 // Handle case when target is a string or something (possible in deep copy)
342 if ( typeof target !== "object" && !jQuery.isFunction(target) ) {
346 // extend jQuery itself if only one argument is passed
347 if ( length === i ) {
352 for ( ; i < length; i++ ) {
353 // Only deal with non-null/undefined values
354 if ( (options = arguments[ i ]) != null ) {
355 // Extend the base object
356 for ( name in options ) {
357 src = target[ name ];
358 copy = options[ name ];
360 // Prevent never-ending loop
361 if ( target === copy ) {
365 // Recurse if we're merging plain objects or arrays
366 if ( deep && copy && ( jQuery.isPlainObject(copy) || (copyIsArray = jQuery.isArray(copy)) ) ) {
369 clone = src && jQuery.isArray(src) ? src : [];
372 clone = src && jQuery.isPlainObject(src) ? src : {};
375 // Never move original objects, clone them
376 target[ name ] = jQuery.extend( deep, clone, copy );
378 // Don't bring in undefined values
379 } else if ( copy !== undefined ) {
380 target[ name ] = copy;
386 // Return the modified object
391 noConflict: function( deep ) {
392 if ( window.$ === jQuery ) {
396 if ( deep && window.jQuery === jQuery ) {
397 window.jQuery = _jQuery;
403 // Is the DOM ready to be used? Set to true once it occurs.
406 // A counter to track how many items to wait for before
407 // the ready event fires. See #6781
410 // Hold (or release) the ready event
411 holdReady: function( hold ) {
415 jQuery.ready( true );
419 // Handle when the DOM is ready
420 ready: function( wait ) {
421 // Either a released hold or an DOMready/load event and not yet ready
422 if ( (wait === true && !--jQuery.readyWait) || (wait !== true && !jQuery.isReady) ) {
423 // Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443).
424 if ( !document.body ) {
425 return setTimeout( jQuery.ready, 1 );
428 // Remember that the DOM is ready
429 jQuery.isReady = true;
431 // If a normal DOM Ready event fired, decrement, and wait if need be
432 if ( wait !== true && --jQuery.readyWait > 0 ) {
436 // If there are functions bound, to execute
437 readyList.resolveWith( document, [ jQuery ] );
439 // Trigger any bound ready events
440 if ( jQuery.fn.trigger ) {
441 jQuery( document ).trigger( "ready" ).unbind( "ready" );
446 bindReady: function() {
451 readyList = jQuery._Deferred();
453 // Catch cases where $(document).ready() is called after the
454 // browser event has already occurred.
455 if ( document.readyState === "complete" ) {
456 // Handle it asynchronously to allow scripts the opportunity to delay ready
457 return setTimeout( jQuery.ready, 1 );
460 // Mozilla, Opera and webkit nightlies currently support this event
461 if ( document.addEventListener ) {
462 // Use the handy event callback
463 document.addEventListener( "DOMContentLoaded", DOMContentLoaded, false );
465 // A fallback to window.onload, that will always work
466 window.addEventListener( "load", jQuery.ready, false );
468 // If IE event model is used
469 } else if ( document.attachEvent ) {
470 // ensure firing before onload,
471 // maybe late but safe also for iframes
472 document.attachEvent( "onreadystatechange", DOMContentLoaded );
474 // A fallback to window.onload, that will always work
475 window.attachEvent( "onload", jQuery.ready );
477 // If IE and not a frame
478 // continually check to see if the document is ready
479 var toplevel = false;
482 toplevel = window.frameElement == null;
485 if ( document.documentElement.doScroll && toplevel ) {
491 // See test/unit/core.js for details concerning isFunction.
492 // Since version 1.3, DOM methods and functions like alert
493 // aren't supported. They return false on IE (#2968).
494 isFunction: function( obj ) {
495 return jQuery.type(obj) === "function";
498 isArray: Array.isArray || function( obj ) {
499 return jQuery.type(obj) === "array";
502 // A crude way of determining if an object is a window
503 isWindow: function( obj ) {
504 return obj && typeof obj === "object" && "setInterval" in obj;
507 isNaN: function( obj ) {
508 return obj == null || !rdigit.test( obj ) || isNaN( obj );
511 type: function( obj ) {
514 class2type[ toString.call(obj) ] || "object";
517 isPlainObject: function( obj ) {
518 // Must be an Object.
519 // Because of IE, we also have to check the presence of the constructor property.
520 // Make sure that DOM nodes and window objects don't pass through, as well
521 if ( !obj || jQuery.type(obj) !== "object" || obj.nodeType || jQuery.isWindow( obj ) ) {
526 // Not own constructor property must be Object
527 if ( obj.constructor &&
528 !hasOwn.call(obj, "constructor") &&
529 !hasOwn.call(obj.constructor.prototype, "isPrototypeOf") ) {
533 // IE8,9 Will throw exceptions on certain host objects #9897
537 // Own properties are enumerated firstly, so to speed up,
538 // if last one is own, then all properties are own.
541 for ( key in obj ) {}
543 return key === undefined || hasOwn.call( obj, key );
546 isEmptyObject: function( obj ) {
547 for ( var name in obj ) {
553 error: function( msg ) {
557 parseJSON: function( data ) {
558 if ( typeof data !== "string" || !data ) {
562 // Make sure leading/trailing whitespace is removed (IE can't handle it)
563 data = jQuery.trim( data );
565 // Attempt to parse using the native JSON parser first
566 if ( window.JSON && window.JSON.parse ) {
567 return window.JSON.parse( data );
570 // Make sure the incoming data is actual JSON
571 // Logic borrowed from http://json.org/json2.js
572 if ( rvalidchars.test( data.replace( rvalidescape, "@" )
573 .replace( rvalidtokens, "]" )
574 .replace( rvalidbraces, "")) ) {
576 return (new Function( "return " + data ))();
579 jQuery.error( "Invalid JSON: " + data );
582 // Cross-browser xml parsing
583 parseXML: function( data ) {
586 if ( window.DOMParser ) { // Standard
587 tmp = new DOMParser();
588 xml = tmp.parseFromString( data , "text/xml" );
590 xml = new ActiveXObject( "Microsoft.XMLDOM" );
597 if ( !xml || !xml.documentElement || xml.getElementsByTagName( "parsererror" ).length ) {
598 jQuery.error( "Invalid XML: " + data );
605 // Evaluates a script in a global context
606 // Workarounds based on findings by Jim Driscoll
607 // http://weblogs.java.net/blog/driscoll/archive/2009/09/08/eval-javascript-global-context
608 globalEval: function( data ) {
609 if ( data && rnotwhite.test( data ) ) {
610 // We use execScript on Internet Explorer
611 // We use an anonymous function so that context is window
612 // rather than jQuery in Firefox
613 ( window.execScript || function( data ) {
614 window[ "eval" ].call( window, data );
619 // Convert dashed to camelCase; used by the css and data modules
620 // Microsoft forgot to hump their vendor prefix (#9572)
621 camelCase: function( string ) {
622 return string.replace( rmsPrefix, "ms-" ).replace( rdashAlpha, fcamelCase );
625 nodeName: function( elem, name ) {
626 return elem.nodeName && elem.nodeName.toUpperCase() === name.toUpperCase();
629 // args is for internal usage only
630 each: function( object, callback, args ) {
632 length = object.length,
633 isObj = length === undefined || jQuery.isFunction( object );
637 for ( name in object ) {
638 if ( callback.apply( object[ name ], args ) === false ) {
643 for ( ; i < length; ) {
644 if ( callback.apply( object[ i++ ], args ) === false ) {
650 // A special, fast, case for the most common use of each
653 for ( name in object ) {
654 if ( callback.call( object[ name ], name, object[ name ] ) === false ) {
659 for ( ; i < length; ) {
660 if ( callback.call( object[ i ], i, object[ i++ ] ) === false ) {
670 // Use native String.trim function wherever possible
673 return text == null ?
678 // Otherwise use our own trimming functionality
680 return text == null ?
682 text.toString().replace( trimLeft, "" ).replace( trimRight, "" );
685 // results is for internal usage only
686 makeArray: function( array, results ) {
687 var ret = results || [];
689 if ( array != null ) {
690 // The window, strings (and functions) also have 'length'
691 // The extra typeof function check is to prevent crashes
692 // in Safari 2 (See: #3039)
693 // Tweaked logic slightly to handle Blackberry 4.7 RegExp issues #6930
694 var type = jQuery.type( array );
696 if ( array.length == null || type === "string" || type === "function" || type === "regexp" || jQuery.isWindow( array ) ) {
697 push.call( ret, array );
699 jQuery.merge( ret, array );
706 inArray: function( elem, array ) {
712 return indexOf.call( array, elem );
715 for ( var i = 0, length = array.length; i < length; i++ ) {
716 if ( array[ i ] === elem ) {
724 merge: function( first, second ) {
725 var i = first.length,
728 if ( typeof second.length === "number" ) {
729 for ( var l = second.length; j < l; j++ ) {
730 first[ i++ ] = second[ j ];
734 while ( second[j] !== undefined ) {
735 first[ i++ ] = second[ j++ ];
744 grep: function( elems, callback, inv ) {
745 var ret = [], retVal;
748 // Go through the array, only saving the items
749 // that pass the validator function
750 for ( var i = 0, length = elems.length; i < length; i++ ) {
751 retVal = !!callback( elems[ i ], i );
752 if ( inv !== retVal ) {
753 ret.push( elems[ i ] );
760 // arg is for internal usage only
761 map: function( elems, callback, arg ) {
762 var value, key, ret = [],
764 length = elems.length,
765 // jquery objects are treated as arrays
766 isArray = elems instanceof jQuery || length !== undefined && typeof length === "number" && ( ( length > 0 && elems[ 0 ] && elems[ length -1 ] ) || length === 0 || jQuery.isArray( elems ) ) ;
768 // Go through the array, translating each of the items to their
770 for ( ; i < length; i++ ) {
771 value = callback( elems[ i ], i, arg );
773 if ( value != null ) {
774 ret[ ret.length ] = value;
778 // Go through every key on the object,
780 for ( key in elems ) {
781 value = callback( elems[ key ], key, arg );
783 if ( value != null ) {
784 ret[ ret.length ] = value;
789 // Flatten any nested arrays
790 return ret.concat.apply( [], ret );
793 // A global GUID counter for objects
796 // Bind a function to a context, optionally partially applying any
798 proxy: function( fn, context ) {
799 if ( typeof context === "string" ) {
800 var tmp = fn[ context ];
805 // Quick check to determine if target is callable, in the spec
806 // this throws a TypeError, but we will just return undefined.
807 if ( !jQuery.isFunction( fn ) ) {
812 var args = slice.call( arguments, 2 ),
814 return fn.apply( context, args.concat( slice.call( arguments ) ) );
817 // Set the guid of unique handler to the same of original handler, so it can be removed
818 proxy.guid = fn.guid = fn.guid || proxy.guid || jQuery.guid++;
823 // Mutifunctional method to get and set values to a collection
824 // The value/s can optionally be executed if it's a function
825 access: function( elems, key, value, exec, fn, pass ) {
826 var length = elems.length;
828 // Setting many attributes
829 if ( typeof key === "object" ) {
830 for ( var k in key ) {
831 jQuery.access( elems, k, key[k], exec, fn, value );
836 // Setting one attribute
837 if ( value !== undefined ) {
838 // Optionally, function values get executed if exec is true
839 exec = !pass && exec && jQuery.isFunction(value);
841 for ( var i = 0; i < length; i++ ) {
842 fn( elems[i], key, exec ? value.call( elems[i], i, fn( elems[i], key ) ) : value, pass );
848 // Getting an attribute
849 return length ? fn( elems[0], key ) : undefined;
853 return (new Date()).getTime();
856 // Use of jQuery.browser is frowned upon.
857 // More details: http://docs.jquery.com/Utilities/jQuery.browser
858 uaMatch: function( ua ) {
859 ua = ua.toLowerCase();
861 var match = rwebkit.exec( ua ) ||
864 ua.indexOf("compatible") < 0 && rmozilla.exec( ua ) ||
867 return { browser: match[1] || "", version: match[2] || "0" };
871 function jQuerySub( selector, context ) {
872 return new jQuerySub.fn.init( selector, context );
874 jQuery.extend( true, jQuerySub, this );
875 jQuerySub.superclass = this;
876 jQuerySub.fn = jQuerySub.prototype = this();
877 jQuerySub.fn.constructor = jQuerySub;
878 jQuerySub.sub = this.sub;
879 jQuerySub.fn.init = function init( selector, context ) {
880 if ( context && context instanceof jQuery && !(context instanceof jQuerySub) ) {
881 context = jQuerySub( context );
884 return jQuery.fn.init.call( this, selector, context, rootjQuerySub );
886 jQuerySub.fn.init.prototype = jQuerySub.fn;
887 var rootjQuerySub = jQuerySub(document);
894 // Populate the class2type map
895 jQuery.each("Boolean Number String Function Array Date RegExp Object".split(" "), function(i, name) {
896 class2type[ "[object " + name + "]" ] = name.toLowerCase();
899 browserMatch = jQuery.uaMatch( userAgent );
900 if ( browserMatch.browser ) {
901 jQuery.browser[ browserMatch.browser ] = true;
902 jQuery.browser.version = browserMatch.version;
905 // Deprecated, use jQuery.browser.webkit instead
906 if ( jQuery.browser.webkit ) {
907 jQuery.browser.safari = true;
910 // IE doesn't match non-breaking spaces with \s
911 if ( rnotwhite.test( "\xA0" ) ) {
912 trimLeft = /^[\s\xA0]+/;
913 trimRight = /[\s\xA0]+$/;
916 // All jQuery objects should point back to these
917 rootjQuery = jQuery(document);
919 // Cleanup functions for the document ready method
920 if ( document.addEventListener ) {
921 DOMContentLoaded = function() {
922 document.removeEventListener( "DOMContentLoaded", DOMContentLoaded, false );
926 } else if ( document.attachEvent ) {
927 DOMContentLoaded = function() {
928 // Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443).
929 if ( document.readyState === "complete" ) {
930 document.detachEvent( "onreadystatechange", DOMContentLoaded );
936 // The DOM ready check for Internet Explorer
937 function doScrollCheck() {
938 if ( jQuery.isReady ) {
943 // If IE is used, use the trick by Diego Perini
944 // http://javascript.nwbox.com/IEContentLoaded/
945 document.documentElement.doScroll("left");
947 setTimeout( doScrollCheck, 1 );
951 // and execute any waiting functions
960 var // Promise methods
961 promiseMethods = "done fail isResolved isRejected promise then always pipe".split( " " ),
962 // Static reference to slice
963 sliceDeferred = [].slice;
966 // Create a simple deferred (one callbacks list)
967 _Deferred: function() {
968 var // callbacks list
970 // stored [ context , args ]
972 // to avoid firing when already doing so
974 // flag to know if the deferred has been cancelled
976 // the deferred itself
979 // done( f1, f2, ...)
982 var args = arguments,
992 for ( i = 0, length = args.length; i < length; i++ ) {
994 type = jQuery.type( elem );
995 if ( type === "array" ) {
996 deferred.done.apply( deferred, elem );
997 } else if ( type === "function" ) {
998 callbacks.push( elem );
1002 deferred.resolveWith( _fired[ 0 ], _fired[ 1 ] );
1008 // resolve with given context and args
1009 resolveWith: function( context, args ) {
1010 if ( !cancelled && !fired && !firing ) {
1011 // make sure args are available (#8421)
1015 while( callbacks[ 0 ] ) {
1016 callbacks.shift().apply( context, args );
1020 fired = [ context, args ];
1027 // resolve with this as context and given arguments
1028 resolve: function() {
1029 deferred.resolveWith( this, arguments );
1033 // Has this deferred been resolved?
1034 isResolved: function() {
1035 return !!( firing || fired );
1039 cancel: function() {
1049 // Full fledged deferred (two callbacks list)
1050 Deferred: function( func ) {
1051 var deferred = jQuery._Deferred(),
1052 failDeferred = jQuery._Deferred(),
1054 // Add errorDeferred methods, then and promise
1055 jQuery.extend( deferred, {
1056 then: function( doneCallbacks, failCallbacks ) {
1057 deferred.done( doneCallbacks ).fail( failCallbacks );
1060 always: function() {
1061 return deferred.done.apply( deferred, arguments ).fail.apply( this, arguments );
1063 fail: failDeferred.done,
1064 rejectWith: failDeferred.resolveWith,
1065 reject: failDeferred.resolve,
1066 isRejected: failDeferred.isResolved,
1067 pipe: function( fnDone, fnFail ) {
1068 return jQuery.Deferred(function( newDefer ) {
1070 done: [ fnDone, "resolve" ],
1071 fail: [ fnFail, "reject" ]
1072 }, function( handler, data ) {
1076 if ( jQuery.isFunction( fn ) ) {
1077 deferred[ handler ](function() {
1078 returned = fn.apply( this, arguments );
1079 if ( returned && jQuery.isFunction( returned.promise ) ) {
1080 returned.promise().then( newDefer.resolve, newDefer.reject );
1082 newDefer[ action + "With" ]( this === deferred ? newDefer : this, [ returned ] );
1086 deferred[ handler ]( newDefer[ action ] );
1091 // Get a promise for this deferred
1092 // If obj is provided, the promise aspect is added to the object
1093 promise: function( obj ) {
1094 if ( obj == null ) {
1100 var i = promiseMethods.length;
1102 obj[ promiseMethods[i] ] = deferred[ promiseMethods[i] ];
1107 // Make sure only one callback list will be used
1108 deferred.done( failDeferred.cancel ).fail( deferred.cancel );
1110 delete deferred.cancel;
1111 // Call given func if any
1113 func.call( deferred, deferred );
1119 when: function( firstParam ) {
1120 var args = arguments,
1122 length = args.length,
1124 deferred = length <= 1 && firstParam && jQuery.isFunction( firstParam.promise ) ?
1127 function resolveFunc( i ) {
1128 return function( value ) {
1129 args[ i ] = arguments.length > 1 ? sliceDeferred.call( arguments, 0 ) : value;
1130 if ( !( --count ) ) {
1131 // Strange bug in FF4:
1132 // Values changed onto the arguments object sometimes end up as undefined values
1133 // outside the $.when method. Cloning the object into a fresh array solves the issue
1134 deferred.resolveWith( deferred, sliceDeferred.call( args, 0 ) );
1139 for( ; i < length; i++ ) {
1140 if ( args[ i ] && jQuery.isFunction( args[ i ].promise ) ) {
1141 args[ i ].promise().then( resolveFunc(i), deferred.reject );
1147 deferred.resolveWith( deferred, args );
1149 } else if ( deferred !== firstParam ) {
1150 deferred.resolveWith( deferred, length ? [ firstParam ] : [] );
1152 return deferred.promise();
1158 jQuery.support = (function() {
1160 var div = document.createElement( "div" ),
1161 documentElement = document.documentElement,
1180 // Preliminary tests
1181 div.setAttribute("className", "t");
1182 div.innerHTML = " <link/><table></table><a href='/a' style='top:1px;float:left;opacity:.55;'>a</a><input type='checkbox'/>";
1185 all = div.getElementsByTagName( "*" );
1186 a = div.getElementsByTagName( "a" )[ 0 ];
1188 // Can't get basic test support
1189 if ( !all || !all.length || !a ) {
1193 // First batch of supports tests
1194 select = document.createElement( "select" );
1195 opt = select.appendChild( document.createElement("option") );
1196 input = div.getElementsByTagName( "input" )[ 0 ];
1199 // IE strips leading whitespace when .innerHTML is used
1200 leadingWhitespace: ( div.firstChild.nodeType === 3 ),
1202 // Make sure that tbody elements aren't automatically inserted
1203 // IE will insert them into empty tables
1204 tbody: !div.getElementsByTagName( "tbody" ).length,
1206 // Make sure that link elements get serialized correctly by innerHTML
1207 // This requires a wrapper element in IE
1208 htmlSerialize: !!div.getElementsByTagName( "link" ).length,
1210 // Get the style information from getAttribute
1211 // (IE uses .cssText instead)
1212 style: /top/.test( a.getAttribute("style") ),
1214 // Make sure that URLs aren't manipulated
1215 // (IE normalizes it by default)
1216 hrefNormalized: ( a.getAttribute( "href" ) === "/a" ),
1218 // Make sure that element opacity exists
1219 // (IE uses filter instead)
1220 // Use a regex to work around a WebKit issue. See #5145
1221 opacity: /^0.55$/.test( a.style.opacity ),
1223 // Verify style float existence
1224 // (IE uses styleFloat instead of cssFloat)
1225 cssFloat: !!a.style.cssFloat,
1227 // Make sure that if no value is specified for a checkbox
1228 // that it defaults to "on".
1229 // (WebKit defaults to "" instead)
1230 checkOn: ( input.value === "on" ),
1232 // Make sure that a selected-by-default option has a working selected property.
1233 // (WebKit defaults to false instead of true, IE too, if it's in an optgroup)
1234 optSelected: opt.selected,
1236 // Test setAttribute on camelCase class. If it works, we need attrFixes when doing get/setAttribute (ie6/7)
1237 getSetAttribute: div.className !== "t",
1239 // Will be defined later
1240 submitBubbles: true,
1241 changeBubbles: true,
1242 focusinBubbles: false,
1243 deleteExpando: true,
1245 inlineBlockNeedsLayout: false,
1246 shrinkWrapBlocks: false,
1247 reliableMarginRight: true
1250 // Make sure checked status is properly cloned
1251 input.checked = true;
1252 support.noCloneChecked = input.cloneNode( true ).checked;
1254 // Make sure that the options inside disabled selects aren't marked as disabled
1255 // (WebKit marks them as disabled)
1256 select.disabled = true;
1257 support.optDisabled = !opt.disabled;
1259 // Test to see if it's possible to delete an expando from an element
1260 // Fails in Internet Explorer
1264 support.deleteExpando = false;
1267 if ( !div.addEventListener && div.attachEvent && div.fireEvent ) {
1268 div.attachEvent( "onclick", function() {
1269 // Cloning a node shouldn't copy over any
1270 // bound event handlers (IE does this)
1271 support.noCloneEvent = false;
1273 div.cloneNode( true ).fireEvent( "onclick" );
1276 // Check if a radio maintains it's value
1277 // after being appended to the DOM
1278 input = document.createElement("input");
1280 input.setAttribute("type", "radio");
1281 support.radioValue = input.value === "t";
1283 input.setAttribute("checked", "checked");
1284 div.appendChild( input );
1285 fragment = document.createDocumentFragment();
1286 fragment.appendChild( div.firstChild );
1288 // WebKit doesn't clone checked state correctly in fragments
1289 support.checkClone = fragment.cloneNode( true ).cloneNode( true ).lastChild.checked;
1293 // Figure out if the W3C box model works as expected
1294 div.style.width = div.style.paddingLeft = "1px";
1296 body = document.getElementsByTagName( "body" )[ 0 ];
1297 // We use our own, invisible, body unless the body is already present
1298 // in which case we use a div (#9239)
1299 testElement = document.createElement( body ? "div" : "body" );
1300 testElementStyle = {
1301 visibility: "hidden",
1309 jQuery.extend( testElementStyle, {
1310 position: "absolute",
1315 for ( i in testElementStyle ) {
1316 testElement.style[ i ] = testElementStyle[ i ];
1318 testElement.appendChild( div );
1319 testElementParent = body || documentElement;
1320 testElementParent.insertBefore( testElement, testElementParent.firstChild );
1322 // Check if a disconnected checkbox will retain its checked
1323 // value of true after appended to the DOM (IE6/7)
1324 support.appendChecked = input.checked;
1326 support.boxModel = div.offsetWidth === 2;
1328 if ( "zoom" in div.style ) {
1329 // Check if natively block-level elements act like inline-block
1330 // elements when setting their display to 'inline' and giving
1332 // (IE < 8 does this)
1333 div.style.display = "inline";
1335 support.inlineBlockNeedsLayout = ( div.offsetWidth === 2 );
1337 // Check if elements with layout shrink-wrap their children
1339 div.style.display = "";
1340 div.innerHTML = "<div style='width:4px;'></div>";
1341 support.shrinkWrapBlocks = ( div.offsetWidth !== 2 );
1344 div.innerHTML = "<table><tr><td style='padding:0;border:0;display:none'></td><td>t</td></tr></table>";
1345 tds = div.getElementsByTagName( "td" );
1347 // Check if table cells still have offsetWidth/Height when they are set
1348 // to display:none and there are still other visible table cells in a
1349 // table row; if so, offsetWidth/Height are not reliable for use when
1350 // determining if an element has been hidden directly using
1351 // display:none (it is still safe to use offsets if a parent element is
1352 // hidden; don safety goggles and see bug #4512 for more information).
1353 // (only IE 8 fails this test)
1354 isSupported = ( tds[ 0 ].offsetHeight === 0 );
1356 tds[ 0 ].style.display = "";
1357 tds[ 1 ].style.display = "none";
1359 // Check if empty table cells still have offsetWidth/Height
1360 // (IE < 8 fail this test)
1361 support.reliableHiddenOffsets = isSupported && ( tds[ 0 ].offsetHeight === 0 );
1364 // Check if div with explicit width and no margin-right incorrectly
1365 // gets computed margin-right based on width of container. For more
1366 // info see bug #3333
1367 // Fails in WebKit before Feb 2011 nightlies
1368 // WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right
1369 if ( document.defaultView && document.defaultView.getComputedStyle ) {
1370 marginDiv = document.createElement( "div" );
1371 marginDiv.style.width = "0";
1372 marginDiv.style.marginRight = "0";
1373 div.appendChild( marginDiv );
1374 support.reliableMarginRight =
1375 ( parseInt( ( document.defaultView.getComputedStyle( marginDiv, null ) || { marginRight: 0 } ).marginRight, 10 ) || 0 ) === 0;
1378 // Remove the body element we added
1379 testElement.innerHTML = "";
1380 testElementParent.removeChild( testElement );
1382 // Technique from Juriy Zaytsev
1383 // http://thinkweb2.com/projects/prototype/detecting-event-support-without-browser-sniffing/
1384 // We only care about the case where non-standard event systems
1385 // are used, namely in IE. Short-circuiting here helps us to
1386 // avoid an eval call (in setAttribute) which can cause CSP
1387 // to go haywire. See: https://developer.mozilla.org/en/Security/CSP
1388 if ( div.attachEvent ) {
1394 eventName = "on" + i;
1395 isSupported = ( eventName in div );
1396 if ( !isSupported ) {
1397 div.setAttribute( eventName, "return;" );
1398 isSupported = ( typeof div[ eventName ] === "function" );
1400 support[ i + "Bubbles" ] = isSupported;
1404 // Null connected elements to avoid leaks in IE
1405 testElement = fragment = select = opt = body = marginDiv = div = input = null;
1410 // Keep track of boxModel
1411 jQuery.boxModel = jQuery.support.boxModel;
1416 var rbrace = /^(?:\{.*\}|\[.*\])$/,
1417 rmultiDash = /([A-Z])/g;
1422 // Please use with caution
1425 // Unique for each copy of jQuery on the page
1426 // Non-digits removed to match rinlinejQuery
1427 expando: "jQuery" + ( jQuery.fn.jquery + Math.random() ).replace( /\D/g, "" ),
1429 // The following elements throw uncatchable exceptions if you
1430 // attempt to add expando properties to them.
1433 // Ban all objects except for Flash (which handle expandos)
1434 "object": "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000",
1438 hasData: function( elem ) {
1439 elem = elem.nodeType ? jQuery.cache[ elem[jQuery.expando] ] : elem[ jQuery.expando ];
1441 return !!elem && !isEmptyDataObject( elem );
1444 data: function( elem, name, data, pvt /* Internal Use Only */ ) {
1445 if ( !jQuery.acceptData( elem ) ) {
1450 internalKey = jQuery.expando,
1451 getByName = typeof name === "string",
1453 // We have to handle DOM nodes and JS objects differently because IE6-7
1454 // can't GC object references properly across the DOM-JS boundary
1455 isNode = elem.nodeType,
1457 // Only DOM nodes need the global jQuery cache; JS object data is
1458 // attached directly to the object so GC can occur automatically
1459 cache = isNode ? jQuery.cache : elem,
1461 // Only defining an ID for JS objects if its cache already exists allows
1462 // the code to shortcut on the same path as a DOM node with no cache
1463 id = isNode ? elem[ jQuery.expando ] : elem[ jQuery.expando ] && jQuery.expando;
1465 // Avoid doing any more work than we need to when trying to get data on an
1466 // object that has no data at all
1467 if ( (!id || (pvt && id && (cache[ id ] && !cache[ id ][ internalKey ]))) && getByName && data === undefined ) {
1472 // Only DOM nodes need a new unique ID for each element since their data
1473 // ends up in the global cache
1475 elem[ jQuery.expando ] = id = ++jQuery.uuid;
1477 id = jQuery.expando;
1481 if ( !cache[ id ] ) {
1484 // TODO: This is a hack for 1.5 ONLY. Avoids exposing jQuery
1485 // metadata on plain JS objects when the object is serialized using
1488 cache[ id ].toJSON = jQuery.noop;
1492 // An object can be passed to jQuery.data instead of a key/value pair; this gets
1493 // shallow copied over onto the existing cache
1494 if ( typeof name === "object" || typeof name === "function" ) {
1496 cache[ id ][ internalKey ] = jQuery.extend(cache[ id ][ internalKey ], name);
1498 cache[ id ] = jQuery.extend(cache[ id ], name);
1502 thisCache = cache[ id ];
1504 // Internal jQuery data is stored in a separate object inside the object's data
1505 // cache in order to avoid key collisions between internal data and user-defined
1508 if ( !thisCache[ internalKey ] ) {
1509 thisCache[ internalKey ] = {};
1512 thisCache = thisCache[ internalKey ];
1515 if ( data !== undefined ) {
1516 thisCache[ jQuery.camelCase( name ) ] = data;
1519 // TODO: This is a hack for 1.5 ONLY. It will be removed in 1.6. Users should
1520 // not attempt to inspect the internal events object using jQuery.data, as this
1521 // internal data object is undocumented and subject to change.
1522 if ( name === "events" && !thisCache[name] ) {
1523 return thisCache[ internalKey ] && thisCache[ internalKey ].events;
1526 // Check for both converted-to-camel and non-converted data property names
1527 // If a data property was specified
1530 // First Try to find as-is property data
1531 ret = thisCache[ name ];
1533 // Test for null|undefined property data
1534 if ( ret == null ) {
1536 // Try to find the camelCased property
1537 ret = thisCache[ jQuery.camelCase( name ) ];
1546 removeData: function( elem, name, pvt /* Internal Use Only */ ) {
1547 if ( !jQuery.acceptData( elem ) ) {
1553 // Reference to internal data cache key
1554 internalKey = jQuery.expando,
1556 isNode = elem.nodeType,
1558 // See jQuery.data for more information
1559 cache = isNode ? jQuery.cache : elem,
1561 // See jQuery.data for more information
1562 id = isNode ? elem[ jQuery.expando ] : jQuery.expando;
1564 // If there is already no cache entry for this object, there is no
1565 // purpose in continuing
1566 if ( !cache[ id ] ) {
1572 thisCache = pvt ? cache[ id ][ internalKey ] : cache[ id ];
1576 // Support interoperable removal of hyphenated or camelcased keys
1577 if ( !thisCache[ name ] ) {
1578 name = jQuery.camelCase( name );
1581 delete thisCache[ name ];
1583 // If there is no data left in the cache, we want to continue
1584 // and let the cache object itself get destroyed
1585 if ( !isEmptyDataObject(thisCache) ) {
1591 // See jQuery.data for more information
1593 delete cache[ id ][ internalKey ];
1595 // Don't destroy the parent cache unless the internal data object
1596 // had been the only thing left in it
1597 if ( !isEmptyDataObject(cache[ id ]) ) {
1602 var internalCache = cache[ id ][ internalKey ];
1604 // Browsers that fail expando deletion also refuse to delete expandos on
1605 // the window, but it will allow it on all other JS objects; other browsers
1607 // Ensure that `cache` is not a window object #10080
1608 if ( jQuery.support.deleteExpando || !cache.setInterval ) {
1614 // We destroyed the entire user cache at once because it's faster than
1615 // iterating through each key, but we need to continue to persist internal
1616 // data if it existed
1617 if ( internalCache ) {
1619 // TODO: This is a hack for 1.5 ONLY. Avoids exposing jQuery
1620 // metadata on plain JS objects when the object is serialized using
1623 cache[ id ].toJSON = jQuery.noop;
1626 cache[ id ][ internalKey ] = internalCache;
1628 // Otherwise, we need to eliminate the expando on the node to avoid
1629 // false lookups in the cache for entries that no longer exist
1630 } else if ( isNode ) {
1631 // IE does not allow us to delete expando properties from nodes,
1632 // nor does it have a removeAttribute function on Document nodes;
1633 // we must handle all of these cases
1634 if ( jQuery.support.deleteExpando ) {
1635 delete elem[ jQuery.expando ];
1636 } else if ( elem.removeAttribute ) {
1637 elem.removeAttribute( jQuery.expando );
1639 elem[ jQuery.expando ] = null;
1644 // For internal use only.
1645 _data: function( elem, name, data ) {
1646 return jQuery.data( elem, name, data, true );
1649 // A method for determining if a DOM node can handle the data expando
1650 acceptData: function( elem ) {
1651 if ( elem.nodeName ) {
1652 var match = jQuery.noData[ elem.nodeName.toLowerCase() ];
1655 return !(match === true || elem.getAttribute("classid") !== match);
1664 data: function( key, value ) {
1667 if ( typeof key === "undefined" ) {
1668 if ( this.length ) {
1669 data = jQuery.data( this[0] );
1671 if ( this[0].nodeType === 1 ) {
1672 var attr = this[0].attributes, name;
1673 for ( var i = 0, l = attr.length; i < l; i++ ) {
1674 name = attr[i].name;
1676 if ( name.indexOf( "data-" ) === 0 ) {
1677 name = jQuery.camelCase( name.substring(5) );
1679 dataAttr( this[0], name, data[ name ] );
1687 } else if ( typeof key === "object" ) {
1688 return this.each(function() {
1689 jQuery.data( this, key );
1693 var parts = key.split(".");
1694 parts[1] = parts[1] ? "." + parts[1] : "";
1696 if ( value === undefined ) {
1697 data = this.triggerHandler("getData" + parts[1] + "!", [parts[0]]);
1699 // Try to fetch any internally stored data first
1700 if ( data === undefined && this.length ) {
1701 data = jQuery.data( this[0], key );
1702 data = dataAttr( this[0], key, data );
1705 return data === undefined && parts[1] ?
1706 this.data( parts[0] ) :
1710 return this.each(function() {
1711 var $this = jQuery( this ),
1712 args = [ parts[0], value ];
1714 $this.triggerHandler( "setData" + parts[1] + "!", args );
1715 jQuery.data( this, key, value );
1716 $this.triggerHandler( "changeData" + parts[1] + "!", args );
1721 removeData: function( key ) {
1722 return this.each(function() {
1723 jQuery.removeData( this, key );
1728 function dataAttr( elem, key, data ) {
1729 // If nothing was found internally, try to fetch any
1730 // data from the HTML5 data-* attribute
1731 if ( data === undefined && elem.nodeType === 1 ) {
1733 var name = "data-" + key.replace( rmultiDash, "-$1" ).toLowerCase();
1735 data = elem.getAttribute( name );
1737 if ( typeof data === "string" ) {
1739 data = data === "true" ? true :
1740 data === "false" ? false :
1741 data === "null" ? null :
1742 !jQuery.isNaN( data ) ? parseFloat( data ) :
1743 rbrace.test( data ) ? jQuery.parseJSON( data ) :
1747 // Make sure we set the data so it isn't changed later
1748 jQuery.data( elem, key, data );
1758 // TODO: This is a hack for 1.5 ONLY to allow objects with a single toJSON
1759 // property to be considered empty objects; this property always exists in
1760 // order to make sure JSON.stringify does not expose internal metadata
1761 function isEmptyDataObject( obj ) {
1762 for ( var name in obj ) {
1763 if ( name !== "toJSON" ) {
1774 function handleQueueMarkDefer( elem, type, src ) {
1775 var deferDataKey = type + "defer",
1776 queueDataKey = type + "queue",
1777 markDataKey = type + "mark",
1778 defer = jQuery.data( elem, deferDataKey, undefined, true );
1780 ( src === "queue" || !jQuery.data( elem, queueDataKey, undefined, true ) ) &&
1781 ( src === "mark" || !jQuery.data( elem, markDataKey, undefined, true ) ) ) {
1782 // Give room for hard-coded callbacks to fire first
1783 // and eventually mark/queue something else on the element
1784 setTimeout( function() {
1785 if ( !jQuery.data( elem, queueDataKey, undefined, true ) &&
1786 !jQuery.data( elem, markDataKey, undefined, true ) ) {
1787 jQuery.removeData( elem, deferDataKey, true );
1796 _mark: function( elem, type ) {
1798 type = (type || "fx") + "mark";
1799 jQuery.data( elem, type, (jQuery.data(elem,type,undefined,true) || 0) + 1, true );
1803 _unmark: function( force, elem, type ) {
1804 if ( force !== true ) {
1810 type = type || "fx";
1811 var key = type + "mark",
1812 count = force ? 0 : ( (jQuery.data( elem, key, undefined, true) || 1 ) - 1 );
1814 jQuery.data( elem, key, count, true );
1816 jQuery.removeData( elem, key, true );
1817 handleQueueMarkDefer( elem, type, "mark" );
1822 queue: function( elem, type, data ) {
1824 type = (type || "fx") + "queue";
1825 var q = jQuery.data( elem, type, undefined, true );
1826 // Speed up dequeue by getting out quickly if this is just a lookup
1828 if ( !q || jQuery.isArray(data) ) {
1829 q = jQuery.data( elem, type, jQuery.makeArray(data), true );
1838 dequeue: function( elem, type ) {
1839 type = type || "fx";
1841 var queue = jQuery.queue( elem, type ),
1845 // If the fx queue is dequeued, always remove the progress sentinel
1846 if ( fn === "inprogress" ) {
1851 // Add a progress sentinel to prevent the fx queue from being
1852 // automatically dequeued
1853 if ( type === "fx" ) {
1854 queue.unshift("inprogress");
1857 fn.call(elem, function() {
1858 jQuery.dequeue(elem, type);
1862 if ( !queue.length ) {
1863 jQuery.removeData( elem, type + "queue", true );
1864 handleQueueMarkDefer( elem, type, "queue" );
1870 queue: function( type, data ) {
1871 if ( typeof type !== "string" ) {
1876 if ( data === undefined ) {
1877 return jQuery.queue( this[0], type );
1879 return this.each(function() {
1880 var queue = jQuery.queue( this, type, data );
1882 if ( type === "fx" && queue[0] !== "inprogress" ) {
1883 jQuery.dequeue( this, type );
1887 dequeue: function( type ) {
1888 return this.each(function() {
1889 jQuery.dequeue( this, type );
1892 // Based off of the plugin by Clint Helfers, with permission.
1893 // http://blindsignals.com/index.php/2009/07/jquery-delay/
1894 delay: function( time, type ) {
1895 time = jQuery.fx ? jQuery.fx.speeds[time] || time : time;
1896 type = type || "fx";
1898 return this.queue( type, function() {
1900 setTimeout(function() {
1901 jQuery.dequeue( elem, type );
1905 clearQueue: function( type ) {
1906 return this.queue( type || "fx", [] );
1908 // Get a promise resolved when queues of a certain type
1909 // are emptied (fx is the type by default)
1910 promise: function( type, object ) {
1911 if ( typeof type !== "string" ) {
1915 type = type || "fx";
1916 var defer = jQuery.Deferred(),
1918 i = elements.length,
1920 deferDataKey = type + "defer",
1921 queueDataKey = type + "queue",
1922 markDataKey = type + "mark",
1924 function resolve() {
1925 if ( !( --count ) ) {
1926 defer.resolveWith( elements, [ elements ] );
1930 if (( tmp = jQuery.data( elements[ i ], deferDataKey, undefined, true ) ||
1931 ( jQuery.data( elements[ i ], queueDataKey, undefined, true ) ||
1932 jQuery.data( elements[ i ], markDataKey, undefined, true ) ) &&
1933 jQuery.data( elements[ i ], deferDataKey, jQuery._Deferred(), true ) )) {
1935 tmp.done( resolve );
1939 return defer.promise();
1946 var rclass = /[\n\t\r]/g,
1949 rtype = /^(?:button|input)$/i,
1950 rfocusable = /^(?:button|input|object|select|textarea)$/i,
1951 rclickable = /^a(?:rea)?$/i,
1952 rboolean = /^(?:autofocus|autoplay|async|checked|controls|defer|disabled|hidden|loop|multiple|open|readonly|required|scoped|selected)$/i,
1956 attr: function( name, value ) {
1957 return jQuery.access( this, name, value, true, jQuery.attr );
1960 removeAttr: function( name ) {
1961 return this.each(function() {
1962 jQuery.removeAttr( this, name );
1966 prop: function( name, value ) {
1967 return jQuery.access( this, name, value, true, jQuery.prop );
1970 removeProp: function( name ) {
1971 name = jQuery.propFix[ name ] || name;
1972 return this.each(function() {
1973 // try/catch handles cases where IE balks (such as removing a property on window)
1975 this[ name ] = undefined;
1976 delete this[ name ];
1981 addClass: function( value ) {
1982 var classNames, i, l, elem,
1985 if ( jQuery.isFunction( value ) ) {
1986 return this.each(function( j ) {
1987 jQuery( this ).addClass( value.call(this, j, this.className) );
1991 if ( value && typeof value === "string" ) {
1992 classNames = value.split( rspace );
1994 for ( i = 0, l = this.length; i < l; i++ ) {
1997 if ( elem.nodeType === 1 ) {
1998 if ( !elem.className && classNames.length === 1 ) {
1999 elem.className = value;
2002 setClass = " " + elem.className + " ";
2004 for ( c = 0, cl = classNames.length; c < cl; c++ ) {
2005 if ( !~setClass.indexOf( " " + classNames[ c ] + " " ) ) {
2006 setClass += classNames[ c ] + " ";
2009 elem.className = jQuery.trim( setClass );
2018 removeClass: function( value ) {
2019 var classNames, i, l, elem, className, c, cl;
2021 if ( jQuery.isFunction( value ) ) {
2022 return this.each(function( j ) {
2023 jQuery( this ).removeClass( value.call(this, j, this.className) );
2027 if ( (value && typeof value === "string") || value === undefined ) {
2028 classNames = (value || "").split( rspace );
2030 for ( i = 0, l = this.length; i < l; i++ ) {
2033 if ( elem.nodeType === 1 && elem.className ) {
2035 className = (" " + elem.className + " ").replace( rclass, " " );
2036 for ( c = 0, cl = classNames.length; c < cl; c++ ) {
2037 className = className.replace(" " + classNames[ c ] + " ", " ");
2039 elem.className = jQuery.trim( className );
2042 elem.className = "";
2051 toggleClass: function( value, stateVal ) {
2052 var type = typeof value,
2053 isBool = typeof stateVal === "boolean";
2055 if ( jQuery.isFunction( value ) ) {
2056 return this.each(function( i ) {
2057 jQuery( this ).toggleClass( value.call(this, i, this.className, stateVal), stateVal );
2061 return this.each(function() {
2062 if ( type === "string" ) {
2063 // toggle individual class names
2066 self = jQuery( this ),
2068 classNames = value.split( rspace );
2070 while ( (className = classNames[ i++ ]) ) {
2071 // check each className given, space seperated list
2072 state = isBool ? state : !self.hasClass( className );
2073 self[ state ? "addClass" : "removeClass" ]( className );
2076 } else if ( type === "undefined" || type === "boolean" ) {
2077 if ( this.className ) {
2078 // store className if set
2079 jQuery._data( this, "__className__", this.className );
2082 // toggle whole className
2083 this.className = this.className || value === false ? "" : jQuery._data( this, "__className__" ) || "";
2088 hasClass: function( selector ) {
2089 var className = " " + selector + " ";
2090 for ( var i = 0, l = this.length; i < l; i++ ) {
2091 if ( this[i].nodeType === 1 && (" " + this[i].className + " ").replace(rclass, " ").indexOf( className ) > -1 ) {
2099 val: function( value ) {
2103 if ( !arguments.length ) {
2105 hooks = jQuery.valHooks[ elem.nodeName.toLowerCase() ] || jQuery.valHooks[ elem.type ];
2107 if ( hooks && "get" in hooks && (ret = hooks.get( elem, "value" )) !== undefined ) {
2113 return typeof ret === "string" ?
2114 // handle most common string cases
2115 ret.replace(rreturn, "") :
2116 // handle cases where value is null/undef or number
2117 ret == null ? "" : ret;
2123 var isFunction = jQuery.isFunction( value );
2125 return this.each(function( i ) {
2126 var self = jQuery(this), val;
2128 if ( this.nodeType !== 1 ) {
2133 val = value.call( this, i, self.val() );
2138 // Treat null/undefined as ""; convert numbers to string
2139 if ( val == null ) {
2141 } else if ( typeof val === "number" ) {
2143 } else if ( jQuery.isArray( val ) ) {
2144 val = jQuery.map(val, function ( value ) {
2145 return value == null ? "" : value + "";
2149 hooks = jQuery.valHooks[ this.nodeName.toLowerCase() ] || jQuery.valHooks[ this.type ];
2151 // If set returns undefined, fall back to normal setting
2152 if ( !hooks || !("set" in hooks) || hooks.set( this, val, "value" ) === undefined ) {
2162 get: function( elem ) {
2163 // attributes.value is undefined in Blackberry 4.7 but
2164 // uses .value. See #6932
2165 var val = elem.attributes.value;
2166 return !val || val.specified ? elem.value : elem.text;
2170 get: function( elem ) {
2172 index = elem.selectedIndex,
2174 options = elem.options,
2175 one = elem.type === "select-one";
2177 // Nothing was selected
2182 // Loop through all the selected options
2183 for ( var i = one ? index : 0, max = one ? index + 1 : options.length; i < max; i++ ) {
2184 var option = options[ i ];
2186 // Don't return options that are disabled or in a disabled optgroup
2187 if ( option.selected && (jQuery.support.optDisabled ? !option.disabled : option.getAttribute("disabled") === null) &&
2188 (!option.parentNode.disabled || !jQuery.nodeName( option.parentNode, "optgroup" )) ) {
2190 // Get the specific value for the option
2191 value = jQuery( option ).val();
2193 // We don't need an array for one selects
2198 // Multi-Selects return an array
2199 values.push( value );
2203 // Fixes Bug #2551 -- select.val() broken in IE after form.reset()
2204 if ( one && !values.length && options.length ) {
2205 return jQuery( options[ index ] ).val();
2211 set: function( elem, value ) {
2212 var values = jQuery.makeArray( value );
2214 jQuery(elem).find("option").each(function() {
2215 this.selected = jQuery.inArray( jQuery(this).val(), values ) >= 0;
2218 if ( !values.length ) {
2219 elem.selectedIndex = -1;
2238 // Always normalize to ensure hook usage
2239 tabindex: "tabIndex"
2242 attr: function( elem, name, value, pass ) {
2243 var nType = elem.nodeType;
2245 // don't get/set attributes on text, comment and attribute nodes
2246 if ( !elem || nType === 3 || nType === 8 || nType === 2 ) {
2250 if ( pass && name in jQuery.attrFn ) {
2251 return jQuery( elem )[ name ]( value );
2254 // Fallback to prop when attributes are not supported
2255 if ( !("getAttribute" in elem) ) {
2256 return jQuery.prop( elem, name, value );
2260 notxml = nType !== 1 || !jQuery.isXMLDoc( elem );
2262 // Normalize the name if needed
2264 name = jQuery.attrFix[ name ] || name;
2266 hooks = jQuery.attrHooks[ name ];
2269 // Use boolHook for boolean attributes
2270 if ( rboolean.test( name ) ) {
2273 // Use nodeHook if available( IE6/7 )
2274 } else if ( nodeHook ) {
2280 if ( value !== undefined ) {
2282 if ( value === null ) {
2283 jQuery.removeAttr( elem, name );
2286 } else if ( hooks && "set" in hooks && notxml && (ret = hooks.set( elem, value, name )) !== undefined ) {
2290 elem.setAttribute( name, "" + value );
2294 } else if ( hooks && "get" in hooks && notxml && (ret = hooks.get( elem, name )) !== null ) {
2299 ret = elem.getAttribute( name );
2301 // Non-existent attributes return null, we normalize to undefined
2302 return ret === null ?
2308 removeAttr: function( elem, name ) {
2310 if ( elem.nodeType === 1 ) {
2311 name = jQuery.attrFix[ name ] || name;
2313 jQuery.attr( elem, name, "" );
2314 elem.removeAttribute( name );
2316 // Set corresponding property to false for boolean attributes
2317 if ( rboolean.test( name ) && (propName = jQuery.propFix[ name ] || name) in elem ) {
2318 elem[ propName ] = false;
2325 set: function( elem, value ) {
2326 // We can't allow the type property to be changed (since it causes problems in IE)
2327 if ( rtype.test( elem.nodeName ) && elem.parentNode ) {
2328 jQuery.error( "type property can't be changed" );
2329 } else if ( !jQuery.support.radioValue && value === "radio" && jQuery.nodeName(elem, "input") ) {
2330 // Setting the type on a radio button after the value resets the value in IE6-9
2331 // Reset value to it's default in case type is set after value
2332 // This is for element creation
2333 var val = elem.value;
2334 elem.setAttribute( "type", value );
2342 // Use the value property for back compat
2343 // Use the nodeHook for button elements in IE6/7 (#1954)
2345 get: function( elem, name ) {
2346 if ( nodeHook && jQuery.nodeName( elem, "button" ) ) {
2347 return nodeHook.get( elem, name );
2349 return name in elem ?
2353 set: function( elem, value, name ) {
2354 if ( nodeHook && jQuery.nodeName( elem, "button" ) ) {
2355 return nodeHook.set( elem, value, name );
2357 // Does not return so that setAttribute is also used
2364 tabindex: "tabIndex",
2365 readonly: "readOnly",
2367 "class": "className",
2368 maxlength: "maxLength",
2369 cellspacing: "cellSpacing",
2370 cellpadding: "cellPadding",
2374 frameborder: "frameBorder",
2375 contenteditable: "contentEditable"
2378 prop: function( elem, name, value ) {
2379 var nType = elem.nodeType;
2381 // don't get/set properties on text, comment and attribute nodes
2382 if ( !elem || nType === 3 || nType === 8 || nType === 2 ) {
2387 notxml = nType !== 1 || !jQuery.isXMLDoc( elem );
2390 // Fix name and attach hooks
2391 name = jQuery.propFix[ name ] || name;
2392 hooks = jQuery.propHooks[ name ];
2395 if ( value !== undefined ) {
2396 if ( hooks && "set" in hooks && (ret = hooks.set( elem, value, name )) !== undefined ) {
2400 return (elem[ name ] = value);
2404 if ( hooks && "get" in hooks && (ret = hooks.get( elem, name )) !== null ) {
2408 return elem[ name ];
2415 get: function( elem ) {
2416 // elem.tabIndex doesn't always return the correct value when it hasn't been explicitly set
2417 // http://fluidproject.org/blog/2008/01/09/getting-setting-and-removing-tabindex-values-with-javascript/
2418 var attributeNode = elem.getAttributeNode("tabindex");
2420 return attributeNode && attributeNode.specified ?
2421 parseInt( attributeNode.value, 10 ) :
2422 rfocusable.test( elem.nodeName ) || rclickable.test( elem.nodeName ) && elem.href ?
2430 // Add the tabindex propHook to attrHooks for back-compat
2431 jQuery.attrHooks.tabIndex = jQuery.propHooks.tabIndex;
2433 // Hook for boolean attributes
2435 get: function( elem, name ) {
2436 // Align boolean attributes with corresponding properties
2437 // Fall back to attribute presence where some booleans are not supported
2439 return jQuery.prop( elem, name ) === true || ( attrNode = elem.getAttributeNode( name ) ) && attrNode.nodeValue !== false ?
2440 name.toLowerCase() :
2443 set: function( elem, value, name ) {
2445 if ( value === false ) {
2446 // Remove boolean attributes when set to false
2447 jQuery.removeAttr( elem, name );
2449 // value is true since we know at this point it's type boolean and not false
2450 // Set boolean attributes to the same name and set the DOM property
2451 propName = jQuery.propFix[ name ] || name;
2452 if ( propName in elem ) {
2453 // Only set the IDL specifically if it already exists on the element
2454 elem[ propName ] = true;
2457 elem.setAttribute( name, name.toLowerCase() );
2463 // IE6/7 do not support getting/setting some attributes with get/setAttribute
2464 if ( !jQuery.support.getSetAttribute ) {
2466 // Use this for any attribute in IE6/7
2467 // This fixes almost every IE6/7 issue
2468 nodeHook = jQuery.valHooks.button = {
2469 get: function( elem, name ) {
2471 ret = elem.getAttributeNode( name );
2472 // Return undefined if nodeValue is empty string
2473 return ret && ret.nodeValue !== "" ?
2477 set: function( elem, value, name ) {
2478 // Set the existing or create a new attribute node
2479 var ret = elem.getAttributeNode( name );
2481 ret = document.createAttribute( name );
2482 elem.setAttributeNode( ret );
2484 return (ret.nodeValue = value + "");
2488 // Set width and height to auto instead of 0 on empty string( Bug #8150 )
2489 // This is for removals
2490 jQuery.each([ "width", "height" ], function( i, name ) {
2491 jQuery.attrHooks[ name ] = jQuery.extend( jQuery.attrHooks[ name ], {
2492 set: function( elem, value ) {
2493 if ( value === "" ) {
2494 elem.setAttribute( name, "auto" );
2503 // Some attributes require a special call on IE
2504 if ( !jQuery.support.hrefNormalized ) {
2505 jQuery.each([ "href", "src", "width", "height" ], function( i, name ) {
2506 jQuery.attrHooks[ name ] = jQuery.extend( jQuery.attrHooks[ name ], {
2507 get: function( elem ) {
2508 var ret = elem.getAttribute( name, 2 );
2509 return ret === null ? undefined : ret;
2515 if ( !jQuery.support.style ) {
2516 jQuery.attrHooks.style = {
2517 get: function( elem ) {
2518 // Return undefined in the case of empty string
2519 // Normalize to lowercase since IE uppercases css property names
2520 return elem.style.cssText.toLowerCase() || undefined;
2522 set: function( elem, value ) {
2523 return (elem.style.cssText = "" + value);
2528 // Safari mis-reports the default selected property of an option
2529 // Accessing the parent's selectedIndex property fixes it
2530 if ( !jQuery.support.optSelected ) {
2531 jQuery.propHooks.selected = jQuery.extend( jQuery.propHooks.selected, {
2532 get: function( elem ) {
2533 var parent = elem.parentNode;
2536 parent.selectedIndex;
2538 // Make sure that it also works with optgroups, see #5701
2539 if ( parent.parentNode ) {
2540 parent.parentNode.selectedIndex;
2548 // Radios and checkboxes getter/setter
2549 if ( !jQuery.support.checkOn ) {
2550 jQuery.each([ "radio", "checkbox" ], function() {
2551 jQuery.valHooks[ this ] = {
2552 get: function( elem ) {
2553 // Handle the case where in Webkit "" is returned instead of "on" if a value isn't specified
2554 return elem.getAttribute("value") === null ? "on" : elem.value;
2559 jQuery.each([ "radio", "checkbox" ], function() {
2560 jQuery.valHooks[ this ] = jQuery.extend( jQuery.valHooks[ this ], {
2561 set: function( elem, value ) {
2562 if ( jQuery.isArray( value ) ) {
2563 return (elem.checked = jQuery.inArray( jQuery(elem).val(), value ) >= 0);
2572 var rnamespaces = /\.(.*)$/,
2573 rformElems = /^(?:textarea|input|select)$/i,
2576 rescape = /[^\w\s.|`]/g,
2577 fcleanup = function( nm ) {
2578 return nm.replace(rescape, "\\$&");
2582 * A number of helper functions used for managing events.
2583 * Many of the ideas behind this code originated from
2584 * Dean Edwards' addEvent library.
2588 // Bind an event to an element
2589 // Original by Dean Edwards
2590 add: function( elem, types, handler, data ) {
2591 if ( elem.nodeType === 3 || elem.nodeType === 8 ) {
2595 if ( handler === false ) {
2596 handler = returnFalse;
2597 } else if ( !handler ) {
2598 // Fixes bug #7229. Fix recommended by jdalton
2602 var handleObjIn, handleObj;
2604 if ( handler.handler ) {
2605 handleObjIn = handler;
2606 handler = handleObjIn.handler;
2609 // Make sure that the function being executed has a unique ID
2610 if ( !handler.guid ) {
2611 handler.guid = jQuery.guid++;
2614 // Init the element's event structure
2615 var elemData = jQuery._data( elem );
2617 // If no elemData is found then we must be trying to bind to one of the
2618 // banned noData elements
2623 var events = elemData.events,
2624 eventHandle = elemData.handle;
2627 elemData.events = events = {};
2630 if ( !eventHandle ) {
2631 elemData.handle = eventHandle = function( e ) {
2632 // Discard the second event of a jQuery.event.trigger() and
2633 // when an event is called after a page has unloaded
2634 return typeof jQuery !== "undefined" && (!e || jQuery.event.triggered !== e.type) ?
2635 jQuery.event.handle.apply( eventHandle.elem, arguments ) :
2640 // Add elem as a property of the handle function
2641 // This is to prevent a memory leak with non-native events in IE.
2642 eventHandle.elem = elem;
2644 // Handle multiple events separated by a space
2645 // jQuery(...).bind("mouseover mouseout", fn);
2646 types = types.split(" ");
2648 var type, i = 0, namespaces;
2650 while ( (type = types[ i++ ]) ) {
2651 handleObj = handleObjIn ?
2652 jQuery.extend({}, handleObjIn) :
2653 { handler: handler, data: data };
2655 // Namespaced event handlers
2656 if ( type.indexOf(".") > -1 ) {
2657 namespaces = type.split(".");
2658 type = namespaces.shift();
2659 handleObj.namespace = namespaces.slice(0).sort().join(".");
2663 handleObj.namespace = "";
2666 handleObj.type = type;
2667 if ( !handleObj.guid ) {
2668 handleObj.guid = handler.guid;
2671 // Get the current list of functions bound to this event
2672 var handlers = events[ type ],
2673 special = jQuery.event.special[ type ] || {};
2675 // Init the event handler queue
2677 handlers = events[ type ] = [];
2679 // Check for a special event handler
2680 // Only use addEventListener/attachEvent if the special
2681 // events handler returns false
2682 if ( !special.setup || special.setup.call( elem, data, namespaces, eventHandle ) === false ) {
2683 // Bind the global event handler to the element
2684 if ( elem.addEventListener ) {
2685 elem.addEventListener( type, eventHandle, false );
2687 } else if ( elem.attachEvent ) {
2688 elem.attachEvent( "on" + type, eventHandle );
2693 if ( special.add ) {
2694 special.add.call( elem, handleObj );
2696 if ( !handleObj.handler.guid ) {
2697 handleObj.handler.guid = handler.guid;
2701 // Add the function to the element's handler list
2702 handlers.push( handleObj );
2704 // Keep track of which events have been used, for event optimization
2705 jQuery.event.global[ type ] = true;
2708 // Nullify elem to prevent memory leaks in IE
2714 // Detach an event or set of events from an element
2715 remove: function( elem, types, handler, pos ) {
2716 // don't do events on text and comment nodes
2717 if ( elem.nodeType === 3 || elem.nodeType === 8 ) {
2721 if ( handler === false ) {
2722 handler = returnFalse;
2725 var ret, type, fn, j, i = 0, all, namespaces, namespace, special, eventType, handleObj, origType,
2726 elemData = jQuery.hasData( elem ) && jQuery._data( elem ),
2727 events = elemData && elemData.events;
2729 if ( !elemData || !events ) {
2733 // types is actually an event object here
2734 if ( types && types.type ) {
2735 handler = types.handler;
2739 // Unbind all events for the element
2740 if ( !types || typeof types === "string" && types.charAt(0) === "." ) {
2741 types = types || "";
2743 for ( type in events ) {
2744 jQuery.event.remove( elem, type + types );
2750 // Handle multiple events separated by a space
2751 // jQuery(...).unbind("mouseover mouseout", fn);
2752 types = types.split(" ");
2754 while ( (type = types[ i++ ]) ) {
2757 all = type.indexOf(".") < 0;
2761 // Namespaced event handlers
2762 namespaces = type.split(".");
2763 type = namespaces.shift();
2765 namespace = new RegExp("(^|\\.)" +
2766 jQuery.map( namespaces.slice(0).sort(), fcleanup ).join("\\.(?:.*\\.)?") + "(\\.|$)");
2769 eventType = events[ type ];
2776 for ( j = 0; j < eventType.length; j++ ) {
2777 handleObj = eventType[ j ];
2779 if ( all || namespace.test( handleObj.namespace ) ) {
2780 jQuery.event.remove( elem, origType, handleObj.handler, j );
2781 eventType.splice( j--, 1 );
2788 special = jQuery.event.special[ type ] || {};
2790 for ( j = pos || 0; j < eventType.length; j++ ) {
2791 handleObj = eventType[ j ];
2793 if ( handler.guid === handleObj.guid ) {
2794 // remove the given handler for the given type
2795 if ( all || namespace.test( handleObj.namespace ) ) {
2796 if ( pos == null ) {
2797 eventType.splice( j--, 1 );
2800 if ( special.remove ) {
2801 special.remove.call( elem, handleObj );
2805 if ( pos != null ) {
2811 // remove generic event handler if no more handlers exist
2812 if ( eventType.length === 0 || pos != null && eventType.length === 1 ) {
2813 if ( !special.teardown || special.teardown.call( elem, namespaces ) === false ) {
2814 jQuery.removeEvent( elem, type, elemData.handle );
2818 delete events[ type ];
2822 // Remove the expando if it's no longer used
2823 if ( jQuery.isEmptyObject( events ) ) {
2824 var handle = elemData.handle;
2829 delete elemData.events;
2830 delete elemData.handle;
2832 if ( jQuery.isEmptyObject( elemData ) ) {
2833 jQuery.removeData( elem, undefined, true );
2838 // Events that are safe to short-circuit if no handlers are attached.
2839 // Native DOM events should not be added, they may have inline handlers.
2846 trigger: function( event, data, elem, onlyHandlers ) {
2847 // Event object or event type
2848 var type = event.type || event,
2852 if ( type.indexOf("!") >= 0 ) {
2853 // Exclusive events trigger only for the exact event (no namespaces)
2854 type = type.slice(0, -1);
2858 if ( type.indexOf(".") >= 0 ) {
2859 // Namespaced trigger; create a regexp to match event type in handle()
2860 namespaces = type.split(".");
2861 type = namespaces.shift();
2865 if ( (!elem || jQuery.event.customEvent[ type ]) && !jQuery.event.global[ type ] ) {
2866 // No jQuery handlers for this event type, and it can't have inline handlers
2870 // Caller can pass in an Event, Object, or just an event type string
2871 event = typeof event === "object" ?
2872 // jQuery.Event object
2873 event[ jQuery.expando ] ? event :
2875 new jQuery.Event( type, event ) :
2876 // Just the event type (string)
2877 new jQuery.Event( type );
2880 event.exclusive = exclusive;
2881 event.namespace = namespaces.join(".");