2 // Will speed up references to window, and allows munging its name.
4 // Will speed up references to undefined, and allows munging its name.
6 // Map over jQuery in case of overwrite
7 _jQuery = window.jQuery,
8 // Map over the $ in case of overwrite
11 jQuery = window.jQuery = window.$ = function( selector, context ) {
12 // The jQuery object is actually just the init constructor 'enhanced'
13 return new jQuery.fn.init( selector, context );
16 // A simple way to check for HTML strings or ID strings
17 // (both of which we optimize for)
18 quickExpr = /^[^<]*(<(.|\s)+>)[^>]*$|^#([\w-]+)$/,
19 // Is it a simple selector
20 isSimple = /^.[^:#\[\.,]*$/;
22 jQuery.fn = jQuery.prototype = {
23 init: function( selector, context ) {
24 // Make sure that a selection was provided
25 selector = selector || document;
27 // Handle $(DOMElement)
28 if ( selector.nodeType ) {
31 this.context = selector;
34 // Handle HTML strings
35 if ( typeof selector === "string" ) {
36 // Are we dealing with HTML string or an ID?
37 var match = quickExpr.exec( selector );
39 // Verify a match, and that no context was specified for #id
40 if ( match && (match[1] || !context) ) {
42 // HANDLE: $(html) -> $(array)
44 selector = jQuery.clean( [ match[1] ], context );
48 var elem = document.getElementById( match[3] );
50 // Handle the case where IE and Opera return items
51 // by name instead of ID
52 if ( elem && elem.id != match[3] )
53 return jQuery().find( selector );
55 // Otherwise, we inject the element directly into the jQuery object
56 var ret = jQuery( elem || [] );
57 ret.context = document;
58 ret.selector = selector;
62 // HANDLE: $(expr, [context])
63 // (which is just equivalent to: $(content).find(expr)
65 return jQuery( context ).find( selector );
67 // HANDLE: $(function)
68 // Shortcut for document ready
69 } else if ( jQuery.isFunction( selector ) )
70 return jQuery( document ).ready( selector );
72 // Make sure that old selector state is passed along
73 if ( selector.selector && selector.context ) {
74 this.selector = selector.selector;
75 this.context = selector.context;
78 return this.setArray(jQuery.isArray( selector ) ?
80 jQuery.makeArray(selector));
83 // Start with an empty selector
86 // The current version of jQuery being used
89 // The number of elements contained in the matched element set
94 // Get the Nth element in the matched element set OR
95 // Get the whole matched element set as a clean array
96 get: function( num ) {
97 return num === undefined ?
99 // Return a 'clean' array
100 Array.prototype.slice.call( this ) :
102 // Return just the object
106 // Take an array of elements and push it onto the stack
107 // (returning the new matched element set)
108 pushStack: function( elems, name, selector ) {
109 // Build a new jQuery matched element set
110 var ret = jQuery( elems );
112 // Add the old object onto the stack (as a reference)
113 ret.prevObject = this;
115 ret.context = this.context;
117 if ( name === "find" )
118 ret.selector = this.selector + (this.selector ? " " : "") + selector;
120 ret.selector = this.selector + "." + name + "(" + selector + ")";
122 // Return the newly-formed element set
126 // Force the current matched set of elements to become
127 // the specified array of elements (destroying the stack in the process)
128 // You should use pushStack() in order to do this, but maintain the stack
129 setArray: function( elems ) {
130 // Resetting the length to 0, then using the native Array push
131 // is a super-fast way to populate an object with array-like properties
133 Array.prototype.push.apply( this, elems );
138 // Execute a callback for every element in the matched set.
139 // (You can seed the arguments with an array of args, but this is
140 // only used internally.)
141 each: function( callback, args ) {
142 return jQuery.each( this, callback, args );
145 // Determine the position of an element within
146 // the matched set of elements
147 index: function( elem ) {
148 // Locate the position of the desired element
149 return jQuery.inArray(
150 // If it receives a jQuery object, the first element is used
151 elem && elem.jquery ? elem[0] : elem
155 attr: function( name, value, type ) {
158 // Look for the case where we're accessing a style value
159 if ( typeof name === "string" )
160 if ( value === undefined )
161 return this[0] && jQuery[ type || "attr" ]( this[0], name );
165 options[ name ] = value;
168 // Check to see if we're setting style values
169 return this.each(function(i){
170 // Set all the styles
171 for ( name in options )
176 name, jQuery.prop( this, options[ name ], type, i, name )
181 css: function( key, value ) {
182 // ignore negative width and height values
183 if ( (key == 'width' || key == 'height') && parseFloat(value) < 0 )
185 return this.attr( key, value, "curCSS" );
188 text: function( text ) {
189 if ( typeof text !== "object" && text != null )
190 return this.empty().append( (this[0] && this[0].ownerDocument || document).createTextNode( text ) );
194 jQuery.each( text || this, function(){
195 jQuery.each( this.childNodes, function(){
196 if ( this.nodeType != 8 )
197 ret += this.nodeType != 1 ?
199 jQuery.fn.text( [ this ] );
206 wrapAll: function( html ) {
208 // The elements to wrap the target around
209 var wrap = jQuery( html, this[0].ownerDocument ).clone();
211 if ( this[0].parentNode )
212 wrap.insertBefore( this[0] );
217 while ( elem.firstChild )
218 elem = elem.firstChild;
227 wrapInner: function( html ) {
228 return this.each(function(){
229 jQuery( this ).contents().wrapAll( html );
233 wrap: function( html ) {
234 return this.each(function(){
235 jQuery( this ).wrapAll( html );
240 return this.domManip(arguments, true, function(elem){
241 if (this.nodeType == 1)
242 this.appendChild( elem );
246 prepend: function() {
247 return this.domManip(arguments, true, function(elem){
248 if (this.nodeType == 1)
249 this.insertBefore( elem, this.firstChild );
254 return this.domManip(arguments, false, function(elem){
255 this.parentNode.insertBefore( elem, this );
260 return this.domManip(arguments, false, function(elem){
261 this.parentNode.insertBefore( elem, this.nextSibling );
266 return this.prevObject || jQuery( [] );
269 // For internal use only.
270 // Behaves like an Array's .push method, not like a jQuery method.
273 find: function( selector ) {
274 if ( this.length === 1 ) {
275 var ret = this.pushStack( [], "find", selector );
277 jQuery.find( selector, this[0], ret );
280 return this.pushStack( jQuery.unique(jQuery.map(this, function(elem){
281 return jQuery.find( selector, elem );
282 })), "find", selector );
286 clone: function( events ) {
288 var ret = this.map(function(){
289 if ( !jQuery.support.noCloneEvent && !jQuery.isXMLDoc(this) ) {
290 // IE copies events bound via attachEvent when
291 // using cloneNode. Calling detachEvent on the
292 // clone will also remove the events from the orignal
293 // In order to get around this, we use innerHTML.
294 // Unfortunately, this means some modifications to
295 // attributes in IE that are actually only stored
296 // as properties will not be copied (such as the
297 // the name attribute on an input).
298 var html = this.outerHTML;
300 var div = this.ownerDocument.createElement("div");
301 div.appendChild( this.cloneNode(true) );
302 html = div.innerHTML;
305 return jQuery.clean([html.replace(/ jQuery\d+="(?:\d+|null)"/g, "").replace(/^\s*/, "")])[0];
307 return this.cloneNode(true);
310 // Copy the events from the original to the clone
311 if ( events === true ) {
312 var orig = this.find("*").andSelf(), i = 0;
314 ret.find("*").andSelf().each(function(){
315 if ( this.nodeName !== orig[i].nodeName )
318 var events = jQuery.data( orig[i], "events" );
320 for ( var type in events ) {
321 for ( var handler in events[ type ] ) {
322 jQuery.event.add( this, type, events[ type ][ handler ], events[ type ][ handler ].data );
330 // Return the cloned set
334 filter: function( selector ) {
335 return this.pushStack(
336 jQuery.isFunction( selector ) &&
337 jQuery.grep(this, function(elem, i){
338 return selector.call( elem, i );
341 jQuery.multiFilter( selector, jQuery.grep(this, function(elem){
342 return elem.nodeType === 1;
343 }) ), "filter", selector );
346 closest: function( selector ) {
347 var pos = jQuery.expr.match.POS.test( selector ) ? jQuery(selector) : null,
350 return this.map(function(){
352 while ( cur && cur.ownerDocument ) {
353 if ( pos ? pos.index(cur) > -1 : jQuery(cur).is(selector) ) {
354 jQuery.data(cur, "closest", closer);
357 cur = cur.parentNode;
363 not: function( selector ) {
364 if ( typeof selector === "string" )
365 // test special case where just one selector is passed in
366 if ( isSimple.test( selector ) )
367 return this.pushStack( jQuery.multiFilter( selector, this, true ), "not", selector );
369 selector = jQuery.multiFilter( selector, this );
371 var isArrayLike = selector.length && selector[selector.length - 1] !== undefined && !selector.nodeType;
372 return this.filter(function() {
373 return isArrayLike ? jQuery.inArray( this, selector ) < 0 : this != selector;
377 add: function( selector ) {
378 return this.pushStack( jQuery.unique( jQuery.merge(
380 typeof selector === "string" ?
382 jQuery.makeArray( selector )
386 is: function( selector ) {
387 return !!selector && jQuery.multiFilter( selector, this ).length > 0;
390 hasClass: function( selector ) {
391 return !!selector && this.is( "." + selector );
394 val: function( value ) {
395 if ( value === undefined ) {
399 if( jQuery.nodeName( elem, 'option' ) )
400 return (elem.attributes.value || {}).specified ? elem.value : elem.text;
402 // We need to handle select boxes special
403 if ( jQuery.nodeName( elem, "select" ) ) {
404 var index = elem.selectedIndex,
406 options = elem.options,
407 one = elem.type == "select-one";
409 // Nothing was selected
413 // Loop through all the selected options
414 for ( var i = one ? index : 0, max = one ? index + 1 : options.length; i < max; i++ ) {
415 var option = options[ i ];
417 if ( option.selected ) {
418 // Get the specifc value for the option
419 value = jQuery(option).val();
421 // We don't need an array for one selects
425 // Multi-Selects return an array
426 values.push( value );
433 // Everything else, we just grab the value
434 return (elem.value || "").replace(/\r/g, "");
441 if ( typeof value === "number" )
444 return this.each(function(){
445 if ( this.nodeType != 1 )
448 if ( jQuery.isArray(value) && /radio|checkbox/.test( this.type ) )
449 this.checked = (jQuery.inArray(this.value, value) >= 0 ||
450 jQuery.inArray(this.name, value) >= 0);
452 else if ( jQuery.nodeName( this, "select" ) ) {
453 var values = jQuery.makeArray(value);
455 jQuery( "option", this ).each(function(){
456 this.selected = (jQuery.inArray( this.value, values ) >= 0 ||
457 jQuery.inArray( this.text, values ) >= 0);
460 if ( !values.length )
461 this.selectedIndex = -1;
468 html: function( value ) {
469 return value === undefined ?
471 this[0].innerHTML.replace(/ jQuery\d+="(?:\d+|null)"/g, "") :
473 this.empty().append( value );
476 replaceWith: function( value ) {
477 return this.after( value ).remove();
481 return this.slice( i, +i + 1 );
485 return this.pushStack( Array.prototype.slice.apply( this, arguments ),
486 "slice", Array.prototype.slice.call(arguments).join(",") );
489 map: function( callback ) {
490 return this.pushStack( jQuery.map(this, function(elem, i){
491 return callback.call( elem, i, elem );
495 andSelf: function() {
496 return this.add( this.prevObject );
499 domManip: function( args, table, callback ) {
501 var fragment = (this[0].ownerDocument || this[0]).createDocumentFragment(),
502 scripts = jQuery.clean( args, (this[0].ownerDocument || this[0]), fragment ),
503 first = fragment.firstChild,
504 extra = this.length > 1 ? fragment.cloneNode(true) : fragment;
507 for ( var i = 0, l = this.length; i < l; i++ )
508 callback.call( root(this[i], first), i > 0 ? extra.cloneNode(true) : fragment );
511 jQuery.each( scripts, evalScript );
516 function root( elem, cur ) {
517 return table && jQuery.nodeName(elem, "table") && jQuery.nodeName(cur, "tr") ?
518 (elem.getElementsByTagName("tbody")[0] ||
519 elem.appendChild(elem.ownerDocument.createElement("tbody"))) :
525 // Give the init function the jQuery prototype for later instantiation
526 jQuery.fn.init.prototype = jQuery.fn;
528 function evalScript( i, elem ) {
537 jQuery.globalEval( elem.text || elem.textContent || elem.innerHTML || "" );
539 if ( elem.parentNode )
540 elem.parentNode.removeChild( elem );
547 jQuery.extend = jQuery.fn.extend = function() {
548 // copy reference to target object
549 var target = arguments[0] || {}, i = 1, length = arguments.length, deep = false, options;
551 // Handle a deep copy situation
552 if ( typeof target === "boolean" ) {
554 target = arguments[1] || {};
555 // skip the boolean and the target
559 // Handle case when target is a string or something (possible in deep copy)
560 if ( typeof target !== "object" && !jQuery.isFunction(target) )
563 // extend jQuery itself if only one argument is passed
569 for ( ; i < length; i++ )
570 // Only deal with non-null/undefined values
571 if ( (options = arguments[ i ]) != null )
572 // Extend the base object
573 for ( var name in options ) {
574 var src = target[ name ], copy = options[ name ];
576 // Prevent never-ending loop
577 if ( target === copy )
580 // Recurse if we're merging object values
581 if ( deep && copy && typeof copy === "object" && !copy.nodeType )
582 target[ name ] = jQuery.extend( deep,
583 // Never move original objects, clone them
584 src || ( copy.length != null ? [ ] : { } )
587 // Don't bring in undefined values
588 else if ( copy !== undefined )
589 target[ name ] = copy;
593 // Return the modified object
597 // exclude the following css properties to add px
598 var exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i,
600 defaultView = document.defaultView || {},
601 toString = Object.prototype.toString;
604 noConflict: function( deep ) {
608 window.jQuery = _jQuery;
613 // See test/unit/core.js for details concerning isFunction.
614 // Since version 1.3, DOM methods and functions like alert
615 // aren't supported. They return false on IE (#2968).
616 isFunction: function( obj ) {
617 return toString.call(obj) === "[object Function]";
620 isArray: function( obj ) {
621 return toString.call(obj) === "[object Array]";
624 // check if an element is in a (or is an) XML document
625 isXMLDoc: function( elem ) {
626 return elem.nodeType === 9 && elem.documentElement.nodeName !== "HTML" ||
627 !!elem.ownerDocument && jQuery.isXMLDoc( elem.ownerDocument );
630 // Evalulates a script in a global context
631 globalEval: function( data ) {
632 if ( data && /\S/.test(data) ) {
633 // Inspired by code by Andrea Giammarchi
634 // http://webreflection.blogspot.com/2007/08/global-scope-evaluation-and-dom.html
635 var head = document.getElementsByTagName("head")[0] || document.documentElement,
636 script = document.createElement("script");
638 script.type = "text/javascript";
639 if ( jQuery.support.scriptEval )
640 script.appendChild( document.createTextNode( data ) );
644 // Use insertBefore instead of appendChild to circumvent an IE6 bug.
645 // This arises when a base node is used (#2709).
646 head.insertBefore( script, head.firstChild );
647 head.removeChild( script );
651 nodeName: function( elem, name ) {
652 return elem.nodeName && elem.nodeName.toUpperCase() == name.toUpperCase();
655 // args is for internal usage only
656 each: function( object, callback, args ) {
657 var name, i = 0, length = object.length;
660 if ( length === undefined ) {
661 for ( name in object )
662 if ( callback.apply( object[ name ], args ) === false )
665 for ( ; i < length; )
666 if ( callback.apply( object[ i++ ], args ) === false )
669 // A special, fast, case for the most common use of each
671 if ( length === undefined ) {
672 for ( name in object )
673 if ( callback.call( object[ name ], name, object[ name ] ) === false )
676 for ( var value = object[0];
677 i < length && callback.call( value, i, value ) !== false; value = object[++i] ){}
683 prop: function( elem, value, type, i, name ) {
684 // Handle executable functions
685 if ( jQuery.isFunction( value ) )
686 value = value.call( elem, i );
688 // Handle passing in a number to a CSS property
689 return typeof value === "number" && type == "curCSS" && !exclude.test( name ) ?
695 // internal only, use addClass("class")
696 add: function( elem, classNames ) {
697 jQuery.each((classNames || "").split(/\s+/), function(i, className){
698 if ( elem.nodeType == 1 && !jQuery.className.has( elem.className, className ) )
699 elem.className += (elem.className ? " " : "") + className;
703 // internal only, use removeClass("class")
704 remove: function( elem, classNames ) {
705 if (elem.nodeType == 1)
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 hasClass("class")
714 has: function( elem, className ) {
715 return elem && 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 ) {
722 // Remember the old values, and insert the new ones
723 for ( var name in options ) {
724 old[ name ] = elem.style[ name ];
725 elem.style[ name ] = options[ name ];
728 callback.call( elem );
730 // Revert the old values
731 for ( var name in options )
732 elem.style[ name ] = old[ name ];
735 css: function( elem, name, force, extra ) {
736 if ( name == "width" || name == "height" ) {
737 var val, props = { position: "absolute", visibility: "hidden", display:"block" }, which = name == "width" ? [ "Left", "Right" ] : [ "Top", "Bottom" ];
740 val = name == "width" ? elem.offsetWidth : elem.offsetHeight;
742 if ( extra === "border" )
745 jQuery.each( which, function() {
747 val -= parseFloat(jQuery.curCSS( elem, "padding" + this, true)) || 0;
748 if ( extra === "margin" )
749 val += parseFloat(jQuery.curCSS( elem, "margin" + this, true)) || 0;
751 val -= parseFloat(jQuery.curCSS( elem, "border" + this + "Width", true)) || 0;
755 if ( elem.offsetWidth !== 0 )
758 jQuery.swap( elem, props, getWH );
760 return Math.max(0, Math.round(val));
763 return jQuery.curCSS( elem, name, force );
766 curCSS: function( elem, name, force ) {
767 var ret, style = elem.style;
769 // We need to handle opacity special in IE
770 if ( name == "opacity" && !jQuery.support.opacity ) {
771 ret = jQuery.attr( style, "opacity" );
778 // Make sure we're using the right name for getting the float value
779 if ( name.match( /float/i ) )
782 if ( !force && style && style[ name ] )
785 else if ( defaultView.getComputedStyle ) {
787 // Only "float" is needed here
788 if ( name.match( /float/i ) )
791 name = name.replace( /([A-Z])/g, "-$1" ).toLowerCase();
793 var computedStyle = defaultView.getComputedStyle( elem, null );
796 ret = computedStyle.getPropertyValue( name );
798 // We should always get a number back from opacity
799 if ( name == "opacity" && ret == "" )
802 } else if ( elem.currentStyle ) {
803 var camelCase = name.replace(/\-(\w)/g, function(all, letter){
804 return letter.toUpperCase();
807 ret = elem.currentStyle[ name ] || elem.currentStyle[ camelCase ];
809 // From the awesome hack by Dean Edwards
810 // http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291
812 // If we're not dealing with a regular pixel number
813 // but a number that has a weird ending, we need to convert it to pixels
814 if ( !/^\d+(px)?$/i.test( ret ) && /^\d/.test( ret ) ) {
815 // Remember the original values
816 var left = style.left, rsLeft = elem.runtimeStyle.left;
818 // Put in the new values to get a computed value out
819 elem.runtimeStyle.left = elem.currentStyle.left;
820 style.left = ret || 0;
821 ret = style.pixelLeft + "px";
823 // Revert the changed values
825 elem.runtimeStyle.left = rsLeft;
832 clean: function( elems, context, fragment ) {
833 context = context || document;
835 // !context.createElement fails in IE with an error but returns typeof 'object'
836 if ( typeof context.createElement === "undefined" )
837 context = context.ownerDocument || context[0] && context[0].ownerDocument || document;
839 // If a single string is passed in and it's a single tag
840 // just do a createElement and skip the rest
841 if ( !fragment && elems.length === 1 && typeof elems[0] === "string" ) {
842 var match = /^<(\w+)\s*\/?>$/.exec(elems[0]);
844 return [ context.createElement( match[1] ) ];
847 var ret = [], scripts = [], div = context.createElement("div");
849 jQuery.each(elems, function(i, elem){
850 if ( typeof elem === "number" )
856 // Convert html string into DOM nodes
857 if ( typeof elem === "string" ) {
858 // Fix "XHTML"-style tags in all browsers
859 elem = elem.replace(/(<(\w+)[^>]*?)\/>/g, function(all, front, tag){
860 return tag.match(/^(abbr|br|col|img|input|link|meta|param|hr|area|embed)$/i) ?
862 front + "></" + tag + ">";
865 // Trim whitespace, otherwise indexOf won't work as expected
866 var tags = elem.replace(/^\s+/, "").substring(0, 10).toLowerCase();
869 // option or optgroup
870 !tags.indexOf("<opt") &&
871 [ 1, "<select multiple='multiple'>", "</select>" ] ||
873 !tags.indexOf("<leg") &&
874 [ 1, "<fieldset>", "</fieldset>" ] ||
876 tags.match(/^<(thead|tbody|tfoot|colg|cap)/) &&
877 [ 1, "<table>", "</table>" ] ||
879 !tags.indexOf("<tr") &&
880 [ 2, "<table><tbody>", "</tbody></table>" ] ||
882 // <thead> matched above
883 (!tags.indexOf("<td") || !tags.indexOf("<th")) &&
884 [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ] ||
886 !tags.indexOf("<col") &&
887 [ 2, "<table><tbody></tbody><colgroup>", "</colgroup></table>" ] ||
889 // IE can't serialize <link> and <script> tags normally
890 !jQuery.support.htmlSerialize &&
891 [ 1, "div<div>", "</div>" ] ||
895 // Go to html and back, then peel off extra wrappers
896 div.innerHTML = wrap[1] + elem + wrap[2];
898 // Move to the right depth
902 // Remove IE's autoinserted <tbody> from table fragments
903 if ( !jQuery.support.tbody ) {
905 // String was a <table>, *may* have spurious <tbody>
906 var hasBody = /<tbody/i.test(elem),
907 tbody = !tags.indexOf("<table") && !hasBody ?
908 div.firstChild && div.firstChild.childNodes :
910 // String was a bare <thead> or <tfoot>
911 wrap[1] == "<table>" && !hasBody ?
915 for ( var j = tbody.length - 1; j >= 0 ; --j )
916 if ( jQuery.nodeName( tbody[ j ], "tbody" ) && !tbody[ j ].childNodes.length )
917 tbody[ j ].parentNode.removeChild( tbody[ j ] );
921 // IE completely kills leading whitespace when innerHTML is used
922 if ( !jQuery.support.leadingWhitespace && /^\s/.test( elem ) )
923 div.insertBefore( context.createTextNode( elem.match(/^\s*/)[0] ), div.firstChild );
925 elem = jQuery.makeArray( div.childNodes );
931 ret = jQuery.merge( ret, elem );
936 for ( var i = 0; ret[i]; i++ ) {
937 if ( jQuery.nodeName( ret[i], "script" ) && (!ret[i].type || ret[i].type.toLowerCase() === "text/javascript") ) {
938 scripts.push( ret[i].parentNode ? ret[i].parentNode.removeChild( ret[i] ) : ret[i] );
940 if ( ret[i].nodeType === 1 )
941 ret.splice.apply( ret, [i + 1, 0].concat(jQuery.makeArray(ret[i].getElementsByTagName("script"))) );
942 fragment.appendChild( ret[i] );
952 attr: function( elem, name, value ) {
953 // don't set attributes on text and comment nodes
954 if (!elem || elem.nodeType == 3 || elem.nodeType == 8)
957 var notxml = !jQuery.isXMLDoc( elem ),
958 // Whether we are setting (or getting)
959 set = value !== undefined;
961 // Try to normalize/fix the name
962 name = notxml && jQuery.props[ name ] || name;
964 // Only do all the following if this is a node (faster for style)
965 // IE elem.getAttribute passes even for style
966 if ( elem.tagName ) {
968 // These attributes require special treatment
969 var special = /href|src|style/.test( name );
971 // Safari mis-reports the default selected property of a hidden option
972 // Accessing the parent's selectedIndex property fixes it
973 if ( name == "selected" && elem.parentNode )
974 elem.parentNode.selectedIndex;
976 // If applicable, access the attribute via the DOM 0 way
977 if ( name in elem && notxml && !special ) {
979 // We can't allow the type property to be changed (since it causes problems in IE)
980 if ( name == "type" && jQuery.nodeName( elem, "input" ) && elem.parentNode )
981 throw "type property can't be changed";
983 elem[ name ] = value;
986 // browsers index elements by id/name on forms, give priority to attributes.
987 if( jQuery.nodeName( elem, "form" ) && elem.getAttributeNode(name) )
988 return elem.getAttributeNode( name ).nodeValue;
990 // elem.tabIndex doesn't always return the correct value when it hasn't been explicitly set
991 // http://fluidproject.org/blog/2008/01/09/getting-setting-and-removing-tabindex-values-with-javascript/
992 if ( name == "tabIndex" ) {
993 var attributeNode = elem.getAttributeNode( "tabIndex" );
994 return attributeNode && attributeNode.specified
995 ? attributeNode.value
996 : elem.nodeName.match(/(button|input|object|select|textarea)/i)
998 : elem.nodeName.match(/^(a|area)$/i) && elem.href
1003 return elem[ name ];
1006 if ( !jQuery.support.style && notxml && name == "style" )
1007 return jQuery.attr( elem.style, "cssText", value );
1010 // convert the value to a string (all browsers do this but IE) see #1070
1011 elem.setAttribute( name, "" + value );
1013 var attr = !jQuery.support.hrefNormalized && notxml && special
1014 // Some attributes require a special call on IE
1015 ? elem.getAttribute( name, 2 )
1016 : elem.getAttribute( name );
1018 // Non-existent attributes return null, we normalize to undefined
1019 return attr === null ? undefined : attr;
1022 // elem is actually elem.style ... set the style
1024 // IE uses filters for opacity
1025 if ( !jQuery.support.opacity && name == "opacity" ) {
1027 // IE has trouble with opacity if it does not have layout
1028 // Force it by setting the zoom level
1031 // Set the alpha filter to set the opacity
1032 elem.filter = (elem.filter || "").replace( /alpha\([^)]*\)/, "" ) +
1033 (parseInt( value ) + '' == "NaN" ? "" : "alpha(opacity=" + value * 100 + ")");
1036 return elem.filter && elem.filter.indexOf("opacity=") >= 0 ?
1037 (parseFloat( elem.filter.match(/opacity=([^)]*)/)[1] ) / 100) + '':
1041 name = name.replace(/-([a-z])/ig, function(all, letter){
1042 return letter.toUpperCase();
1046 elem[ name ] = value;
1048 return elem[ name ];
1051 trim: function( text ) {
1052 return (text || "").replace( /^\s+|\s+$/g, "" );
1055 makeArray: function( array ) {
1058 if( array != null ){
1059 var i = array.length;
1060 // The window, strings (and functions) also have 'length'
1061 if( i == null || typeof array === "string" || jQuery.isFunction(array) || array.setInterval )
1065 ret[--i] = array[i];
1071 inArray: function( elem, array ) {
1072 for ( var i = 0, length = array.length; i < length; i++ )
1073 // Use === because on IE, window == document
1074 if ( array[ i ] === elem )
1080 merge: function( first, second ) {
1081 // We have to loop this way because IE & Opera overwrite the length
1082 // expando of getElementsByTagName
1083 var i = 0, elem, pos = first.length;
1084 // Also, we need to make sure that the correct elements are being returned
1085 // (IE returns comment nodes in a '*' query)
1086 if ( !jQuery.support.getAll ) {
1087 while ( (elem = second[ i++ ]) != null )
1088 if ( elem.nodeType != 8 )
1089 first[ pos++ ] = elem;
1092 while ( (elem = second[ i++ ]) != null )
1093 first[ pos++ ] = elem;
1098 unique: function( array ) {
1099 var ret = [], done = {};
1103 for ( var i = 0, length = array.length; i < length; i++ ) {
1104 var id = jQuery.data( array[ i ] );
1106 if ( !done[ id ] ) {
1108 ret.push( array[ i ] );
1119 grep: function( elems, callback, inv ) {
1122 // Go through the array, only saving the items
1123 // that pass the validator function
1124 for ( var i = 0, length = elems.length; i < length; i++ )
1125 if ( !inv != !callback( elems[ i ], i ) )
1126 ret.push( elems[ i ] );
1131 map: function( elems, callback ) {
1134 // Go through the array, translating each of the items to their
1135 // new value (or values).
1136 for ( var i = 0, length = elems.length; i < length; i++ ) {
1137 var value = callback( elems[ i ], i );
1139 if ( value != null )
1140 ret[ ret.length ] = value;
1143 return ret.concat.apply( [], ret );
1147 // Use of jQuery.browser is deprecated.
1148 // It's included for backwards compatibility and plugins,
1149 // although they should work to migrate away.
1151 var userAgent = navigator.userAgent.toLowerCase();
1153 // Figure out what browser is being used
1155 version: (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [0,'0'])[1],
1156 safari: /webkit/.test( userAgent ),
1157 opera: /opera/.test( userAgent ),
1158 msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
1159 mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )
1163 parent: function(elem){return elem.parentNode;},
1164 parents: function(elem){return jQuery.dir(elem,"parentNode");},
1165 next: function(elem){return jQuery.nth(elem,2,"nextSibling");},
1166 prev: function(elem){return jQuery.nth(elem,2,"previousSibling");},
1167 nextAll: function(elem){return jQuery.dir(elem,"nextSibling");},
1168 prevAll: function(elem){return jQuery.dir(elem,"previousSibling");},
1169 siblings: function(elem){return jQuery.sibling(elem.parentNode.firstChild,elem);},
1170 children: function(elem){return jQuery.sibling(elem.firstChild);},
1171 contents: function(elem){return jQuery.nodeName(elem,"iframe")?elem.contentDocument||elem.contentWindow.document:jQuery.makeArray(elem.childNodes);}
1172 }, function(name, fn){
1173 jQuery.fn[ name ] = function( selector ) {
1174 var ret = jQuery.map( this, fn );
1176 if ( selector && typeof selector == "string" )
1177 ret = jQuery.multiFilter( selector, ret );
1179 return this.pushStack( jQuery.unique( ret ), name, selector );
1185 prependTo: "prepend",
1186 insertBefore: "before",
1187 insertAfter: "after",
1188 replaceAll: "replaceWith"
1189 }, function(name, original){
1190 jQuery.fn[ name ] = function() {
1191 var args = arguments;
1193 return this.each(function(){
1194 for ( var i = 0, length = args.length; i < length; i++ )
1195 jQuery( args[ i ] )[ original ]( this );
1201 removeAttr: function( name ) {
1202 jQuery.attr( this, name, "" );
1203 if (this.nodeType == 1)
1204 this.removeAttribute( name );
1207 addClass: function( classNames ) {
1208 jQuery.className.add( this, classNames );
1211 removeClass: function( classNames ) {
1212 jQuery.className.remove( this, classNames );
1215 toggleClass: function( classNames, state ) {
1216 if( typeof state !== "boolean" )
1217 state = !jQuery.className.has( this, classNames );
1218 jQuery.className[ state ? "add" : "remove" ]( this, classNames );
1221 remove: function( selector ) {
1222 if ( !selector || jQuery.filter( selector, [ this ] ).length ) {
1223 // Prevent memory leaks
1224 jQuery( "*", this ).add([this]).each(function(){
1225 jQuery.event.remove(this);
1226 jQuery.removeData(this);
1228 if (this.parentNode)
1229 this.parentNode.removeChild( this );
1234 // Remove element nodes and prevent memory leaks
1235 jQuery( ">*", this ).remove();
1237 // Remove any remaining nodes
1238 while ( this.firstChild )
1239 this.removeChild( this.firstChild );
1241 }, function(name, fn){
1242 jQuery.fn[ name ] = function(){
1243 return this.each( fn, arguments );
1247 // Helper function used by the dimensions and offset modules
1248 function num(elem, prop) {
1249 return elem[0] && parseInt( jQuery.curCSS(elem[0], prop, true), 10 ) || 0;