2 * jQuery @VERSION - New Wave Javascript
4 * Copyright (c) 2007 John Resig (jquery.com)
5 * Dual licensed under the MIT (MIT-LICENSE.txt)
6 * and GPL (GPL-LICENSE.txt) licenses.
12 // Map over jQuery in case of overwrite
14 var _jQuery = window.jQuery;
16 var jQuery = window.jQuery = function( selector, context ) {
17 // If the context is a namespace object, return a new object
18 return this instanceof jQuery ?
19 this.init( selector, context ) :
20 new jQuery( selector, context );
23 // Map over the $ in case of overwrite
27 // Map the jQuery namespace to the '$' one
30 // A simple way to check for HTML strings or ID strings
31 // (both of which we optimize for)
32 var quickExpr = /^[^<]*(<(.|\s)+>)[^>]*$|^#(\w+)$/;
34 jQuery.fn = jQuery.prototype = {
35 init: function( selector, context ) {
36 // Make sure that a selection was provided
37 selector = selector || document;
39 // Handle $(DOMElement)
40 if ( selector.nodeType ) {
45 // Handle HTML strings
46 } else if ( typeof selector == "string" ) {
47 // Are we dealing with HTML string or an ID?
48 var match = quickExpr.exec( selector );
50 // Verify a match, and that no context was specified for #id
51 if ( match && (match[1] || !context) ) {
53 // HANDLE: $(html) -> $(array)
55 selector = jQuery.clean( [ match[1] ], context );
59 var elem = document.getElementById( match[3] );
61 // Make sure an element was located
63 // Handle the case where IE and Opera return items
64 // by name instead of ID
65 if ( elem.id != match[3] )
66 return jQuery().find( selector );
68 // Otherwise, we inject the element directly into the jQuery object
79 // HANDLE: $(expr, [context])
80 // (which is just equivalent to: $(content).find(expr)
82 return new jQuery( context ).find( selector );
84 // HANDLE: $(function)
85 // Shortcut for document ready
86 } else if ( jQuery.isFunction( selector ) )
87 return new jQuery( document )[ jQuery.fn.ready ? "ready" : "load" ]( selector );
91 selector.constructor == Array && selector ||
93 // HANDLE: $(arraylike)
94 // Watch for when an array-like object, contains DOM nodes, is passed in as the selector
95 (selector.jquery || selector.length && selector != window && !selector.nodeType && selector[0] != undefined && selector[0].nodeType) && jQuery.makeArray( selector ) ||
101 // The current version of jQuery being used
104 // The number of elements contained in the matched element set
109 // The number of elements contained in the matched element set
112 // Get the Nth element in the matched element set OR
113 // Get the whole matched element set as a clean array
114 get: function( num ) {
115 return num == undefined ?
117 // Return a 'clean' array
118 jQuery.makeArray( this ) :
120 // Return just the object
124 // Take an array of elements and push it onto the stack
125 // (returning the new matched element set)
126 pushStack: function( elems ) {
127 // Build a new jQuery matched element set
128 var ret = jQuery( elems );
130 // Add the old object onto the stack (as a reference)
131 ret.prevObject = this;
133 // Return the newly-formed element set
137 // Force the current matched set of elements to become
138 // the specified array of elements (destroying the stack in the process)
139 // You should use pushStack() in order to do this, but maintain the stack
140 setArray: function( elems ) {
141 // Resetting the length to 0, then using the native Array push
142 // is a super-fast way to populate an object with array-like properties
144 Array.prototype.push.apply( this, elems );
149 // Execute a callback for every element in the matched set.
150 // (You can seed the arguments with an array of args, but this is
151 // only used internally.)
152 each: function( callback, args ) {
153 return jQuery.each( this, callback, args );
156 // Determine the position of an element within
157 // the matched set of elements
158 index: function( elem ) {
161 // Locate the position of the desired element
162 this.each(function(i){
170 attr: function( name, value, type ) {
173 // Look for the case where we're accessing a style value
174 if ( name.constructor == String )
175 if ( value == undefined )
176 return this.length && jQuery[ type || "attr" ]( this[0], name ) || undefined;
180 options[ name ] = value;
183 // Check to see if we're setting style values
184 return this.each(function(i){
185 // Set all the styles
186 for ( name in options )
191 name, jQuery.prop( this, options[ name ], type, i, name )
196 css: function( key, value ) {
197 // ignore negative width and height values
198 if ( (key == 'width' || key == 'height') && parseFloat(value) < 0 )
200 return this.attr( key, value, "curCSS" );
203 text: function( text ) {
204 if ( typeof text != "object" && text != null )
205 return this.empty().append( document.createTextNode( text ) );
209 jQuery.each( text || this, function(){
210 jQuery.each( this.childNodes, function(){
211 if ( this.nodeType != 8 )
212 ret += this.nodeType != 1 ?
214 jQuery.fn.text( [ this ] );
221 wrapAll: function( html ) {
223 // The elements to wrap the target around
224 jQuery( html, this[0].ownerDocument )
226 .insertBefore( this[0] )
230 while ( elem.firstChild )
231 elem = elem.firstChild;
240 wrapInner: function( html ) {
241 return this.each(function(){
242 jQuery( this ).contents().wrapAll( html );
246 wrap: function( html ) {
247 return this.each(function(){
248 jQuery( this ).wrapAll( html );
253 return this.domManip(arguments, true, false, function(elem){
254 this.appendChild( elem );
258 prepend: function() {
259 return this.domManip(arguments, true, true, function(elem){
260 this.insertBefore( elem, this.firstChild );
265 return this.domManip(arguments, false, false, function(elem){
266 this.parentNode.insertBefore( elem, this );
271 return this.domManip(arguments, false, true, function(elem){
272 this.parentNode.insertBefore( elem, this.nextSibling );
277 return this.prevObject || jQuery( [] );
280 find: function( selector ) {
281 var elems = jQuery.map(this, function(elem){
282 return jQuery.find( selector, elem );
285 return this.pushStack( /[^+>] [^+>]/.test( selector ) || selector.indexOf("..") > -1 ?
286 jQuery.unique( elems ) :
290 clone: function( events ) {
292 var ret = this.map(function(){
293 return this.outerHTML ?
294 jQuery( this.outerHTML )[0] :
295 this.cloneNode( true );
298 // Need to set the expando to null on the cloned set if it exists
299 // removeData doesn't work here, IE removes it from the original as well
300 // this is primarily for IE but the data expando shouldn't be copied over in any browser
301 var clone = ret.find("*").andSelf().each(function(){
302 if ( this[ expando ] != undefined )
303 this[ expando ] = null;
306 // Copy the events from the original to the clone
307 if ( events === true )
308 this.find("*").andSelf().each(function(i){
309 var events = jQuery.data( this, "events" );
311 for ( var type in events )
312 for ( var handler in events[ type ] )
313 jQuery.event.add( clone[ i ], type, events[ type ][ handler ], events[ type ][ handler ].data );
316 // Return the cloned set
320 filter: function( selector ) {
321 return this.pushStack(
322 jQuery.isFunction( selector ) &&
323 jQuery.grep(this, function(elem, i){
324 return selector.call( elem, i );
327 jQuery.multiFilter( selector, this ) );
330 not: function( selector ) {
331 return this.pushStack(
332 selector.constructor == String &&
333 jQuery.multiFilter( selector, this, true ) ||
335 jQuery.grep(this, function(elem) {
336 return selector.constructor == Array || selector.jquery ?
337 jQuery.inArray( elem, selector ) < 0 :
342 add: function( selector ) {
343 return this.pushStack( jQuery.merge(
345 selector.constructor == String ?
346 jQuery( selector ).get() :
347 selector.length != undefined && (!selector.nodeName || jQuery.nodeName(selector, "form")) ?
348 selector : [selector] ) );
351 is: function( selector ) {
353 jQuery.multiFilter( selector, this ).length > 0 :
357 hasClass: function( selector ) {
358 return this.is( "." + selector );
361 val: function( value ) {
362 if ( value == undefined ) {
367 // We need to handle select boxes special
368 if ( jQuery.nodeName( elem, "select" ) ) {
369 var index = elem.selectedIndex,
371 options = elem.options,
372 one = elem.type == "select-one";
374 // Nothing was selected
378 // Loop through all the selected options
379 for ( var i = one ? index : 0, max = one ? index + 1 : options.length; i < max; i++ ) {
380 var option = options[ i ];
382 if ( option.selected ) {
383 // Get the specifc value for the option
384 value = jQuery.browser.msie && !option.attributes.value.specified ? option.text : option.value;
386 // We don't need an array for one selects
390 // Multi-Selects return an array
391 values.push( value );
397 // Everything else, we just grab the value
399 return (this[0].value || "").replace(/\r/g, "");
404 return this.each(function(){
405 if ( value.constructor == Array && /radio|checkbox/.test( this.type ) )
406 this.checked = (jQuery.inArray(this.value, value) >= 0 ||
407 jQuery.inArray(this.name, value) >= 0);
409 else if ( jQuery.nodeName( this, "select" ) ) {
410 var values = value.constructor == Array ?
414 jQuery( "option", this ).each(function(){
415 this.selected = (jQuery.inArray( this.value, values ) >= 0 ||
416 jQuery.inArray( this.text, values ) >= 0);
419 if ( !values.length )
420 this.selectedIndex = -1;
427 html: function( value ) {
428 return value == undefined ?
432 this.empty().append( value );
435 replaceWith: function( value ) {
436 return this.after( value ).remove();
440 return this.slice( i, i + 1 );
444 return this.pushStack( Array.prototype.slice.apply( this, arguments ) );
447 map: function( callback ) {
448 return this.pushStack( jQuery.map(this, function(elem, i){
449 return callback.call( elem, i, elem );
453 andSelf: function() {
454 return this.add( this.prevObject );
457 domManip: function( args, table, reverse, callback ) {
458 var clone = this.length > 1, elems;
460 return this.each(function(){
462 elems = jQuery.clean( args, this.ownerDocument );
470 if ( table && jQuery.nodeName( this, "table" ) && jQuery.nodeName( elems[0], "tr" ) )
471 obj = this.getElementsByTagName("tbody")[0] || this.appendChild( document.createElement("tbody") );
473 var scripts = jQuery( [] );
475 jQuery.each(elems, function(){
477 this.cloneNode( true ) :
480 if ( jQuery.nodeName( elem, "script" ) ) {
482 // If scripts are waiting to be executed, wait on this script as well
483 if ( scripts.length )
484 scripts = scripts.add( elem );
486 // If nothing is waiting to be executed, run immediately
488 evalScript( 0, elem );
491 // Remove any inner scripts for later evaluation
492 if ( elem.nodeType == 1 )
493 scripts = scripts.add( jQuery( "script", elem ).remove() );
495 // Inject the elements into the document
496 callback.call( obj, elem );
500 scripts.each( evalScript );
505 function evalScript( i, elem ) {
514 jQuery.globalEval( elem.text || elem.textContent || elem.innerHTML || "" );
516 if ( elem.parentNode )
517 elem.parentNode.removeChild( elem );
520 jQuery.extend = jQuery.fn.extend = function() {
521 // copy reference to target object
522 var target = arguments[0] || {}, i = 1, length = arguments.length, deep = false, options;
524 // Handle a deep copy situation
525 if ( target.constructor == Boolean ) {
527 target = arguments[1] || {};
528 // skip the boolean and the target
532 // Handle case when target is a string or something (possible in deep copy)
533 if ( typeof target != "object" )
536 // extend jQuery itself if only one argument is passed
542 for ( ; i < length; i++ )
543 // Only deal with non-null/undefined values
544 if ( (options = arguments[ i ]) != null )
545 // Extend the base object
546 for ( var name in options ) {
547 // Prevent never-ending loop
548 if ( target === options[ name ] )
551 // Recurse if we're merging object values
552 if ( deep && options[ name ] && typeof options[ name ] == "object" && target[ name ] && !options[ name ].nodeType )
553 target[ name ] = jQuery.extend( target[ name ], options[ name ] );
555 // Don't bring in undefined values
556 else if ( options[ name ] != undefined )
557 target[ name ] = options[ name ];
561 // Return the modified object
565 var expando = "jQuery" + (new Date()).getTime(), uuid = 0, windowData = {};
567 // exclude the following css properties to add px
568 var exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i;
571 noConflict: function( deep ) {
575 window.jQuery = _jQuery;
580 // This may seem like some crazy code, but trust me when I say that this
581 // is the only cross-browser way to do this. --John
582 isFunction: function( fn ) {
583 return !!fn && typeof fn != "string" && !fn.nodeName &&
584 fn.constructor != Array && /function/i.test( fn + "" );
587 // check if an element is in a (or is an) XML document
588 isXMLDoc: function( elem ) {
589 return elem.documentElement && !elem.body ||
590 elem.tagName && elem.ownerDocument && !elem.ownerDocument.body;
593 // Evalulates a script in a global context
594 // Evaluates Async. in Safari 2 :-(
595 globalEval: function( data ) {
596 data = jQuery.trim( data );
599 // Inspired by code by Andrea Giammarchi
600 // http://webreflection.blogspot.com/2007/08/global-scope-evaluation-and-dom.html
601 var head = document.getElementsByTagName("head")[0] || document.documentElement,
602 script = document.createElement("script");
604 script.type = "text/javascript";
605 if ( jQuery.browser.msie )
608 script.appendChild( document.createTextNode( data ) );
610 head.appendChild( script );
611 head.removeChild( script );
615 nodeName: function( elem, name ) {
616 return elem.nodeName && elem.nodeName.toUpperCase() == name.toUpperCase();
621 data: function( elem, name, data ) {
622 elem = elem == window ?
626 var id = elem[ expando ];
628 // Compute a unique ID for the element
630 id = elem[ expando ] = ++uuid;
632 // Only generate the data cache if we're
633 // trying to access or manipulate it
634 if ( name && !jQuery.cache[ id ] )
635 jQuery.cache[ id ] = {};
637 // Prevent overriding the named cache with undefined values
638 if ( data != undefined )
639 jQuery.cache[ id ][ name ] = data;
641 // Return the named cache data, or the ID for the element
643 jQuery.cache[ id ][ name ] :
647 removeData: function( elem, name ) {
648 elem = elem == window ?
652 var id = elem[ expando ];
654 // If we want to remove a specific section of the element's data
656 if ( jQuery.cache[ id ] ) {
657 // Remove the section of cache data
658 delete jQuery.cache[ id ][ name ];
660 // If we've removed all the data, remove the element's cache
663 for ( name in jQuery.cache[ id ] )
667 jQuery.removeData( elem );
670 // Otherwise, we want to remove all of the element's data
672 // Clean up the element expando
674 delete elem[ expando ];
676 // IE has trouble directly removing the expando
677 // but it's ok with using removeAttribute
678 if ( elem.removeAttribute )
679 elem.removeAttribute( expando );
682 // Completely remove the data cache
683 delete jQuery.cache[ id ];
687 // args is for internal usage only
688 each: function( object, callback, args ) {
690 if ( object.length == undefined )
691 for ( var name in object )
692 callback.apply( object[ name ], args );
694 for ( var i = 0, length = object.length; i < length; i++ )
695 if ( callback.apply( object[ i ], args ) === false )
698 // A special, fast, case for the most common use of each
700 if ( object.length == undefined )
701 for ( var name in object )
702 callback.call( object[ name ], name, object[ name ] );
704 for ( var i = 0, length = object.length, value = object[0];
705 i < length && callback.call( value, i, value ) !== false; value = object[++i] ){}
711 prop: function( elem, value, type, i, name ) {
712 // Handle executable functions
713 if ( jQuery.isFunction( value ) )
714 value = value.call( elem, i );
716 // Handle passing in a number to a CSS property
717 return value && value.constructor == Number && type == "curCSS" && !exclude.test( name ) ?
723 // internal only, use addClass("class")
724 add: function( elem, classNames ) {
725 jQuery.each((classNames || "").split(/\s+/), function(i, className){
726 if ( !jQuery.className.has( elem.className, className ) )
727 elem.className += (elem.className ? " " : "") + className;
731 // internal only, use removeClass("class")
732 remove: function( elem, classNames ) {
733 elem.className = classNames != undefined ?
734 jQuery.grep(elem.className.split(/\s+/), function(className){
735 return !jQuery.className.has( classNames, className );
740 // internal only, use is(".class")
741 has: function( elem, className ) {
742 return jQuery.inArray( className, (elem.className || elem).toString().split(/\s+/) ) > -1;
746 // A method for quickly swapping in/out CSS properties to get correct calculations
747 swap: function( elem, options, callback ) {
748 // Remember the old values, and insert the new ones
749 for ( var name in options ) {
750 elem.style[ "old" + name ] = elem.style[ name ];
751 elem.style[ name ] = options[ name ];
754 callback.call( elem );
756 // Revert the old values
757 for ( var name in options )
758 elem.style[ name ] = elem.style[ "old" + name ];
761 css: function( elem, name, force ) {
762 if ( name == "height" || name == "width" ) {
763 var old = {}, height, width;
765 // Revert the padding and border widths to get the
766 // correct height/width values
767 jQuery.each([ "Top", "Bottom", "Right", "Left" ], function(){
768 old[ "padding" + this ] = 0;
769 old[ "border" + this + "Width" ] = 0;
772 // Swap out the padding/border values temporarily
773 jQuery.swap( elem, old, function() {
775 // If the element is visible, then the calculation is easy
776 if ( jQuery( elem ).is(":visible") ) {
777 height = elem.offsetHeight;
778 width = elem.offsetWidth;
780 // Otherwise, we need to flip out more values
782 elem = jQuery( elem.cloneNode(true) )
783 .find(":radio").removeAttr("checked").removeAttr("defaultChecked").end()
785 visibility: "hidden",
786 position: "absolute",
790 }).appendTo( elem.parentNode )[0];
792 var position = jQuery.css( elem.parentNode, "position" ) || "static";
793 if ( position == "static" )
794 elem.parentNode.style.position = "relative";
796 height = elem.clientHeight;
797 width = elem.clientWidth;
799 if ( position == "static" )
800 elem.parentNode.style.position = "static";
802 elem.parentNode.removeChild( elem );
806 return name == "height" ?
811 return jQuery.curCSS( elem, name, force );
814 curCSS: function( elem, name, force ) {
817 // A helper method for determining if an element's values are broken
818 function color( elem ) {
819 if ( !jQuery.browser.safari )
822 var ret = document.defaultView.getComputedStyle( elem, null );
823 return !ret || ret.getPropertyValue("color") == "";
826 // We need to handle opacity special in IE
827 if ( name == "opacity" && jQuery.browser.msie ) {
828 ret = jQuery.attr( elem.style, "opacity" );
835 // Make sure we're using the right name for getting the float value
836 if ( name.match( /float/i ) )
839 if ( !force && elem.style[ name ] )
840 ret = elem.style[ name ];
842 else if ( document.defaultView && document.defaultView.getComputedStyle ) {
844 // Only "float" is needed here
845 if ( name.match( /float/i ) )
848 name = name.replace( /([A-Z])/g, "-$1" ).toLowerCase();
850 var getComputedStyle = document.defaultView.getComputedStyle( elem, null );
852 if ( getComputedStyle && !color( elem ) )
853 ret = getComputedStyle.getPropertyValue( name );
855 // If the element isn't reporting its values properly in Safari
856 // then some display: none elements are involved
858 var swap = [], stack = [];
860 // Locate all of the parent display: none elements
861 for ( var a = elem; a && color(a); a = a.parentNode )
864 // Go through and make them visible, but in reverse
865 // (It would be better if we knew the exact display type that they had)
866 for ( var i = 0; i < stack.length; i++ )
867 if ( color( stack[ i ] ) ) {
868 swap[ i ] = stack[ i ].style.display;
869 stack[ i ].style.display = "block";
872 // Since we flip the display style, we have to handle that
873 // one special, otherwise get the value
874 ret = name == "display" && swap[ stack.length - 1 ] != null ?
876 ( getComputedStyle && getComputedStyle.getPropertyValue( name ) ) || "";
878 // Finally, revert the display styles back
879 for ( var i = 0; i < swap.length; i++ )
880 if ( swap[ i ] != null )
881 stack[ i ].style.display = swap[ i ];
884 // We should always get a number back from opacity
885 if ( name == "opacity" && ret == "" )
888 } else if ( elem.currentStyle ) {
889 var camelCase = name.replace(/\-(\w)/g, function(all, letter){
890 return letter.toUpperCase();
893 ret = elem.currentStyle[ name ] || elem.currentStyle[ camelCase ];
895 // From the awesome hack by Dean Edwards
896 // http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291
898 // If we're not dealing with a regular pixel number
899 // but a number that has a weird ending, we need to convert it to pixels
900 if ( !/^\d+(px)?$/i.test( ret ) && /^\d/.test( ret ) ) {
901 // Remember the original values
902 var style = elem.style.left, runtimeStyle = elem.runtimeStyle.left;
904 // Put in the new values to get a computed value out
905 elem.runtimeStyle.left = elem.currentStyle.left;
906 elem.style.left = ret || 0;
907 ret = elem.style.pixelLeft + "px";
909 // Revert the changed values
910 elem.style.left = style;
911 elem.runtimeStyle.left = runtimeStyle;
918 clean: function( elems, context ) {
920 context = context || document;
922 jQuery.each(elems, function(i, elem){
926 if ( elem.constructor == Number )
927 elem = elem.toString();
929 // Convert html string into DOM nodes
930 if ( typeof elem == "string" ) {
931 // Fix "XHTML"-style tags in all browsers
932 elem = elem.replace(/(<(\w+)[^>]*?)\/>/g, function(all, front, tag){
933 return tag.match(/^(abbr|br|col|img|input|link|meta|param|hr|area)$/i) ?
935 front + "></" + tag + ">";
938 // Trim whitespace, otherwise indexOf won't work as expected
939 var tags = jQuery.trim( elem ).toLowerCase(), div = context.createElement("div");
942 // option or optgroup
943 !tags.indexOf("<opt") &&
944 [ 1, "<select multiple='multiple'>", "</select>" ] ||
946 !tags.indexOf("<leg") &&
947 [ 1, "<fieldset>", "</fieldset>" ] ||
949 tags.match(/^<(thead|tbody|tfoot|colg|cap)/) &&
950 [ 1, "<table>", "</table>" ] ||
952 !tags.indexOf("<tr") &&
953 [ 2, "<table><tbody>", "</tbody></table>" ] ||
955 // <thead> matched above
956 (!tags.indexOf("<td") || !tags.indexOf("<th")) &&
957 [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ] ||
959 !tags.indexOf("<col") &&
960 [ 2, "<table><tbody></tbody><colgroup>", "</colgroup></table>" ] ||
962 // IE can't serialize <link> and <script> tags normally
963 jQuery.browser.msie &&
964 [ 1, "div<div>", "</div>" ] ||
968 // Go to html and back, then peel off extra wrappers
969 div.innerHTML = wrap[1] + elem + wrap[2];
971 // Move to the right depth
975 // Remove IE's autoinserted <tbody> from table fragments
976 if ( jQuery.browser.msie ) {
978 // String was a <table>, *may* have spurious <tbody>
979 var tbody = !tags.indexOf("<table") && tags.indexOf("<tbody") < 0 ?
980 div.firstChild && div.firstChild.childNodes :
982 // String was a bare <thead> or <tfoot>
983 wrap[1] == "<table>" && tags.indexOf("<tbody") < 0 ?
987 for ( var i = tbody.length - 1; i >= 0 ; --i )
988 if ( jQuery.nodeName( tbody[ i ], "tbody" ) && !tbody[ i ].childNodes.length )
989 tbody[ i ].parentNode.removeChild( tbody[ i ] );
991 // IE completely kills leading whitespace when innerHTML is used
992 if ( /^\s/.test( elem ) )
993 div.insertBefore( context.createTextNode( elem.match(/^\s*/)[0] ), div.firstChild );
997 elem = jQuery.makeArray( div.childNodes );
1000 if ( elem.length === 0 && (!jQuery.nodeName( elem, "form" ) && !jQuery.nodeName( elem, "select" )) )
1003 if ( elem[0] == undefined || jQuery.nodeName( elem, "form" ) || elem.options )
1007 ret = jQuery.merge( ret, elem );
1014 attr: function( elem, name, value ) {
1015 var fix = jQuery.isXMLDoc( elem ) ?
1019 // Safari mis-reports the default selected property of a hidden option
1020 // Accessing the parent's selectedIndex property fixes it
1021 if ( name == "selected" && jQuery.browser.safari )
1022 elem.parentNode.selectedIndex;
1024 // Certain attributes only work when accessed via the old DOM 0 way
1025 if ( fix[ name ] ) {
1026 if ( value != undefined )
1027 elem[ fix[ name ] ] = value;
1029 return elem[ fix[ name ] ];
1031 } else if ( jQuery.browser.msie && name == "style" )
1032 return jQuery.attr( elem.style, "cssText", value );
1034 else if ( value == undefined && jQuery.browser.msie && jQuery.nodeName( elem, "form" ) && (name == "action" || name == "method") )
1035 return elem.getAttributeNode( name ).nodeValue;
1037 // IE elem.getAttribute passes even for style
1038 else if ( elem.tagName ) {
1040 if ( value != undefined ) {
1041 // We can't allow the type property to be changed (since it causes problems in IE)
1042 if ( name == "type" && jQuery.nodeName( elem, "input" ) && elem.parentNode )
1043 throw "type property can't be changed";
1045 // convert the value to a string (all browsers do this but IE) see #1070
1046 elem.setAttribute( name, "" + value );
1049 if ( jQuery.browser.msie && /href|src/.test( name ) && !jQuery.isXMLDoc( elem ) )
1050 return elem.getAttribute( name, 2 );
1052 return elem.getAttribute( name );
1054 // elem is actually elem.style ... set the style
1056 // IE actually uses filters for opacity
1057 if ( name == "opacity" && jQuery.browser.msie ) {
1058 if ( value != undefined ) {
1059 // IE has trouble with opacity if it does not have layout
1060 // Force it by setting the zoom level
1063 // Set the alpha filter to set the opacity
1064 elem.filter = (elem.filter || "").replace( /alpha\([^)]*\)/, "" ) +
1065 (parseFloat( value ).toString() == "NaN" ? "" : "alpha(opacity=" + value * 100 + ")");
1068 return elem.filter ?
1069 (parseFloat( elem.filter.match(/opacity=([^)]*)/)[1] ) / 100).toString() :
1073 name = name.replace(/-([a-z])/ig, function(all, letter){
1074 return letter.toUpperCase();
1077 if ( value != undefined )
1078 elem[ name ] = value;
1080 return elem[ name ];
1084 trim: function( text ) {
1085 return (text || "").replace( /^\s+|\s+$/g, "" );
1088 makeArray: function( array ) {
1091 // Need to use typeof to fight Safari childNodes crashes
1092 if ( typeof array != "array" )
1093 for ( var i = 0, length = array.length; i < length; i++ )
1094 ret.push( array[ i ] );
1096 ret = array.slice( 0 );
1101 inArray: function( elem, array ) {
1102 for ( var i = 0, length = array.length; i < length; i++ )
1103 if ( array[ i ] == elem )
1109 merge: function( first, second ) {
1110 // We have to loop this way because IE & Opera overwrite the length
1111 // expando of getElementsByTagName
1113 // Also, we need to make sure that the correct elements are being returned
1114 // (IE returns comment nodes in a '*' query)
1115 if ( jQuery.browser.msie ) {
1116 for ( var i = 0; second[ i ]; i++ )
1117 if ( second[ i ].nodeType != 8 )
1118 first.push( second[ i ] );
1121 for ( var i = 0; second[ i ]; i++ )
1122 first.push( second[ i ] );
1127 unique: function( array ) {
1128 var ret = [], done = {};
1132 for ( var i = 0, length = array.length; i < length; i++ ) {
1133 var id = jQuery.data( array[ i ] );
1135 if ( !done[ id ] ) {
1137 ret.push( array[ i ] );
1148 grep: function( elems, callback, inv ) {
1149 // If a string is passed in for the function, make a function
1150 // for it (a handy shortcut)
1151 if ( typeof callback == "string" )
1152 callback = eval("false||function(a,i){return " + callback + "}");
1156 // Go through the array, only saving the items
1157 // that pass the validator function
1158 for ( var i = 0, length = elems.length; i < length; i++ )
1159 if ( !inv && callback( elems[ i ], i ) || inv && !callback( elems[ i ], i ) )
1160 ret.push( elems[ i ] );
1165 map: function( elems, callback ) {
1168 // Go through the array, translating each of the items to their
1169 // new value (or values).
1170 for ( var i = 0, length = elems.length; i < length; i++ ) {
1171 var value = callback( elems[ i ], i );
1173 if ( value !== null && value != undefined ) {
1174 if ( value.constructor != Array )
1177 ret = ret.concat( value );
1185 var userAgent = navigator.userAgent.toLowerCase();
1187 // Figure out what browser is being used
1189 version: (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [])[1],
1190 safari: /webkit/.test( userAgent ),
1191 opera: /opera/.test( userAgent ),
1192 msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
1193 mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )
1196 var styleFloat = jQuery.browser.msie ?
1201 // Check to see if the W3C box model is being used
1202 boxModel: !jQuery.browser.msie || document.compatMode == "CSS1Compat",
1206 "class": "className",
1207 "float": styleFloat,
1208 cssFloat: styleFloat,
1209 styleFloat: styleFloat,
1210 innerHTML: "innerHTML",
1211 className: "className",
1213 disabled: "disabled",
1215 readonly: "readOnly",
1216 selected: "selected",
1217 maxlength: "maxLength",
1218 selectedIndex: "selectedIndex",
1219 defaultValue: "defaultValue",
1221 nodeName: "nodeName"
1226 parent: "elem.parentNode",
1227 parents: "jQuery.dir(elem,'parentNode')",
1228 next: "jQuery.nth(elem,2,'nextSibling')",
1229 prev: "jQuery.nth(elem,2,'previousSibling')",
1230 nextAll: "jQuery.dir(elem,'nextSibling')",
1231 prevAll: "jQuery.dir(elem,'previousSibling')",
1232 siblings: "jQuery.sibling(elem.parentNode.firstChild,elem)",
1233 children: "jQuery.sibling(elem.firstChild)",
1234 contents: "jQuery.nodeName(elem,'iframe')?elem.contentDocument||elem.contentWindow.document:jQuery.makeArray(elem.childNodes)"
1235 }, function(name, fn){
1236 fn = eval("false||function(elem){return " + fn + "}");
1238 jQuery.fn[ name ] = function( selector ) {
1239 var ret = jQuery.map( this, fn );
1241 if ( selector && typeof selector == "string" )
1242 ret = jQuery.multiFilter( selector, ret );
1244 return this.pushStack( jQuery.unique( ret ) );
1250 prependTo: "prepend",
1251 insertBefore: "before",
1252 insertAfter: "after",
1253 replaceAll: "replaceWith"
1254 }, function(name, original){
1255 jQuery.fn[ name ] = function() {
1256 var args = arguments;
1258 return this.each(function(){
1259 for ( var i = 0, length = args.length; i < length; i++ )
1260 jQuery( args[ i ] )[ original ]( this );
1266 removeAttr: function( name ) {
1267 jQuery.attr( this, name, "" );
1268 this.removeAttribute( name );
1271 addClass: function( classNames ) {
1272 jQuery.className.add( this, classNames );
1275 removeClass: function( classNames ) {
1276 jQuery.className.remove( this, classNames );
1279 toggleClass: function( classNames ) {
1280 jQuery.className[ jQuery.className.has( this, classNames ) ? "remove" : "add" ]( this, classNames );
1283 remove: function( selector ) {
1284 if ( !selector || jQuery.filter( selector, [ this ] ).r.length ) {
1285 // Prevent memory leaks
1286 jQuery( "*", this ).add(this).each(function(){
1287 jQuery.event.remove(this);
1288 jQuery.removeData(this);
1290 if (this.parentNode)
1291 this.parentNode.removeChild( this );
1296 // Remove element nodes and prevent memory leaks
1297 jQuery( ">*", this ).remove();
1299 // Remove any remaining nodes
1300 while ( this.firstChild )
1301 this.removeChild( this.firstChild );
1303 }, function(name, fn){
1304 jQuery.fn[ name ] = function(){
1305 return this.each( fn, arguments );
1309 jQuery.each([ "Height", "Width" ], function(i, name){
1310 var type = name.toLowerCase();
1312 jQuery.fn[ type ] = function( size ) {
1313 // Get window width or height
1314 return this[0] == window ?
1315 // Opera reports document.body.client[Width/Height] properly in both quirks and standards
1316 jQuery.browser.opera && document.body[ "client" + name ] ||
1318 // Safari reports inner[Width/Height] just fine (Mozilla and Opera include scroll bar widths)
1319 jQuery.browser.safari && window[ "inner" + name ] ||
1321 // Everyone else use document.documentElement or document.body depending on Quirks vs Standards mode
1322 document.compatMode == "CSS1Compat" && document.documentElement[ "client" + name ] || document.body[ "client" + name ] :
1324 // Get document width or height
1325 this[0] == document ?
1326 // Either scroll[Width/Height] or offset[Width/Height], whichever is greater (Mozilla reports scrollWidth the same as offsetWidth)
1327 Math.max( document.body[ "scroll" + name ], document.body[ "offset" + name ] ) :
1329 // Get or set width or height on the element
1331 // Get width or height on the element
1332 (this.length ? jQuery.css( this[0], type ) : null) :
1334 // Set the width or height on the element (default to pixels if value is unitless)
1335 this.css( type, size.constructor == String ? size : size + "px" );