3 * jQuery 1.2.3 - New Wave Javascript
5 * Copyright (c) 2008 John Resig (jquery.com)
6 * Dual licensed under the MIT (MIT-LICENSE.txt)
7 * and GPL (GPL-LICENSE.txt) licenses.
9 * $Date: 2008-02-06 00:21:25 -0500 (Wed, 06 Feb 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 container.appendChild(clone);
309 return jQuery.clean([container.innerHTML])[0];
311 return this.cloneNode(true);
314 // Need to set the expando to null on the cloned set if it exists
315 // removeData doesn't work here, IE removes it from the original as well
316 // this is primarily for IE but the data expando shouldn't be copied over in any browser
317 var clone = ret.find("*").andSelf().each(function(){
318 if ( this[ expando ] != undefined )
319 this[ expando ] = null;
322 // Copy the events from the original to the clone
323 if ( events === true )
324 this.find("*").andSelf().each(function(i){
325 if (this.nodeType == 3)
327 var events = jQuery.data( this, "events" );
329 for ( var type in events )
330 for ( var handler in events[ type ] )
331 jQuery.event.add( clone[ i ], type, events[ type ][ handler ], events[ type ][ handler ].data );
334 // Return the cloned set
338 filter: function( selector ) {
339 return this.pushStack(
340 jQuery.isFunction( selector ) &&
341 jQuery.grep(this, function(elem, i){
342 return selector.call( elem, i );
345 jQuery.multiFilter( selector, this ) );
348 not: function( selector ) {
349 if ( selector.constructor == String )
350 // test special case where just one selector is passed in
351 if ( isSimple.test( selector ) )
352 return this.pushStack( jQuery.multiFilter( selector, this, true ) );
354 selector = jQuery.multiFilter( selector, this );
356 var isArrayLike = selector.length && selector[selector.length - 1] !== undefined && !selector.nodeType;
357 return this.filter(function() {
358 return isArrayLike ? jQuery.inArray( this, selector ) < 0 : this != selector;
362 add: function( selector ) {
363 return !selector ? this : this.pushStack( jQuery.merge(
365 selector.constructor == String ?
366 jQuery( selector ).get() :
367 selector.length != undefined && (!selector.nodeName || jQuery.nodeName(selector, "form")) ?
368 selector : [selector] ) );
371 is: function( selector ) {
373 jQuery.multiFilter( selector, this ).length > 0 :
377 hasClass: function( selector ) {
378 return this.is( "." + selector );
381 val: function( value ) {
382 if ( value == undefined ) {
387 // We need to handle select boxes special
388 if ( jQuery.nodeName( elem, "select" ) ) {
389 var index = elem.selectedIndex,
391 options = elem.options,
392 one = elem.type == "select-one";
394 // Nothing was selected
398 // Loop through all the selected options
399 for ( var i = one ? index : 0, max = one ? index + 1 : options.length; i < max; i++ ) {
400 var option = options[ i ];
402 if ( option.selected ) {
403 // Get the specifc value for the option
404 value = jQuery.browser.msie && !option.attributes.value.specified ? option.text : option.value;
406 // We don't need an array for one selects
410 // Multi-Selects return an array
411 values.push( value );
417 // Everything else, we just grab the value
419 return (this[0].value || "").replace(/\r/g, "");
426 return this.each(function(){
427 if ( this.nodeType != 1 )
430 if ( value.constructor == Array && /radio|checkbox/.test( this.type ) )
431 this.checked = (jQuery.inArray(this.value, value) >= 0 ||
432 jQuery.inArray(this.name, value) >= 0);
434 else if ( jQuery.nodeName( this, "select" ) ) {
435 var values = value.constructor == Array ?
439 jQuery( "option", this ).each(function(){
440 this.selected = (jQuery.inArray( this.value, values ) >= 0 ||
441 jQuery.inArray( this.text, values ) >= 0);
444 if ( !values.length )
445 this.selectedIndex = -1;
452 html: function( value ) {
453 return value == undefined ?
457 this.empty().append( value );
460 replaceWith: function( value ) {
461 return this.after( value ).remove();
465 return this.slice( i, i + 1 );
469 return this.pushStack( Array.prototype.slice.apply( this, arguments ) );
472 map: function( callback ) {
473 return this.pushStack( jQuery.map(this, function(elem, i){
474 return callback.call( elem, i, elem );
478 andSelf: function() {
479 return this.add( this.prevObject );
482 data: function( key, value ){
483 var parts = key.split(".");
484 parts[1] = parts[1] ? "." + parts[1] : "";
486 if ( value == null ) {
487 var data = this.triggerHandler("getData" + parts[1] + "!", [parts[0]]);
489 if ( data == undefined && this.length )
490 data = jQuery.data( this[0], key );
492 return data == null && parts[1] ?
493 this.data( parts[0] ) :
496 return this.trigger("setData" + parts[1] + "!", [parts[0], value]).each(function(){
497 jQuery.data( this, key, value );
501 removeData: function( key ){
502 return this.each(function(){
503 jQuery.removeData( this, key );
507 domManip: function( args, table, reverse, callback ) {
508 var clone = this.length > 1, elems;
510 return this.each(function(){
512 elems = jQuery.clean( args, this.ownerDocument );
520 if ( table && jQuery.nodeName( this, "table" ) && jQuery.nodeName( elems[0], "tr" ) )
521 obj = this.getElementsByTagName("tbody")[0] || this.appendChild( this.ownerDocument.createElement("tbody") );
523 var scripts = jQuery( [] );
525 jQuery.each(elems, function(){
527 jQuery( this ).clone( true )[0] :
530 // execute all scripts after the elements have been injected
531 if ( jQuery.nodeName( elem, "script" ) ) {
532 scripts = scripts.add( elem );
534 // Remove any inner scripts for later evaluation
535 if ( elem.nodeType == 1 )
536 scripts = scripts.add( jQuery( "script", elem ).remove() );
538 // Inject the elements into the document
539 callback.call( obj, elem );
543 scripts.each( evalScript );
548 // Give the init function the jQuery prototype for later instantiation
549 jQuery.prototype.init.prototype = jQuery.prototype;
551 function evalScript( i, elem ) {
560 jQuery.globalEval( elem.text || elem.textContent || elem.innerHTML || "" );
562 if ( elem.parentNode )
563 elem.parentNode.removeChild( elem );
566 jQuery.extend = jQuery.fn.extend = function() {
567 // copy reference to target object
568 var target = arguments[0] || {}, i = 1, length = arguments.length, deep = false, options;
570 // Handle a deep copy situation
571 if ( target.constructor == Boolean ) {
573 target = arguments[1] || {};
574 // skip the boolean and the target
578 // Handle case when target is a string or something (possible in deep copy)
579 if ( typeof target != "object" && typeof target != "function" )
582 // extend jQuery itself if only one argument is passed
588 for ( ; i < length; i++ )
589 // Only deal with non-null/undefined values
590 if ( (options = arguments[ i ]) != null )
591 // Extend the base object
592 for ( var name in options ) {
593 // Prevent never-ending loop
594 if ( target === options[ name ] )
597 // Recurse if we're merging object values
598 if ( deep && options[ name ] && typeof options[ name ] == "object" && target[ name ] && !options[ name ].nodeType )
599 target[ name ] = jQuery.extend( target[ name ], options[ name ] );
601 // Don't bring in undefined values
602 else if ( options[ name ] != undefined )
603 target[ name ] = options[ name ];
607 // Return the modified object
611 var expando = "jQuery" + (new Date()).getTime(), uuid = 0, windowData = {};
613 // exclude the following css properties to add px
614 var exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i;
617 noConflict: function( deep ) {
621 window.jQuery = _jQuery;
626 // See test/unit/core.js for details concerning this function.
627 isFunction: function( fn ) {
628 return !!fn && typeof fn != "string" && !fn.nodeName &&
629 fn.constructor != Array && /function/i.test( fn + "" );
632 // check if an element is in a (or is an) XML document
633 isXMLDoc: function( elem ) {
634 return elem.documentElement && !elem.body ||
635 elem.tagName && elem.ownerDocument && !elem.ownerDocument.body;
638 // Evalulates a script in a global context
639 globalEval: function( data ) {
640 data = jQuery.trim( data );
643 // Inspired by code by Andrea Giammarchi
644 // http://webreflection.blogspot.com/2007/08/global-scope-evaluation-and-dom.html
645 var head = document.getElementsByTagName("head")[0] || document.documentElement,
646 script = document.createElement("script");
648 script.type = "text/javascript";
649 if ( jQuery.browser.msie )
652 script.appendChild( document.createTextNode( data ) );
654 head.appendChild( script );
655 head.removeChild( script );
659 nodeName: function( elem, name ) {
660 return elem.nodeName && elem.nodeName.toUpperCase() == name.toUpperCase();
665 data: function( elem, name, data ) {
666 elem = elem == window ?
670 var id = elem[ expando ];
672 // Compute a unique ID for the element
674 id = elem[ expando ] = ++uuid;
676 // Only generate the data cache if we're
677 // trying to access or manipulate it
678 if ( name && !jQuery.cache[ id ] )
679 jQuery.cache[ id ] = {};
681 // Prevent overriding the named cache with undefined values
682 if ( data != undefined )
683 jQuery.cache[ id ][ name ] = data;
685 // Return the named cache data, or the ID for the element
687 jQuery.cache[ id ][ name ] :
691 removeData: function( elem, name ) {
692 elem = elem == window ?
696 var id = elem[ expando ];
698 // If we want to remove a specific section of the element's data
700 if ( jQuery.cache[ id ] ) {
701 // Remove the section of cache data
702 delete jQuery.cache[ id ][ name ];
704 // If we've removed all the data, remove the element's cache
707 for ( name in jQuery.cache[ id ] )
711 jQuery.removeData( elem );
714 // Otherwise, we want to remove all of the element's data
716 // Clean up the element expando
718 delete elem[ expando ];
720 // IE has trouble directly removing the expando
721 // but it's ok with using removeAttribute
722 if ( elem.removeAttribute )
723 elem.removeAttribute( expando );
726 // Completely remove the data cache
727 delete jQuery.cache[ id ];
731 // args is for internal usage only
732 each: function( object, callback, args ) {
734 if ( object.length == undefined ) {
735 for ( var name in object )
736 if ( callback.apply( object[ name ], args ) === false )
739 for ( var i = 0, length = object.length; i < length; i++ )
740 if ( callback.apply( object[ i ], args ) === false )
743 // A special, fast, case for the most common use of each
745 if ( object.length == undefined ) {
746 for ( var name in object )
747 if ( callback.call( object[ name ], name, object[ name ] ) === false )
750 for ( var i = 0, length = object.length, value = object[0];
751 i < length && callback.call( value, i, value ) !== false; value = object[++i] ){}
757 prop: function( elem, value, type, i, name ) {
758 // Handle executable functions
759 if ( jQuery.isFunction( value ) )
760 value = value.call( elem, i );
762 // Handle passing in a number to a CSS property
763 return value && value.constructor == Number && type == "curCSS" && !exclude.test( name ) ?
769 // internal only, use addClass("class")
770 add: function( elem, classNames ) {
771 jQuery.each((classNames || "").split(/\s+/), function(i, className){
772 if ( elem.nodeType == 1 && !jQuery.className.has( elem.className, className ) )
773 elem.className += (elem.className ? " " : "") + className;
777 // internal only, use removeClass("class")
778 remove: function( elem, classNames ) {
779 if (elem.nodeType == 1)
780 elem.className = classNames != undefined ?
781 jQuery.grep(elem.className.split(/\s+/), function(className){
782 return !jQuery.className.has( classNames, className );
787 // internal only, use is(".class")
788 has: function( elem, className ) {
789 return jQuery.inArray( className, (elem.className || elem).toString().split(/\s+/) ) > -1;
793 // A method for quickly swapping in/out CSS properties to get correct calculations
794 swap: function( elem, options, callback ) {
796 // Remember the old values, and insert the new ones
797 for ( var name in options ) {
798 old[ name ] = elem.style[ name ];
799 elem.style[ name ] = options[ name ];
802 callback.call( elem );
804 // Revert the old values
805 for ( var name in options )
806 elem.style[ name ] = old[ name ];
809 css: function( elem, name, force ) {
810 if ( name == "width" || name == "height" ) {
811 var val, props = { position: "absolute", visibility: "hidden", display:"block" }, which = name == "width" ? [ "Left", "Right" ] : [ "Top", "Bottom" ];
814 val = name == "width" ? elem.offsetWidth : elem.offsetHeight;
815 var padding = 0, border = 0;
816 jQuery.each( which, function() {
817 padding += parseFloat(jQuery.curCSS( elem, "padding" + this, true)) || 0;
818 border += parseFloat(jQuery.curCSS( elem, "border" + this + "Width", true)) || 0;
820 val -= Math.round(padding + border);
823 if ( jQuery(elem).is(":visible") )
826 jQuery.swap( elem, props, getWH );
828 return Math.max(0, val);
831 return jQuery.curCSS( elem, name, force );
834 curCSS: function( elem, name, force ) {
837 // A helper method for determining if an element's values are broken
838 function color( elem ) {
839 if ( !jQuery.browser.safari )
842 var ret = document.defaultView.getComputedStyle( elem, null );
843 return !ret || ret.getPropertyValue("color") == "";
846 // We need to handle opacity special in IE
847 if ( name == "opacity" && jQuery.browser.msie ) {
848 ret = jQuery.attr( elem.style, "opacity" );
854 // Opera sometimes will give the wrong display answer, this fixes it, see #2037
855 if ( jQuery.browser.opera && name == "display" ) {
856 var save = elem.style.outline;
857 elem.style.outline = "0 solid black";
858 elem.style.outline = save;
861 // Make sure we're using the right name for getting the float value
862 if ( name.match( /float/i ) )
865 if ( !force && elem.style && elem.style[ name ] )
866 ret = elem.style[ name ];
868 else if ( document.defaultView && document.defaultView.getComputedStyle ) {
870 // Only "float" is needed here
871 if ( name.match( /float/i ) )
874 name = name.replace( /([A-Z])/g, "-$1" ).toLowerCase();
876 var getComputedStyle = document.defaultView.getComputedStyle( elem, null );
878 if ( getComputedStyle && !color( elem ) )
879 ret = getComputedStyle.getPropertyValue( name );
881 // If the element isn't reporting its values properly in Safari
882 // then some display: none elements are involved
884 var swap = [], stack = [];
886 // Locate all of the parent display: none elements
887 for ( var a = elem; a && color(a); a = a.parentNode )
890 // Go through and make them visible, but in reverse
891 // (It would be better if we knew the exact display type that they had)
892 for ( var i = 0; i < stack.length; i++ )
893 if ( color( stack[ i ] ) ) {
894 swap[ i ] = stack[ i ].style.display;
895 stack[ i ].style.display = "block";
898 // Since we flip the display style, we have to handle that
899 // one special, otherwise get the value
900 ret = name == "display" && swap[ stack.length - 1 ] != null ?
902 ( getComputedStyle && getComputedStyle.getPropertyValue( name ) ) || "";
904 // Finally, revert the display styles back
905 for ( var i = 0; i < swap.length; i++ )
906 if ( swap[ i ] != null )
907 stack[ i ].style.display = swap[ i ];
910 // We should always get a number back from opacity
911 if ( name == "opacity" && ret == "" )
914 } else if ( elem.currentStyle ) {
915 var camelCase = name.replace(/\-(\w)/g, function(all, letter){
916 return letter.toUpperCase();
919 ret = elem.currentStyle[ name ] || elem.currentStyle[ camelCase ];
921 // From the awesome hack by Dean Edwards
922 // http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291
924 // If we're not dealing with a regular pixel number
925 // but a number that has a weird ending, we need to convert it to pixels
926 if ( !/^\d+(px)?$/i.test( ret ) && /^\d/.test( ret ) ) {
927 // Remember the original values
928 var style = elem.style.left, runtimeStyle = elem.runtimeStyle.left;
930 // Put in the new values to get a computed value out
931 elem.runtimeStyle.left = elem.currentStyle.left;
932 elem.style.left = ret || 0;
933 ret = elem.style.pixelLeft + "px";
935 // Revert the changed values
936 elem.style.left = style;
937 elem.runtimeStyle.left = runtimeStyle;
944 clean: function( elems, context ) {
946 context = context || document;
947 // !context.createElement fails in IE with an error but returns typeof 'object'
948 if (typeof context.createElement == 'undefined')
949 context = context.ownerDocument || context[0] && context[0].ownerDocument || document;
951 jQuery.each(elems, function(i, elem){
955 if ( elem.constructor == Number )
956 elem = elem.toString();
958 // Convert html string into DOM nodes
959 if ( typeof elem == "string" ) {
960 // Fix "XHTML"-style tags in all browsers
961 elem = elem.replace(/(<(\w+)[^>]*?)\/>/g, function(all, front, tag){
962 return tag.match(/^(abbr|br|col|img|input|link|meta|param|hr|area|embed)$/i) ?
964 front + "></" + tag + ">";
967 // Trim whitespace, otherwise indexOf won't work as expected
968 var tags = jQuery.trim( elem ).toLowerCase(), div = context.createElement("div");
971 // option or optgroup
972 !tags.indexOf("<opt") &&
973 [ 1, "<select multiple='multiple'>", "</select>" ] ||
975 !tags.indexOf("<leg") &&
976 [ 1, "<fieldset>", "</fieldset>" ] ||
978 tags.match(/^<(thead|tbody|tfoot|colg|cap)/) &&
979 [ 1, "<table>", "</table>" ] ||
981 !tags.indexOf("<tr") &&
982 [ 2, "<table><tbody>", "</tbody></table>" ] ||
984 // <thead> matched above
985 (!tags.indexOf("<td") || !tags.indexOf("<th")) &&
986 [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ] ||
988 !tags.indexOf("<col") &&
989 [ 2, "<table><tbody></tbody><colgroup>", "</colgroup></table>" ] ||
991 // IE can't serialize <link> and <script> tags normally
992 jQuery.browser.msie &&
993 [ 1, "div<div>", "</div>" ] ||
997 // Go to html and back, then peel off extra wrappers
998 div.innerHTML = wrap[1] + elem + wrap[2];
1000 // Move to the right depth
1002 div = div.lastChild;
1004 // Remove IE's autoinserted <tbody> from table fragments
1005 if ( jQuery.browser.msie ) {
1007 // String was a <table>, *may* have spurious <tbody>
1008 var tbody = !tags.indexOf("<table") && tags.indexOf("<tbody") < 0 ?
1009 div.firstChild && div.firstChild.childNodes :
1011 // String was a bare <thead> or <tfoot>
1012 wrap[1] == "<table>" && tags.indexOf("<tbody") < 0 ?
1016 for ( var j = tbody.length - 1; j >= 0 ; --j )
1017 if ( jQuery.nodeName( tbody[ j ], "tbody" ) && !tbody[ j ].childNodes.length )
1018 tbody[ j ].parentNode.removeChild( tbody[ j ] );
1020 // IE completely kills leading whitespace when innerHTML is used
1021 if ( /^\s/.test( elem ) )
1022 div.insertBefore( context.createTextNode( elem.match(/^\s*/)[0] ), div.firstChild );
1026 elem = jQuery.makeArray( div.childNodes );
1029 if ( elem.length === 0 && (!jQuery.nodeName( elem, "form" ) && !jQuery.nodeName( elem, "select" )) )
1032 if ( elem[0] == undefined || jQuery.nodeName( elem, "form" ) || elem.options )
1036 ret = jQuery.merge( ret, elem );
1043 attr: function( elem, name, value ) {
1044 // don't set attributes on text and comment nodes
1045 if (!elem || elem.nodeType == 3 || elem.nodeType == 8)
1048 var fix = jQuery.isXMLDoc( elem ) ?
1052 // Safari mis-reports the default selected property of a hidden option
1053 // Accessing the parent's selectedIndex property fixes it
1054 if ( name == "selected" && jQuery.browser.safari )
1055 elem.parentNode.selectedIndex;
1057 // Certain attributes only work when accessed via the old DOM 0 way
1058 if ( fix[ name ] ) {
1059 if ( value != undefined )
1060 elem[ fix[ name ] ] = value;
1062 return elem[ fix[ name ] ];
1064 } else if ( jQuery.browser.msie && name == "style" )
1065 return jQuery.attr( elem.style, "cssText", value );
1067 else if ( value == undefined && jQuery.browser.msie && jQuery.nodeName( elem, "form" ) && (name == "action" || name == "method") )
1068 return elem.getAttributeNode( name ).nodeValue;
1070 // IE elem.getAttribute passes even for style
1071 else if ( elem.tagName ) {
1073 if ( value != undefined ) {
1074 // We can't allow the type property to be changed (since it causes problems in IE)
1075 if ( name == "type" && jQuery.nodeName( elem, "input" ) && elem.parentNode )
1076 throw "type property can't be changed";
1078 // convert the value to a string (all browsers do this but IE) see #1070
1079 elem.setAttribute( name, "" + value );
1082 if ( jQuery.browser.msie && /href|src/.test( name ) && !jQuery.isXMLDoc( elem ) )
1083 return elem.getAttribute( name, 2 );
1085 return elem.getAttribute( name );
1087 // elem is actually elem.style ... set the style
1089 // IE actually uses filters for opacity
1090 if ( name == "opacity" && jQuery.browser.msie ) {
1091 if ( value != undefined ) {
1092 // IE has trouble with opacity if it does not have layout
1093 // Force it by setting the zoom level
1096 // Set the alpha filter to set the opacity
1097 elem.filter = (elem.filter || "").replace( /alpha\([^)]*\)/, "" ) +
1098 (parseFloat( value ).toString() == "NaN" ? "" : "alpha(opacity=" + value * 100 + ")");
1101 return elem.filter && elem.filter.indexOf("opacity=") >= 0 ?
1102 (parseFloat( elem.filter.match(/opacity=([^)]*)/)[1] ) / 100).toString() :
1106 name = name.replace(/-([a-z])/ig, function(all, letter){
1107 return letter.toUpperCase();
1110 if ( value != undefined )
1111 elem[ name ] = value;
1113 return elem[ name ];
1117 trim: function( text ) {
1118 return (text || "").replace( /^\s+|\s+$/g, "" );
1121 makeArray: function( array ) {
1124 // Need to use typeof to fight Safari childNodes crashes
1125 if ( typeof array != "array" )
1126 for ( var i = 0, length = array.length; i < length; i++ )
1127 ret.push( array[ i ] );
1129 ret = array.slice( 0 );
1134 inArray: function( elem, array ) {
1135 for ( var i = 0, length = array.length; i < length; i++ )
1136 if ( array[ i ] == elem )
1142 merge: function( first, second ) {
1143 // We have to loop this way because IE & Opera overwrite the length
1144 // expando of getElementsByTagName
1146 // Also, we need to make sure that the correct elements are being returned
1147 // (IE returns comment nodes in a '*' query)
1148 if ( jQuery.browser.msie ) {
1149 for ( var i = 0; second[ i ]; i++ )
1150 if ( second[ i ].nodeType != 8 )
1151 first.push( second[ i ] );
1154 for ( var i = 0; second[ i ]; i++ )
1155 first.push( second[ i ] );
1160 unique: function( array ) {
1161 var ret = [], done = {};
1165 for ( var i = 0, length = array.length; i < length; i++ ) {
1166 var id = jQuery.data( array[ i ] );
1168 if ( !done[ id ] ) {
1170 ret.push( array[ i ] );
1181 grep: function( elems, callback, inv ) {
1184 // Go through the array, only saving the items
1185 // that pass the validator function
1186 for ( var i = 0, length = elems.length; i < length; i++ )
1187 if ( !inv && callback( elems[ i ], i ) || inv && !callback( elems[ i ], i ) )
1188 ret.push( elems[ i ] );
1193 map: function( elems, callback ) {
1196 // Go through the array, translating each of the items to their
1197 // new value (or values).
1198 for ( var i = 0, length = elems.length; i < length; i++ ) {
1199 var value = callback( elems[ i ], i );
1201 if ( value !== null && value != undefined ) {
1202 if ( value.constructor != Array )
1205 ret = ret.concat( value );
1213 var userAgent = navigator.userAgent.toLowerCase();
1215 // Figure out what browser is being used
1217 version: (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [])[1],
1218 safari: /webkit/.test( userAgent ),
1219 opera: /opera/.test( userAgent ),
1220 msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
1221 mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )
1224 var styleFloat = jQuery.browser.msie ?
1229 // Check to see if the W3C box model is being used
1230 boxModel: !jQuery.browser.msie || document.compatMode == "CSS1Compat",
1234 "class": "className",
1235 "float": styleFloat,
1236 cssFloat: styleFloat,
1237 styleFloat: styleFloat,
1238 innerHTML: "innerHTML",
1239 className: "className",
1241 disabled: "disabled",
1243 readonly: "readOnly",
1244 selected: "selected",
1245 maxlength: "maxLength",
1246 selectedIndex: "selectedIndex",
1247 defaultValue: "defaultValue",
1249 nodeName: "nodeName"
1254 parent: function(elem){return elem.parentNode;},
1255 parents: function(elem){return jQuery.dir(elem,"parentNode");},
1256 next: function(elem){return jQuery.nth(elem,2,"nextSibling");},
1257 prev: function(elem){return jQuery.nth(elem,2,"previousSibling");},
1258 nextAll: function(elem){return jQuery.dir(elem,"nextSibling");},
1259 prevAll: function(elem){return jQuery.dir(elem,"previousSibling");},
1260 siblings: function(elem){return jQuery.sibling(elem.parentNode.firstChild,elem);},
1261 children: function(elem){return jQuery.sibling(elem.firstChild);},
1262 contents: function(elem){return jQuery.nodeName(elem,"iframe")?elem.contentDocument||elem.contentWindow.document:jQuery.makeArray(elem.childNodes);}
1263 }, function(name, fn){
1264 jQuery.fn[ name ] = function( selector ) {
1265 var ret = jQuery.map( this, fn );
1267 if ( selector && typeof selector == "string" )
1268 ret = jQuery.multiFilter( selector, ret );
1270 return this.pushStack( jQuery.unique( ret ) );
1276 prependTo: "prepend",
1277 insertBefore: "before",
1278 insertAfter: "after",
1279 replaceAll: "replaceWith"
1280 }, function(name, original){
1281 jQuery.fn[ name ] = function() {
1282 var args = arguments;
1284 return this.each(function(){
1285 for ( var i = 0, length = args.length; i < length; i++ )
1286 jQuery( args[ i ] )[ original ]( this );
1292 removeAttr: function( name ) {
1293 jQuery.attr( this, name, "" );
1294 if (this.nodeType == 1)
1295 this.removeAttribute( name );
1298 addClass: function( classNames ) {
1299 jQuery.className.add( this, classNames );
1302 removeClass: function( classNames ) {
1303 jQuery.className.remove( this, classNames );
1306 toggleClass: function( classNames ) {
1307 jQuery.className[ jQuery.className.has( this, classNames ) ? "remove" : "add" ]( this, classNames );
1310 remove: function( selector ) {
1311 if ( !selector || jQuery.filter( selector, [ this ] ).r.length ) {
1312 // Prevent memory leaks
1313 jQuery( "*", this ).add(this).each(function(){
1314 jQuery.event.remove(this);
1315 jQuery.removeData(this);
1317 if (this.parentNode)
1318 this.parentNode.removeChild( this );
1323 // Remove element nodes and prevent memory leaks
1324 jQuery( ">*", this ).remove();
1326 // Remove any remaining nodes
1327 while ( this.firstChild )
1328 this.removeChild( this.firstChild );
1330 }, function(name, fn){
1331 jQuery.fn[ name ] = function(){
1332 return this.each( fn, arguments );
1336 jQuery.each([ "Height", "Width" ], function(i, name){
1337 var type = name.toLowerCase();
1339 jQuery.fn[ type ] = function( size ) {
1340 // Get window width or height
1341 return this[0] == window ?
1342 // Opera reports document.body.client[Width/Height] properly in both quirks and standards
1343 jQuery.browser.opera && document.body[ "client" + name ] ||
1345 // Safari reports inner[Width/Height] just fine (Mozilla and Opera include scroll bar widths)
1346 jQuery.browser.safari && window[ "inner" + name ] ||
1348 // Everyone else use document.documentElement or document.body depending on Quirks vs Standards mode
1349 document.compatMode == "CSS1Compat" && document.documentElement[ "client" + name ] || document.body[ "client" + name ] :
1351 // Get document width or height
1352 this[0] == document ?
1353 // Either scroll[Width/Height] or offset[Width/Height], whichever is greater
1355 Math.max(document.body["scroll" + name], document.documentElement["scroll" + name]),
1356 Math.max(document.body["offset" + name], document.documentElement["offset" + name])
1359 // Get or set width or height on the element
1361 // Get width or height on the element
1362 (this.length ? jQuery.css( this[0], type ) : null) :
1364 // Set the width or height on the element (default to pixels if value is unitless)
1365 this.css( type, size.constructor == String ? size : size + "px" );
1369 var chars = jQuery.browser.safari && parseInt(jQuery.browser.version) < 417 ?
1370 "(?:[\\w*_-]|\\\\.)" :
1371 "(?:[\\w\u0128-\uFFFF*_-]|\\\\.)",
1372 quickChild = new RegExp("^>\\s*(" + chars + "+)"),
1373 quickID = new RegExp("^(" + chars + "+)(#)(" + chars + "+)"),
1374 quickClass = new RegExp("^([#.]?)(" + chars + "*)");
1378 "": function(a,i,m){return m[2]=="*"||jQuery.nodeName(a,m[2]);},
1379 "#": function(a,i,m){return a.getAttribute("id")==m[2];},
1382 lt: function(a,i,m){return i<m[3]-0;},
1383 gt: function(a,i,m){return i>m[3]-0;},
1384 nth: function(a,i,m){return m[3]-0==i;},
1385 eq: function(a,i,m){return m[3]-0==i;},
1386 first: function(a,i){return i==0;},
1387 last: function(a,i,m,r){return i==r.length-1;},
1388 even: function(a,i){return i%2==0;},
1389 odd: function(a,i){return i%2;},
1392 "first-child": function(a){return a.parentNode.getElementsByTagName("*")[0]==a;},
1393 "last-child": function(a){return jQuery.nth(a.parentNode.lastChild,1,"previousSibling")==a;},
1394 "only-child": function(a){return !jQuery.nth(a.parentNode.lastChild,2,"previousSibling");},
1397 parent: function(a){return a.firstChild;},
1398 empty: function(a){return !a.firstChild;},
1401 contains: function(a,i,m){return (a.textContent||a.innerText||jQuery(a).text()||"").indexOf(m[3])>=0;},
1404 visible: function(a){return "hidden"!=a.type&&jQuery.css(a,"display")!="none"&&jQuery.css(a,"visibility")!="hidden";},
1405 hidden: function(a){return "hidden"==a.type||jQuery.css(a,"display")=="none"||jQuery.css(a,"visibility")=="hidden";},
1408 enabled: function(a){return !a.disabled;},
1409 disabled: function(a){return a.disabled;},
1410 checked: function(a){return a.checked;},
1411 selected: function(a){return a.selected||jQuery.attr(a,"selected");},
1414 text: function(a){return "text"==a.type;},
1415 radio: function(a){return "radio"==a.type;},
1416 checkbox: function(a){return "checkbox"==a.type;},
1417 file: function(a){return "file"==a.type;},
1418 password: function(a){return "password"==a.type;},
1419 submit: function(a){return "submit"==a.type;},
1420 image: function(a){return "image"==a.type;},
1421 reset: function(a){return "reset"==a.type;},
1422 button: function(a){return "button"==a.type||jQuery.nodeName(a,"button");},
1423 input: function(a){return /input|select|textarea|button/i.test(a.nodeName);},
1426 has: function(a,i,m){return jQuery.find(m[3],a).length;},
1429 header: function(a){return /h\d/i.test(a.nodeName);},
1432 animated: function(a){return jQuery.grep(jQuery.timers,function(fn){return a==fn.elem;}).length;}
1436 // The regular expressions that power the parsing engine
1438 // Match: [@value='test'], [@foo]
1439 /^(\[) *@?([\w-]+) *([!*$^~=]*) *('?"?)(.*?)\4 *\]/,
1441 // Match: :contains('foo')
1442 /^(:)([\w-]+)\("?'?(.*?(\(.*?\))?[^(]*?)"?'?\)/,
1444 // Match: :even, :last-chlid, #id, .class
1445 new RegExp("^([:.#]*)(" + chars + "+)")
1448 multiFilter: function( expr, elems, not ) {
1451 while ( expr && expr != old ) {
1453 var f = jQuery.filter( expr, elems, not );
1454 expr = f.t.replace(/^\s*,\s*/, "" );
1455 cur = not ? elems = f.r : jQuery.merge( cur, f.r );
1461 find: function( t, context ) {
1462 // Quickly handle non-string expressions
1463 if ( typeof t != "string" )
1466 // check to make sure context is a DOM element or a document
1467 if ( context && context.nodeType != 1 && context.nodeType != 9)
1470 // Set the correct context (if none is provided)
1471 context = context || document;
1473 // Initialize the search
1474 var ret = [context], done = [], last, nodeName;
1476 // Continue while a selector expression exists, and while
1477 // we're no longer looping upon ourselves
1478 while ( t && last != t ) {
1484 var foundToken = false;
1486 // An attempt at speeding up child selectors that
1487 // point to a specific element tag
1488 var re = quickChild;
1492 nodeName = m[1].toUpperCase();
1494 // Perform our own iteration and filter
1495 for ( var i = 0; ret[i]; i++ )
1496 for ( var c = ret[i].firstChild; c; c = c.nextSibling )
1497 if ( c.nodeType == 1 && (nodeName == "*" || c.nodeName.toUpperCase() == nodeName) )
1501 t = t.replace( re, "" );
1502 if ( t.indexOf(" ") == 0 ) continue;
1505 re = /^([>+~])\s*(\w*)/i;
1507 if ( (m = re.exec(t)) != null ) {
1511 nodeName = m[2].toUpperCase();
1514 for ( var j = 0, rl = ret.length; j < rl; j++ ) {
1515 var n = m == "~" || m == "+" ? ret[j].nextSibling : ret[j].firstChild;
1516 for ( ; n; n = n.nextSibling )
1517 if ( n.nodeType == 1 ) {
1518 var id = jQuery.data(n);
1520 if ( m == "~" && merge[id] ) break;
1522 if (!nodeName || n.nodeName.toUpperCase() == nodeName ) {
1523 if ( m == "~" ) merge[id] = true;
1527 if ( m == "+" ) break;
1533 // And remove the token
1534 t = jQuery.trim( t.replace( re, "" ) );
1539 // See if there's still an expression, and that we haven't already
1541 if ( t && !foundToken ) {
1542 // Handle multiple expressions
1543 if ( !t.indexOf(",") ) {
1544 // Clean the result set
1545 if ( context == ret[0] ) ret.shift();
1547 // Merge the result sets
1548 done = jQuery.merge( done, ret );
1550 // Reset the context
1551 r = ret = [context];
1553 // Touch up the selector string
1554 t = " " + t.substr(1,t.length);
1557 // Optimize for the case nodeName#idName
1559 var m = re2.exec(t);
1561 // Re-organize the results, so that they're consistent
1563 m = [ 0, m[2], m[3], m[1] ];
1566 // Otherwise, do a traditional filter check for
1567 // ID, class, and element selectors
1572 m[2] = m[2].replace(/\\/g, "");
1574 var elem = ret[ret.length-1];
1576 // Try to do a global search by ID, where we can
1577 if ( m[1] == "#" && elem && elem.getElementById && !jQuery.isXMLDoc(elem) ) {
1578 // Optimization for HTML document case
1579 var oid = elem.getElementById(m[2]);
1581 // Do a quick check for the existence of the actual ID attribute
1582 // to avoid selecting by the name attribute in IE
1583 // also check to insure id is a string to avoid selecting an element with the name of 'id' inside a form
1584 if ( (jQuery.browser.msie||jQuery.browser.opera) && oid && typeof oid.id == "string" && oid.id != m[2] )
1585 oid = jQuery('[@id="'+m[2]+'"]', elem)[0];
1587 // Do a quick check for node name (where applicable) so
1588 // that div#foo searches will be really fast
1589 ret = r = oid && (!m[3] || jQuery.nodeName(oid, m[3])) ? [oid] : [];
1591 // We need to find all descendant elements
1592 for ( var i = 0; ret[i]; i++ ) {
1593 // Grab the tag name being searched for
1594 var tag = m[1] == "#" && m[3] ? m[3] : m[1] != "" || m[0] == "" ? "*" : m[2];
1596 // Handle IE7 being really dumb about <object>s
1597 if ( tag == "*" && ret[i].nodeName.toLowerCase() == "object" )
1600 r = jQuery.merge( r, ret[i].getElementsByTagName( tag ));
1603 // It's faster to filter by class and be done with it
1605 r = jQuery.classFilter( r, m[2] );
1607 // Same with ID filtering
1608 if ( m[1] == "#" ) {
1611 // Try to find the element with the ID
1612 for ( var i = 0; r[i]; i++ )
1613 if ( r[i].getAttribute("id") == m[2] ) {
1624 t = t.replace( re2, "" );
1629 // If a selector string still exists
1631 // Attempt to filter it
1632 var val = jQuery.filter(t,r);
1634 t = jQuery.trim(val.t);
1638 // An error occurred with the selector;
1639 // just return an empty set instead
1643 // Remove the root context
1644 if ( ret && context == ret[0] )
1647 // And combine the results
1648 done = jQuery.merge( done, ret );
1653 classFilter: function(r,m,not){
1656 for ( var i = 0; r[i]; i++ ) {
1657 var pass = (" " + r[i].className + " ").indexOf( m ) >= 0;
1658 if ( !not && pass || not && !pass )
1664 filter: function(t,r,not) {
1667 // Look for common filter expressions
1668 while ( t && t != last ) {
1671 var p = jQuery.parse, m;
1673 for ( var i = 0; p[i]; i++ ) {
1677 // Remove what we just matched
1678 t = t.substring( m[0].length );
1680 m[2] = m[2].replace(/\\/g, "");
1688 // :not() is a special case that can be optimized by
1689 // keeping it out of the expression list
1690 if ( m[1] == ":" && m[2] == "not" )
1691 // optimize if only one selector found (most common case)
1692 r = isSimple.test( m[3] ) ?
1693 jQuery.filter(m[3], r, true).r :
1694 jQuery( r ).not( m[3] );
1696 // We can get a big speed boost by filtering by class here
1697 else if ( m[1] == "." )
1698 r = jQuery.classFilter(r, m[2], not);
1700 else if ( m[1] == "[" ) {
1701 var tmp = [], type = m[3];
1703 for ( var i = 0, rl = r.length; i < rl; i++ ) {
1704 var a = r[i], z = a[ jQuery.props[m[2]] || m[2] ];
1706 if ( z == null || /href|src|selected/.test(m[2]) )
1707 z = jQuery.attr(a,m[2]) || '';
1709 if ( (type == "" && !!z ||
1710 type == "=" && z == m[5] ||
1711 type == "!=" && z != m[5] ||
1712 type == "^=" && z && !z.indexOf(m[5]) ||
1713 type == "$=" && z.substr(z.length - m[5].length) == m[5] ||
1714 (type == "*=" || type == "~=") && z.indexOf(m[5]) >= 0) ^ not )
1720 // We can get a speed boost by handling nth-child here
1721 } else if ( m[1] == ":" && m[2] == "nth-child" ) {
1722 var merge = {}, tmp = [],
1723 // parse equations like 'even', 'odd', '5', '2n', '3n+2', '4n-1', '-n+6'
1724 test = /(-?)(\d*)n((?:\+|-)?\d*)/.exec(
1725 m[3] == "even" && "2n" || m[3] == "odd" && "2n+1" ||
1726 !/\D/.test(m[3]) && "0n+" + m[3] || m[3]),
1727 // calculate the numbers (first)n+(last) including if they are negative
1728 first = (test[1] + (test[2] || 1)) - 0, last = test[3] - 0;
1730 // loop through all the elements left in the jQuery object
1731 for ( var i = 0, rl = r.length; i < rl; i++ ) {
1732 var node = r[i], parentNode = node.parentNode, id = jQuery.data(parentNode);
1737 for ( var n = parentNode.firstChild; n; n = n.nextSibling )
1738 if ( n.nodeType == 1 )
1747 if ( node.nodeIndex == last )
1749 } else if ( (node.nodeIndex - last) % first == 0 && (node.nodeIndex - last) / first >= 0 )
1758 // Otherwise, find the expression to execute
1760 var fn = jQuery.expr[ m[1] ];
1761 if ( typeof fn == "object" )
1764 if ( typeof fn == "string" )
1765 fn = eval("false||function(a,i){return " + fn + ";}");
1767 // Execute it against the current filter
1768 r = jQuery.grep( r, function(elem, i){
1769 return fn(elem, i, m, r);
1774 // Return an array of filtered elements (r)
1775 // and the modified expression string (t)
1776 return { r: r, t: t };
1779 dir: function( elem, dir ){
1781 var cur = elem[dir];
1782 while ( cur && cur != document ) {
1783 if ( cur.nodeType == 1 )
1784 matched.push( cur );
1790 nth: function(cur,result,dir,elem){
1791 result = result || 1;
1794 for ( ; cur; cur = cur[dir] )
1795 if ( cur.nodeType == 1 && ++num == result )
1801 sibling: function( n, elem ) {
1804 for ( ; n; n = n.nextSibling ) {
1805 if ( n.nodeType == 1 && (!elem || n != elem) )
1814 * A number of helper functions used for managing events.
1815 * Many of the ideas behind this code orignated from
1816 * Dean Edwards' addEvent library.
1820 // Bind an event to an element
1821 // Original by Dean Edwards
1822 add: function(elem, types, handler, data) {
1823 if ( elem.nodeType == 3 || elem.nodeType == 8 )
1826 // For whatever reason, IE has trouble passing the window object
1827 // around, causing it to be cloned in the process
1828 if ( jQuery.browser.msie && elem.setInterval != undefined )
1831 // Make sure that the function being executed has a unique ID
1832 if ( !handler.guid )
1833 handler.guid = this.guid++;
1835 // if data is passed, bind to handler
1836 if( data != undefined ) {
1837 // Create temporary function pointer to original handler
1840 // Create unique handler function, wrapped around original handler
1841 handler = function() {
1842 // Pass arguments and context to original handler
1843 return fn.apply(this, arguments);
1846 // Store data in unique handler
1847 handler.data = data;
1849 // Set the guid of unique handler to the same of original handler, so it can be removed
1850 handler.guid = fn.guid;
1853 // Init the element's event structure
1854 var events = jQuery.data(elem, "events") || jQuery.data(elem, "events", {}),
1855 handle = jQuery.data(elem, "handle") || jQuery.data(elem, "handle", function(){
1856 // returned undefined or false
1859 // Handle the second event of a trigger and when
1860 // an event is called after a page has unloaded
1861 if ( typeof jQuery == "undefined" || jQuery.event.triggered )
1864 val = jQuery.event.handle.apply(arguments.callee.elem, arguments);
1868 // Add elem as a property of the handle function
1869 // This is to prevent a memory leak with non-native
1873 // Handle multiple events seperated by a space
1874 // jQuery(...).bind("mouseover mouseout", fn);
1875 jQuery.each(types.split(/\s+/), function(index, type) {
1876 // Namespaced event handlers
1877 var parts = type.split(".");
1879 handler.type = parts[1];
1881 // Get the current list of functions bound to this event
1882 var handlers = events[type];
1884 // Init the event handler queue
1886 handlers = events[type] = {};
1888 // Check for a special event handler
1889 // Only use addEventListener/attachEvent if the special
1890 // events handler returns false
1891 if ( !jQuery.event.special[type] || jQuery.event.special[type].setup.call(elem) === false ) {
1892 // Bind the global event handler to the element
1893 if (elem.addEventListener)
1894 elem.addEventListener(type, handle, false);
1895 else if (elem.attachEvent)
1896 elem.attachEvent("on" + type, handle);
1900 // Add the function to the element's handler list
1901 handlers[handler.guid] = handler;
1903 // Keep track of which events have been used, for global triggering
1904 jQuery.event.global[type] = true;
1907 // Nullify elem to prevent memory leaks in IE
1914 // Detach an event or set of events from an element
1915 remove: function(elem, types, handler) {
1916 // don't do events on text and comment nodes
1917 if ( elem.nodeType == 3 || elem.nodeType == 8 )
1920 var events = jQuery.data(elem, "events"), ret, index;
1923 // Unbind all events for the element
1924 if ( types == undefined || (typeof types == "string" && types.charAt(0) == ".") )
1925 for ( var type in events )
1926 this.remove( elem, type + (types || "") );
1928 // types is actually an event object here
1930 handler = types.handler;
1934 // Handle multiple events seperated by a space
1935 // jQuery(...).unbind("mouseover mouseout", fn);
1936 jQuery.each(types.split(/\s+/), function(index, type){
1937 // Namespaced event handlers
1938 var parts = type.split(".");
1941 if ( events[type] ) {
1942 // remove the given handler for the given type
1944 delete events[type][handler.guid];
1946 // remove all handlers for the given type
1948 for ( handler in events[type] )
1949 // Handle the removal of namespaced events
1950 if ( !parts[1] || events[type][handler].type == parts[1] )
1951 delete events[type][handler];
1953 // remove generic event handler if no more handlers exist
1954 for ( ret in events[type] ) break;
1956 if ( !jQuery.event.special[type] || jQuery.event.special[type].teardown.call(elem) === false ) {
1957 if (elem.removeEventListener)
1958 elem.removeEventListener(type, jQuery.data(elem, "handle"), false);
1959 else if (elem.detachEvent)
1960 elem.detachEvent("on" + type, jQuery.data(elem, "handle"));
1963 delete events[type];
1969 // Remove the expando if it's no longer used
1970 for ( ret in events ) break;
1972 var handle = jQuery.data( elem, "handle" );
1973 if ( handle ) handle.elem = null;
1974 jQuery.removeData( elem, "events" );
1975 jQuery.removeData( elem, "handle" );
1980 trigger: function(type, data, elem, donative, extra) {
1981 // Clone the incoming data, if any
1982 data = jQuery.makeArray(data || []);
1984 if ( type.indexOf("!") >= 0 ) {
1985 type = type.slice(0, -1);
1986 var exclusive = true;
1989 // Handle a global trigger
1991 // Only trigger if we've ever bound an event for it
1992 if ( this.global[type] )
1993 jQuery("*").add([window, document]).trigger(type, data);
1995 // Handle triggering a single element
1997 // don't do events on text and comment nodes
1998 if ( elem.nodeType == 3 || elem.nodeType == 8 )
2001 var val, ret, fn = jQuery.isFunction( elem[ type ] || null ),
2002 // Check to see if we need to provide a fake event, or not
2003 event = !data[0] || !data[0].preventDefault;
2005 // Pass along a fake event
2007 data.unshift( this.fix({ type: type, target: elem }) );
2009 // Enforce the right trigger type
2010 data[0].type = type;
2012 data[0].exclusive = true;
2014 // Trigger the event
2015 if ( jQuery.isFunction( jQuery.data(elem, "handle") ) )
2016 val = jQuery.data(elem, "handle").apply( elem, data );
2018 // Handle triggering native .onfoo handlers
2019 if ( !fn && elem["on"+type] && elem["on"+type].apply( elem, data ) === false )
2022 // Extra functions don't get the custom event object
2026 // Handle triggering of extra function
2027 if ( extra && jQuery.isFunction( extra ) ) {
2028 // call the extra function and tack the current return value on the end for possible inspection
2029 ret = extra.apply( elem, val == null ? data : data.concat( val ) );
2030 // if anything is returned, give it precedence and have it overwrite the previous value
2031 if (ret !== undefined)
2035 // Trigger the native events (except for clicks on links)
2036 if ( fn && donative !== false && val !== false && !(jQuery.nodeName(elem, 'a') && type == "click") ) {
2037 this.triggered = true;
2040 // prevent IE from throwing an error for some hidden elements
2044 this.triggered = false;
2050 handle: function(event) {
2051 // returned undefined or false
2054 // Empty object is for triggered events with no data
2055 event = jQuery.event.fix( event || window.event || {} );
2057 // Namespaced event handlers
2058 var parts = event.type.split(".");
2059 event.type = parts[0];
2061 var handlers = jQuery.data(this, "events") && jQuery.data(this, "events")[event.type], args = Array.prototype.slice.call( arguments, 1 );
2062 args.unshift( event );
2064 for ( var j in handlers ) {
2065 var handler = handlers[j];
2066 // Pass in a reference to the handler function itself
2067 // So that we can later remove it
2068 args[0].handler = handler;
2069 args[0].data = handler.data;
2071 // Filter the functions by class
2072 if ( !parts[1] && !event.exclusive || handler.type == parts[1] ) {
2073 var ret = handler.apply( this, args );
2075 if ( val !== false )
2078 if ( ret === false ) {
2079 event.preventDefault();
2080 event.stopPropagation();
2085 // Clean up added properties in IE to prevent memory leak
2086 if (jQuery.browser.msie)
2087 event.target = event.preventDefault = event.stopPropagation =
2088 event.handler = event.data = null;
2093 fix: function(event) {
2094 // store a copy of the original event object
2095 // and clone to set read-only properties
2096 var originalEvent = event;
2097 event = jQuery.extend({}, originalEvent);
2099 // add preventDefault and stopPropagation since
2100 // they will not work on the clone
2101 event.preventDefault = function() {
2102 // if preventDefault exists run it on the original event
2103 if (originalEvent.preventDefault)
2104 originalEvent.preventDefault();
2105 // otherwise set the returnValue property of the original event to false (IE)
2106 originalEvent.returnValue = false;
2108 event.stopPropagation = function() {
2109 // if stopPropagation exists run it on the original event
2110 if (originalEvent.stopPropagation)
2111 originalEvent.stopPropagation();
2112 // otherwise set the cancelBubble property of the original event to true (IE)
2113 originalEvent.cancelBubble = true;
2116 // Fix target property, if necessary
2117 if ( !event.target )
2118 event.target = event.srcElement || document; // Fixes #1925 where srcElement might not be defined either
2120 // check if target is a textnode (safari)
2121 if ( event.target.nodeType == 3 )
2122 event.target = originalEvent.target.parentNode;
2124 // Add relatedTarget, if necessary
2125 if ( !event.relatedTarget && event.fromElement )
2126 event.relatedTarget = event.fromElement == event.target ? event.toElement : event.fromElement;
2128 // Calculate pageX/Y if missing and clientX/Y available
2129 if ( event.pageX == null && event.clientX != null ) {
2130 var doc = document.documentElement, body = document.body;
2131 event.pageX = event.clientX + (doc && doc.scrollLeft || body && body.scrollLeft || 0) - (doc.clientLeft || 0);
2132 event.pageY = event.clientY + (doc && doc.scrollTop || body && body.scrollTop || 0) - (doc.clientTop || 0);
2135 // Add which for key events
2136 if ( !event.which && ((event.charCode || event.charCode === 0) ? event.charCode : event.keyCode) )
2137 event.which = event.charCode || event.keyCode;
2139 // Add metaKey to non-Mac browsers (use ctrl for PC's and Meta for Macs)
2140 if ( !event.metaKey && event.ctrlKey )
2141 event.metaKey = event.ctrlKey;
2143 // Add which for click: 1 == left; 2 == middle; 3 == right
2144 // Note: button is not normalized, so don't use it
2145 if ( !event.which && event.button )
2146 event.which = (event.button & 1 ? 1 : ( event.button & 2 ? 3 : ( event.button & 4 ? 2 : 0 ) ));
2154 // Make sure the ready event is setup
2159 teardown: function() { return; }
2164 if ( jQuery.browser.msie ) return false;
2165 jQuery(this).bind("mouseover", jQuery.event.special.mouseenter.handler);
2169 teardown: function() {
2170 if ( jQuery.browser.msie ) return false;
2171 jQuery(this).unbind("mouseover", jQuery.event.special.mouseenter.handler);
2175 handler: function(event) {
2176 // If we actually just moused on to a sub-element, ignore it
2177 if ( withinElement(event, this) ) return true;
2178 // Execute the right handlers by setting the event type to mouseenter
2179 arguments[0].type = "mouseenter";
2180 return jQuery.event.handle.apply(this, arguments);
2186 if ( jQuery.browser.msie ) return false;
2187 jQuery(this).bind("mouseout", jQuery.event.special.mouseleave.handler);
2191 teardown: function() {
2192 if ( jQuery.browser.msie ) return false;
2193 jQuery(this).unbind("mouseout", jQuery.event.special.mouseleave.handler);
2197 handler: function(event) {
2198 // If we actually just moused on to a sub-element, ignore it
2199 if ( withinElement(event, this) ) return true;
2200 // Execute the right handlers by setting the event type to mouseleave
2201 arguments[0].type = "mouseleave";
2202 return jQuery.event.handle.apply(this, arguments);
2209 bind: function( type, data, fn ) {
2210 return type == "unload" ? this.one(type, data, fn) : this.each(function(){
2211 jQuery.event.add( this, type, fn || data, fn && data );
2215 one: function( type, data, fn ) {
2216 return this.each(function(){
2217 jQuery.event.add( this, type, function(event) {
2218 jQuery(this).unbind(event);
2219 return (fn || data).apply( this, arguments);
2224 unbind: function( type, fn ) {
2225 return this.each(function(){
2226 jQuery.event.remove( this, type, fn );
2230 trigger: function( type, data, fn ) {
2231 return this.each(function(){
2232 jQuery.event.trigger( type, data, this, true, fn );
2236 triggerHandler: function( type, data, fn ) {
2238 return jQuery.event.trigger( type, data, this[0], false, fn );
2242 toggle: function() {
2243 // Save reference to arguments for access in closure
2244 var args = arguments;
2246 return this.click(function(event) {
2247 // Figure out which function to execute
2248 this.lastToggle = 0 == this.lastToggle ? 1 : 0;
2250 // Make sure that clicks stop
2251 event.preventDefault();
2253 // and execute the function
2254 return args[this.lastToggle].apply( this, arguments ) || false;
2258 hover: function(fnOver, fnOut) {
2259 return this.bind('mouseenter', fnOver).bind('mouseleave', fnOut);
2262 ready: function(fn) {
2263 // Attach the listeners
2266 // If the DOM is already ready
2267 if ( jQuery.isReady )
2268 // Execute the function immediately
2269 fn.call( document, jQuery );
2271 // Otherwise, remember the function for later
2273 // Add the function to the wait list
2274 jQuery.readyList.push( function() { return fn.call(this, jQuery); } );
2283 // Handle when the DOM is ready
2285 // Make sure that the DOM is not already loaded
2286 if ( !jQuery.isReady ) {
2287 // Remember that the DOM is ready
2288 jQuery.isReady = true;
2290 // If there are functions bound, to execute
2291 if ( jQuery.readyList ) {
2292 // Execute all of them
2293 jQuery.each( jQuery.readyList, function(){
2294 this.apply( document );
2297 // Reset the list of functions
2298 jQuery.readyList = null;
2301 // Trigger any bound ready events
2302 jQuery(document).triggerHandler("ready");
2307 var readyBound = false;
2309 function bindReady(){
2310 if ( readyBound ) return;
2313 // Mozilla, Opera (see further below for it) and webkit nightlies currently support this event
2314 if ( document.addEventListener && !jQuery.browser.opera)
2315 // Use the handy event callback
2316 document.addEventListener( "DOMContentLoaded", jQuery.ready, false );
2318 // If IE is used and is not in a frame
2319 // Continually check to see if the document is ready
2320 if ( jQuery.browser.msie && window == top ) (function(){
2321 if (jQuery.isReady) return;
2323 // If IE is used, use the trick by Diego Perini
2324 // http://javascript.nwbox.com/IEContentLoaded/
2325 document.documentElement.doScroll("left");
2327 setTimeout( arguments.callee, 0 );
2330 // and execute any waiting functions
2334 if ( jQuery.browser.opera )
2335 document.addEventListener( "DOMContentLoaded", function () {
2336 if (jQuery.isReady) return;
2337 for (var i = 0; i < document.styleSheets.length; i++)
2338 if (document.styleSheets[i].disabled) {
2339 setTimeout( arguments.callee, 0 );
2342 // and execute any waiting functions
2346 if ( jQuery.browser.safari ) {
2349 if (jQuery.isReady) return;
2350 if ( document.readyState != "loaded" && document.readyState != "complete" ) {
2351 setTimeout( arguments.callee, 0 );
2354 if ( numStyles === undefined )
2355 numStyles = jQuery("style, link[rel=stylesheet]").length;
2356 if ( document.styleSheets.length != numStyles ) {
2357 setTimeout( arguments.callee, 0 );
2360 // and execute any waiting functions
2365 // A fallback to window.onload, that will always work
2366 jQuery.event.add( window, "load", jQuery.ready );
2369 jQuery.each( ("blur,focus,load,resize,scroll,unload,click,dblclick," +
2370 "mousedown,mouseup,mousemove,mouseover,mouseout,change,select," +
2371 "submit,keydown,keypress,keyup,error").split(","), function(i, name){
2373 // Handle event binding
2374 jQuery.fn[name] = function(fn){
2375 return fn ? this.bind(name, fn) : this.trigger(name);
2379 // Checks if an event happened on an element within another element
2380 // Used in jQuery.event.special.mouseenter and mouseleave handlers
2381 var withinElement = function(event, elem) {
2382 // Check if mouse(over|out) are still within the same parent element
2383 var parent = event.relatedTarget;
2384 // Traverse up the tree
2385 while ( parent && parent != elem ) try { parent = parent.parentNode; } catch(error) { parent = elem; }
2386 // Return true if we actually just moused on to a sub-element
2387 return parent == elem;
2390 // Prevent memory leaks in IE
2391 // And prevent errors on refresh with events like mouseover in other browsers
2392 // Window isn't included so as not to unbind existing unload events
2393 jQuery(window).bind("unload", function() {
2394 jQuery("*").add(document).unbind();
2397 load: function( url, params, callback ) {
2398 if ( jQuery.isFunction( url ) )
2399 return this.bind("load", url);
2401 var off = url.indexOf(" ");
2403 var selector = url.slice(off, url.length);
2404 url = url.slice(0, off);
2407 callback = callback || function(){};
2409 // Default to a GET request
2412 // If the second parameter was provided
2414 // If it's a function
2415 if ( jQuery.isFunction( params ) ) {
2416 // We assume that it's the callback
2420 // Otherwise, build a param string
2422 params = jQuery.param( params );
2428 // Request the remote document
2434 complete: function(res, status){
2435 // If successful, inject the HTML into all the matched elements
2436 if ( status == "success" || status == "notmodified" )
2437 // See if a selector was specified
2438 self.html( selector ?
2439 // Create a dummy div to hold the results
2441 // inject the contents of the document in, removing the scripts
2442 // to avoid any 'Permission Denied' errors in IE
2443 .append(res.responseText.replace(/<script(.|\s)*?\/script>/g, ""))
2445 // Locate the specified elements
2448 // If not, just inject the full result
2451 self.each( callback, [res.responseText, status, res] );
2457 serialize: function() {
2458 return jQuery.param(this.serializeArray());
2460 serializeArray: function() {
2461 return this.map(function(){
2462 return jQuery.nodeName(this, "form") ?
2463 jQuery.makeArray(this.elements) : this;
2466 return this.name && !this.disabled &&
2467 (this.checked || /select|textarea/i.test(this.nodeName) ||
2468 /text|hidden|password/i.test(this.type));
2470 .map(function(i, elem){
2471 var val = jQuery(this).val();
2472 return val == null ? null :
2473 val.constructor == Array ?
2474 jQuery.map( val, function(val, i){
2475 return {name: elem.name, value: val};
2477 {name: elem.name, value: val};
2482 // Attach a bunch of functions for handling common AJAX events
2483 jQuery.each( "ajaxStart,ajaxStop,ajaxComplete,ajaxError,ajaxSuccess,ajaxSend".split(","), function(i,o){
2484 jQuery.fn[o] = function(f){
2485 return this.bind(o, f);
2489 var jsc = (new Date).getTime();
2492 get: function( url, data, callback, type ) {
2493 // shift arguments if data argument was ommited
2494 if ( jQuery.isFunction( data ) ) {
2499 return jQuery.ajax({
2508 getScript: function( url, callback ) {
2509 return jQuery.get(url, null, callback, "script");
2512 getJSON: function( url, data, callback ) {
2513 return jQuery.get(url, data, callback, "json");
2516 post: function( url, data, callback, type ) {
2517 if ( jQuery.isFunction( data ) ) {
2522 return jQuery.ajax({
2531 ajaxSetup: function( settings ) {
2532 jQuery.extend( jQuery.ajaxSettings, settings );
2539 contentType: "application/x-www-form-urlencoded",
2546 xml: "application/xml, text/xml",
2548 script: "text/javascript, application/javascript",
2549 json: "application/json, text/javascript",
2555 // Last-Modified header cache for next request
2558 ajax: function( s ) {
2559 var jsonp, jsre = /=\?(&|$)/g, status, data;
2561 // Extend the settings, but re-extend 's' so that it can be
2562 // checked again later (in the test suite, specifically)
2563 s = jQuery.extend(true, s, jQuery.extend(true, {}, jQuery.ajaxSettings, s));
2565 // convert data if not already a string
2566 if ( s.data && s.processData && typeof s.data != "string" )
2567 s.data = jQuery.param(s.data);
2569 // Handle JSONP Parameter Callbacks
2570 if ( s.dataType == "jsonp" ) {
2571 if ( s.type.toLowerCase() == "get" ) {
2572 if ( !s.url.match(jsre) )
2573 s.url += (s.url.match(/\?/) ? "&" : "?") + (s.jsonp || "callback") + "=?";
2574 } else if ( !s.data || !s.data.match(jsre) )
2575 s.data = (s.data ? s.data + "&" : "") + (s.jsonp || "callback") + "=?";
2576 s.dataType = "json";
2579 // Build temporary JSONP function
2580 if ( s.dataType == "json" && (s.data && s.data.match(jsre) || s.url.match(jsre)) ) {
2581 jsonp = "jsonp" + jsc++;
2583 // Replace the =? sequence both in the query string and the data
2585 s.data = (s.data + "").replace(jsre, "=" + jsonp + "$1");
2586 s.url = s.url.replace(jsre, "=" + jsonp + "$1");
2588 // We need to make sure
2589 // that a JSONP style response is executed properly
2590 s.dataType = "script";
2592 // Handle JSONP-style loading
2593 window[ jsonp ] = function(tmp){
2598 window[ jsonp ] = undefined;
2599 try{ delete window[ jsonp ]; } catch(e){}
2601 head.removeChild( script );
2605 if ( s.dataType == "script" && s.cache == null )
2608 if ( s.cache === false && s.type.toLowerCase() == "get" ) {
2609 var ts = (new Date()).getTime();
2610 // try replacing _= if it is there
2611 var ret = s.url.replace(/(\?|&)_=.*?(&|$)/, "$1_=" + ts + "$2");
2612 // if nothing was replaced, add timestamp to the end
2613 s.url = ret + ((ret == s.url) ? (s.url.match(/\?/) ? "&" : "?") + "_=" + ts : "");
2616 // If data is available, append data to url for get requests
2617 if ( s.data && s.type.toLowerCase() == "get" ) {
2618 s.url += (s.url.match(/\?/) ? "&" : "?") + s.data;
2620 // IE likes to send both get and post data, prevent this
2624 // Watch for a new set of requests
2625 if ( s.global && ! jQuery.active++ )
2626 jQuery.event.trigger( "ajaxStart" );
2628 // If we're requesting a remote document
2629 // and trying to load JSON or Script with a GET
2630 if ( (!s.url.indexOf("http") || !s.url.indexOf("//")) && s.dataType == "script" && s.type.toLowerCase() == "get" ) {
2631 var head = document.getElementsByTagName("head")[0];
2632 var script = document.createElement("script");
2634 if (s.scriptCharset)
2635 script.charset = s.scriptCharset;
2637 // Handle Script loading
2641 // Attach handlers for all browsers
2642 script.onload = script.onreadystatechange = function(){
2643 if ( !done && (!this.readyState ||
2644 this.readyState == "loaded" || this.readyState == "complete") ) {
2648 head.removeChild( script );
2653 head.appendChild(script);
2655 // We handle everything using the script element injection
2659 var requestDone = false;
2661 // Create the request object; Microsoft failed to properly
2662 // implement the XMLHttpRequest in IE7, so we use the ActiveXObject when it is available
2663 var xml = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
2666 xml.open(s.type, s.url, s.async, s.username, s.password);
2668 // Need an extra try/catch for cross domain requests in Firefox 3
2670 // Set the correct header, if data is being sent
2672 xml.setRequestHeader("Content-Type", s.contentType);
2674 // Set the If-Modified-Since header, if ifModified mode.
2676 xml.setRequestHeader("If-Modified-Since",
2677 jQuery.lastModified[s.url] || "Thu, 01 Jan 1970 00:00:00 GMT" );
2679 // Set header so the called script knows that it's an XMLHttpRequest
2680 xml.setRequestHeader("X-Requested-With", "XMLHttpRequest");
2682 // Set the Accepts header for the server, depending on the dataType
2683 xml.setRequestHeader("Accept", s.dataType && s.accepts[ s.dataType ] ?
2684 s.accepts[ s.dataType ] + ", */*" :
2685 s.accepts._default );
2688 // Allow custom headers/mimetypes
2693 jQuery.event.trigger("ajaxSend", [xml, s]);
2695 // Wait for a response to come back
2696 var onreadystatechange = function(isTimeout){
2697 // The transfer is complete and the data is available, or the request timed out
2698 if ( !requestDone && xml && (xml.readyState == 4 || isTimeout == "timeout") ) {
2701 // clear poll interval
2703 clearInterval(ival);
2707 status = isTimeout == "timeout" && "timeout" ||
2708 !jQuery.httpSuccess( xml ) && "error" ||
2709 s.ifModified && jQuery.httpNotModified( xml, s.url ) && "notmodified" ||
2712 if ( status == "success" ) {
2713 // Watch for, and catch, XML document parse errors
2715 // process the data (runs the xml through httpData regardless of callback)
2716 data = jQuery.httpData( xml, s.dataType );
2718 status = "parsererror";
2722 // Make sure that the request was successful or notmodified
2723 if ( status == "success" ) {
2724 // Cache Last-Modified header, if ifModified mode.
2727 modRes = xml.getResponseHeader("Last-Modified");
2728 } catch(e) {} // swallow exception thrown by FF if header is not available
2730 if ( s.ifModified && modRes )
2731 jQuery.lastModified[s.url] = modRes;
2733 // JSONP handles its own success callback
2737 jQuery.handleError(s, xml, status);
2739 // Fire the complete handlers
2742 // Stop memory leaks
2749 // don't attach the handler to the request, just poll it instead
2750 var ival = setInterval(onreadystatechange, 13);
2753 if ( s.timeout > 0 )
2754 setTimeout(function(){
2755 // Check to see if the request is still happening
2757 // Cancel the request
2761 onreadystatechange( "timeout" );
2770 jQuery.handleError(s, xml, null, e);
2773 // firefox 1.5 doesn't fire statechange for sync requests
2775 onreadystatechange();
2778 // If a local callback was specified, fire it and pass it the data
2780 s.success( data, status );
2782 // Fire the global callback
2784 jQuery.event.trigger( "ajaxSuccess", [xml, s] );
2787 function complete(){
2790 s.complete(xml, status);
2792 // The request was completed
2794 jQuery.event.trigger( "ajaxComplete", [xml, s] );
2796 // Handle the global AJAX counter
2797 if ( s.global && ! --jQuery.active )
2798 jQuery.event.trigger( "ajaxStop" );
2801 // return XMLHttpRequest to allow aborting the request etc.
2805 handleError: function( s, xml, status, e ) {
2806 // If a local callback was specified, fire it
2807 if ( s.error ) s.error( xml, status, e );
2809 // Fire the global callback
2811 jQuery.event.trigger( "ajaxError", [xml, s, e] );
2814 // Counter for holding the number of active queries
2817 // Determines if an XMLHttpRequest was successful or not
2818 httpSuccess: function( r ) {
2820 // IE error sometimes returns 1223 when it should be 204 so treat it as success, see #1450
2821 return !r.status && location.protocol == "file:" ||
2822 ( r.status >= 200 && r.status < 300 ) || r.status == 304 || r.status == 1223 ||
2823 jQuery.browser.safari && r.status == undefined;
2828 // Determines if an XMLHttpRequest returns NotModified
2829 httpNotModified: function( xml, url ) {
2831 var xmlRes = xml.getResponseHeader("Last-Modified");
2833 // Firefox always returns 200. check Last-Modified date
2834 return xml.status == 304 || xmlRes == jQuery.lastModified[url] ||
2835 jQuery.browser.safari && xml.status == undefined;
2840 httpData: function( r, type ) {
2841 var ct = r.getResponseHeader("content-type");
2842 var xml = type == "xml" || !type && ct && ct.indexOf("xml") >= 0;
2843 var data = xml ? r.responseXML : r.responseText;
2845 if ( xml && data.documentElement.tagName == "parsererror" )
2846 throw "parsererror";
2848 // If the type is "script", eval it in global context
2849 if ( type == "script" )
2850 jQuery.globalEval( data );
2852 // Get the JavaScript object, if JSON is used.
2853 if ( type == "json" )
2854 data = eval("(" + data + ")");
2859 // Serialize an array of form elements or a set of
2860 // key/values into a query string
2861 param: function( a ) {
2864 // If an array was passed in, assume that it is an array
2866 if ( a.constructor == Array || a.jquery )
2867 // Serialize the form elements
2868 jQuery.each( a, function(){
2869 s.push( encodeURIComponent(this.name) + "=" + encodeURIComponent( this.value ) );
2872 // Otherwise, assume that it's an object of key/value pairs
2874 // Serialize the key/values
2876 // If the value is an array then the key names need to be repeated
2877 if ( a[j] && a[j].constructor == Array )
2878 jQuery.each( a[j], function(){
2879 s.push( encodeURIComponent(j) + "=" + encodeURIComponent( this ) );
2882 s.push( encodeURIComponent(j) + "=" + encodeURIComponent( a[j] ) );
2884 // Return the resulting serialization
2885 return s.join("&").replace(/%20/g, "+");
2890 show: function(speed,callback){
2893 height: "show", width: "show", opacity: "show"
2894 }, speed, callback) :
2896 this.filter(":hidden").each(function(){
2897 this.style.display = this.oldblock || "";
2898 if ( jQuery.css(this,"display") == "none" ) {
2899 var elem = jQuery("<" + this.tagName + " />").appendTo("body");
2900 this.style.display = elem.css("display");
2901 // handle an edge condition where css is - div { display:none; } or similar
2902 if (this.style.display == "none")
2903 this.style.display = "block";
2909 hide: function(speed,callback){
2912 height: "hide", width: "hide", opacity: "hide"
2913 }, speed, callback) :
2915 this.filter(":visible").each(function(){
2916 this.oldblock = this.oldblock || jQuery.css(this,"display");
2917 this.style.display = "none";
2921 // Save the old toggle function
2922 _toggle: jQuery.fn.toggle,
2924 toggle: function( fn, fn2 ){
2925 return jQuery.isFunction(fn) && jQuery.isFunction(fn2) ?
2926 this._toggle( fn, fn2 ) :
2929 height: "toggle", width: "toggle", opacity: "toggle"
2931 this.each(function(){
2932 jQuery(this)[ jQuery(this).is(":hidden") ? "show" : "hide" ]();
2936 slideDown: function(speed,callback){
2937 return this.animate({height: "show"}, speed, callback);
2940 slideUp: function(speed,callback){
2941 return this.animate({height: "hide"}, speed, callback);
2944 slideToggle: function(speed, callback){
2945 return this.animate({height: "toggle"}, speed, callback);
2948 fadeIn: function(speed, callback){
2949 return this.animate({opacity: "show"}, speed, callback);
2952 fadeOut: function(speed, callback){
2953 return this.animate({opacity: "hide"}, speed, callback);
2956 fadeTo: function(speed,to,callback){
2957 return this.animate({opacity: to}, speed, callback);
2960 animate: function( prop, speed, easing, callback ) {
2961 var optall = jQuery.speed(speed, easing, callback);
2963 return this[ optall.queue === false ? "each" : "queue" ](function(){
2964 if ( this.nodeType != 1)
2967 var opt = jQuery.extend({}, optall);
2968 var hidden = jQuery(this).is(":hidden"), self = this;
2970 for ( var p in prop ) {
2971 if ( prop[p] == "hide" && hidden || prop[p] == "show" && !hidden )
2972 return jQuery.isFunction(opt.complete) && opt.complete.apply(this);
2974 if ( p == "height" || p == "width" ) {
2975 // Store display property
2976 opt.display = jQuery.css(this, "display");
2978 // Make sure that nothing sneaks out
2979 opt.overflow = this.style.overflow;
2983 if ( opt.overflow != null )
2984 this.style.overflow = "hidden";
2986 opt.curAnim = jQuery.extend({}, prop);
2988 jQuery.each( prop, function(name, val){
2989 var e = new jQuery.fx( self, opt, name );
2991 if ( /toggle|show|hide/.test(val) )
2992 e[ val == "toggle" ? hidden ? "show" : "hide" : val ]( prop );
2994 var parts = val.toString().match(/^([+-]=)?([\d+-.]+)(.*)$/),
2995 start = e.cur(true) || 0;
2998 var end = parseFloat(parts[2]),
2999 unit = parts[3] || "px";
3001 // We need to compute starting value
3002 if ( unit != "px" ) {
3003 self.style[ name ] = (end || 1) + unit;
3004 start = ((end || 1) / e.cur(true)) * start;
3005 self.style[ name ] = start + unit;
3008 // If a +=/-= token was provided, we're doing a relative animation
3010 end = ((parts[1] == "-=" ? -1 : 1) * end) + start;
3012 e.custom( start, end, unit );
3014 e.custom( start, val, "" );
3018 // For JS strict compliance
3023 queue: function(type, fn){
3024 if ( jQuery.isFunction(type) || ( type && type.constructor == Array )) {
3029 if ( !type || (typeof type == "string" && !fn) )
3030 return queue( this[0], type );
3032 return this.each(function(){
3033 if ( fn.constructor == Array )
3034 queue(this, type, fn);
3036 queue(this, type).push( fn );
3038 if ( queue(this, type).length == 1 )
3044 stop: function(clearQueue, gotoEnd){
3045 var timers = jQuery.timers;
3050 this.each(function(){
3051 // go in reverse order so anything added to the queue during the loop is ignored
3052 for ( var i = timers.length - 1; i >= 0; i-- )
3053 if ( timers[i].elem == this ) {
3055 // force the next step to be the last
3057 timers.splice(i, 1);
3061 // start the next in the queue if the last step wasn't forced
3070 var queue = function( elem, type, array ) {
3074 type = type || "fx";
3076 var q = jQuery.data( elem, type + "queue" );
3079 q = jQuery.data( elem, type + "queue",
3080 array ? jQuery.makeArray(array) : [] );
3085 jQuery.fn.dequeue = function(type){
3086 type = type || "fx";
3088 return this.each(function(){
3089 var q = queue(this, type);
3100 speed: function(speed, easing, fn) {
3101 var opt = speed && speed.constructor == Object ? speed : {
3102 complete: fn || !fn && easing ||
3103 jQuery.isFunction( speed ) && speed,
3105 easing: fn && easing || easing && easing.constructor != Function && easing
3108 opt.duration = (opt.duration && opt.duration.constructor == Number ?
3110 { slow: 600, fast: 200 }[opt.duration]) || 400;
3113 opt.old = opt.complete;
3114 opt.complete = function(){
3115 if ( opt.queue !== false )
3116 jQuery(this).dequeue();
3117 if ( jQuery.isFunction( opt.old ) )
3118 opt.old.apply( this );
3125 linear: function( p, n, firstNum, diff ) {
3126 return firstNum + diff * p;
3128 swing: function( p, n, firstNum, diff ) {
3129 return ((-Math.cos(p*Math.PI)/2) + 0.5) * diff + firstNum;
3136 fx: function( elem, options, prop ){
3137 this.options = options;
3141 if ( !options.orig )
3147 jQuery.fx.prototype = {
3149 // Simple function for setting a style value
3151 if ( this.options.step )
3152 this.options.step.apply( this.elem, [ this.now, this ] );
3154 (jQuery.fx.step[this.prop] || jQuery.fx.step._default)( this );
3156 // Set display property to block for height/width animations
3157 if ( this.prop == "height" || this.prop == "width" )
3158 this.elem.style.display = "block";
3161 // Get the current size
3162 cur: function(force){
3163 if ( this.elem[this.prop] != null && this.elem.style[this.prop] == null )
3164 return this.elem[ this.prop ];
3166 var r = parseFloat(jQuery.css(this.elem, this.prop, force));
3167 return r && r > -10000 ? r : parseFloat(jQuery.curCSS(this.elem, this.prop)) || 0;
3170 // Start an animation from one number to another
3171 custom: function(from, to, unit){
3172 this.startTime = (new Date()).getTime();
3175 this.unit = unit || this.unit || "px";
3176 this.now = this.start;
3177 this.pos = this.state = 0;
3181 function t(gotoEnd){
3182 return self.step(gotoEnd);
3187 jQuery.timers.push(t);
3189 if ( jQuery.timerId == null ) {
3190 jQuery.timerId = setInterval(function(){
3191 var timers = jQuery.timers;
3193 for ( var i = 0; i < timers.length; i++ )
3195 timers.splice(i--, 1);
3197 if ( !timers.length ) {
3198 clearInterval( jQuery.timerId );
3199 jQuery.timerId = null;
3205 // Simple 'show' function
3207 // Remember where we started, so that we can go back to it later
3208 this.options.orig[this.prop] = jQuery.attr( this.elem.style, this.prop );
3209 this.options.show = true;
3211 // Begin the animation
3212 this.custom(0, this.cur());
3214 // Make sure that we start at a small width/height to avoid any
3216 if ( this.prop == "width" || this.prop == "height" )
3217 this.elem.style[this.prop] = "1px";
3219 // Start by showing the element
3220 jQuery(this.elem).show();
3223 // Simple 'hide' function
3225 // Remember where we started, so that we can go back to it later
3226 this.options.orig[this.prop] = jQuery.attr( this.elem.style, this.prop );
3227 this.options.hide = true;
3229 // Begin the animation
3230 this.custom(this.cur(), 0);
3233 // Each step of an animation
3234 step: function(gotoEnd){
3235 var t = (new Date()).getTime();
3237 if ( gotoEnd || t > this.options.duration + this.startTime ) {
3238 this.now = this.end;
3239 this.pos = this.state = 1;
3242 this.options.curAnim[ this.prop ] = true;
3245 for ( var i in this.options.curAnim )
3246 if ( this.options.curAnim[i] !== true )
3250 if ( this.options.display != null ) {
3251 // Reset the overflow
3252 this.elem.style.overflow = this.options.overflow;
3254 // Reset the display
3255 this.elem.style.display = this.options.display;
3256 if ( jQuery.css(this.elem, "display") == "none" )
3257 this.elem.style.display = "block";
3260 // Hide the element if the "hide" operation was done
3261 if ( this.options.hide )
3262 this.elem.style.display = "none";
3264 // Reset the properties, if the item has been hidden or shown
3265 if ( this.options.hide || this.options.show )
3266 for ( var p in this.options.curAnim )
3267 jQuery.attr(this.elem.style, p, this.options.orig[p]);
3270 // If a callback was provided, execute it
3271 if ( done && jQuery.isFunction( this.options.complete ) )
3272 // Execute the complete function
3273 this.options.complete.apply( this.elem );
3277 var n = t - this.startTime;
3278 this.state = n / this.options.duration;
3280 // Perform the easing function, defaults to swing
3281 this.pos = jQuery.easing[this.options.easing || (jQuery.easing.swing ? "swing" : "linear")](this.state, n, 0, 1, this.options.duration);
3282 this.now = this.start + ((this.end - this.start) * this.pos);
3284 // Perform the next step of the animation
3294 scrollLeft: function(fx){
3295 fx.elem.scrollLeft = fx.now;
3298 scrollTop: function(fx){
3299 fx.elem.scrollTop = fx.now;
3302 opacity: function(fx){
3303 jQuery.attr(fx.elem.style, "opacity", fx.now);
3306 _default: function(fx){
3307 fx.elem.style[ fx.prop ] = fx.now + fx.unit;
3310 // The Offset Method
3311 // Originally By Brandon Aaron, part of the Dimension Plugin
3312 // http://jquery.com/plugins/project/dimensions
3313 jQuery.fn.offset = function() {
3314 var left = 0, top = 0, elem = this[0], results;
3316 if ( elem ) with ( jQuery.browser ) {
3317 var parent = elem.parentNode,
3319 offsetParent = elem.offsetParent,
3320 doc = elem.ownerDocument,
3321 safari2 = safari && parseInt(version) < 522 && !/adobeair/i.test(userAgent),
3322 fixed = jQuery.css(elem, "position") == "fixed";
3324 // Use getBoundingClientRect if available
3325 if ( elem.getBoundingClientRect ) {
3326 var box = elem.getBoundingClientRect();
3328 // Add the document scroll offsets
3329 add(box.left + Math.max(doc.documentElement.scrollLeft, doc.body.scrollLeft),
3330 box.top + Math.max(doc.documentElement.scrollTop, doc.body.scrollTop));
3332 // IE adds the HTML element's border, by default it is medium which is 2px
3333 // IE 6 and 7 quirks mode the border width is overwritable by the following css html { border: 0; }
3334 // IE 7 standards mode, the border is always 2px
3335 // This border/offset is typically represented by the clientLeft and clientTop properties
3336 // However, in IE6 and 7 quirks mode the clientLeft and clientTop properties are not updated when overwriting it via CSS
3337 // Therefore this method will be off by 2px in IE while in quirksmode
3338 add( -doc.documentElement.clientLeft, -doc.documentElement.clientTop );
3340 // Otherwise loop through the offsetParents and parentNodes
3343 // Initial element offsets
3344 add( elem.offsetLeft, elem.offsetTop );
3346 // Get parent offsets
3347 while ( offsetParent ) {
3348 // Add offsetParent offsets
3349 add( offsetParent.offsetLeft, offsetParent.offsetTop );
3351 // Mozilla and Safari > 2 does not include the border on offset parents
3352 // However Mozilla adds the border for table or table cells
3353 if ( mozilla && !/^t(able|d|h)$/i.test(offsetParent.tagName) || safari && !safari2 )
3354 border( offsetParent );
3356 // Add the document scroll offsets if position is fixed on any offsetParent
3357 if ( !fixed && jQuery.css(offsetParent, "position") == "fixed" )
3360 // Set offsetChild to previous offsetParent unless it is the body element
3361 offsetChild = /^body$/i.test(offsetParent.tagName) ? offsetChild : offsetParent;
3362 // Get next offsetParent
3363 offsetParent = offsetParent.offsetParent;
3366 // Get parent scroll offsets
3367 while ( parent && parent.tagName && !/^body|html$/i.test(parent.tagName) ) {
3368 // Remove parent scroll UNLESS that parent is inline or a table to work around Opera inline/table scrollLeft/Top bug
3369 if ( !/^inline|table.*$/i.test(jQuery.css(parent, "display")) )
3370 // Subtract parent scroll offsets
3371 add( -parent.scrollLeft, -parent.scrollTop );
3373 // Mozilla does not add the border for a parent that has overflow != visible
3374 if ( mozilla && jQuery.css(parent, "overflow") != "visible" )
3378 parent = parent.parentNode;
3381 // Safari <= 2 doubles body offsets with a fixed position element/offsetParent or absolutely positioned offsetChild
3382 // Mozilla doubles body offsets with a non-absolutely positioned offsetChild
3383 if ( (safari2 && (fixed || jQuery.css(offsetChild, "position") == "absolute")) ||
3384 (mozilla && jQuery.css(offsetChild, "position") != "absolute") )
3385 add( -doc.body.offsetLeft, -doc.body.offsetTop );
3387 // Add the document scroll offsets if position is fixed
3389 add(Math.max(doc.documentElement.scrollLeft, doc.body.scrollLeft),
3390 Math.max(doc.documentElement.scrollTop, doc.body.scrollTop));
3393 // Return an object with top and left properties
3394 results = { top: top, left: left };
3397 function border(elem) {
3398 add( jQuery.curCSS(elem, "borderLeftWidth", true), jQuery.curCSS(elem, "borderTopWidth", true) );
3401 function add(l, t) {
3402 left += parseInt(l) || 0;
3403 top += parseInt(t) || 0;