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
13 if ( typeof jQuery != "undefined" )
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
24 if ( typeof $ != "undefined" )
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 HTML strings
40 if ( typeof selector == "string" ) {
41 // Are we dealing with HTML string or an ID?
42 var match = quickExpr.exec( selector );
44 // Verify a match, and that no context was specified for #id
45 if ( match && (match[1] || !context) ) {
47 // HANDLE: $(html) -> $(array)
49 selector = jQuery.clean( [ match[1] ], context );
53 var elem = document.getElementById( match[3] );
55 // Make sure an element was located
57 // Handle the case where IE and Opera return items
58 // by name instead of ID
59 if ( elem.id != match[3] )
60 return jQuery().find( selector );
62 // Otherwise, we inject the element directly into the jQuery object
73 // HANDLE: $(expr, [context])
74 // (which is just equivalent to: $(content).find(expr)
76 return new jQuery( context ).find( selector );
78 // HANDLE: $(function)
79 // Shortcut for document ready
80 } else if ( jQuery.isFunction( selector ) )
81 return new jQuery( document )[ jQuery.fn.ready ? "ready" : "load" ]( selector );
85 selector.constructor == Array && selector ||
87 // HANDLE: $(arraylike)
88 // Watch for when an array-like object, contains DOM nodes, is passed in as the selector
89 (selector.jquery || selector.length && selector != window && !selector.nodeType && selector[0] != undefined && selector[0].nodeType) && jQuery.makeArray( selector ) ||
95 // The current version of jQuery being used
98 // The number of elements contained in the matched element set
103 // The number of elements contained in the matched element set
106 // Get the Nth element in the matched element set OR
107 // Get the whole matched element set as a clean array
108 get: function( num ) {
109 return num == undefined ?
111 // Return a 'clean' array
112 jQuery.makeArray( this ) :
114 // Return just the object
118 // Take an array of elements and push it onto the stack
119 // (returning the new matched element set)
120 pushStack: function( elems ) {
121 // Build a new jQuery matched element set
122 var ret = jQuery( elems );
124 // Add the old object onto the stack (as a reference)
125 ret.prevObject = this;
127 // Return the newly-formed element set
131 // Force the current matched set of elements to become
132 // the specified array of elements (destroying the stack in the process)
133 // You should use pushStack() in order to do this, but maintain the stack
134 setArray: function( elems ) {
135 // Resetting the length to 0, then using the native Array push
136 // is a super-fast way to populate an object with array-like properties
138 Array.prototype.push.apply( this, elems );
143 // Execute a callback for every element in the matched set.
144 // (You can seed the arguments with an array of args, but this is
145 // only used internally.)
146 each: function( callback, args ) {
147 return jQuery.each( this, callback, args );
150 // Determine the position of an element within
151 // the matched set of elements
152 index: function( elem ) {
155 // Locate the position of the desired element
156 this.each(function(i){
164 attr: function( name, value, type ) {
167 // Look for the case where we're accessing a style value
168 if ( name.constructor == String )
169 if ( value == undefined )
170 return this.length && jQuery[ type || "attr" ]( this[0], name ) || undefined;
174 options[ name ] = value;
177 // Check to see if we're setting style values
178 return this.each(function(i){
179 // Set all the styles
180 for ( name in options )
185 name, jQuery.prop( this, options[ name ], type, i, name )
190 css: function( key, value ) {
191 return this.attr( key, value, "curCSS" );
194 text: function( text ) {
195 if ( typeof text != "object" && text != null )
196 return this.empty().append( document.createTextNode( text ) );
200 jQuery.each( text || this, function(){
201 jQuery.each( this.childNodes, function(){
202 if ( this.nodeType != 8 )
203 ret += this.nodeType != 1 ?
205 jQuery.fn.text( [ this ] );
212 wrapAll: function( html ) {
214 // The elements to wrap the target around
215 jQuery( html, this[0].ownerDocument )
217 .insertBefore( this[0] )
221 while ( elem.firstChild )
222 elem = elem.firstChild;
231 wrapInner: function( html ) {
232 return this.each(function(){
233 jQuery( this ).contents().wrapAll( html );
237 wrap: function( html ) {
238 return this.each(function(){
239 jQuery( this ).wrapAll( html );
244 return this.domManip(arguments, true, false, function(elem){
245 this.appendChild( elem );
249 prepend: function() {
250 return this.domManip(arguments, true, true, function(elem){
251 this.insertBefore( elem, this.firstChild );
256 return this.domManip(arguments, false, false, function(elem){
257 this.parentNode.insertBefore( elem, this );
262 return this.domManip(arguments, false, true, function(elem){
263 this.parentNode.insertBefore( elem, this.nextSibling );
268 return this.prevObject || jQuery( [] );
271 find: function( selector ) {
272 var elems = jQuery.map(this, function(elem){
273 return jQuery.find( selector, elem );
276 return this.pushStack( /[^+>] [^+>]/.test( selector ) || selector.indexOf("..") > -1 ?
277 jQuery.unique( elems ) :
281 clone: function( events ) {
283 var ret = this.map(function(){
284 return this.outerHTML ?
285 jQuery( this.outerHTML )[0] :
286 this.cloneNode( true );
289 // Need to set the expando to null on the cloned set if it exists
290 // removeData doesn't work here, IE removes it from the original as well
291 // this is primarily for IE but the data expando shouldn't be copied over in any browser
292 var clone = ret.find("*").andSelf().each(function(){
293 if ( this[ expando ] != undefined )
294 this[ expando ] = null;
297 // Copy the events from the original to the clone
298 if ( events === true )
299 this.find("*").andSelf().each(function(i){
300 var events = jQuery.data( this, "events" );
302 for ( var type in events )
303 for ( var handler in events[ type ] )
304 jQuery.event.add( clone[ i ], type, events[ type ][ handler ], events[ type ][ handler ].data );
307 // Return the cloned set
311 filter: function( selector ) {
312 return this.pushStack(
313 jQuery.isFunction( selector ) &&
314 jQuery.grep(this, function(elem, i){
315 return selector.call( elem, i );
318 jQuery.multiFilter( selector, this ) );
321 not: function( selector ) {
322 return this.pushStack(
323 selector.constructor == String &&
324 jQuery.multiFilter( selector, this, true ) ||
326 jQuery.grep(this, function(elem) {
327 return selector.constructor == Array || selector.jquery ?
328 jQuery.inArray( elem, selector ) < 0 :
333 add: function( selector ) {
334 return this.pushStack( jQuery.merge(
336 selector.constructor == String ?
337 jQuery( selector ).get() :
338 selector.length != undefined && (!selector.nodeName || jQuery.nodeName(selector, "form")) ?
339 selector : [selector] ) );
342 is: function( selector ) {
344 jQuery.multiFilter( selector, this ).length > 0 :
348 hasClass: function( selector ) {
349 return this.is( "." + selector );
352 val: function( value ) {
353 if ( value == undefined ) {
358 // We need to handle select boxes special
359 if ( jQuery.nodeName( elem, "select" ) ) {
360 var index = elem.selectedIndex,
362 options = elem.options,
363 one = elem.type == "select-one";
365 // Nothing was selected
369 // Loop through all the selected options
370 for ( var i = one ? index : 0, max = one ? index + 1 : options.length; i < max; i++ ) {
371 var option = options[ i ];
373 if ( option.selected ) {
374 // Get the specifc value for the option
375 value = jQuery.browser.msie && !option.attributes.value.specified ? option.text : option.value;
377 // We don't need an array for one selects
381 // Multi-Selects return an array
382 values.push( value );
388 // Everything else, we just grab the value
390 return this[0].value.replace(/\r/g, "");
395 return this.each(function(){
396 if ( value.constructor == Array && /radio|checkbox/.test( this.type ) )
397 this.checked = (jQuery.inArray(this.value, value) >= 0 ||
398 jQuery.inArray(this.name, value) >= 0);
400 else if ( jQuery.nodeName( this, "select" ) ) {
401 var values = value.constructor == Array ?
405 jQuery( "option", this ).each(function(){
406 this.selected = (jQuery.inArray( this.value, values ) >= 0 ||
407 jQuery.inArray( this.text, values ) >= 0);
411 this.selectedIndex = -1;
418 html: function( value ) {
419 return value == undefined ?
423 this.empty().append( value );
426 replaceWith: function( value ) {
427 return this.after( value ).remove();
431 return this.slice( i, i + 1 );
435 return this.pushStack( Array.prototype.slice.apply( this, arguments ) );
438 map: function( callback ) {
439 return this.pushStack( jQuery.map(this, function(elem, i){
440 return callback.call( elem, i, elem );
444 andSelf: function() {
445 return this.add( this.prevObject );
448 domManip: function( args, table, reverse, callback ) {
449 var clone = this.length > 1, elems;
451 return this.each(function(){
453 elems = jQuery.clean( args, this.ownerDocument );
461 if ( table && jQuery.nodeName( this, "table" ) && jQuery.nodeName( elems[0], "tr" ) )
462 obj = this.getElementsByTagName("tbody")[0] || this.appendChild( document.createElement("tbody") );
464 jQuery.each(elems, function(){
466 this.cloneNode( true ) :
469 if ( !evalScript( 0, elem ) )
470 callback.call( obj, elem );
476 function evalScript( i, elem ) {
477 var script = jQuery.nodeName( elem, "script" );
488 jQuery.globalEval( elem.text || elem.textContent || elem.innerHTML || "" );
490 if ( elem.parentNode )
491 elem.parentNode.removeChild( elem );
493 } else if ( elem.nodeType == 1 )
494 jQuery( "script", elem ).each( evalScript );
499 jQuery.extend = jQuery.fn.extend = function() {
500 // copy reference to target object
501 var target = arguments[0] || {}, i = 1, length = arguments.length, deep = false, options;
503 // Handle a deep copy situation
504 if ( target.constructor == Boolean ) {
506 target = arguments[1] || {};
509 // extend jQuery itself if only one argument is passed
515 for ( ; i < length; i++ )
516 // Only deal with non-null/undefined values
517 if ( (options = arguments[ i ]) != null )
518 // Extend the base object
519 for ( var name in options ) {
520 // Prevent never-ending loop
521 if ( target == options[ name ] )
524 // Recurse if we're merging object values
525 if ( deep && typeof options[ name ] == "object" && target[ name ] )
526 jQuery.extend( target[ name ], options[ name ] );
528 // Don't bring in undefined values
529 else if ( options[ name ] != undefined )
530 target[ name ] = options[ name ];
534 // Return the modified object
538 var expando = "jQuery" + (new Date()).getTime(), uuid = 0, windowData = {};
540 // exclude the following css properties to add px
541 var exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i;
544 noConflict: function( deep ) {
548 window.jQuery = _jQuery;
553 // This may seem like some crazy code, but trust me when I say that this
554 // is the only cross-browser way to do this. --John
555 isFunction: function( fn ) {
556 return !!fn && typeof fn != "string" && !fn.nodeName &&
557 fn.constructor != Array && /function/i.test( fn + "" );
560 // check if an element is in a (or is an) XML document
561 isXMLDoc: function( elem ) {
562 return elem.documentElement && !elem.body ||
563 elem.tagName && elem.ownerDocument && !elem.ownerDocument.body;
566 // Evalulates a script in a global context
567 // Evaluates Async. in Safari 2 :-(
568 globalEval: function( data ) {
569 data = jQuery.trim( data );
572 // Inspired by code by Andrea Giammarchi
573 // http://webreflection.blogspot.com/2007/08/global-scope-evaluation-and-dom.html
574 var head = document.getElementsByTagName("head")[0] || document.documentElement,
575 script = document.createElement("script");
577 script.type = "text/javascript";
578 if ( jQuery.browser.msie )
581 script.appendChild( document.createTextNode( data ) );
583 head.appendChild( script );
584 head.removeChild( script );
588 nodeName: function( elem, name ) {
589 return elem.nodeName && elem.nodeName.toUpperCase() == name.toUpperCase();
594 data: function( elem, name, data ) {
595 elem = elem == window ?
599 var id = elem[ expando ];
601 // Compute a unique ID for the element
603 id = elem[ expando ] = ++uuid;
605 // Only generate the data cache if we're
606 // trying to access or manipulate it
607 if ( name && !jQuery.cache[ id ] )
608 jQuery.cache[ id ] = {};
610 // Prevent overriding the named cache with undefined values
611 if ( data != undefined )
612 jQuery.cache[ id ][ name ] = data;
614 // Return the named cache data, or the ID for the element
616 jQuery.cache[ id ][ name ] :
620 removeData: function( elem, name ) {
621 elem = elem == window ?
625 var id = elem[ expando ];
627 // If we want to remove a specific section of the element's data
629 if ( jQuery.cache[ id ] ) {
630 // Remove the section of cache data
631 delete jQuery.cache[ id ][ name ];
633 // If we've removed all the data, remove the element's cache
636 for ( name in jQuery.cache[ id ] )
640 jQuery.removeData( elem );
643 // Otherwise, we want to remove all of the element's data
645 // Clean up the element expando
647 delete elem[ expando ];
649 // IE has trouble directly removing the expando
650 // but it's ok with using removeAttribute
651 if ( elem.removeAttribute )
652 elem.removeAttribute( expando );
655 // Completely remove the data cache
656 delete jQuery.cache[ id ];
660 // args is for internal usage only
661 each: function( object, callback, args ) {
663 if ( object.length == undefined )
664 for ( var name in object )
665 callback.apply( object[ name ], args );
667 for ( var i = 0, length = object.length; i < length; i++ )
668 if ( callback.apply( object[ i ], args ) === false )
671 // A special, fast, case for the most common use of each
673 if ( object.length == undefined )
674 for ( var name in object )
675 callback.call( object[ name ], name, object[ name ] );
677 for ( var i = 0, length = object.length, value = object[0];
678 i < length && callback.call( value, i, value ) !== false; value = object[++i] ){}
684 prop: function( elem, value, type, i, name ) {
685 // Handle executable functions
686 if ( jQuery.isFunction( value ) )
687 value = value.call( elem, i );
689 // Handle passing in a number to a CSS property
690 return value && value.constructor == Number && type == "curCSS" && !exclude.test( name ) ?
696 // internal only, use addClass("class")
697 add: function( elem, classNames ) {
698 jQuery.each((classNames || "").split(/\s+/), function(i, className){
699 if ( !jQuery.className.has( elem.className, className ) )
700 elem.className += (elem.className ? " " : "") + className;
704 // internal only, use removeClass("class")
705 remove: function( elem, classNames ) {
706 elem.className = classNames != undefined ?
707 jQuery.grep(elem.className.split(/\s+/), function(className){
708 return !jQuery.className.has( classNames, className );
713 // internal only, use is(".class")
714 has: function( elem, className ) {
715 return jQuery.inArray( className, (elem.className || elem).toString().split(/\s+/) ) > -1;
719 // A method for quickly swapping in/out CSS properties to get correct calculations
720 swap: function( elem, options, callback ) {
721 // Remember the old values, and insert the new ones
722 for ( var name in options ) {
723 elem.style[ "old" + name ] = elem.style[ name ];
724 elem.style[ name ] = options[ name ];
727 callback.call( elem );
729 // Revert the old values
730 for ( var name in options )
731 elem.style[ name ] = elem.style[ "old" + name ];
734 css: function( elem, name ) {
735 if ( name == "height" || name == "width" ) {
736 var old = {}, height, width;
738 // Revert the padding and border widths to get the
739 // correct height/width values
740 jQuery.each([ "Top", "Bottom", "Right", "Left" ], function(){
741 old[ "padding" + this ] = 0;
742 old[ "border" + this + "Width" ] = 0;
745 // Swap out the padding/border values temporarily
746 jQuery.swap( elem, old, function() {
748 // If the element is visible, then the calculation is easy
749 if ( jQuery( elem ).is(":visible") ) {
750 height = elem.offsetHeight;
751 width = elem.offsetWidth;
753 // Otherwise, we need to flip out more values
755 elem = jQuery( elem.cloneNode(true) )
756 .find(":radio").removeAttr("checked").end()
758 visibility: "hidden",
759 position: "absolute",
763 }).appendTo( elem.parentNode )[0];
765 var position = jQuery.css( elem.parentNode, "position" ) || "static";
766 if ( position == "static" )
767 elem.parentNode.style.position = "relative";
769 height = elem.clientHeight;
770 width = elem.clientWidth;
772 if ( position == "static" )
773 elem.parentNode.style.position = "static";
775 elem.parentNode.removeChild( elem );
779 return name == "height" ?
784 return jQuery.curCSS( elem, name );
787 curCSS: function( elem, name, force ) {
790 // A helper method for determining if an element's values are broken
791 function color( elem ) {
792 if ( !jQuery.browser.safari )
795 var ret = document.defaultView.getComputedStyle( elem, null );
796 return !ret || ret.getPropertyValue("color") == "";
799 // We need to handle opacity special in IE
800 if ( name == "opacity" && jQuery.browser.msie ) {
801 ret = jQuery.attr( elem.style, "opacity" );
808 // Make sure we're using the right name for getting the float value
809 if ( name.match( /float/i ) )
812 if ( !force && elem.style[ name ] )
813 ret = elem.style[ name ];
815 else if ( document.defaultView && document.defaultView.getComputedStyle ) {
817 // Only "float" is needed here
818 if ( name.match( /float/i ) )
821 name = name.replace( /([A-Z])/g, "-$1" ).toLowerCase();
823 var getComputedStyle = document.defaultView.getComputedStyle( elem, null );
825 if ( getComputedStyle && !color( elem ) )
826 ret = getComputedStyle.getPropertyValue( name );
828 // If the element isn't reporting its values properly in Safari
829 // then some display: none elements are involved
831 var swap = [], stack = [];
833 // Locate all of the parent display: none elements
834 for ( var a = elem; a && color(a); a = a.parentNode )
837 // Go through and make them visible, but in reverse
838 // (It would be better if we knew the exact display type that they had)
839 for ( var i = 0; i < stack.length; i++ )
840 if ( color( stack[ i ] ) ) {
841 swap[ i ] = stack[ i ].style.display;
842 stack[ i ].style.display = "block";
845 // Since we flip the display style, we have to handle that
846 // one special, otherwise get the value
847 ret = name == "display" && swap[ stack.length - 1 ] != null ?
849 document.defaultView.getComputedStyle( elem, null ).getPropertyValue( name ) || "";
851 // Finally, revert the display styles back
852 for ( var i = 0; i < swap.length; i++ )
853 if ( swap[ i ] != null )
854 stack[ i ].style.display = swap[ i ];
857 // We should always get a number back from opacity
858 if ( name == "opacity" && ret == "" )
861 } else if ( elem.currentStyle ) {
862 var camelCase = name.replace(/\-(\w)/g, function(all, letter){
863 return letter.toUpperCase();
866 ret = elem.currentStyle[ name ] || elem.currentStyle[ camelCase ];
868 // From the awesome hack by Dean Edwards
869 // http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291
871 // If we're not dealing with a regular pixel number
872 // but a number that has a weird ending, we need to convert it to pixels
873 if ( !/^\d+(px)?$/i.test( ret ) && /^\d/.test( ret ) ) {
874 // Remember the original values
875 var style = elem.style.left, runtimeStyle = elem.runtimeStyle.left;
877 // Put in the new values to get a computed value out
878 elem.runtimeStyle.left = elem.currentStyle.left;
879 elem.style.left = ret || 0;
880 ret = elem.style.pixelLeft + "px";
882 // Revert the changed values
883 elem.style.left = style;
884 elem.runtimeStyle.left = runtimeStyle;
891 clean: function( elems, context ) {
893 context = context || document;
895 jQuery.each(elems, function(i, elem){
899 if ( elem.constructor == Number )
900 elem = elem.toString();
902 // Convert html string into DOM nodes
903 if ( typeof elem == "string" ) {
904 // Fix "XHTML"-style tags in all browsers
905 elem = elem.replace(/(<(\w+)[^>]*?)\/>/g, function(all, front, tag){
906 return tag.match(/^(abbr|br|col|img|input|link|meta|param|hr|area)$/i) ?
908 front + "></" + tag + ">";
911 // Trim whitespace, otherwise indexOf won't work as expected
912 var tags = jQuery.trim( elem ).toLowerCase(), div = context.createElement("div");
915 // option or optgroup
916 !tags.indexOf("<opt") &&
917 [ 1, "<select>", "</select>" ] ||
919 !tags.indexOf("<leg") &&
920 [ 1, "<fieldset>", "</fieldset>" ] ||
922 tags.match(/^<(thead|tbody|tfoot|colg|cap)/) &&
923 [ 1, "<table>", "</table>" ] ||
925 !tags.indexOf("<tr") &&
926 [ 2, "<table><tbody>", "</tbody></table>" ] ||
928 // <thead> matched above
929 (!tags.indexOf("<td") || !tags.indexOf("<th")) &&
930 [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ] ||
932 !tags.indexOf("<col") &&
933 [ 2, "<table><tbody></tbody><colgroup>", "</colgroup></table>" ] ||
935 // IE can't serialize <link> and <script> tags normally
936 jQuery.browser.msie &&
937 [ 1, "div<div>", "</div>" ] ||
941 // Go to html and back, then peel off extra wrappers
942 div.innerHTML = wrap[1] + elem + wrap[2];
944 // Move to the right depth
948 // Remove IE's autoinserted <tbody> from table fragments
949 if ( jQuery.browser.msie ) {
951 // String was a <table>, *may* have spurious <tbody>
952 var tbody = !tags.indexOf("<table") && tags.indexOf("<tbody") < 0 ?
953 div.firstChild && div.firstChild.childNodes :
955 // String was a bare <thead> or <tfoot>
956 wrap[1] == "<table>" && tags.indexOf("<tbody") < 0 ?
960 for ( var i = tbody.length - 1; i >= 0 ; --i )
961 if ( jQuery.nodeName( tbody[ i ], "tbody" ) && !tbody[ i ].childNodes.length )
962 tbody[ i ].parentNode.removeChild( tbody[ i ] );
964 // IE completely kills leading whitespace when innerHTML is used
965 if ( /^\s/.test( elem ) )
966 div.insertBefore( context.createTextNode( elem.match(/^\s*/)[0] ), div.firstChild );
970 elem = jQuery.makeArray( div.childNodes );
973 if ( elem.length === 0 && (!jQuery.nodeName( elem, "form" ) && !jQuery.nodeName( elem, "select" )) )
976 if ( elem[0] == undefined || jQuery.nodeName( elem, "form" ) || elem.options )
980 ret = jQuery.merge( ret, elem );
987 attr: function( elem, name, value ) {
988 var fix = jQuery.isXMLDoc( elem ) ?
992 // Safari mis-reports the default selected property of a hidden option
993 // Accessing the parent's selectedIndex property fixes it
994 if ( name == "selected" && jQuery.browser.safari )
995 elem.parentNode.selectedIndex;
997 // Certain attributes only work when accessed via the old DOM 0 way
999 if ( value != undefined )
1000 elem[ fix[ name ] ] = value;
1002 return elem[ fix[ name ] ];
1004 } else if ( jQuery.browser.msie && name == "style" )
1005 return jQuery.attr( elem.style, "cssText", value );
1007 else if ( value == undefined && jQuery.browser.msie && jQuery.nodeName( elem, "form" ) && (name == "action" || name == "method") )
1008 return elem.getAttributeNode( name ).nodeValue;
1010 // IE elem.getAttribute passes even for style
1011 else if ( elem.tagName ) {
1013 if ( value != undefined ) {
1014 // We can't allow the type property to be changed (since it causes problems in IE)
1015 if ( name == "type" && jQuery.nodeName( elem, "input" ) && elem.parentNode )
1016 throw "type property can't be changed";
1018 elem.setAttribute( name, value );
1021 if ( jQuery.browser.msie && /href|src/.test( name ) && !jQuery.isXMLDoc( elem ) )
1022 return elem.getAttribute( name, 2 );
1024 return elem.getAttribute( name );
1026 // elem is actually elem.style ... set the style
1028 // IE actually uses filters for opacity
1029 if ( name == "opacity" && jQuery.browser.msie ) {
1030 if ( value != undefined ) {
1031 // IE has trouble with opacity if it does not have layout
1032 // Force it by setting the zoom level
1035 // Set the alpha filter to set the opacity
1036 elem.filter = (elem.filter || "").replace( /alpha\([^)]*\)/, "" ) +
1037 (parseFloat( value ).toString() == "NaN" ? "" : "alpha(opacity=" + value * 100 + ")");
1040 return elem.filter ?
1041 (parseFloat( elem.filter.match(/opacity=([^)]*)/)[1] ) / 100).toString() :
1045 name = name.replace(/-([a-z])/ig, function(all, letter){
1046 return letter.toUpperCase();
1049 if ( value != undefined )
1050 elem[ name ] = value;
1052 return elem[ name ];
1056 trim: function( text ) {
1057 return (text || "").replace( /^\s+|\s+$/g, "" );
1060 makeArray: function( array ) {
1063 // Need to use typeof to fight Safari childNodes crashes
1064 if ( typeof array != "array" )
1065 for ( var i = 0, length = array.length; i < length; i++ )
1066 ret.push( array[ i ] );
1068 ret = array.slice( 0 );
1073 inArray: function( elem, array ) {
1074 for ( var i = 0, length = array.length; i < length; i++ )
1075 if ( array[ i ] == elem )
1081 merge: function( first, second ) {
1082 // We have to loop this way because IE & Opera overwrite the length
1083 // expando of getElementsByTagName
1085 // Also, we need to make sure that the correct elements are being returned
1086 // (IE returns comment nodes in a '*' query)
1087 if ( jQuery.browser.msie ) {
1088 for ( var i = 0; second[ i ]; i++ )
1089 if ( second[ i ].nodeType != 8 )
1090 first.push( second[ i ] );
1093 for ( var i = 0; second[ i ]; i++ )
1094 first.push( second[ i ] );
1099 unique: function( array ) {
1100 var ret = [], done = {};
1104 for ( var i = 0, length = array.length; i < length; i++ ) {
1105 var id = jQuery.data( array[ i ] );
1107 if ( !done[ id ] ) {
1109 ret.push( array[ i ] );
1120 grep: function( elems, callback, inv ) {
1121 // If a string is passed in for the function, make a function
1122 // for it (a handy shortcut)
1123 if ( typeof callback == "string" )
1124 callback = eval("false||function(a,i){return " + callback + "}");
1128 // Go through the array, only saving the items
1129 // that pass the validator function
1130 for ( var i = 0, length = elems.length; i < length; i++ )
1131 if ( !inv && callback( elems[ i ], i ) || inv && !callback( elems[ i ], i ) )
1132 ret.push( elems[ i ] );
1137 map: function( elems, callback ) {
1140 // Go through the array, translating each of the items to their
1141 // new value (or values).
1142 for ( var i = 0, length = elems.length; i < length; i++ ) {
1143 var value = callback( elems[ i ], i );
1145 if ( value !== null && value != undefined ) {
1146 if ( value.constructor != Array )
1149 ret = ret.concat( value );
1157 var userAgent = navigator.userAgent.toLowerCase();
1159 // Figure out what browser is being used
1161 version: (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [])[1],
1162 safari: /webkit/.test( userAgent ),
1163 opera: /opera/.test( userAgent ),
1164 msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
1165 mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )
1168 var styleFloat = jQuery.browser.msie ?
1173 // Check to see if the W3C box model is being used
1174 boxModel: !jQuery.browser.msie || document.compatMode == "CSS1Compat",
1178 "class": "className",
1179 "float": styleFloat,
1180 cssFloat: styleFloat,
1181 styleFloat: styleFloat,
1182 innerHTML: "innerHTML",
1183 className: "className",
1185 disabled: "disabled",
1187 readonly: "readOnly",
1188 selected: "selected",
1189 maxlength: "maxLength",
1190 selectedIndex: "selectedIndex"
1195 parent: "elem.parentNode",
1196 parents: "jQuery.dir(elem,'parentNode')",
1197 next: "jQuery.nth(elem,2,'nextSibling')",
1198 prev: "jQuery.nth(elem,2,'previousSibling')",
1199 nextAll: "jQuery.dir(elem,'nextSibling')",
1200 prevAll: "jQuery.dir(elem,'previousSibling')",
1201 siblings: "jQuery.sibling(elem.parentNode.firstChild,elem)",
1202 children: "jQuery.sibling(elem.firstChild)",
1203 contents: "jQuery.nodeName(elem,'iframe')?elem.contentDocument||elem.contentWindow.document:jQuery.makeArray(elem.childNodes)"
1204 }, function(name, fn){
1205 fn = eval("false||function(elem){return " + fn + "}");
1207 jQuery.fn[ name ] = function( selector ) {
1208 var ret = jQuery.map( this, fn );
1210 if ( selector && typeof selector == "string" )
1211 ret = jQuery.multiFilter( selector, ret );
1213 return this.pushStack( jQuery.unique( ret ) );
1219 prependTo: "prepend",
1220 insertBefore: "before",
1221 insertAfter: "after",
1222 replaceAll: "replaceWith"
1223 }, function(name, original){
1224 jQuery.fn[ name ] = function() {
1225 var args = arguments;
1227 return this.each(function(){
1228 for ( var i = 0, length = args.length; i < length; i++ )
1229 jQuery( args[ i ] )[ original ]( this );
1235 removeAttr: function( name ) {
1236 jQuery.attr( this, name, "" );
1237 this.removeAttribute( name );
1240 addClass: function( classNames ) {
1241 jQuery.className.add( this, classNames );
1244 removeClass: function( classNames ) {
1245 jQuery.className.remove( this, classNames );
1248 toggleClass: function( classNames ) {
1249 jQuery.className[ jQuery.className.has( this, classNames ) ? "remove" : "add" ]( this, classNames );
1252 remove: function( selector ) {
1253 if ( !selector || jQuery.filter( selector, [ this ] ).r.length ) {
1254 jQuery.removeData( this );
1255 this.parentNode.removeChild( this );
1260 // Clean up the cache
1261 jQuery( "*", this ).each(function(){
1262 jQuery.removeData(this);
1265 while ( this.firstChild )
1266 this.removeChild( this.firstChild );
1268 }, function(name, fn){
1269 jQuery.fn[ name ] = function(){
1270 return this.each( fn, arguments );
1274 jQuery.each([ "Height", "Width" ], function(i, name){
1275 var type = name.toLowerCase();
1277 jQuery.fn[ type ] = function( size ) {
1278 // Get window width or height
1279 return this[0] == window ?
1280 // Opera reports document.body.client[Width/Height] properly in both quirks and standards
1281 jQuery.browser.opera && document.body[ "client" + name ] ||
1283 // Safari reports inner[Width/Height] just fine (Mozilla and Opera include scroll bar widths)
1284 jQuery.browser.safari && self[ "inner" + name ] ||
1286 // Everyone else use document.documentElement or document.body depending on Quirks vs Standards mode
1287 document.compatMode == "CSS1Compat" && document.documentElement[ "client" + name ] || document.body[ "client" + name ] :
1289 // Get document width or height
1290 this[0] == document ?
1291 // Either scroll[Width/Height] or offset[Width/Height], whichever is greater (Mozilla reports scrollWidth the same as offsetWidth)
1292 Math.max( document.body[ "scroll" + name ], document.body[ "offset" + name ] ) :
1294 // Get or set width or height on the element
1296 // Get width or height on the element
1297 (this.length ? jQuery.css( this[0], type ) : null) :
1299 // Set the width or height on the element (default to pixels if value is unitless)
1300 this.css( type, size.constructor == String ? size : size + "px" );