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( (this[0] && this[0].ownerDocument || 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 if (this.nodeType == 1)
255 this.appendChild( elem );
259 prepend: function() {
260 return this.domManip(arguments, true, true, function(elem){
261 if (this.nodeType == 1)
262 this.insertBefore( elem, this.firstChild );
267 return this.domManip(arguments, false, false, function(elem){
268 this.parentNode.insertBefore( elem, this );
273 return this.domManip(arguments, false, true, function(elem){
274 this.parentNode.insertBefore( elem, this.nextSibling );
279 return this.prevObject || jQuery( [] );
282 find: function( selector ) {
283 var elems = jQuery.map(this, function(elem){
284 return jQuery.find( selector, elem );
287 return this.pushStack( /[^+>] [^+>]/.test( selector ) || selector.indexOf("..") > -1 ?
288 jQuery.unique( elems ) :
292 clone: function( events ) {
294 var ret = this.map(function(){
295 return this.outerHTML ?
296 jQuery( this.outerHTML )[0] :
297 this.cloneNode( true );
300 // Need to set the expando to null on the cloned set if it exists
301 // removeData doesn't work here, IE removes it from the original as well
302 // this is primarily for IE but the data expando shouldn't be copied over in any browser
303 var clone = ret.find("*").andSelf().each(function(){
304 if ( this[ expando ] != undefined )
305 this[ expando ] = null;
308 // Copy the events from the original to the clone
309 if ( events === true )
310 this.find("*").andSelf().each(function(i){
311 var events = jQuery.data( this, "events" );
313 for ( var type in events )
314 for ( var handler in events[ type ] )
315 jQuery.event.add( clone[ i ], type, events[ type ][ handler ], events[ type ][ handler ].data );
318 // Return the cloned set
322 filter: function( selector ) {
323 return this.pushStack(
324 jQuery.isFunction( selector ) &&
325 jQuery.grep(this, function(elem, i){
326 return selector.call( elem, i );
329 jQuery.multiFilter( selector, this ) );
332 not: function( selector ) {
333 return this.pushStack(
334 selector.constructor == String &&
335 jQuery.multiFilter( selector, this, true ) ||
337 jQuery.grep(this, function(elem) {
338 return selector.constructor == Array || selector.jquery ?
339 jQuery.inArray( elem, selector ) < 0 :
344 add: function( selector ) {
345 return !selector ? this : this.pushStack( jQuery.merge(
347 selector.constructor == String ?
348 jQuery( selector ).get() :
349 selector.length != undefined && (!selector.nodeName || jQuery.nodeName(selector, "form")) ?
350 selector : [selector] ) );
353 is: function( selector ) {
355 jQuery.multiFilter( selector, this ).length > 0 :
359 hasClass: function( selector ) {
360 return this.is( "." + selector );
363 val: function( value ) {
364 if ( value == undefined ) {
369 // We need to handle select boxes special
370 if ( jQuery.nodeName( elem, "select" ) ) {
371 var index = elem.selectedIndex,
373 options = elem.options,
374 one = elem.type == "select-one";
376 // Nothing was selected
380 // Loop through all the selected options
381 for ( var i = one ? index : 0, max = one ? index + 1 : options.length; i < max; i++ ) {
382 var option = options[ i ];
384 if ( option.selected ) {
385 // Get the specifc value for the option
386 value = jQuery.browser.msie && !option.attributes.value.specified ? option.text : option.value;
388 // We don't need an array for one selects
392 // Multi-Selects return an array
393 values.push( value );
399 // Everything else, we just grab the value
401 return (this[0].value || "").replace(/\r/g, "");
406 return this.each(function(){
407 if ( this.nodeType != 1 )
410 if ( value.constructor == Array && /radio|checkbox/.test( this.type ) )
411 this.checked = (jQuery.inArray(this.value, value) >= 0 ||
412 jQuery.inArray(this.name, value) >= 0);
414 else if ( jQuery.nodeName( this, "select" ) ) {
415 var values = value.constructor == Array ?
419 jQuery( "option", this ).each(function(){
420 this.selected = (jQuery.inArray( this.value, values ) >= 0 ||
421 jQuery.inArray( this.text, values ) >= 0);
424 if ( !values.length )
425 this.selectedIndex = -1;
432 html: function( value ) {
433 return value == undefined ?
437 this.empty().append( value );
440 replaceWith: function( value ) {
441 return this.after( value ).remove();
445 return this.slice( i, i + 1 );
449 return this.pushStack( Array.prototype.slice.apply( this, arguments ) );
452 map: function( callback ) {
453 return this.pushStack( jQuery.map(this, function(elem, i){
454 return callback.call( elem, i, elem );
458 andSelf: function() {
459 return this.add( this.prevObject );
462 domManip: function( args, table, reverse, callback ) {
463 var clone = this.length > 1, elems;
465 return this.each(function(){
467 elems = jQuery.clean( args, this.ownerDocument );
475 if ( table && jQuery.nodeName( this, "table" ) && jQuery.nodeName( elems[0], "tr" ) )
476 obj = this.getElementsByTagName("tbody")[0] || this.appendChild( this.ownerDocument.createElement("tbody") );
478 var scripts = jQuery( [] );
480 jQuery.each(elems, function(){
482 this.cloneNode( true ) :
485 if ( jQuery.nodeName( elem, "script" ) ) {
487 // If scripts are waiting to be executed, wait on this script as well
488 if ( scripts.length )
489 scripts = scripts.add( elem );
491 // If nothing is waiting to be executed, run immediately
493 evalScript( 0, elem );
496 // Remove any inner scripts for later evaluation
497 if ( elem.nodeType == 1 )
498 scripts = scripts.add( jQuery( "script", elem ).remove() );
500 // Inject the elements into the document
501 callback.call( obj, elem );
505 scripts.each( evalScript );
510 function evalScript( i, elem ) {
519 jQuery.globalEval( elem.text || elem.textContent || elem.innerHTML || "" );
521 if ( elem.parentNode )
522 elem.parentNode.removeChild( elem );
525 jQuery.extend = jQuery.fn.extend = function() {
526 // copy reference to target object
527 var target = arguments[0] || {}, i = 1, length = arguments.length, deep = false, options;
529 // Handle a deep copy situation
530 if ( target.constructor == Boolean ) {
532 target = arguments[1] || {};
533 // skip the boolean and the target
537 // Handle case when target is a string or something (possible in deep copy)
538 if ( typeof target != "object" && typeof target != "function" )
541 // extend jQuery itself if only one argument is passed
547 for ( ; i < length; i++ )
548 // Only deal with non-null/undefined values
549 if ( (options = arguments[ i ]) != null )
550 // Extend the base object
551 for ( var name in options ) {
552 // Prevent never-ending loop
553 if ( target === options[ name ] )
556 // Recurse if we're merging object values
557 if ( deep && options[ name ] && typeof options[ name ] == "object" && target[ name ] && !options[ name ].nodeType )
558 target[ name ] = jQuery.extend( target[ name ], options[ name ] );
560 // Don't bring in undefined values
561 else if ( options[ name ] != undefined )
562 target[ name ] = options[ name ];
566 // Return the modified object
570 var expando = "jQuery" + (new Date()).getTime(), uuid = 0, windowData = {};
572 // exclude the following css properties to add px
573 var exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i;
576 noConflict: function( deep ) {
580 window.jQuery = _jQuery;
585 // This may seem like some crazy code, but trust me when I say that this
586 // is the only cross-browser way to do this. --John
587 isFunction: function( fn ) {
588 return !!fn && typeof fn != "string" && !fn.nodeName &&
589 fn.constructor != Array && /function/i.test( fn + "" );
592 // check if an element is in a (or is an) XML document
593 isXMLDoc: function( elem ) {
594 return elem.documentElement && !elem.body ||
595 elem.tagName && elem.ownerDocument && !elem.ownerDocument.body;
598 // Evalulates a script in a global context
599 globalEval: function( data ) {
600 data = jQuery.trim( data );
603 // Inspired by code by Andrea Giammarchi
604 // http://webreflection.blogspot.com/2007/08/global-scope-evaluation-and-dom.html
605 var head = document.getElementsByTagName("head")[0] || document.documentElement,
606 script = document.createElement("script");
608 script.type = "text/javascript";
609 if ( jQuery.browser.msie )
612 script.appendChild( document.createTextNode( data ) );
614 head.appendChild( script );
615 head.removeChild( script );
619 nodeName: function( elem, name ) {
620 return elem.nodeName && elem.nodeName.toUpperCase() == name.toUpperCase();
625 data: function( elem, name, data ) {
626 elem = elem == window ?
630 var id = elem[ expando ];
632 // Compute a unique ID for the element
634 id = elem[ expando ] = ++uuid;
636 // Only generate the data cache if we're
637 // trying to access or manipulate it
638 if ( name && !jQuery.cache[ id ] )
639 jQuery.cache[ id ] = {};
641 // Prevent overriding the named cache with undefined values
642 if ( data != undefined )
643 jQuery.cache[ id ][ name ] = data;
645 // Return the named cache data, or the ID for the element
647 jQuery.cache[ id ][ name ] :
651 removeData: function( elem, name ) {
652 elem = elem == window ?
656 var id = elem[ expando ];
658 // If we want to remove a specific section of the element's data
660 if ( jQuery.cache[ id ] ) {
661 // Remove the section of cache data
662 delete jQuery.cache[ id ][ name ];
664 // If we've removed all the data, remove the element's cache
667 for ( name in jQuery.cache[ id ] )
671 jQuery.removeData( elem );
674 // Otherwise, we want to remove all of the element's data
676 // Clean up the element expando
678 delete elem[ expando ];
680 // IE has trouble directly removing the expando
681 // but it's ok with using removeAttribute
682 if ( elem.removeAttribute )
683 elem.removeAttribute( expando );
686 // Completely remove the data cache
687 delete jQuery.cache[ id ];
691 // args is for internal usage only
692 each: function( object, callback, args ) {
694 if ( object.length == undefined )
695 for ( var name in object )
696 callback.apply( object[ name ], args );
698 for ( var i = 0, length = object.length; i < length; i++ )
699 if ( callback.apply( object[ i ], args ) === false )
702 // A special, fast, case for the most common use of each
704 if ( object.length == undefined )
705 for ( var name in object )
706 callback.call( object[ name ], name, object[ name ] );
708 for ( var i = 0, length = object.length, value = object[0];
709 i < length && callback.call( value, i, value ) !== false; value = object[++i] ){}
715 prop: function( elem, value, type, i, name ) {
716 // Handle executable functions
717 if ( jQuery.isFunction( value ) )
718 value = value.call( elem, i );
720 // Handle passing in a number to a CSS property
721 return value && value.constructor == Number && type == "curCSS" && !exclude.test( name ) ?
727 // internal only, use addClass("class")
728 add: function( elem, classNames ) {
729 jQuery.each((classNames || "").split(/\s+/), function(i, className){
730 if ( elem.nodeType == 1 && !jQuery.className.has( elem.className, className ) )
731 elem.className += (elem.className ? " " : "") + className;
735 // internal only, use removeClass("class")
736 remove: function( elem, classNames ) {
737 if (elem.nodeType == 1)
738 elem.className = classNames != undefined ?
739 jQuery.grep(elem.className.split(/\s+/), function(className){
740 return !jQuery.className.has( classNames, className );
745 // internal only, use is(".class")
746 has: function( elem, className ) {
747 return jQuery.inArray( className, (elem.className || elem).toString().split(/\s+/) ) > -1;
751 // A method for quickly swapping in/out CSS properties to get correct calculations
752 swap: function( elem, options, callback ) {
753 // Remember the old values, and insert the new ones
754 for ( var name in options ) {
755 elem.style[ "old" + name ] = elem.style[ name ];
756 elem.style[ name ] = options[ name ];
759 callback.call( elem );
761 // Revert the old values
762 for ( var name in options )
763 elem.style[ name ] = elem.style[ "old" + name ];
766 css: function( elem, name, force ) {
767 if ( name == "height" || name == "width" ) {
768 var old = {}, height, width;
770 // Revert the padding and border widths to get the
771 // correct height/width values
772 jQuery.each([ "Top", "Bottom", "Right", "Left" ], function(){
773 old[ "padding" + this ] = 0;
774 old[ "border" + this + "Width" ] = 0;
777 // Swap out the padding/border values temporarily
778 jQuery.swap( elem, old, function() {
780 // If the element is visible, then the calculation is easy
781 if ( jQuery( elem ).is(":visible") ) {
782 height = elem.offsetHeight;
783 width = elem.offsetWidth;
785 // Otherwise, we need to flip out more values
787 elem = jQuery( elem.cloneNode(true) )
788 .find(":radio").removeAttr("checked").removeAttr("defaultChecked").end()
790 visibility: "hidden",
791 position: "absolute",
795 }).appendTo( elem.parentNode )[0];
797 var position = jQuery.css( elem.parentNode, "position" ) || "static";
798 if ( position == "static" )
799 elem.parentNode.style.position = "relative";
801 height = elem.clientHeight;
802 width = elem.clientWidth;
804 if ( position == "static" )
805 elem.parentNode.style.position = "static";
807 elem.parentNode.removeChild( elem );
811 return name == "height" ?
816 return jQuery.curCSS( elem, name, force );
819 curCSS: function( elem, name, force ) {
822 // A helper method for determining if an element's values are broken
823 function color( elem ) {
824 if ( !jQuery.browser.safari )
827 var ret = document.defaultView.getComputedStyle( elem, null );
828 return !ret || ret.getPropertyValue("color") == "";
831 // We need to handle opacity special in IE
832 if ( name == "opacity" && jQuery.browser.msie ) {
833 ret = jQuery.attr( elem.style, "opacity" );
840 // Make sure we're using the right name for getting the float value
841 if ( name.match( /float/i ) )
844 if ( !force && elem.style[ name ] )
845 ret = elem.style[ name ];
847 else if ( document.defaultView && document.defaultView.getComputedStyle ) {
849 // Only "float" is needed here
850 if ( name.match( /float/i ) )
853 name = name.replace( /([A-Z])/g, "-$1" ).toLowerCase();
855 var getComputedStyle = document.defaultView.getComputedStyle( elem, null );
857 if ( getComputedStyle && !color( elem ) )
858 ret = getComputedStyle.getPropertyValue( name );
860 // If the element isn't reporting its values properly in Safari
861 // then some display: none elements are involved
863 var swap = [], stack = [];
865 // Locate all of the parent display: none elements
866 for ( var a = elem; a && color(a); a = a.parentNode )
869 // Go through and make them visible, but in reverse
870 // (It would be better if we knew the exact display type that they had)
871 for ( var i = 0; i < stack.length; i++ )
872 if ( color( stack[ i ] ) ) {
873 swap[ i ] = stack[ i ].style.display;
874 stack[ i ].style.display = "block";
877 // Since we flip the display style, we have to handle that
878 // one special, otherwise get the value
879 ret = name == "display" && swap[ stack.length - 1 ] != null ?
881 ( getComputedStyle && getComputedStyle.getPropertyValue( name ) ) || "";
883 // Finally, revert the display styles back
884 for ( var i = 0; i < swap.length; i++ )
885 if ( swap[ i ] != null )
886 stack[ i ].style.display = swap[ i ];
889 // We should always get a number back from opacity
890 if ( name == "opacity" && ret == "" )
893 } else if ( elem.currentStyle ) {
894 var camelCase = name.replace(/\-(\w)/g, function(all, letter){
895 return letter.toUpperCase();
898 ret = elem.currentStyle[ name ] || elem.currentStyle[ camelCase ];
900 // From the awesome hack by Dean Edwards
901 // http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291
903 // If we're not dealing with a regular pixel number
904 // but a number that has a weird ending, we need to convert it to pixels
905 if ( !/^\d+(px)?$/i.test( ret ) && /^\d/.test( ret ) ) {
906 // Remember the original values
907 var style = elem.style.left, runtimeStyle = elem.runtimeStyle.left;
909 // Put in the new values to get a computed value out
910 elem.runtimeStyle.left = elem.currentStyle.left;
911 elem.style.left = ret || 0;
912 ret = elem.style.pixelLeft + "px";
914 // Revert the changed values
915 elem.style.left = style;
916 elem.runtimeStyle.left = runtimeStyle;
923 clean: function( elems, context ) {
925 context = context || document;
926 // !context.createElement fails in IE with an error but returns typeof 'object'
927 if (typeof context.createElement == 'undefined')
928 context = context.ownerDocument || context[0] && context[0].ownerDocument || document;
930 jQuery.each(elems, function(i, elem){
934 if ( elem.constructor == Number )
935 elem = elem.toString();
937 // Convert html string into DOM nodes
938 if ( typeof elem == "string" ) {
939 // Fix "XHTML"-style tags in all browsers
940 elem = elem.replace(/(<(\w+)[^>]*?)\/>/g, function(all, front, tag){
941 return tag.match(/^(abbr|br|col|img|input|link|meta|param|hr|area)$/i) ?
943 front + "></" + tag + ">";
946 // Trim whitespace, otherwise indexOf won't work as expected
947 var tags = jQuery.trim( elem ).toLowerCase(), div = context.createElement("div");
950 // option or optgroup
951 !tags.indexOf("<opt") &&
952 [ 1, "<select multiple='multiple'>", "</select>" ] ||
954 !tags.indexOf("<leg") &&
955 [ 1, "<fieldset>", "</fieldset>" ] ||
957 tags.match(/^<(thead|tbody|tfoot|colg|cap)/) &&
958 [ 1, "<table>", "</table>" ] ||
960 !tags.indexOf("<tr") &&
961 [ 2, "<table><tbody>", "</tbody></table>" ] ||
963 // <thead> matched above
964 (!tags.indexOf("<td") || !tags.indexOf("<th")) &&
965 [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ] ||
967 !tags.indexOf("<col") &&
968 [ 2, "<table><tbody></tbody><colgroup>", "</colgroup></table>" ] ||
970 // IE can't serialize <link> and <script> tags normally
971 jQuery.browser.msie &&
972 [ 1, "div<div>", "</div>" ] ||
976 // Go to html and back, then peel off extra wrappers
977 div.innerHTML = wrap[1] + elem + wrap[2];
979 // Move to the right depth
983 // Remove IE's autoinserted <tbody> from table fragments
984 if ( jQuery.browser.msie ) {
986 // String was a <table>, *may* have spurious <tbody>
987 var tbody = !tags.indexOf("<table") && tags.indexOf("<tbody") < 0 ?
988 div.firstChild && div.firstChild.childNodes :
990 // String was a bare <thead> or <tfoot>
991 wrap[1] == "<table>" && tags.indexOf("<tbody") < 0 ?
995 for ( var i = tbody.length - 1; i >= 0 ; --i )
996 if ( jQuery.nodeName( tbody[ i ], "tbody" ) && !tbody[ i ].childNodes.length )
997 tbody[ i ].parentNode.removeChild( tbody[ i ] );
999 // IE completely kills leading whitespace when innerHTML is used
1000 if ( /^\s/.test( elem ) )
1001 div.insertBefore( context.createTextNode( elem.match(/^\s*/)[0] ), div.firstChild );
1005 elem = jQuery.makeArray( div.childNodes );
1008 if ( elem.length === 0 && (!jQuery.nodeName( elem, "form" ) && !jQuery.nodeName( elem, "select" )) )
1011 if ( elem[0] == undefined || jQuery.nodeName( elem, "form" ) || elem.options )
1015 ret = jQuery.merge( ret, elem );
1022 attr: function( elem, name, value ) {
1023 // don't set attributes on text and comment nodes
1024 if (!elem || elem.nodeType == 3 || elem.nodeType == 8)
1027 var fix = jQuery.isXMLDoc( elem ) ?
1031 // Safari mis-reports the default selected property of a hidden option
1032 // Accessing the parent's selectedIndex property fixes it
1033 if ( name == "selected" && jQuery.browser.safari )
1034 elem.parentNode.selectedIndex;
1036 // Certain attributes only work when accessed via the old DOM 0 way
1037 if ( fix[ name ] ) {
1038 if ( value != undefined )
1039 elem[ fix[ name ] ] = value;
1041 return elem[ fix[ name ] ];
1043 } else if ( jQuery.browser.msie && name == "style" )
1044 return jQuery.attr( elem.style, "cssText", value );
1046 else if ( value == undefined && jQuery.browser.msie && jQuery.nodeName( elem, "form" ) && (name == "action" || name == "method") )
1047 return elem.getAttributeNode( name ).nodeValue;
1049 // IE elem.getAttribute passes even for style
1050 else if ( elem.tagName ) {
1052 if ( value != undefined ) {
1053 // We can't allow the type property to be changed (since it causes problems in IE)
1054 if ( name == "type" && jQuery.nodeName( elem, "input" ) && elem.parentNode )
1055 throw "type property can't be changed";
1057 // convert the value to a string (all browsers do this but IE) see #1070
1058 elem.setAttribute( name, "" + value );
1061 if ( jQuery.browser.msie && /href|src/.test( name ) && !jQuery.isXMLDoc( elem ) )
1062 return elem.getAttribute( name, 2 );
1064 return elem.getAttribute( name );
1066 // elem is actually elem.style ... set the style
1068 // IE actually uses filters for opacity
1069 if ( name == "opacity" && jQuery.browser.msie ) {
1070 if ( value != undefined ) {
1071 // IE has trouble with opacity if it does not have layout
1072 // Force it by setting the zoom level
1075 // Set the alpha filter to set the opacity
1076 elem.filter = (elem.filter || "").replace( /alpha\([^)]*\)/, "" ) +
1077 (parseFloat( value ).toString() == "NaN" ? "" : "alpha(opacity=" + value * 100 + ")");
1080 return elem.filter && elem.filter.indexOf("opacity=") >= 0 ?
1081 (parseFloat( elem.filter.match(/opacity=([^)]*)/)[1] ) / 100).toString() :
1085 name = name.replace(/-([a-z])/ig, function(all, letter){
1086 return letter.toUpperCase();
1089 if ( value != undefined )
1090 elem[ name ] = value;
1092 return elem[ name ];
1096 trim: function( text ) {
1097 return (text || "").replace( /^\s+|\s+$/g, "" );
1100 makeArray: function( array ) {
1103 // Need to use typeof to fight Safari childNodes crashes
1104 if ( typeof array != "array" )
1105 for ( var i = 0, length = array.length; i < length; i++ )
1106 ret.push( array[ i ] );
1108 ret = array.slice( 0 );
1113 inArray: function( elem, array ) {
1114 for ( var i = 0, length = array.length; i < length; i++ )
1115 if ( array[ i ] == elem )
1121 merge: function( first, second ) {
1122 // We have to loop this way because IE & Opera overwrite the length
1123 // expando of getElementsByTagName
1125 // Also, we need to make sure that the correct elements are being returned
1126 // (IE returns comment nodes in a '*' query)
1127 if ( jQuery.browser.msie ) {
1128 for ( var i = 0; second[ i ]; i++ )
1129 if ( second[ i ].nodeType != 8 )
1130 first.push( second[ i ] );
1133 for ( var i = 0; second[ i ]; i++ )
1134 first.push( second[ i ] );
1139 unique: function( array ) {
1140 var ret = [], done = {};
1144 for ( var i = 0, length = array.length; i < length; i++ ) {
1145 var id = jQuery.data( array[ i ] );
1147 if ( !done[ id ] ) {
1149 ret.push( array[ i ] );
1160 grep: function( elems, callback, inv ) {
1161 // If a string is passed in for the function, make a function
1162 // for it (a handy shortcut)
1163 if ( typeof callback == "string" )
1164 callback = eval("false||function(a,i){return " + callback + "}");
1168 // Go through the array, only saving the items
1169 // that pass the validator function
1170 for ( var i = 0, length = elems.length; i < length; i++ )
1171 if ( !inv && callback( elems[ i ], i ) || inv && !callback( elems[ i ], i ) )
1172 ret.push( elems[ i ] );
1177 map: function( elems, callback ) {
1180 // Go through the array, translating each of the items to their
1181 // new value (or values).
1182 for ( var i = 0, length = elems.length; i < length; i++ ) {
1183 var value = callback( elems[ i ], i );
1185 if ( value !== null && value != undefined ) {
1186 if ( value.constructor != Array )
1189 ret = ret.concat( value );
1197 var userAgent = navigator.userAgent.toLowerCase();
1199 // Figure out what browser is being used
1201 version: (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [])[1],
1202 safari: /webkit/.test( userAgent ),
1203 opera: /opera/.test( userAgent ),
1204 msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
1205 mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )
1208 var styleFloat = jQuery.browser.msie ?
1213 // Check to see if the W3C box model is being used
1214 boxModel: !jQuery.browser.msie || document.compatMode == "CSS1Compat",
1218 "class": "className",
1219 "float": styleFloat,
1220 cssFloat: styleFloat,
1221 styleFloat: styleFloat,
1222 innerHTML: "innerHTML",
1223 className: "className",
1225 disabled: "disabled",
1227 readonly: "readOnly",
1228 selected: "selected",
1229 maxlength: "maxLength",
1230 selectedIndex: "selectedIndex",
1231 defaultValue: "defaultValue",
1233 nodeName: "nodeName"
1238 parent: "elem.parentNode",
1239 parents: "jQuery.dir(elem,'parentNode')",
1240 next: "jQuery.nth(elem,2,'nextSibling')",
1241 prev: "jQuery.nth(elem,2,'previousSibling')",
1242 nextAll: "jQuery.dir(elem,'nextSibling')",
1243 prevAll: "jQuery.dir(elem,'previousSibling')",
1244 siblings: "jQuery.sibling(elem.parentNode.firstChild,elem)",
1245 children: "jQuery.sibling(elem.firstChild)",
1246 contents: "jQuery.nodeName(elem,'iframe')?elem.contentDocument||elem.contentWindow.document:jQuery.makeArray(elem.childNodes)"
1247 }, function(name, fn){
1248 fn = eval("false||function(elem){return " + fn + "}");
1250 jQuery.fn[ name ] = function( selector ) {
1251 var ret = jQuery.map( this, fn );
1253 if ( selector && typeof selector == "string" )
1254 ret = jQuery.multiFilter( selector, ret );
1256 return this.pushStack( jQuery.unique( ret ) );
1262 prependTo: "prepend",
1263 insertBefore: "before",
1264 insertAfter: "after",
1265 replaceAll: "replaceWith"
1266 }, function(name, original){
1267 jQuery.fn[ name ] = function() {
1268 var args = arguments;
1270 return this.each(function(){
1271 for ( var i = 0, length = args.length; i < length; i++ )
1272 jQuery( args[ i ] )[ original ]( this );
1278 removeAttr: function( name ) {
1279 jQuery.attr( this, name, "" );
1280 if (this.nodeType == 1)
1281 this.removeAttribute( name );
1284 addClass: function( classNames ) {
1285 jQuery.className.add( this, classNames );
1288 removeClass: function( classNames ) {
1289 jQuery.className.remove( this, classNames );
1292 toggleClass: function( classNames ) {
1293 jQuery.className[ jQuery.className.has( this, classNames ) ? "remove" : "add" ]( this, classNames );
1296 remove: function( selector ) {
1297 if ( !selector || jQuery.filter( selector, [ this ] ).r.length ) {
1298 // Prevent memory leaks
1299 jQuery( "*", this ).add(this).each(function(){
1300 jQuery.event.remove(this);
1301 jQuery.removeData(this);
1303 if (this.parentNode)
1304 this.parentNode.removeChild( this );
1309 // Remove element nodes and prevent memory leaks
1310 jQuery( ">*", this ).remove();
1312 // Remove any remaining nodes
1313 while ( this.firstChild )
1314 this.removeChild( this.firstChild );
1316 }, function(name, fn){
1317 jQuery.fn[ name ] = function(){
1318 return this.each( fn, arguments );
1322 jQuery.each([ "Height", "Width" ], function(i, name){
1323 var type = name.toLowerCase();
1325 jQuery.fn[ type ] = function( size ) {
1326 // Get window width or height
1327 return this[0] == window ?
1328 // Opera reports document.body.client[Width/Height] properly in both quirks and standards
1329 jQuery.browser.opera && document.body[ "client" + name ] ||
1331 // Safari reports inner[Width/Height] just fine (Mozilla and Opera include scroll bar widths)
1332 jQuery.browser.safari && window[ "inner" + name ] ||
1334 // Everyone else use document.documentElement or document.body depending on Quirks vs Standards mode
1335 document.compatMode == "CSS1Compat" && document.documentElement[ "client" + name ] || document.body[ "client" + name ] :
1337 // Get document width or height
1338 this[0] == document ?
1339 // Either scroll[Width/Height] or offset[Width/Height], whichever is greater (Mozilla reports scrollWidth the same as offsetWidth)
1340 Math.max( document.body[ "scroll" + name ], document.body[ "offset" + name ] ) :
1342 // Get or set width or height on the element
1344 // Get width or height on the element
1345 (this.length ? jQuery.css( this[0], type ) : null) :
1347 // Set the width or height on the element (default to pixels if value is unitless)
1348 this.css( type, size.constructor == String ? size : size + "px" );