3 * jQuery 1.2.2 - New Wave Javascript
5 * Copyright (c) 2007 John Resig (jquery.com)
6 * Dual licensed under the MIT (MIT-LICENSE.txt)
7 * and GPL (GPL-LICENSE.txt) licenses.
9 * $Date: 2008-01-14 17:56:07 -0500 (Mon, 14 Jan 2008) $
13 // Map over jQuery in case of overwrite
15 var _jQuery = window.jQuery;
17 var jQuery = window.jQuery = function( selector, context ) {
18 // The jQuery object is actually just the init constructor 'enhanced'
19 return new jQuery.prototype.init( selector, context );
22 // Map over the $ in case of overwrite
26 // Map the jQuery namespace to the '$' one
29 // A simple way to check for HTML strings or ID strings
30 // (both of which we optimize for)
31 var quickExpr = /^[^<]*(<(.|\s)+>)[^>]*$|^#(\w+)$/;
33 // Is it a simple selector
34 var isSimple = /^.[^:#\[\.]*$/;
36 jQuery.fn = jQuery.prototype = {
37 init: function( selector, context ) {
38 // Make sure that a selection was provided
39 selector = selector || document;
41 // Handle $(DOMElement)
42 if ( selector.nodeType ) {
47 // Handle HTML strings
48 } else if ( typeof selector == "string" ) {
49 // Are we dealing with HTML string or an ID?
50 var match = quickExpr.exec( selector );
52 // Verify a match, and that no context was specified for #id
53 if ( match && (match[1] || !context) ) {
55 // HANDLE: $(html) -> $(array)
57 selector = jQuery.clean( [ match[1] ], context );
61 var elem = document.getElementById( match[3] );
63 // Make sure an element was located
65 // Handle the case where IE and Opera return items
66 // by name instead of ID
67 if ( elem.id != match[3] )
68 return jQuery().find( selector );
70 // Otherwise, we inject the element directly into the jQuery object
81 // HANDLE: $(expr, [context])
82 // (which is just equivalent to: $(content).find(expr)
84 return new jQuery( context ).find( selector );
86 // HANDLE: $(function)
87 // Shortcut for document ready
88 } else if ( jQuery.isFunction( selector ) )
89 return new jQuery( document )[ jQuery.fn.ready ? "ready" : "load" ]( selector );
93 selector.constructor == Array && selector ||
95 // HANDLE: $(arraylike)
96 // Watch for when an array-like object, contains DOM nodes, is passed in as the selector
97 (selector.jquery || selector.length && selector != window && !selector.nodeType && selector[0] != undefined && selector[0].nodeType) && jQuery.makeArray( selector ) ||
103 // The current version of jQuery being used
106 // The number of elements contained in the matched element set
111 // The number of elements contained in the matched element set
114 // Get the Nth element in the matched element set OR
115 // Get the whole matched element set as a clean array
116 get: function( num ) {
117 return num == undefined ?
119 // Return a 'clean' array
120 jQuery.makeArray( this ) :
122 // Return just the object
126 // Take an array of elements and push it onto the stack
127 // (returning the new matched element set)
128 pushStack: function( elems ) {
129 // Build a new jQuery matched element set
130 var ret = jQuery( elems );
132 // Add the old object onto the stack (as a reference)
133 ret.prevObject = this;
135 // Return the newly-formed element set
139 // Force the current matched set of elements to become
140 // the specified array of elements (destroying the stack in the process)
141 // You should use pushStack() in order to do this, but maintain the stack
142 setArray: function( elems ) {
143 // Resetting the length to 0, then using the native Array push
144 // is a super-fast way to populate an object with array-like properties
146 Array.prototype.push.apply( this, elems );
151 // Execute a callback for every element in the matched set.
152 // (You can seed the arguments with an array of args, but this is
153 // only used internally.)
154 each: function( callback, args ) {
155 return jQuery.each( this, callback, args );
158 // Determine the position of an element within
159 // the matched set of elements
160 index: function( elem ) {
163 // Locate the position of the desired element
164 this.each(function(i){
172 attr: function( name, value, type ) {
175 // Look for the case where we're accessing a style value
176 if ( name.constructor == String )
177 if ( value == undefined )
178 return this.length && jQuery[ type || "attr" ]( this[0], name ) || undefined;
182 options[ name ] = value;
185 // Check to see if we're setting style values
186 return this.each(function(i){
187 // Set all the styles
188 for ( name in options )
193 name, jQuery.prop( this, options[ name ], type, i, name )
198 css: function( key, value ) {
199 // ignore negative width and height values
200 if ( (key == 'width' || key == 'height') && parseFloat(value) < 0 )
202 return this.attr( key, value, "curCSS" );
205 text: function( text ) {
206 if ( typeof text != "object" && text != null )
207 return this.empty().append( (this[0] && this[0].ownerDocument || document).createTextNode( text ) );
211 jQuery.each( text || this, function(){
212 jQuery.each( this.childNodes, function(){
213 if ( this.nodeType != 8 )
214 ret += this.nodeType != 1 ?
216 jQuery.fn.text( [ this ] );
223 wrapAll: function( html ) {
225 // The elements to wrap the target around
226 jQuery( html, this[0].ownerDocument )
228 .insertBefore( this[0] )
232 while ( elem.firstChild )
233 elem = elem.firstChild;
242 wrapInner: function( html ) {
243 return this.each(function(){
244 jQuery( this ).contents().wrapAll( html );
248 wrap: function( html ) {
249 return this.each(function(){
250 jQuery( this ).wrapAll( html );
255 return this.domManip(arguments, true, false, function(elem){
256 if (this.nodeType == 1)
257 this.appendChild( elem );
261 prepend: function() {
262 return this.domManip(arguments, true, true, function(elem){
263 if (this.nodeType == 1)
264 this.insertBefore( elem, this.firstChild );
269 return this.domManip(arguments, false, false, function(elem){
270 this.parentNode.insertBefore( elem, this );
275 return this.domManip(arguments, false, true, function(elem){
276 this.parentNode.insertBefore( elem, this.nextSibling );
281 return this.prevObject || jQuery( [] );
284 find: function( selector ) {
285 var elems = jQuery.map(this, function(elem){
286 return jQuery.find( selector, elem );
289 return this.pushStack( /[^+>] [^+>]/.test( selector ) || selector.indexOf("..") > -1 ?
290 jQuery.unique( elems ) :
294 clone: function( events ) {
296 var ret = this.map(function(){
297 if ( jQuery.browser.msie && !jQuery.isXMLDoc(this) ) {
298 // IE copies events bound via attachEvent when
299 // using cloneNode. Calling detachEvent on the
300 // clone will also remove the events from the orignal
301 // In order to get around this, we use innerHTML.
302 // Unfortunately, this means some modifications to
303 // attributes in IE that are actually only stored
304 // as properties will not be copied (such as the
305 // the name attribute on an input).
306 var clone = this.cloneNode(true),
307 container = document.createElement("div"),
308 container2 = document.createElement("div");
309 container.appendChild(clone);
310 container2.innerHTML = container.innerHTML;
311 return container2.firstChild;
313 return this.cloneNode(true);
316 // Need to set the expando to null on the cloned set if it exists
317 // removeData doesn't work here, IE removes it from the original as well
318 // this is primarily for IE but the data expando shouldn't be copied over in any browser
319 var clone = ret.find("*").andSelf().each(function(){
320 if ( this[ expando ] != undefined )
321 this[ expando ] = null;
324 // Copy the events from the original to the clone
325 if ( events === true )
326 this.find("*").andSelf().each(function(i){
327 if (this.nodeType == 3)
329 var events = jQuery.data( this, "events" );
331 for ( var type in events )
332 for ( var handler in events[ type ] )
333 jQuery.event.add( clone[ i ], type, events[ type ][ handler ], events[ type ][ handler ].data );
336 // Return the cloned set
340 filter: function( selector ) {
341 return this.pushStack(
342 jQuery.isFunction( selector ) &&
343 jQuery.grep(this, function(elem, i){
344 return selector.call( elem, i );
347 jQuery.multiFilter( selector, this ) );
350 not: function( selector ) {
351 if ( selector.constructor == String )
352 // test special case where just one selector is passed in
353 if ( isSimple.test( selector ) )
354 return this.pushStack( jQuery.multiFilter( selector, this, true ) );
356 selector = jQuery.multiFilter( selector, this );
358 var isArrayLike = selector.length && selector[selector.length - 1] !== undefined && !selector.nodeType;
359 return this.filter(function() {
360 return isArrayLike ? jQuery.inArray( this, selector ) < 0 : this != selector;
364 add: function( selector ) {
365 return !selector ? this : this.pushStack( jQuery.merge(
367 selector.constructor == String ?
368 jQuery( selector ).get() :
369 selector.length != undefined && (!selector.nodeName || jQuery.nodeName(selector, "form")) ?
370 selector : [selector] ) );
373 is: function( selector ) {
375 jQuery.multiFilter( selector, this ).length > 0 :
379 hasClass: function( selector ) {
380 return this.is( "." + selector );
383 val: function( value ) {
384 if ( value == undefined ) {
389 // We need to handle select boxes special
390 if ( jQuery.nodeName( elem, "select" ) ) {
391 var index = elem.selectedIndex,
393 options = elem.options,
394 one = elem.type == "select-one";
396 // Nothing was selected
400 // Loop through all the selected options
401 for ( var i = one ? index : 0, max = one ? index + 1 : options.length; i < max; i++ ) {
402 var option = options[ i ];
404 if ( option.selected ) {
405 // Get the specifc value for the option
406 value = jQuery.browser.msie && !option.attributes.value.specified ? option.text : option.value;
408 // We don't need an array for one selects
412 // Multi-Selects return an array
413 values.push( value );
419 // Everything else, we just grab the value
421 return (this[0].value || "").replace(/\r/g, "");
428 return this.each(function(){
429 if ( this.nodeType != 1 )
432 if ( value.constructor == Array && /radio|checkbox/.test( this.type ) )
433 this.checked = (jQuery.inArray(this.value, value) >= 0 ||
434 jQuery.inArray(this.name, value) >= 0);
436 else if ( jQuery.nodeName( this, "select" ) ) {
437 var values = value.constructor == Array ?
441 jQuery( "option", this ).each(function(){
442 this.selected = (jQuery.inArray( this.value, values ) >= 0 ||
443 jQuery.inArray( this.text, values ) >= 0);
446 if ( !values.length )
447 this.selectedIndex = -1;
454 html: function( value ) {
455 return value == undefined ?
459 this.empty().append( value );
462 replaceWith: function( value ) {
463 return this.after( value ).remove();
467 return this.slice( i, i + 1 );
471 return this.pushStack( Array.prototype.slice.apply( this, arguments ) );
474 map: function( callback ) {
475 return this.pushStack( jQuery.map(this, function(elem, i){
476 return callback.call( elem, i, elem );
480 andSelf: function() {
481 return this.add( this.prevObject );
484 domManip: function( args, table, reverse, callback ) {
485 var clone = this.length > 1, elems;
487 return this.each(function(){
489 elems = jQuery.clean( args, this.ownerDocument );
497 if ( table && jQuery.nodeName( this, "table" ) && jQuery.nodeName( elems[0], "tr" ) )
498 obj = this.getElementsByTagName("tbody")[0] || this.appendChild( this.ownerDocument.createElement("tbody") );
500 var scripts = jQuery( [] );
502 jQuery.each(elems, function(){
504 jQuery( this ).clone( true )[0] :
507 // execute all scripts after the elements have been injected
508 if ( jQuery.nodeName( elem, "script" ) ) {
509 scripts = scripts.add( elem );
511 // Remove any inner scripts for later evaluation
512 if ( elem.nodeType == 1 )
513 scripts = scripts.add( jQuery( "script", elem ).remove() );
515 // Inject the elements into the document
516 callback.call( obj, elem );
520 scripts.each( evalScript );
525 // Give the init function the jQuery prototype for later instantiation
526 jQuery.prototype.init.prototype = jQuery.prototype;
528 function evalScript( i, elem ) {
537 jQuery.globalEval( elem.text || elem.textContent || elem.innerHTML || "" );
539 if ( elem.parentNode )
540 elem.parentNode.removeChild( elem );
543 jQuery.extend = jQuery.fn.extend = function() {
544 // copy reference to target object
545 var target = arguments[0] || {}, i = 1, length = arguments.length, deep = false, options;
547 // Handle a deep copy situation
548 if ( target.constructor == Boolean ) {
550 target = arguments[1] || {};
551 // skip the boolean and the target
555 // Handle case when target is a string or something (possible in deep copy)
556 if ( typeof target != "object" && typeof target != "function" )
559 // extend jQuery itself if only one argument is passed
565 for ( ; i < length; i++ )
566 // Only deal with non-null/undefined values
567 if ( (options = arguments[ i ]) != null )
568 // Extend the base object
569 for ( var name in options ) {
570 // Prevent never-ending loop
571 if ( target === options[ name ] )
574 // Recurse if we're merging object values
575 if ( deep && options[ name ] && typeof options[ name ] == "object" && target[ name ] && !options[ name ].nodeType )
576 target[ name ] = jQuery.extend( target[ name ], options[ name ] );
578 // Don't bring in undefined values
579 else if ( options[ name ] != undefined )
580 target[ name ] = options[ name ];
584 // Return the modified object
588 var expando = "jQuery" + (new Date()).getTime(), uuid = 0, windowData = {};
590 // exclude the following css properties to add px
591 var exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i;
594 noConflict: function( deep ) {
598 window.jQuery = _jQuery;
603 // See test/unit/core.js for details concerning this function.
604 isFunction: function( fn ) {
605 return !!fn && typeof fn != "string" && !fn.nodeName &&
606 fn.constructor != Array && /function/i.test( fn + "" );
609 // check if an element is in a (or is an) XML document
610 isXMLDoc: function( elem ) {
611 return elem.documentElement && !elem.body ||
612 elem.tagName && elem.ownerDocument && !elem.ownerDocument.body;
615 // Evalulates a script in a global context
616 globalEval: function( data ) {
617 data = jQuery.trim( data );
620 // Inspired by code by Andrea Giammarchi
621 // http://webreflection.blogspot.com/2007/08/global-scope-evaluation-and-dom.html
622 var head = document.getElementsByTagName("head")[0] || document.documentElement,
623 script = document.createElement("script");
625 script.type = "text/javascript";
626 if ( jQuery.browser.msie )
629 script.appendChild( document.createTextNode( data ) );
631 head.appendChild( script );
632 head.removeChild( script );
636 nodeName: function( elem, name ) {
637 return elem.nodeName && elem.nodeName.toUpperCase() == name.toUpperCase();
642 data: function( elem, name, data ) {
643 elem = elem == window ?
647 var id = elem[ expando ];
649 // Compute a unique ID for the element
651 id = elem[ expando ] = ++uuid;
653 // Only generate the data cache if we're
654 // trying to access or manipulate it
655 if ( name && !jQuery.cache[ id ] )
656 jQuery.cache[ id ] = {};
658 // Prevent overriding the named cache with undefined values
659 if ( data != undefined )
660 jQuery.cache[ id ][ name ] = data;
662 // Return the named cache data, or the ID for the element
664 jQuery.cache[ id ][ name ] :
668 removeData: function( elem, name ) {
669 elem = elem == window ?
673 var id = elem[ expando ];
675 // If we want to remove a specific section of the element's data
677 if ( jQuery.cache[ id ] ) {
678 // Remove the section of cache data
679 delete jQuery.cache[ id ][ name ];
681 // If we've removed all the data, remove the element's cache
684 for ( name in jQuery.cache[ id ] )
688 jQuery.removeData( elem );
691 // Otherwise, we want to remove all of the element's data
693 // Clean up the element expando
695 delete elem[ expando ];
697 // IE has trouble directly removing the expando
698 // but it's ok with using removeAttribute
699 if ( elem.removeAttribute )
700 elem.removeAttribute( expando );
703 // Completely remove the data cache
704 delete jQuery.cache[ id ];
708 // args is for internal usage only
709 each: function( object, callback, args ) {
711 if ( object.length == undefined ) {
712 for ( var name in object )
713 if ( callback.apply( object[ name ], args ) === false )
716 for ( var i = 0, length = object.length; i < length; i++ )
717 if ( callback.apply( object[ i ], args ) === false )
720 // A special, fast, case for the most common use of each
722 if ( object.length == undefined ) {
723 for ( var name in object )
724 if ( callback.call( object[ name ], name, object[ name ] ) === false )
727 for ( var i = 0, length = object.length, value = object[0];
728 i < length && callback.call( value, i, value ) !== false; value = object[++i] ){}
734 prop: function( elem, value, type, i, name ) {
735 // Handle executable functions
736 if ( jQuery.isFunction( value ) )
737 value = value.call( elem, i );
739 // Handle passing in a number to a CSS property
740 return value && value.constructor == Number && type == "curCSS" && !exclude.test( name ) ?
746 // internal only, use addClass("class")
747 add: function( elem, classNames ) {
748 jQuery.each((classNames || "").split(/\s+/), function(i, className){
749 if ( elem.nodeType == 1 && !jQuery.className.has( elem.className, className ) )
750 elem.className += (elem.className ? " " : "") + className;
754 // internal only, use removeClass("class")
755 remove: function( elem, classNames ) {
756 if (elem.nodeType == 1)
757 elem.className = classNames != undefined ?
758 jQuery.grep(elem.className.split(/\s+/), function(className){
759 return !jQuery.className.has( classNames, className );
764 // internal only, use is(".class")
765 has: function( elem, className ) {
766 return jQuery.inArray( className, (elem.className || elem).toString().split(/\s+/) ) > -1;
770 // A method for quickly swapping in/out CSS properties to get correct calculations
771 swap: function( elem, options, callback ) {
773 // Remember the old values, and insert the new ones
774 for ( var name in options ) {
775 old[ name ] = elem.style[ name ];
776 elem.style[ name ] = options[ name ];
779 callback.call( elem );
781 // Revert the old values
782 for ( var name in options )
783 elem.style[ name ] = old[ name ];
786 css: function( elem, name, force ) {
787 if ( name == "width" || name == "height" ) {
788 var val, props = { position: "absolute", visibility: "hidden", display:"block" }, which = name == "width" ? [ "Left", "Right" ] : [ "Top", "Bottom" ];
791 val = name == "width" ? elem.offsetWidth : elem.offsetHeight;
792 var padding = 0, border = 0;
793 jQuery.each( which, function() {
794 padding += parseFloat(jQuery.curCSS( elem, "padding" + this, true)) || 0;
795 border += parseFloat(jQuery.curCSS( elem, "border" + this + "Width", true)) || 0;
797 val -= Math.round(padding + border);
800 if ( jQuery(elem).is(":visible") )
803 jQuery.swap( elem, props, getWH );
805 return Math.max(0, val);
808 return jQuery.curCSS( elem, name, force );
811 curCSS: function( elem, name, force ) {
814 // A helper method for determining if an element's values are broken
815 function color( elem ) {
816 if ( !jQuery.browser.safari )
819 var ret = document.defaultView.getComputedStyle( elem, null );
820 return !ret || ret.getPropertyValue("color") == "";
823 // We need to handle opacity special in IE
824 if ( name == "opacity" && jQuery.browser.msie ) {
825 ret = jQuery.attr( elem.style, "opacity" );
831 // Opera sometimes will give the wrong display answer, this fixes it, see #2037
832 if ( jQuery.browser.opera && name == "display" ) {
833 var save = elem.style.display;
834 elem.style.display = "block";
835 elem.style.display = save;
838 // Make sure we're using the right name for getting the float value
839 if ( name.match( /float/i ) )
842 if ( !force && elem.style && elem.style[ name ] )
843 ret = elem.style[ name ];
845 else if ( document.defaultView && document.defaultView.getComputedStyle ) {
847 // Only "float" is needed here
848 if ( name.match( /float/i ) )
851 name = name.replace( /([A-Z])/g, "-$1" ).toLowerCase();
853 var getComputedStyle = document.defaultView.getComputedStyle( elem, null );
855 if ( getComputedStyle && !color( elem ) )
856 ret = getComputedStyle.getPropertyValue( name );
858 // If the element isn't reporting its values properly in Safari
859 // then some display: none elements are involved
861 var swap = [], stack = [];
863 // Locate all of the parent display: none elements
864 for ( var a = elem; a && color(a); a = a.parentNode )
867 // Go through and make them visible, but in reverse
868 // (It would be better if we knew the exact display type that they had)
869 for ( var i = 0; i < stack.length; i++ )
870 if ( color( stack[ i ] ) ) {
871 swap[ i ] = stack[ i ].style.display;
872 stack[ i ].style.display = "block";
875 // Since we flip the display style, we have to handle that
876 // one special, otherwise get the value
877 ret = name == "display" && swap[ stack.length - 1 ] != null ?
879 ( getComputedStyle && getComputedStyle.getPropertyValue( name ) ) || "";
881 // Finally, revert the display styles back
882 for ( var i = 0; i < swap.length; i++ )
883 if ( swap[ i ] != null )
884 stack[ i ].style.display = swap[ i ];
887 // We should always get a number back from opacity
888 if ( name == "opacity" && ret == "" )
891 } else if ( elem.currentStyle ) {
892 var camelCase = name.replace(/\-(\w)/g, function(all, letter){
893 return letter.toUpperCase();
896 ret = elem.currentStyle[ name ] || elem.currentStyle[ camelCase ];
898 // From the awesome hack by Dean Edwards
899 // http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291
901 // If we're not dealing with a regular pixel number
902 // but a number that has a weird ending, we need to convert it to pixels
903 if ( !/^\d+(px)?$/i.test( ret ) && /^\d/.test( ret ) ) {
904 // Remember the original values
905 var style = elem.style.left, runtimeStyle = elem.runtimeStyle.left;
907 // Put in the new values to get a computed value out
908 elem.runtimeStyle.left = elem.currentStyle.left;
909 elem.style.left = ret || 0;
910 ret = elem.style.pixelLeft + "px";
912 // Revert the changed values
913 elem.style.left = style;
914 elem.runtimeStyle.left = runtimeStyle;
921 clean: function( elems, context ) {
923 context = context || document;
924 // !context.createElement fails in IE with an error but returns typeof 'object'
925 if (typeof context.createElement == 'undefined')
926 context = context.ownerDocument || context[0] && context[0].ownerDocument || document;
928 jQuery.each(elems, function(i, elem){
932 if ( elem.constructor == Number )
933 elem = elem.toString();
935 // Convert html string into DOM nodes
936 if ( typeof elem == "string" ) {
937 // Fix "XHTML"-style tags in all browsers
938 elem = elem.replace(/(<(\w+)[^>]*?)\/>/g, function(all, front, tag){
939 return tag.match(/^(abbr|br|col|img|input|link|meta|param|hr|area|embed)$/i) ?
941 front + "></" + tag + ">";
944 // Trim whitespace, otherwise indexOf won't work as expected
945 var tags = jQuery.trim( elem ).toLowerCase(), div = context.createElement("div");
948 // option or optgroup
949 !tags.indexOf("<opt") &&
950 [ 1, "<select multiple='multiple'>", "</select>" ] ||
952 !tags.indexOf("<leg") &&
953 [ 1, "<fieldset>", "</fieldset>" ] ||
955 tags.match(/^<(thead|tbody|tfoot|colg|cap)/) &&
956 [ 1, "<table>", "</table>" ] ||
958 !tags.indexOf("<tr") &&
959 [ 2, "<table><tbody>", "</tbody></table>" ] ||
961 // <thead> matched above
962 (!tags.indexOf("<td") || !tags.indexOf("<th")) &&
963 [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ] ||
965 !tags.indexOf("<col") &&
966 [ 2, "<table><tbody></tbody><colgroup>", "</colgroup></table>" ] ||
968 // IE can't serialize <link> and <script> tags normally
969 jQuery.browser.msie &&
970 [ 1, "div<div>", "</div>" ] ||
974 // Go to html and back, then peel off extra wrappers
975 div.innerHTML = wrap[1] + elem + wrap[2];
977 // Move to the right depth
981 // Remove IE's autoinserted <tbody> from table fragments
982 if ( jQuery.browser.msie ) {
984 // String was a <table>, *may* have spurious <tbody>
985 var tbody = !tags.indexOf("<table") && tags.indexOf("<tbody") < 0 ?
986 div.firstChild && div.firstChild.childNodes :
988 // String was a bare <thead> or <tfoot>
989 wrap[1] == "<table>" && tags.indexOf("<tbody") < 0 ?
993 for ( var j = tbody.length - 1; j >= 0 ; --j )
994 if ( jQuery.nodeName( tbody[ j ], "tbody" ) && !tbody[ j ].childNodes.length )
995 tbody[ j ].parentNode.removeChild( tbody[ j ] );
997 // IE completely kills leading whitespace when innerHTML is used
998 if ( /^\s/.test( elem ) )
999 div.insertBefore( context.createTextNode( elem.match(/^\s*/)[0] ), div.firstChild );
1003 elem = jQuery.makeArray( div.childNodes );
1006 if ( elem.length === 0 && (!jQuery.nodeName( elem, "form" ) && !jQuery.nodeName( elem, "select" )) )
1009 if ( elem[0] == undefined || jQuery.nodeName( elem, "form" ) || elem.options )
1013 ret = jQuery.merge( ret, elem );
1020 attr: function( elem, name, value ) {
1021 // don't set attributes on text and comment nodes
1022 if (!elem || elem.nodeType == 3 || elem.nodeType == 8)
1025 var fix = jQuery.isXMLDoc( elem ) ?
1029 // Safari mis-reports the default selected property of a hidden option
1030 // Accessing the parent's selectedIndex property fixes it
1031 if ( name == "selected" && jQuery.browser.safari )
1032 elem.parentNode.selectedIndex;
1034 // Certain attributes only work when accessed via the old DOM 0 way
1035 if ( fix[ name ] ) {
1036 if ( value != undefined )
1037 elem[ fix[ name ] ] = value;
1039 return elem[ fix[ name ] ];
1041 } else if ( jQuery.browser.msie && name == "style" )
1042 return jQuery.attr( elem.style, "cssText", value );
1044 else if ( value == undefined && jQuery.browser.msie && jQuery.nodeName( elem, "form" ) && (name == "action" || name == "method") )
1045 return elem.getAttributeNode( name ).nodeValue;
1047 // IE elem.getAttribute passes even for style
1048 else if ( elem.tagName ) {
1050 if ( value != undefined ) {
1051 // We can't allow the type property to be changed (since it causes problems in IE)
1052 if ( name == "type" && jQuery.nodeName( elem, "input" ) && elem.parentNode )
1053 throw "type property can't be changed";
1055 // convert the value to a string (all browsers do this but IE) see #1070
1056 elem.setAttribute( name, "" + value );
1059 if ( jQuery.browser.msie && /href|src/.test( name ) && !jQuery.isXMLDoc( elem ) )
1060 return elem.getAttribute( name, 2 );
1062 return elem.getAttribute( name );
1064 // elem is actually elem.style ... set the style
1066 // IE actually uses filters for opacity
1067 if ( name == "opacity" && jQuery.browser.msie ) {
1068 if ( value != undefined ) {
1069 // IE has trouble with opacity if it does not have layout
1070 // Force it by setting the zoom level
1073 // Set the alpha filter to set the opacity
1074 elem.filter = (elem.filter || "").replace( /alpha\([^)]*\)/, "" ) +
1075 (parseFloat( value ).toString() == "NaN" ? "" : "alpha(opacity=" + value * 100 + ")");
1078 return elem.filter && elem.filter.indexOf("opacity=") >= 0 ?
1079 (parseFloat( elem.filter.match(/opacity=([^)]*)/)[1] ) / 100).toString() :
1083 name = name.replace(/-([a-z])/ig, function(all, letter){
1084 return letter.toUpperCase();
1087 if ( value != undefined )
1088 elem[ name ] = value;
1090 return elem[ name ];
1094 trim: function( text ) {
1095 return (text || "").replace( /^\s+|\s+$/g, "" );
1098 makeArray: function( array ) {
1101 // Need to use typeof to fight Safari childNodes crashes
1102 if ( typeof array != "array" )
1103 for ( var i = 0, length = array.length; i < length; i++ )
1104 ret.push( array[ i ] );
1106 ret = array.slice( 0 );
1111 inArray: function( elem, array ) {
1112 for ( var i = 0, length = array.length; i < length; i++ )
1113 if ( array[ i ] == elem )
1119 merge: function( first, second ) {
1120 // We have to loop this way because IE & Opera overwrite the length
1121 // expando of getElementsByTagName
1123 // Also, we need to make sure that the correct elements are being returned
1124 // (IE returns comment nodes in a '*' query)
1125 if ( jQuery.browser.msie ) {
1126 for ( var i = 0; second[ i ]; i++ )
1127 if ( second[ i ].nodeType != 8 )
1128 first.push( second[ i ] );
1131 for ( var i = 0; second[ i ]; i++ )
1132 first.push( second[ i ] );
1137 unique: function( array ) {
1138 var ret = [], done = {};
1142 for ( var i = 0, length = array.length; i < length; i++ ) {
1143 var id = jQuery.data( array[ i ] );
1145 if ( !done[ id ] ) {
1147 ret.push( array[ i ] );
1158 grep: function( elems, callback, inv ) {
1159 // If a string is passed in for the function, make a function
1160 // for it (a handy shortcut)
1161 if ( typeof callback == "string" )
1162 callback = eval("false||function(a,i){return " + callback + "}");
1166 // Go through the array, only saving the items
1167 // that pass the validator function
1168 for ( var i = 0, length = elems.length; i < length; i++ )
1169 if ( !inv && callback( elems[ i ], i ) || inv && !callback( elems[ i ], i ) )
1170 ret.push( elems[ i ] );
1175 map: function( elems, callback ) {
1178 // Go through the array, translating each of the items to their
1179 // new value (or values).
1180 for ( var i = 0, length = elems.length; i < length; i++ ) {
1181 var value = callback( elems[ i ], i );
1183 if ( value !== null && value != undefined ) {
1184 if ( value.constructor != Array )
1187 ret = ret.concat( value );
1195 var userAgent = navigator.userAgent.toLowerCase();
1197 // Figure out what browser is being used
1199 version: (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [])[1],
1200 safari: /webkit/.test( userAgent ),
1201 opera: /opera/.test( userAgent ),
1202 msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
1203 mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )
1206 var styleFloat = jQuery.browser.msie ?
1211 // Check to see if the W3C box model is being used
1212 boxModel: !jQuery.browser.msie || document.compatMode == "CSS1Compat",
1216 "class": "className",
1217 "float": styleFloat,
1218 cssFloat: styleFloat,
1219 styleFloat: styleFloat,
1220 innerHTML: "innerHTML",
1221 className: "className",
1223 disabled: "disabled",
1225 readonly: "readOnly",
1226 selected: "selected",
1227 maxlength: "maxLength",
1228 selectedIndex: "selectedIndex",
1229 defaultValue: "defaultValue",
1231 nodeName: "nodeName"
1236 parent: "elem.parentNode",
1237 parents: "jQuery.dir(elem,'parentNode')",
1238 next: "jQuery.nth(elem,2,'nextSibling')",
1239 prev: "jQuery.nth(elem,2,'previousSibling')",
1240 nextAll: "jQuery.dir(elem,'nextSibling')",
1241 prevAll: "jQuery.dir(elem,'previousSibling')",
1242 siblings: "jQuery.sibling(elem.parentNode.firstChild,elem)",
1243 children: "jQuery.sibling(elem.firstChild)",
1244 contents: "jQuery.nodeName(elem,'iframe')?elem.contentDocument||elem.contentWindow.document:jQuery.makeArray(elem.childNodes)"
1245 }, function(name, fn){
1246 fn = eval("false||function(elem){return " + fn + "}");
1248 jQuery.fn[ name ] = function( selector ) {
1249 var ret = jQuery.map( this, fn );
1251 if ( selector && typeof selector == "string" )
1252 ret = jQuery.multiFilter( selector, ret );
1254 return this.pushStack( jQuery.unique( ret ) );
1260 prependTo: "prepend",
1261 insertBefore: "before",
1262 insertAfter: "after",
1263 replaceAll: "replaceWith"
1264 }, function(name, original){
1265 jQuery.fn[ name ] = function() {
1266 var args = arguments;
1268 return this.each(function(){
1269 for ( var i = 0, length = args.length; i < length; i++ )
1270 jQuery( args[ i ] )[ original ]( this );
1276 removeAttr: function( name ) {
1277 jQuery.attr( this, name, "" );
1278 if (this.nodeType == 1)
1279 this.removeAttribute( name );
1282 addClass: function( classNames ) {
1283 jQuery.className.add( this, classNames );
1286 removeClass: function( classNames ) {
1287 jQuery.className.remove( this, classNames );
1290 toggleClass: function( classNames ) {
1291 jQuery.className[ jQuery.className.has( this, classNames ) ? "remove" : "add" ]( this, classNames );
1294 remove: function( selector ) {
1295 if ( !selector || jQuery.filter( selector, [ this ] ).r.length ) {
1296 // Prevent memory leaks
1297 jQuery( "*", this ).add(this).each(function(){
1298 jQuery.event.remove(this);
1299 jQuery.removeData(this);
1301 if (this.parentNode)
1302 this.parentNode.removeChild( this );
1307 // Remove element nodes and prevent memory leaks
1308 jQuery( ">*", this ).remove();
1310 // Remove any remaining nodes
1311 while ( this.firstChild )
1312 this.removeChild( this.firstChild );
1314 }, function(name, fn){
1315 jQuery.fn[ name ] = function(){
1316 return this.each( fn, arguments );
1320 jQuery.each([ "Height", "Width" ], function(i, name){
1321 var type = name.toLowerCase();
1323 jQuery.fn[ type ] = function( size ) {
1324 // Get window width or height
1325 return this[0] == window ?
1326 // Opera reports document.body.client[Width/Height] properly in both quirks and standards
1327 jQuery.browser.opera && document.body[ "client" + name ] ||
1329 // Safari reports inner[Width/Height] just fine (Mozilla and Opera include scroll bar widths)
1330 jQuery.browser.safari && window[ "inner" + name ] ||
1332 // Everyone else use document.documentElement or document.body depending on Quirks vs Standards mode
1333 document.compatMode == "CSS1Compat" && document.documentElement[ "client" + name ] || document.body[ "client" + name ] :
1335 // Get document width or height
1336 this[0] == document ?
1337 // Either scroll[Width/Height] or offset[Width/Height], whichever is greater
1339 Math.max(document.body["scroll" + name], document.documentElement["scroll" + name]),
1340 Math.max(document.body["offset" + name], document.documentElement["offset" + name])
1343 // Get or set width or height on the element
1345 // Get width or height on the element
1346 (this.length ? jQuery.css( this[0], type ) : null) :
1348 // Set the width or height on the element (default to pixels if value is unitless)
1349 this.css( type, size.constructor == String ? size : size + "px" );
1353 var chars = jQuery.browser.safari && parseInt(jQuery.browser.version) < 417 ?
1354 "(?:[\\w*_-]|\\\\.)" :
1355 "(?:[\\w\u0128-\uFFFF*_-]|\\\\.)",
1356 quickChild = new RegExp("^>\\s*(" + chars + "+)"),
1357 quickID = new RegExp("^(" + chars + "+)(#)(" + chars + "+)"),
1358 quickClass = new RegExp("^([#.]?)(" + chars + "*)");
1362 "": "m[2]=='*'||jQuery.nodeName(a,m[2])",
1363 "#": "a.getAttribute('id')==m[2]",
1371 last: "i==r.length-1",
1376 "first-child": "a.parentNode.getElementsByTagName('*')[0]==a",
1377 "last-child": "jQuery.nth(a.parentNode.lastChild,1,'previousSibling')==a",
1378 "only-child": "!jQuery.nth(a.parentNode.lastChild,2,'previousSibling')",
1381 parent: "a.firstChild",
1382 empty: "!a.firstChild",
1385 contains: "(a.textContent||a.innerText||jQuery(a).text()||'').indexOf(m[3])>=0",
1388 visible: '"hidden"!=a.type&&jQuery.css(a,"display")!="none"&&jQuery.css(a,"visibility")!="hidden"',
1389 hidden: '"hidden"==a.type||jQuery.css(a,"display")=="none"||jQuery.css(a,"visibility")=="hidden"',
1392 enabled: "!a.disabled",
1393 disabled: "a.disabled",
1394 checked: "a.checked",
1395 selected: "a.selected||jQuery.attr(a,'selected')",
1398 text: "'text'==a.type",
1399 radio: "'radio'==a.type",
1400 checkbox: "'checkbox'==a.type",
1401 file: "'file'==a.type",
1402 password: "'password'==a.type",
1403 submit: "'submit'==a.type",
1404 image: "'image'==a.type",
1405 reset: "'reset'==a.type",
1406 button: '"button"==a.type||jQuery.nodeName(a,"button")',
1407 input: "/input|select|textarea|button/i.test(a.nodeName)",
1410 has: "jQuery.find(m[3],a).length",
1413 header: "/h\\d/i.test(a.nodeName)",
1416 animated: "jQuery.grep(jQuery.timers,function(fn){return a==fn.elem;}).length"
1420 // The regular expressions that power the parsing engine
1422 // Match: [@value='test'], [@foo]
1423 /^(\[) *@?([\w-]+) *([!*$^~=]*) *('?"?)(.*?)\4 *\]/,
1425 // Match: :contains('foo')
1426 /^(:)([\w-]+)\("?'?(.*?(\(.*?\))?[^(]*?)"?'?\)/,
1428 // Match: :even, :last-chlid, #id, .class
1429 new RegExp("^([:.#]*)(" + chars + "+)")
1432 multiFilter: function( expr, elems, not ) {
1435 while ( expr && expr != old ) {
1437 var f = jQuery.filter( expr, elems, not );
1438 expr = f.t.replace(/^\s*,\s*/, "" );
1439 cur = not ? elems = f.r : jQuery.merge( cur, f.r );
1445 find: function( t, context ) {
1446 // Quickly handle non-string expressions
1447 if ( typeof t != "string" )
1450 // check to make sure context is a DOM element or a document
1451 if ( context && context.nodeType != 1 && context.nodeType != 9)
1454 // Set the correct context (if none is provided)
1455 context = context || document;
1457 // Initialize the search
1458 var ret = [context], done = [], last, nodeName;
1460 // Continue while a selector expression exists, and while
1461 // we're no longer looping upon ourselves
1462 while ( t && last != t ) {
1468 var foundToken = false;
1470 // An attempt at speeding up child selectors that
1471 // point to a specific element tag
1472 var re = quickChild;
1476 nodeName = m[1].toUpperCase();
1478 // Perform our own iteration and filter
1479 for ( var i = 0; ret[i]; i++ )
1480 for ( var c = ret[i].firstChild; c; c = c.nextSibling )
1481 if ( c.nodeType == 1 && (nodeName == "*" || c.nodeName.toUpperCase() == nodeName) )
1485 t = t.replace( re, "" );
1486 if ( t.indexOf(" ") == 0 ) continue;
1489 re = /^([>+~])\s*(\w*)/i;
1491 if ( (m = re.exec(t)) != null ) {
1495 nodeName = m[2].toUpperCase();
1498 for ( var j = 0, rl = ret.length; j < rl; j++ ) {
1499 var n = m == "~" || m == "+" ? ret[j].nextSibling : ret[j].firstChild;
1500 for ( ; n; n = n.nextSibling )
1501 if ( n.nodeType == 1 ) {
1502 var id = jQuery.data(n);
1504 if ( m == "~" && merge[id] ) break;
1506 if (!nodeName || n.nodeName.toUpperCase() == nodeName ) {
1507 if ( m == "~" ) merge[id] = true;
1511 if ( m == "+" ) break;
1517 // And remove the token
1518 t = jQuery.trim( t.replace( re, "" ) );
1523 // See if there's still an expression, and that we haven't already
1525 if ( t && !foundToken ) {
1526 // Handle multiple expressions
1527 if ( !t.indexOf(",") ) {
1528 // Clean the result set
1529 if ( context == ret[0] ) ret.shift();
1531 // Merge the result sets
1532 done = jQuery.merge( done, ret );
1534 // Reset the context
1535 r = ret = [context];
1537 // Touch up the selector string
1538 t = " " + t.substr(1,t.length);
1541 // Optimize for the case nodeName#idName
1543 var m = re2.exec(t);
1545 // Re-organize the results, so that they're consistent
1547 m = [ 0, m[2], m[3], m[1] ];
1550 // Otherwise, do a traditional filter check for
1551 // ID, class, and element selectors
1556 m[2] = m[2].replace(/\\/g, "");
1558 var elem = ret[ret.length-1];
1560 // Try to do a global search by ID, where we can
1561 if ( m[1] == "#" && elem && elem.getElementById && !jQuery.isXMLDoc(elem) ) {
1562 // Optimization for HTML document case
1563 var oid = elem.getElementById(m[2]);
1565 // Do a quick check for the existence of the actual ID attribute
1566 // to avoid selecting by the name attribute in IE
1567 // also check to insure id is a string to avoid selecting an element with the name of 'id' inside a form
1568 if ( (jQuery.browser.msie||jQuery.browser.opera) && oid && typeof oid.id == "string" && oid.id != m[2] )
1569 oid = jQuery('[@id="'+m[2]+'"]', elem)[0];
1571 // Do a quick check for node name (where applicable) so
1572 // that div#foo searches will be really fast
1573 ret = r = oid && (!m[3] || jQuery.nodeName(oid, m[3])) ? [oid] : [];
1575 // We need to find all descendant elements
1576 for ( var i = 0; ret[i]; i++ ) {
1577 // Grab the tag name being searched for
1578 var tag = m[1] == "#" && m[3] ? m[3] : m[1] != "" || m[0] == "" ? "*" : m[2];
1580 // Handle IE7 being really dumb about <object>s
1581 if ( tag == "*" && ret[i].nodeName.toLowerCase() == "object" )
1584 r = jQuery.merge( r, ret[i].getElementsByTagName( tag ));
1587 // It's faster to filter by class and be done with it
1589 r = jQuery.classFilter( r, m[2] );
1591 // Same with ID filtering
1592 if ( m[1] == "#" ) {
1595 // Try to find the element with the ID
1596 for ( var i = 0; r[i]; i++ )
1597 if ( r[i].getAttribute("id") == m[2] ) {
1608 t = t.replace( re2, "" );
1613 // If a selector string still exists
1615 // Attempt to filter it
1616 var val = jQuery.filter(t,r);
1618 t = jQuery.trim(val.t);
1622 // An error occurred with the selector;
1623 // just return an empty set instead
1627 // Remove the root context
1628 if ( ret && context == ret[0] )
1631 // And combine the results
1632 done = jQuery.merge( done, ret );
1637 classFilter: function(r,m,not){
1640 for ( var i = 0; r[i]; i++ ) {
1641 var pass = (" " + r[i].className + " ").indexOf( m ) >= 0;
1642 if ( !not && pass || not && !pass )
1648 filter: function(t,r,not) {
1651 // Look for common filter expressions
1652 while ( t && t != last ) {
1655 var p = jQuery.parse, m;
1657 for ( var i = 0; p[i]; i++ ) {
1661 // Remove what we just matched
1662 t = t.substring( m[0].length );
1664 m[2] = m[2].replace(/\\/g, "");
1672 // :not() is a special case that can be optimized by
1673 // keeping it out of the expression list
1674 if ( m[1] == ":" && m[2] == "not" )
1675 // optimize if only one selector found (most common case)
1676 r = isSimple.test( m[3] ) ?
1677 jQuery.filter(m[3], r, true).r :
1678 jQuery( r ).not( m[3] );
1680 // We can get a big speed boost by filtering by class here
1681 else if ( m[1] == "." )
1682 r = jQuery.classFilter(r, m[2], not);
1684 else if ( m[1] == "[" ) {
1685 var tmp = [], type = m[3];
1687 for ( var i = 0, rl = r.length; i < rl; i++ ) {
1688 var a = r[i], z = a[ jQuery.props[m[2]] || m[2] ];
1690 if ( z == null || /href|src|selected/.test(m[2]) )
1691 z = jQuery.attr(a,m[2]) || '';
1693 if ( (type == "" && !!z ||
1694 type == "=" && z == m[5] ||
1695 type == "!=" && z != m[5] ||
1696 type == "^=" && z && !z.indexOf(m[5]) ||
1697 type == "$=" && z.substr(z.length - m[5].length) == m[5] ||
1698 (type == "*=" || type == "~=") && z.indexOf(m[5]) >= 0) ^ not )
1704 // We can get a speed boost by handling nth-child here
1705 } else if ( m[1] == ":" && m[2] == "nth-child" ) {
1706 var merge = {}, tmp = [],
1707 // parse equations like 'even', 'odd', '5', '2n', '3n+2', '4n-1', '-n+6'
1708 test = /(-?)(\d*)n((?:\+|-)?\d*)/.exec(
1709 m[3] == "even" && "2n" || m[3] == "odd" && "2n+1" ||
1710 !/\D/.test(m[3]) && "0n+" + m[3] || m[3]),
1711 // calculate the numbers (first)n+(last) including if they are negative
1712 first = (test[1] + (test[2] || 1)) - 0, last = test[3] - 0;
1714 // loop through all the elements left in the jQuery object
1715 for ( var i = 0, rl = r.length; i < rl; i++ ) {
1716 var node = r[i], parentNode = node.parentNode, id = jQuery.data(parentNode);
1721 for ( var n = parentNode.firstChild; n; n = n.nextSibling )
1722 if ( n.nodeType == 1 )
1731 if ( node.nodeIndex == last )
1733 } else if ( (node.nodeIndex - last) % first == 0 && (node.nodeIndex - last) / first >= 0 )
1742 // Otherwise, find the expression to execute
1744 var f = jQuery.expr[m[1]];
1745 if ( typeof f != "string" )
1746 f = jQuery.expr[m[1]][m[2]];
1748 // Build a custom macro to enclose it
1749 f = eval("false||function(a,i){return " + f + "}");
1751 // Execute it against the current filter
1752 r = jQuery.grep( r, f, not );
1756 // Return an array of filtered elements (r)
1757 // and the modified expression string (t)
1758 return { r: r, t: t };
1761 dir: function( elem, dir ){
1763 var cur = elem[dir];
1764 while ( cur && cur != document ) {
1765 if ( cur.nodeType == 1 )
1766 matched.push( cur );
1772 nth: function(cur,result,dir,elem){
1773 result = result || 1;
1776 for ( ; cur; cur = cur[dir] )
1777 if ( cur.nodeType == 1 && ++num == result )
1783 sibling: function( n, elem ) {
1786 for ( ; n; n = n.nextSibling ) {
1787 if ( n.nodeType == 1 && (!elem || n != elem) )
1796 * A number of helper functions used for managing events.
1797 * Many of the ideas behind this code orignated from
1798 * Dean Edwards' addEvent library.
1802 // Bind an event to an element
1803 // Original by Dean Edwards
1804 add: function(elem, types, handler, data) {
1805 if ( elem.nodeType == 3 || elem.nodeType == 8 )
1808 // For whatever reason, IE has trouble passing the window object
1809 // around, causing it to be cloned in the process
1810 if ( jQuery.browser.msie && elem.setInterval != undefined )
1813 // Make sure that the function being executed has a unique ID
1814 if ( !handler.guid )
1815 handler.guid = this.guid++;
1817 // if data is passed, bind to handler
1818 if( data != undefined ) {
1819 // Create temporary function pointer to original handler
1822 // Create unique handler function, wrapped around original handler
1823 handler = function() {
1824 // Pass arguments and context to original handler
1825 return fn.apply(this, arguments);
1828 // Store data in unique handler
1829 handler.data = data;
1831 // Set the guid of unique handler to the same of original handler, so it can be removed
1832 handler.guid = fn.guid;
1835 // Init the element's event structure
1836 var events = jQuery.data(elem, "events") || jQuery.data(elem, "events", {}),
1837 handle = jQuery.data(elem, "handle") || jQuery.data(elem, "handle", function(){
1838 // returned undefined or false
1841 // Handle the second event of a trigger and when
1842 // an event is called after a page has unloaded
1843 if ( typeof jQuery == "undefined" || jQuery.event.triggered )
1846 val = jQuery.event.handle.apply(arguments.callee.elem, arguments);
1850 // Add elem as a property of the handle function
1851 // This is to prevent a memory leak with non-native
1855 // Handle multiple events seperated by a space
1856 // jQuery(...).bind("mouseover mouseout", fn);
1857 jQuery.each(types.split(/\s+/), function(index, type) {
1858 // Namespaced event handlers
1859 var parts = type.split(".");
1861 handler.type = parts[1];
1863 // Get the current list of functions bound to this event
1864 var handlers = events[type];
1866 // Init the event handler queue
1868 handlers = events[type] = {};
1870 // Check for a special event handler
1871 // Only use addEventListener/attachEvent if the special
1872 // events handler returns false
1873 if ( !jQuery.event.special[type] || jQuery.event.special[type].setup.call(elem) === false ) {
1874 // Bind the global event handler to the element
1875 if (elem.addEventListener)
1876 elem.addEventListener(type, handle, false);
1877 else if (elem.attachEvent)
1878 elem.attachEvent("on" + type, handle);
1882 // Add the function to the element's handler list
1883 handlers[handler.guid] = handler;
1885 // Keep track of which events have been used, for global triggering
1886 jQuery.event.global[type] = true;
1889 // Nullify elem to prevent memory leaks in IE
1896 // Detach an event or set of events from an element
1897 remove: function(elem, types, handler) {
1898 // don't do events on text and comment nodes
1899 if ( elem.nodeType == 3 || elem.nodeType == 8 )
1902 var events = jQuery.data(elem, "events"), ret, index;
1905 // Unbind all events for the element
1906 if ( types == undefined )
1907 for ( var type in events )
1908 this.remove( elem, type );
1910 // types is actually an event object here
1912 handler = types.handler;
1916 // Handle multiple events seperated by a space
1917 // jQuery(...).unbind("mouseover mouseout", fn);
1918 jQuery.each(types.split(/\s+/), function(index, type){
1919 // Namespaced event handlers
1920 var parts = type.split(".");
1923 if ( events[type] ) {
1924 // remove the given handler for the given type
1926 delete events[type][handler.guid];
1928 // remove all handlers for the given type
1930 for ( handler in events[type] )
1931 // Handle the removal of namespaced events
1932 if ( !parts[1] || events[type][handler].type == parts[1] )
1933 delete events[type][handler];
1935 // remove generic event handler if no more handlers exist
1936 for ( ret in events[type] ) break;
1938 if ( !jQuery.event.special[type] || jQuery.event.special[type].teardown.call(elem) === false ) {
1939 if (elem.removeEventListener)
1940 elem.removeEventListener(type, jQuery.data(elem, "handle"), false);
1941 else if (elem.detachEvent)
1942 elem.detachEvent("on" + type, jQuery.data(elem, "handle"));
1945 delete events[type];
1951 // Remove the expando if it's no longer used
1952 for ( ret in events ) break;
1954 var handle = jQuery.data( elem, "handle" );
1955 if ( handle ) handle.elem = null;
1956 jQuery.removeData( elem, "events" );
1957 jQuery.removeData( elem, "handle" );
1962 trigger: function(type, data, elem, donative, extra) {
1963 // Clone the incoming data, if any
1964 data = jQuery.makeArray(data || []);
1966 // Handle a global trigger
1968 // Only trigger if we've ever bound an event for it
1969 if ( this.global[type] )
1970 jQuery("*").add([window, document]).trigger(type, data);
1972 // Handle triggering a single element
1974 // don't do events on text and comment nodes
1975 if ( elem.nodeType == 3 || elem.nodeType == 8 )
1978 var val, ret, fn = jQuery.isFunction( elem[ type ] || null ),
1979 // Check to see if we need to provide a fake event, or not
1980 event = !data[0] || !data[0].preventDefault;
1982 // Pass along a fake event
1984 data.unshift( this.fix({ type: type, target: elem }) );
1986 // Enforce the right trigger type
1987 data[0].type = type;
1989 // Trigger the event
1990 if ( jQuery.isFunction( jQuery.data(elem, "handle") ) )
1991 val = jQuery.data(elem, "handle").apply( elem, data );
1993 // Handle triggering native .onfoo handlers
1994 if ( !fn && elem["on"+type] && elem["on"+type].apply( elem, data ) === false )
1997 // Extra functions don't get the custom event object
2001 // Handle triggering of extra function
2002 if ( extra && jQuery.isFunction( extra ) ) {
2003 // call the extra function and tack the current return value on the end for possible inspection
2004 ret = extra.apply( elem, val == null ? data : data.concat( val ) );
2005 // if anything is returned, give it precedence and have it overwrite the previous value
2006 if (ret !== undefined)
2010 // Trigger the native events (except for clicks on links)
2011 if ( fn && donative !== false && val !== false && !(jQuery.nodeName(elem, 'a') && type == "click") ) {
2012 this.triggered = true;
2015 // prevent IE from throwing an error for some hidden elements
2019 this.triggered = false;
2025 handle: function(event) {
2026 // returned undefined or false
2029 // Empty object is for triggered events with no data
2030 event = jQuery.event.fix( event || window.event || {} );
2032 // Namespaced event handlers
2033 var parts = event.type.split(".");
2034 event.type = parts[0];
2036 var handlers = jQuery.data(this, "events") && jQuery.data(this, "events")[event.type], args = Array.prototype.slice.call( arguments, 1 );
2037 args.unshift( event );
2039 for ( var j in handlers ) {
2040 var handler = handlers[j];
2041 // Pass in a reference to the handler function itself
2042 // So that we can later remove it
2043 args[0].handler = handler;
2044 args[0].data = handler.data;
2046 // Filter the functions by class
2047 if ( !parts[1] || handler.type == parts[1] ) {
2048 var ret = handler.apply( this, args );
2050 if ( val !== false )
2053 if ( ret === false ) {
2054 event.preventDefault();
2055 event.stopPropagation();
2060 // Clean up added properties in IE to prevent memory leak
2061 if (jQuery.browser.msie)
2062 event.target = event.preventDefault = event.stopPropagation =
2063 event.handler = event.data = null;
2068 fix: function(event) {
2069 // store a copy of the original event object
2070 // and clone to set read-only properties
2071 var originalEvent = event;
2072 event = jQuery.extend({}, originalEvent);
2074 // add preventDefault and stopPropagation since
2075 // they will not work on the clone
2076 event.preventDefault = function() {
2077 // if preventDefault exists run it on the original event
2078 if (originalEvent.preventDefault)
2079 originalEvent.preventDefault();
2080 // otherwise set the returnValue property of the original event to false (IE)
2081 originalEvent.returnValue = false;
2083 event.stopPropagation = function() {
2084 // if stopPropagation exists run it on the original event
2085 if (originalEvent.stopPropagation)
2086 originalEvent.stopPropagation();
2087 // otherwise set the cancelBubble property of the original event to true (IE)
2088 originalEvent.cancelBubble = true;
2091 // Fix target property, if necessary
2092 if ( !event.target )
2093 event.target = event.srcElement || document; // Fixes #1925 where srcElement might not be defined either
2095 // check if target is a textnode (safari)
2096 if ( event.target.nodeType == 3 )
2097 event.target = originalEvent.target.parentNode;
2099 // Add relatedTarget, if necessary
2100 if ( !event.relatedTarget && event.fromElement )
2101 event.relatedTarget = event.fromElement == event.target ? event.toElement : event.fromElement;
2103 // Calculate pageX/Y if missing and clientX/Y available
2104 if ( event.pageX == null && event.clientX != null ) {
2105 var doc = document.documentElement, body = document.body;
2106 event.pageX = event.clientX + (doc && doc.scrollLeft || body && body.scrollLeft || 0) - (doc.clientLeft || 0);
2107 event.pageY = event.clientY + (doc && doc.scrollTop || body && body.scrollTop || 0) - (doc.clientTop || 0);
2110 // Add which for key events
2111 if ( !event.which && ((event.charCode || event.charCode === 0) ? event.charCode : event.keyCode) )
2112 event.which = event.charCode || event.keyCode;
2114 // Add metaKey to non-Mac browsers (use ctrl for PC's and Meta for Macs)
2115 if ( !event.metaKey && event.ctrlKey )
2116 event.metaKey = event.ctrlKey;
2118 // Add which for click: 1 == left; 2 == middle; 3 == right
2119 // Note: button is not normalized, so don't use it
2120 if ( !event.which && event.button )
2121 event.which = (event.button & 1 ? 1 : ( event.button & 2 ? 3 : ( event.button & 4 ? 2 : 0 ) ));
2129 // Make sure the ready event is setup
2134 teardown: function() { return; }
2139 if ( jQuery.browser.msie ) return false;
2140 jQuery(this).bind("mouseover", jQuery.event.special.mouseenter.handler);
2144 teardown: function() {
2145 if ( jQuery.browser.msie ) return false;
2146 jQuery(this).unbind("mouseover", jQuery.event.special.mouseenter.handler);
2150 handler: function(event) {
2151 // If we actually just moused on to a sub-element, ignore it
2152 if ( withinElement(event, this) ) return true;
2153 // Execute the right handlers by setting the event type to mouseenter
2154 arguments[0].type = "mouseenter";
2155 return jQuery.event.handle.apply(this, arguments);
2161 if ( jQuery.browser.msie ) return false;
2162 jQuery(this).bind("mouseout", jQuery.event.special.mouseleave.handler);
2166 teardown: function() {
2167 if ( jQuery.browser.msie ) return false;
2168 jQuery(this).unbind("mouseout", jQuery.event.special.mouseleave.handler);
2172 handler: function(event) {
2173 // If we actually just moused on to a sub-element, ignore it
2174 if ( withinElement(event, this) ) return true;
2175 // Execute the right handlers by setting the event type to mouseleave
2176 arguments[0].type = "mouseleave";
2177 return jQuery.event.handle.apply(this, arguments);
2184 bind: function( type, data, fn ) {
2185 return type == "unload" ? this.one(type, data, fn) : this.each(function(){
2186 jQuery.event.add( this, type, fn || data, fn && data );
2190 one: function( type, data, fn ) {
2191 return this.each(function(){
2192 jQuery.event.add( this, type, function(event) {
2193 jQuery(this).unbind(event);
2194 return (fn || data).apply( this, arguments);
2199 unbind: function( type, fn ) {
2200 return this.each(function(){
2201 jQuery.event.remove( this, type, fn );
2205 trigger: function( type, data, fn ) {
2206 return this.each(function(){
2207 jQuery.event.trigger( type, data, this, true, fn );
2211 triggerHandler: function( type, data, fn ) {
2213 return jQuery.event.trigger( type, data, this[0], false, fn );
2217 toggle: function() {
2218 // Save reference to arguments for access in closure
2219 var args = arguments;
2221 return this.click(function(event) {
2222 // Figure out which function to execute
2223 this.lastToggle = 0 == this.lastToggle ? 1 : 0;
2225 // Make sure that clicks stop
2226 event.preventDefault();
2228 // and execute the function
2229 return args[this.lastToggle].apply( this, arguments ) || false;
2233 hover: function(fnOver, fnOut) {
2234 return this.bind('mouseenter', fnOver).bind('mouseleave', fnOut);
2237 ready: function(fn) {
2238 // Attach the listeners
2241 // If the DOM is already ready
2242 if ( jQuery.isReady )
2243 // Execute the function immediately
2244 fn.call( document, jQuery );
2246 // Otherwise, remember the function for later
2248 // Add the function to the wait list
2249 jQuery.readyList.push( function() { return fn.call(this, jQuery); } );
2258 // Handle when the DOM is ready
2260 // Make sure that the DOM is not already loaded
2261 if ( !jQuery.isReady ) {
2262 // Remember that the DOM is ready
2263 jQuery.isReady = true;
2265 // If there are functions bound, to execute
2266 if ( jQuery.readyList ) {
2267 // Execute all of them
2268 jQuery.each( jQuery.readyList, function(){
2269 this.apply( document );
2272 // Reset the list of functions
2273 jQuery.readyList = null;
2276 // Trigger any bound ready events
2277 jQuery(document).triggerHandler("ready");
2282 var readyBound = false;
2284 function bindReady(){
2285 if ( readyBound ) return;
2288 // Mozilla, Opera (see further below for it) and webkit nightlies currently support this event
2289 if ( document.addEventListener && !jQuery.browser.opera)
2290 // Use the handy event callback
2291 document.addEventListener( "DOMContentLoaded", jQuery.ready, false );
2293 // If IE is used and is not in a frame
2294 // Continually check to see if the document is ready
2295 if ( jQuery.browser.msie && window == top ) (function(){
2296 if (jQuery.isReady) return;
2298 // If IE is used, use the trick by Diego Perini
2299 // http://javascript.nwbox.com/IEContentLoaded/
2300 document.documentElement.doScroll("left");
2302 setTimeout( arguments.callee, 0 );
2305 // and execute any waiting functions
2309 if ( jQuery.browser.opera )
2310 document.addEventListener( "DOMContentLoaded", function () {
2311 if (jQuery.isReady) return;
2312 for (var i = 0; i < document.styleSheets.length; i++)
2313 if (document.styleSheets[i].disabled) {
2314 setTimeout( arguments.callee, 0 );
2317 // and execute any waiting functions
2321 if ( jQuery.browser.safari ) {
2324 if (jQuery.isReady) return;
2325 if ( document.readyState != "loaded" && document.readyState != "complete" ) {
2326 setTimeout( arguments.callee, 0 );
2329 if ( numStyles === undefined )
2330 numStyles = jQuery("style, link[rel=stylesheet]").length;
2331 if ( document.styleSheets.length != numStyles ) {
2332 setTimeout( arguments.callee, 0 );
2335 // and execute any waiting functions
2340 // A fallback to window.onload, that will always work
2341 jQuery.event.add( window, "load", jQuery.ready );
2344 jQuery.each( ("blur,focus,load,resize,scroll,unload,click,dblclick," +
2345 "mousedown,mouseup,mousemove,mouseover,mouseout,change,select," +
2346 "submit,keydown,keypress,keyup,error").split(","), function(i, name){
2348 // Handle event binding
2349 jQuery.fn[name] = function(fn){
2350 return fn ? this.bind(name, fn) : this.trigger(name);
2354 // Checks if an event happened on an element within another element
2355 // Used in jQuery.event.special.mouseenter and mouseleave handlers
2356 var withinElement = function(event, elem) {
2357 // Check if mouse(over|out) are still within the same parent element
2358 var parent = event.relatedTarget;
2359 // Traverse up the tree
2360 while ( parent && parent != elem ) try { parent = parent.parentNode; } catch(error) { parent = elem; }
2361 // Return true if we actually just moused on to a sub-element
2362 return parent == elem;
2365 // Prevent memory leaks in IE
2366 // And prevent errors on refresh with events like mouseover in other browsers
2367 // Window isn't included so as not to unbind existing unload events
2368 jQuery(window).bind("unload", function() {
2369 jQuery("*").add(document).unbind();
2372 load: function( url, params, callback ) {
2373 if ( jQuery.isFunction( url ) )
2374 return this.bind("load", url);
2376 var off = url.indexOf(" ");
2378 var selector = url.slice(off, url.length);
2379 url = url.slice(0, off);
2382 callback = callback || function(){};
2384 // Default to a GET request
2387 // If the second parameter was provided
2389 // If it's a function
2390 if ( jQuery.isFunction( params ) ) {
2391 // We assume that it's the callback
2395 // Otherwise, build a param string
2397 params = jQuery.param( params );
2403 // Request the remote document
2409 complete: function(res, status){
2410 // If successful, inject the HTML into all the matched elements
2411 if ( status == "success" || status == "notmodified" )
2412 // See if a selector was specified
2413 self.html( selector ?
2414 // Create a dummy div to hold the results
2416 // inject the contents of the document in, removing the scripts
2417 // to avoid any 'Permission Denied' errors in IE
2418 .append(res.responseText.replace(/<script(.|\s)*?\/script>/g, ""))
2420 // Locate the specified elements
2423 // If not, just inject the full result
2426 self.each( callback, [res.responseText, status, res] );
2432 serialize: function() {
2433 return jQuery.param(this.serializeArray());
2435 serializeArray: function() {
2436 return this.map(function(){
2437 return jQuery.nodeName(this, "form") ?
2438 jQuery.makeArray(this.elements) : this;
2441 return this.name && !this.disabled &&
2442 (this.checked || /select|textarea/i.test(this.nodeName) ||
2443 /text|hidden|password/i.test(this.type));
2445 .map(function(i, elem){
2446 var val = jQuery(this).val();
2447 return val == null ? null :
2448 val.constructor == Array ?
2449 jQuery.map( val, function(val, i){
2450 return {name: elem.name, value: val};
2452 {name: elem.name, value: val};
2457 // Attach a bunch of functions for handling common AJAX events
2458 jQuery.each( "ajaxStart,ajaxStop,ajaxComplete,ajaxError,ajaxSuccess,ajaxSend".split(","), function(i,o){
2459 jQuery.fn[o] = function(f){
2460 return this.bind(o, f);
2464 var jsc = (new Date).getTime();
2467 get: function( url, data, callback, type ) {
2468 // shift arguments if data argument was ommited
2469 if ( jQuery.isFunction( data ) ) {
2474 return jQuery.ajax({
2483 getScript: function( url, callback ) {
2484 return jQuery.get(url, null, callback, "script");
2487 getJSON: function( url, data, callback ) {
2488 return jQuery.get(url, data, callback, "json");
2491 post: function( url, data, callback, type ) {
2492 if ( jQuery.isFunction( data ) ) {
2497 return jQuery.ajax({
2506 ajaxSetup: function( settings ) {
2507 jQuery.extend( jQuery.ajaxSettings, settings );
2514 contentType: "application/x-www-form-urlencoded",
2521 xml: "application/xml, text/xml",
2523 script: "text/javascript, application/javascript",
2524 json: "application/json, text/javascript",
2530 // Last-Modified header cache for next request
2533 ajax: function( s ) {
2534 var jsonp, jsre = /=\?(&|$)/g, status, data;
2536 // Extend the settings, but re-extend 's' so that it can be
2537 // checked again later (in the test suite, specifically)
2538 s = jQuery.extend(true, s, jQuery.extend(true, {}, jQuery.ajaxSettings, s));
2540 // convert data if not already a string
2541 if ( s.data && s.processData && typeof s.data != "string" )
2542 s.data = jQuery.param(s.data);
2544 // Handle JSONP Parameter Callbacks
2545 if ( s.dataType == "jsonp" ) {
2546 if ( s.type.toLowerCase() == "get" ) {
2547 if ( !s.url.match(jsre) )
2548 s.url += (s.url.match(/\?/) ? "&" : "?") + (s.jsonp || "callback") + "=?";
2549 } else if ( !s.data || !s.data.match(jsre) )
2550 s.data = (s.data ? s.data + "&" : "") + (s.jsonp || "callback") + "=?";
2551 s.dataType = "json";
2554 // Build temporary JSONP function
2555 if ( s.dataType == "json" && (s.data && s.data.match(jsre) || s.url.match(jsre)) ) {
2556 jsonp = "jsonp" + jsc++;
2558 // Replace the =? sequence both in the query string and the data
2560 s.data = (s.data + "").replace(jsre, "=" + jsonp + "$1");
2561 s.url = s.url.replace(jsre, "=" + jsonp + "$1");
2563 // We need to make sure
2564 // that a JSONP style response is executed properly
2565 s.dataType = "script";
2567 // Handle JSONP-style loading
2568 window[ jsonp ] = function(tmp){
2573 window[ jsonp ] = undefined;
2574 try{ delete window[ jsonp ]; } catch(e){}
2576 head.removeChild( script );
2580 if ( s.dataType == "script" && s.cache == null )
2583 if ( s.cache === false && s.type.toLowerCase() == "get" ) {
2584 var ts = (new Date()).getTime();
2585 // try replacing _= if it is there
2586 var ret = s.url.replace(/(\?|&)_=.*?(&|$)/, "$1_=" + ts + "$2");
2587 // if nothing was replaced, add timestamp to the end
2588 s.url = ret + ((ret == s.url) ? (s.url.match(/\?/) ? "&" : "?") + "_=" + ts : "");
2591 // If data is available, append data to url for get requests
2592 if ( s.data && s.type.toLowerCase() == "get" ) {
2593 s.url += (s.url.match(/\?/) ? "&" : "?") + s.data;
2595 // IE likes to send both get and post data, prevent this
2599 // Watch for a new set of requests
2600 if ( s.global && ! jQuery.active++ )
2601 jQuery.event.trigger( "ajaxStart" );
2603 // If we're requesting a remote document
2604 // and trying to load JSON or Script with a GET
2605 if ( (!s.url.indexOf("http") || !s.url.indexOf("//")) && ( s.dataType == "script" || s.dataType =="json" ) && s.type.toLowerCase() == "get" ) {
2606 var head = document.getElementsByTagName("head")[0];
2607 var script = document.createElement("script");
2609 if (s.scriptCharset)
2610 script.charset = s.scriptCharset;
2612 // Handle Script loading
2616 // Attach handlers for all browsers
2617 script.onload = script.onreadystatechange = function(){
2618 if ( !done && (!this.readyState ||
2619 this.readyState == "loaded" || this.readyState == "complete") ) {
2623 head.removeChild( script );
2628 head.appendChild(script);
2630 // We handle everything using the script element injection
2634 var requestDone = false;
2636 // Create the request object; Microsoft failed to properly
2637 // implement the XMLHttpRequest in IE7, so we use the ActiveXObject when it is available
2638 var xml = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
2641 xml.open(s.type, s.url, s.async, s.username, s.password);
2643 // Need an extra try/catch for cross domain requests in Firefox 3
2645 // Set the correct header, if data is being sent
2647 xml.setRequestHeader("Content-Type", s.contentType);
2649 // Set the If-Modified-Since header, if ifModified mode.
2651 xml.setRequestHeader("If-Modified-Since",
2652 jQuery.lastModified[s.url] || "Thu, 01 Jan 1970 00:00:00 GMT" );
2654 // Set header so the called script knows that it's an XMLHttpRequest
2655 xml.setRequestHeader("X-Requested-With", "XMLHttpRequest");
2657 // Set the Accepts header for the server, depending on the dataType
2658 xml.setRequestHeader("Accept", s.dataType && s.accepts[ s.dataType ] ?
2659 s.accepts[ s.dataType ] + ", */*" :
2660 s.accepts._default );
2663 // Allow custom headers/mimetypes
2668 jQuery.event.trigger("ajaxSend", [xml, s]);
2670 // Wait for a response to come back
2671 var onreadystatechange = function(isTimeout){
2672 // The transfer is complete and the data is available, or the request timed out
2673 if ( !requestDone && xml && (xml.readyState == 4 || isTimeout == "timeout") ) {
2676 // clear poll interval
2678 clearInterval(ival);
2682 status = isTimeout == "timeout" && "timeout" ||
2683 !jQuery.httpSuccess( xml ) && "error" ||
2684 s.ifModified && jQuery.httpNotModified( xml, s.url ) && "notmodified" ||
2687 if ( status == "success" ) {
2688 // Watch for, and catch, XML document parse errors
2690 // process the data (runs the xml through httpData regardless of callback)
2691 data = jQuery.httpData( xml, s.dataType );
2693 status = "parsererror";
2697 // Make sure that the request was successful or notmodified
2698 if ( status == "success" ) {
2699 // Cache Last-Modified header, if ifModified mode.
2702 modRes = xml.getResponseHeader("Last-Modified");
2703 } catch(e) {} // swallow exception thrown by FF if header is not available
2705 if ( s.ifModified && modRes )
2706 jQuery.lastModified[s.url] = modRes;
2708 // JSONP handles its own success callback
2712 jQuery.handleError(s, xml, status);
2714 // Fire the complete handlers
2717 // Stop memory leaks
2724 // don't attach the handler to the request, just poll it instead
2725 var ival = setInterval(onreadystatechange, 13);
2728 if ( s.timeout > 0 )
2729 setTimeout(function(){
2730 // Check to see if the request is still happening
2732 // Cancel the request
2736 onreadystatechange( "timeout" );
2745 jQuery.handleError(s, xml, null, e);
2748 // firefox 1.5 doesn't fire statechange for sync requests
2750 onreadystatechange();
2753 // If a local callback was specified, fire it and pass it the data
2755 s.success( data, status );
2757 // Fire the global callback
2759 jQuery.event.trigger( "ajaxSuccess", [xml, s] );
2762 function complete(){
2765 s.complete(xml, status);
2767 // The request was completed
2769 jQuery.event.trigger( "ajaxComplete", [xml, s] );
2771 // Handle the global AJAX counter
2772 if ( s.global && ! --jQuery.active )
2773 jQuery.event.trigger( "ajaxStop" );
2776 // return XMLHttpRequest to allow aborting the request etc.
2780 handleError: function( s, xml, status, e ) {
2781 // If a local callback was specified, fire it
2782 if ( s.error ) s.error( xml, status, e );
2784 // Fire the global callback
2786 jQuery.event.trigger( "ajaxError", [xml, s, e] );
2789 // Counter for holding the number of active queries
2792 // Determines if an XMLHttpRequest was successful or not
2793 httpSuccess: function( r ) {
2795 // IE error sometimes returns 1223 when it should be 204 so treat it as success, see #1450
2796 return !r.status && location.protocol == "file:" ||
2797 ( r.status >= 200 && r.status < 300 ) || r.status == 304 || r.status == 1223 ||
2798 jQuery.browser.safari && r.status == undefined;
2803 // Determines if an XMLHttpRequest returns NotModified
2804 httpNotModified: function( xml, url ) {
2806 var xmlRes = xml.getResponseHeader("Last-Modified");
2808 // Firefox always returns 200. check Last-Modified date
2809 return xml.status == 304 || xmlRes == jQuery.lastModified[url] ||
2810 jQuery.browser.safari && xml.status == undefined;
2815 httpData: function( r, type ) {
2816 var ct = r.getResponseHeader("content-type");
2817 var xml = type == "xml" || !type && ct && ct.indexOf("xml") >= 0;
2818 var data = xml ? r.responseXML : r.responseText;
2820 if ( xml && data.documentElement.tagName == "parsererror" )
2821 throw "parsererror";
2823 // If the type is "script", eval it in global context
2824 if ( type == "script" )
2825 jQuery.globalEval( data );
2827 // Get the JavaScript object, if JSON is used.
2828 if ( type == "json" )
2829 data = eval("(" + data + ")");
2834 // Serialize an array of form elements or a set of
2835 // key/values into a query string
2836 param: function( a ) {
2839 // If an array was passed in, assume that it is an array
2841 if ( a.constructor == Array || a.jquery )
2842 // Serialize the form elements
2843 jQuery.each( a, function(){
2844 s.push( encodeURIComponent(this.name) + "=" + encodeURIComponent( this.value ) );
2847 // Otherwise, assume that it's an object of key/value pairs
2849 // Serialize the key/values
2851 // If the value is an array then the key names need to be repeated
2852 if ( a[j] && a[j].constructor == Array )
2853 jQuery.each( a[j], function(){
2854 s.push( encodeURIComponent(j) + "=" + encodeURIComponent( this ) );
2857 s.push( encodeURIComponent(j) + "=" + encodeURIComponent( a[j] ) );
2859 // Return the resulting serialization
2860 return s.join("&").replace(/%20/g, "+");
2865 show: function(speed,callback){
2868 height: "show", width: "show", opacity: "show"
2869 }, speed, callback) :
2871 this.filter(":hidden").each(function(){
2872 this.style.display = this.oldblock || "";
2873 if ( jQuery.css(this,"display") == "none" ) {
2874 var elem = jQuery("<" + this.tagName + " />").appendTo("body");
2875 this.style.display = elem.css("display");
2876 // handle an edge condition where css is - div { display:none; } or similar
2877 if (this.style.display == "none")
2878 this.style.display = "block";
2884 hide: function(speed,callback){
2887 height: "hide", width: "hide", opacity: "hide"
2888 }, speed, callback) :
2890 this.filter(":visible").each(function(){
2891 this.oldblock = this.oldblock || jQuery.css(this,"display");
2892 this.style.display = "none";
2896 // Save the old toggle function
2897 _toggle: jQuery.fn.toggle,
2899 toggle: function( fn, fn2 ){
2900 return jQuery.isFunction(fn) && jQuery.isFunction(fn2) ?
2901 this._toggle( fn, fn2 ) :
2904 height: "toggle", width: "toggle", opacity: "toggle"
2906 this.each(function(){
2907 jQuery(this)[ jQuery(this).is(":hidden") ? "show" : "hide" ]();
2911 slideDown: function(speed,callback){
2912 return this.animate({height: "show"}, speed, callback);
2915 slideUp: function(speed,callback){
2916 return this.animate({height: "hide"}, speed, callback);
2919 slideToggle: function(speed, callback){
2920 return this.animate({height: "toggle"}, speed, callback);
2923 fadeIn: function(speed, callback){
2924 return this.animate({opacity: "show"}, speed, callback);
2927 fadeOut: function(speed, callback){
2928 return this.animate({opacity: "hide"}, speed, callback);
2931 fadeTo: function(speed,to,callback){
2932 return this.animate({opacity: to}, speed, callback);
2935 animate: function( prop, speed, easing, callback ) {
2936 var optall = jQuery.speed(speed, easing, callback);
2938 return this[ optall.queue === false ? "each" : "queue" ](function(){
2939 if ( this.nodeType != 1)
2942 var opt = jQuery.extend({}, optall);
2943 var hidden = jQuery(this).is(":hidden"), self = this;
2945 for ( var p in prop ) {
2946 if ( prop[p] == "hide" && hidden || prop[p] == "show" && !hidden )
2947 return jQuery.isFunction(opt.complete) && opt.complete.apply(this);
2949 if ( p == "height" || p == "width" ) {
2950 // Store display property
2951 opt.display = jQuery.css(this, "display");
2953 // Make sure that nothing sneaks out
2954 opt.overflow = this.style.overflow;
2958 if ( opt.overflow != null )
2959 this.style.overflow = "hidden";
2961 opt.curAnim = jQuery.extend({}, prop);
2963 jQuery.each( prop, function(name, val){
2964 var e = new jQuery.fx( self, opt, name );
2966 if ( /toggle|show|hide/.test(val) )
2967 e[ val == "toggle" ? hidden ? "show" : "hide" : val ]( prop );
2969 var parts = val.toString().match(/^([+-]=)?([\d+-.]+)(.*)$/),
2970 start = e.cur(true) || 0;
2973 var end = parseFloat(parts[2]),
2974 unit = parts[3] || "px";
2976 // We need to compute starting value
2977 if ( unit != "px" ) {
2978 self.style[ name ] = (end || 1) + unit;
2979 start = ((end || 1) / e.cur(true)) * start;
2980 self.style[ name ] = start + unit;
2983 // If a +=/-= token was provided, we're doing a relative animation
2985 end = ((parts[1] == "-=" ? -1 : 1) * end) + start;
2987 e.custom( start, end, unit );
2989 e.custom( start, val, "" );
2993 // For JS strict compliance
2998 queue: function(type, fn){
2999 if ( jQuery.isFunction(type) || ( type && type.constructor == Array )) {
3004 if ( !type || (typeof type == "string" && !fn) )
3005 return queue( this[0], type );
3007 return this.each(function(){
3008 if ( fn.constructor == Array )
3009 queue(this, type, fn);
3011 queue(this, type).push( fn );
3013 if ( queue(this, type).length == 1 )
3019 stop: function(clearQueue, gotoEnd){
3020 var timers = jQuery.timers;
3025 this.each(function(){
3026 // go in reverse order so anything added to the queue during the loop is ignored
3027 for ( var i = timers.length - 1; i >= 0; i-- )
3028 if ( timers[i].elem == this ) {
3030 // force the next step to be the last
3032 timers.splice(i, 1);
3036 // start the next in the queue if the last step wasn't forced
3045 var queue = function( elem, type, array ) {
3049 type = type || "fx";
3051 var q = jQuery.data( elem, type + "queue" );
3054 q = jQuery.data( elem, type + "queue",
3055 array ? jQuery.makeArray(array) : [] );
3060 jQuery.fn.dequeue = function(type){
3061 type = type || "fx";
3063 return this.each(function(){
3064 var q = queue(this, type);
3075 speed: function(speed, easing, fn) {
3076 var opt = speed && speed.constructor == Object ? speed : {
3077 complete: fn || !fn && easing ||
3078 jQuery.isFunction( speed ) && speed,
3080 easing: fn && easing || easing && easing.constructor != Function && easing
3083 opt.duration = (opt.duration && opt.duration.constructor == Number ?
3085 { slow: 600, fast: 200 }[opt.duration]) || 400;
3088 opt.old = opt.complete;
3089 opt.complete = function(){
3090 if ( opt.queue !== false )
3091 jQuery(this).dequeue();
3092 if ( jQuery.isFunction( opt.old ) )
3093 opt.old.apply( this );
3100 linear: function( p, n, firstNum, diff ) {
3101 return firstNum + diff * p;
3103 swing: function( p, n, firstNum, diff ) {
3104 return ((-Math.cos(p*Math.PI)/2) + 0.5) * diff + firstNum;
3111 fx: function( elem, options, prop ){
3112 this.options = options;
3116 if ( !options.orig )
3122 jQuery.fx.prototype = {
3124 // Simple function for setting a style value
3126 if ( this.options.step )
3127 this.options.step.apply( this.elem, [ this.now, this ] );
3129 (jQuery.fx.step[this.prop] || jQuery.fx.step._default)( this );
3131 // Set display property to block for height/width animations
3132 if ( this.prop == "height" || this.prop == "width" )
3133 this.elem.style.display = "block";
3136 // Get the current size
3137 cur: function(force){
3138 if ( this.elem[this.prop] != null && this.elem.style[this.prop] == null )
3139 return this.elem[ this.prop ];
3141 var r = parseFloat(jQuery.css(this.elem, this.prop, force));
3142 return r && r > -10000 ? r : parseFloat(jQuery.curCSS(this.elem, this.prop)) || 0;
3145 // Start an animation from one number to another
3146 custom: function(from, to, unit){
3147 this.startTime = (new Date()).getTime();
3150 this.unit = unit || this.unit || "px";
3151 this.now = this.start;
3152 this.pos = this.state = 0;
3156 function t(gotoEnd){
3157 return self.step(gotoEnd);
3162 jQuery.timers.push(t);
3164 if ( jQuery.timerId == null ) {
3165 jQuery.timerId = setInterval(function(){
3166 var timers = jQuery.timers;
3168 for ( var i = 0; i < timers.length; i++ )
3170 timers.splice(i--, 1);
3172 if ( !timers.length ) {
3173 clearInterval( jQuery.timerId );
3174 jQuery.timerId = null;
3180 // Simple 'show' function
3182 // Remember where we started, so that we can go back to it later
3183 this.options.orig[this.prop] = jQuery.attr( this.elem.style, this.prop );
3184 this.options.show = true;
3186 // Begin the animation
3187 this.custom(0, this.cur());
3189 // Make sure that we start at a small width/height to avoid any
3191 if ( this.prop == "width" || this.prop == "height" )
3192 this.elem.style[this.prop] = "1px";
3194 // Start by showing the element
3195 jQuery(this.elem).show();
3198 // Simple 'hide' function
3200 // Remember where we started, so that we can go back to it later
3201 this.options.orig[this.prop] = jQuery.attr( this.elem.style, this.prop );
3202 this.options.hide = true;
3204 // Begin the animation
3205 this.custom(this.cur(), 0);
3208 // Each step of an animation
3209 step: function(gotoEnd){
3210 var t = (new Date()).getTime();
3212 if ( gotoEnd || t > this.options.duration + this.startTime ) {
3213 this.now = this.end;
3214 this.pos = this.state = 1;
3217 this.options.curAnim[ this.prop ] = true;
3220 for ( var i in this.options.curAnim )
3221 if ( this.options.curAnim[i] !== true )
3225 if ( this.options.display != null ) {
3226 // Reset the overflow
3227 this.elem.style.overflow = this.options.overflow;
3229 // Reset the display
3230 this.elem.style.display = this.options.display;
3231 if ( jQuery.css(this.elem, "display") == "none" )
3232 this.elem.style.display = "block";
3235 // Hide the element if the "hide" operation was done
3236 if ( this.options.hide )
3237 this.elem.style.display = "none";
3239 // Reset the properties, if the item has been hidden or shown
3240 if ( this.options.hide || this.options.show )
3241 for ( var p in this.options.curAnim )
3242 jQuery.attr(this.elem.style, p, this.options.orig[p]);
3245 // If a callback was provided, execute it
3246 if ( done && jQuery.isFunction( this.options.complete ) )
3247 // Execute the complete function
3248 this.options.complete.apply( this.elem );
3252 var n = t - this.startTime;
3253 this.state = n / this.options.duration;
3255 // Perform the easing function, defaults to swing
3256 this.pos = jQuery.easing[this.options.easing || (jQuery.easing.swing ? "swing" : "linear")](this.state, n, 0, 1, this.options.duration);
3257 this.now = this.start + ((this.end - this.start) * this.pos);
3259 // Perform the next step of the animation
3269 scrollLeft: function(fx){
3270 fx.elem.scrollLeft = fx.now;
3273 scrollTop: function(fx){
3274 fx.elem.scrollTop = fx.now;
3277 opacity: function(fx){
3278 jQuery.attr(fx.elem.style, "opacity", fx.now);
3281 _default: function(fx){
3282 fx.elem.style[ fx.prop ] = fx.now + fx.unit;
3285 // The Offset Method
3286 // Originally By Brandon Aaron, part of the Dimension Plugin
3287 // http://jquery.com/plugins/project/dimensions
3288 jQuery.fn.offset = function() {
3289 var left = 0, top = 0, elem = this[0], results;
3291 if ( elem ) with ( jQuery.browser ) {
3292 var parent = elem.parentNode,
3294 offsetParent = elem.offsetParent,
3295 doc = elem.ownerDocument,
3296 safari2 = safari && parseInt(version) < 522,
3297 fixed = jQuery.css(elem, "position") == "fixed";
3299 // Use getBoundingClientRect if available
3300 if ( elem.getBoundingClientRect ) {
3301 var box = elem.getBoundingClientRect();
3303 // Add the document scroll offsets
3304 add(box.left + Math.max(doc.documentElement.scrollLeft, doc.body.scrollLeft),
3305 box.top + Math.max(doc.documentElement.scrollTop, doc.body.scrollTop));
3307 // IE adds the HTML element's border, by default it is medium which is 2px
3308 // IE 6 and 7 quirks mode the border width is overwritable by the following css html { border: 0; }
3309 // IE 7 standards mode, the border is always 2px
3310 // This border/offset is typically represented by the clientLeft and clientTop properties
3311 // However, in IE6 and 7 quirks mode the clientLeft and clientTop properties are not updated when overwriting it via CSS
3312 // Therefore this method will be off by 2px in IE while in quirksmode
3313 add( -doc.documentElement.clientLeft, -doc.documentElement.clientTop );
3315 // Otherwise loop through the offsetParents and parentNodes
3318 // Initial element offsets
3319 add( elem.offsetLeft, elem.offsetTop );
3321 // Get parent offsets
3322 while ( offsetParent ) {
3323 // Add offsetParent offsets
3324 add( offsetParent.offsetLeft, offsetParent.offsetTop );
3326 // Mozilla and Safari > 2 does not include the border on offset parents
3327 // However Mozilla adds the border for table or table cells
3328 if ( mozilla && !/^t(able|d|h)$/i.test(offsetParent.tagName) || safari && !safari2 )
3329 border( offsetParent );
3331 // Add the document scroll offsets if position is fixed on any offsetParent
3332 if ( !fixed && jQuery.css(offsetParent, "position") == "fixed" )
3335 // Set offsetChild to previous offsetParent unless it is the body element
3336 offsetChild = /^body$/i.test(offsetParent.tagName) ? offsetChild : offsetParent;
3337 // Get next offsetParent
3338 offsetParent = offsetParent.offsetParent;
3341 // Get parent scroll offsets
3342 while ( parent && parent.tagName && !/^body|html$/i.test(parent.tagName) ) {
3343 // Remove parent scroll UNLESS that parent is inline or a table to work around Opera inline/table scrollLeft/Top bug
3344 if ( !/^inline|table.*$/i.test(jQuery.css(parent, "display")) )
3345 // Subtract parent scroll offsets
3346 add( -parent.scrollLeft, -parent.scrollTop );
3348 // Mozilla does not add the border for a parent that has overflow != visible
3349 if ( mozilla && jQuery.css(parent, "overflow") != "visible" )
3353 parent = parent.parentNode;
3356 // Safari <= 2 doubles body offsets with a fixed position element/offsetParent or absolutely positioned offsetChild
3357 // Mozilla doubles body offsets with a non-absolutely positioned offsetChild
3358 if ( (safari2 && (fixed || jQuery.css(offsetChild, "position") == "absolute")) ||
3359 (mozilla && jQuery.css(offsetChild, "position") != "absolute") )
3360 add( -doc.body.offsetLeft, -doc.body.offsetTop );
3362 // Add the document scroll offsets if position is fixed
3364 add(Math.max(doc.documentElement.scrollLeft, doc.body.scrollLeft),
3365 Math.max(doc.documentElement.scrollTop, doc.body.scrollTop));
3368 // Return an object with top and left properties
3369 results = { top: top, left: left };
3372 function border(elem) {
3373 add( jQuery.curCSS(elem, "borderLeftWidth", true), jQuery.curCSS(elem, "borderTopWidth", true) );
3376 function add(l, t) {
3377 left += parseInt(l) || 0;
3378 top += parseInt(t) || 0;