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 method, not like a jQuery method.
275 find: function( selector ) {
276 if ( this.length === 1 ) {
277 var ret = this.pushStack( [], "find", selector );
279 jQuery.find( selector, this[0], ret );
282 return this.pushStack( jQuery.unique(jQuery.map(this, function(elem){
283 return jQuery.find( selector, elem );
284 })), "find", selector );
288 clone: function( events ) {
290 var ret = this.map(function(){
291 if ( !jQuery.support.noCloneEvent && !jQuery.isXMLDoc(this) ) {
292 // IE copies events bound via attachEvent when
293 // using cloneNode. Calling detachEvent on the
294 // clone will also remove the events from the orignal
295 // In order to get around this, we use innerHTML.
296 // Unfortunately, this means some modifications to
297 // attributes in IE that are actually only stored
298 // as properties will not be copied (such as the
299 // the name attribute on an input).
300 var html = this.outerHTML;
302 var div = this.ownerDocument.createElement("div");
303 div.appendChild( this.cloneNode(true) );
304 html = div.innerHTML;
307 return jQuery.clean([html.replace(/ jQuery\d+="(?:\d+|null)"/g, "").replace(/^\s*/, "")])[0];
309 return this.cloneNode(true);
312 // Copy the events from the original to the clone
313 if ( events === true ) {
314 var orig = this.find("*").andSelf(), i = 0;
316 ret.find("*").andSelf().each(function(){
317 if ( this.nodeName !== orig[i].nodeName )
320 var events = jQuery.data( orig[i], "events" );
322 for ( var type in events ) {
323 for ( var handler in events[ type ] ) {
324 jQuery.event.add( this, type, events[ type ][ handler ], events[ type ][ handler ].data );
332 // Return the cloned set
336 filter: function( selector ) {
337 return this.pushStack(
338 jQuery.isFunction( selector ) &&
339 jQuery.grep(this, function(elem, i){
340 return selector.call( elem, i );
343 jQuery.multiFilter( selector, jQuery.grep(this, function(elem){
344 return elem.nodeType === 1;
345 }) ), "filter", selector );
348 closest: function( selector ) {
349 var pos = jQuery.expr.match.POS.test( selector ) ? jQuery(selector) : null,
352 return this.map(function(){
354 while ( cur && cur.ownerDocument ) {
355 if ( pos ? pos.index(cur) > -1 : jQuery(cur).is(selector) ) {
356 jQuery.data(cur, "closest", closer);
359 cur = cur.parentNode;
365 not: function( selector ) {
366 if ( typeof selector === "string" )
367 // test special case where just one selector is passed in
368 if ( isSimple.test( selector ) )
369 return this.pushStack( jQuery.multiFilter( selector, this, true ), "not", selector );
371 selector = jQuery.multiFilter( selector, this );
373 var isArrayLike = selector.length && selector[selector.length - 1] !== undefined && !selector.nodeType;
374 return this.filter(function() {
375 return isArrayLike ? jQuery.inArray( this, selector ) < 0 : this != selector;
379 add: function( selector ) {
380 return this.pushStack( jQuery.unique( jQuery.merge(
382 typeof selector === "string" ?
384 jQuery.makeArray( selector )
388 is: function( selector ) {
389 return !!selector && jQuery.multiFilter( selector, this ).length > 0;
392 hasClass: function( selector ) {
393 return !!selector && this.is( "." + selector );
396 val: function( value ) {
397 if ( value === undefined ) {
401 if( jQuery.nodeName( elem, 'option' ) )
402 return (elem.attributes.value || {}).specified ? elem.value : elem.text;
404 // We need to handle select boxes special
405 if ( jQuery.nodeName( elem, "select" ) ) {
406 var index = elem.selectedIndex,
408 options = elem.options,
409 one = elem.type == "select-one";
411 // Nothing was selected
415 // Loop through all the selected options
416 for ( var i = one ? index : 0, max = one ? index + 1 : options.length; i < max; i++ ) {
417 var option = options[ i ];
419 if ( option.selected ) {
420 // Get the specifc value for the option
421 value = jQuery(option).val();
423 // We don't need an array for one selects
427 // Multi-Selects return an array
428 values.push( value );
435 // Everything else, we just grab the value
436 return (elem.value || "").replace(/\r/g, "");
443 if ( typeof value === "number" )
446 return this.each(function(){
447 if ( this.nodeType != 1 )
450 if ( jQuery.isArray(value) && /radio|checkbox/.test( this.type ) )
451 this.checked = (jQuery.inArray(this.value, value) >= 0 ||
452 jQuery.inArray(this.name, value) >= 0);
454 else if ( jQuery.nodeName( this, "select" ) ) {
455 var values = jQuery.makeArray(value);
457 jQuery( "option", this ).each(function(){
458 this.selected = (jQuery.inArray( this.value, values ) >= 0 ||
459 jQuery.inArray( this.text, values ) >= 0);
462 if ( !values.length )
463 this.selectedIndex = -1;
470 html: function( value ) {
471 return value === undefined ?
473 this[0].innerHTML.replace(/ jQuery\d+="(?:\d+|null)"/g, "") :
475 this.empty().append( value );
478 replaceWith: function( value ) {
479 return this.after( value ).remove();
483 return this.slice( i, +i + 1 );
487 return this.pushStack( Array.prototype.slice.apply( this, arguments ),
488 "slice", Array.prototype.slice.call(arguments).join(",") );
491 map: function( callback ) {
492 return this.pushStack( jQuery.map(this, function(elem, i){
493 return callback.call( elem, i, elem );
497 andSelf: function() {
498 return this.add( this.prevObject );
501 domManip: function( args, table, callback ) {
503 var fragment = (this[0].ownerDocument || this[0]).createDocumentFragment(),
504 scripts = jQuery.clean( args, (this[0].ownerDocument || this[0]), fragment ),
505 first = fragment.firstChild,
506 extra = this.length > 1 ? fragment.cloneNode(true) : fragment;
509 for ( var i = 0, l = this.length; i < l; i++ )
510 callback.call( root(this[i], first), i > 0 ? extra.cloneNode(true) : fragment );
513 jQuery.each( scripts, evalScript );
518 function root( elem, cur ) {
519 return table && jQuery.nodeName(elem, "table") && jQuery.nodeName(cur, "tr") ?
520 (elem.getElementsByTagName("tbody")[0] ||
521 elem.appendChild(elem.ownerDocument.createElement("tbody"))) :
527 // Give the init function the jQuery prototype for later instantiation
528 jQuery.fn.init.prototype = jQuery.fn;
530 function evalScript( i, elem ) {
539 jQuery.globalEval( elem.text || elem.textContent || elem.innerHTML || "" );
541 if ( elem.parentNode )
542 elem.parentNode.removeChild( elem );
549 jQuery.extend = jQuery.fn.extend = function() {
550 // copy reference to target object
551 var target = arguments[0] || {}, i = 1, length = arguments.length, deep = false, options;
553 // Handle a deep copy situation
554 if ( typeof target === "boolean" ) {
556 target = arguments[1] || {};
557 // skip the boolean and the target
561 // Handle case when target is a string or something (possible in deep copy)
562 if ( typeof target !== "object" && !jQuery.isFunction(target) )
565 // extend jQuery itself if only one argument is passed
571 for ( ; i < length; i++ )
572 // Only deal with non-null/undefined values
573 if ( (options = arguments[ i ]) != null )
574 // Extend the base object
575 for ( var name in options ) {
576 var src = target[ name ], copy = options[ name ];
578 // Prevent never-ending loop
579 if ( target === copy )
582 // Recurse if we're merging object values
583 if ( deep && copy && typeof copy === "object" && !copy.nodeType )
584 target[ name ] = jQuery.extend( deep,
585 // Never move original objects, clone them
586 src || ( copy.length != null ? [ ] : { } )
589 // Don't bring in undefined values
590 else if ( copy !== undefined )
591 target[ name ] = copy;
595 // Return the modified object
599 // exclude the following css properties to add px
600 var exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i,
602 defaultView = document.defaultView || {},
603 toString = Object.prototype.toString;
606 noConflict: function( deep ) {
610 window.jQuery = _jQuery;
615 // See test/unit/core.js for details concerning isFunction.
616 // Since version 1.3, DOM methods and functions like alert
617 // aren't supported. They return false on IE (#2968).
618 isFunction: function( obj ) {
619 return toString.call(obj) === "[object Function]";
622 isArray: function( obj ) {
623 return toString.call(obj) === "[object Array]";
626 // check if an element is in a (or is an) XML document
627 isXMLDoc: function( elem ) {
628 return elem.nodeType === 9 && elem.documentElement.nodeName !== "HTML" ||
629 !!elem.ownerDocument && jQuery.isXMLDoc( elem.ownerDocument );
632 // Evalulates a script in a global context
633 globalEval: function( data ) {
634 if ( data && /\S/.test(data) ) {
635 // Inspired by code by Andrea Giammarchi
636 // http://webreflection.blogspot.com/2007/08/global-scope-evaluation-and-dom.html
637 var head = document.getElementsByTagName("head")[0] || document.documentElement,
638 script = document.createElement("script");
640 script.type = "text/javascript";
641 if ( jQuery.support.scriptEval )
642 script.appendChild( document.createTextNode( data ) );
646 // Use insertBefore instead of appendChild to circumvent an IE6 bug.
647 // This arises when a base node is used (#2709).
648 head.insertBefore( script, head.firstChild );
649 head.removeChild( script );
653 nodeName: function( elem, name ) {
654 return elem.nodeName && elem.nodeName.toUpperCase() == name.toUpperCase();
657 // args is for internal usage only
658 each: function( object, callback, args ) {
659 var name, i = 0, length = object.length;
662 if ( length === undefined ) {
663 for ( name in object )
664 if ( callback.apply( object[ name ], args ) === false )
667 for ( ; i < length; )
668 if ( callback.apply( object[ i++ ], args ) === false )
671 // A special, fast, case for the most common use of each
673 if ( length === undefined ) {
674 for ( name in object )
675 if ( callback.call( object[ name ], name, object[ name ] ) === false )
678 for ( var value = object[0];
679 i < length && callback.call( value, i, value ) !== false; value = object[++i] ){}
685 prop: function( elem, value, type, i, name ) {
686 // Handle executable functions
687 if ( jQuery.isFunction( value ) )
688 value = value.call( elem, i );
690 // Handle passing in a number to a CSS property
691 return typeof value === "number" && type == "curCSS" && !exclude.test( name ) ?
697 // internal only, use addClass("class")
698 add: function( elem, classNames ) {
699 jQuery.each((classNames || "").split(/\s+/), function(i, className){
700 if ( elem.nodeType == 1 && !jQuery.className.has( elem.className, className ) )
701 elem.className += (elem.className ? " " : "") + className;
705 // internal only, use removeClass("class")
706 remove: function( elem, classNames ) {
707 if (elem.nodeType == 1)
708 elem.className = classNames !== undefined ?
709 jQuery.grep(elem.className.split(/\s+/), function(className){
710 return !jQuery.className.has( classNames, className );
715 // internal only, use hasClass("class")
716 has: function( elem, className ) {
717 return elem && jQuery.inArray( className, (elem.className || elem).toString().split(/\s+/) ) > -1;
721 // A method for quickly swapping in/out CSS properties to get correct calculations
722 swap: function( elem, options, callback ) {
724 // Remember the old values, and insert the new ones
725 for ( var name in options ) {
726 old[ name ] = elem.style[ name ];
727 elem.style[ name ] = options[ name ];
730 callback.call( elem );
732 // Revert the old values
733 for ( var name in options )
734 elem.style[ name ] = old[ name ];
737 css: function( elem, name, force, extra ) {
738 if ( name == "width" || name == "height" ) {
739 var val, props = { position: "absolute", visibility: "hidden", display:"block" }, which = name == "width" ? [ "Left", "Right" ] : [ "Top", "Bottom" ];
742 val = name == "width" ? elem.offsetWidth : elem.offsetHeight;
744 if ( extra === "border" )
747 jQuery.each( which, function() {
749 val -= parseFloat(jQuery.curCSS( elem, "padding" + this, true)) || 0;
750 if ( extra === "margin" )
751 val += parseFloat(jQuery.curCSS( elem, "margin" + this, true)) || 0;
753 val -= parseFloat(jQuery.curCSS( elem, "border" + this + "Width", true)) || 0;
757 if ( elem.offsetWidth !== 0 )
760 jQuery.swap( elem, props, getWH );
762 return Math.max(0, Math.round(val));
765 return jQuery.curCSS( elem, name, force );
768 curCSS: function( elem, name, force ) {
769 var ret, style = elem.style;
771 // We need to handle opacity special in IE
772 if ( name == "opacity" && !jQuery.support.opacity ) {
773 ret = jQuery.attr( style, "opacity" );
780 // Make sure we're using the right name for getting the float value
781 if ( name.match( /float/i ) )
784 if ( !force && style && style[ name ] )
787 else if ( defaultView.getComputedStyle ) {
789 // Only "float" is needed here
790 if ( name.match( /float/i ) )
793 name = name.replace( /([A-Z])/g, "-$1" ).toLowerCase();
795 var computedStyle = defaultView.getComputedStyle( elem, null );
798 ret = computedStyle.getPropertyValue( name );
800 // We should always get a number back from opacity
801 if ( name == "opacity" && ret == "" )
804 } else if ( elem.currentStyle ) {
805 var camelCase = name.replace(/\-(\w)/g, function(all, letter){
806 return letter.toUpperCase();
809 ret = elem.currentStyle[ name ] || elem.currentStyle[ camelCase ];
811 // From the awesome hack by Dean Edwards
812 // http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291
814 // If we're not dealing with a regular pixel number
815 // but a number that has a weird ending, we need to convert it to pixels
816 if ( !/^\d+(px)?$/i.test( ret ) && /^\d/.test( ret ) ) {
817 // Remember the original values
818 var left = style.left, rsLeft = elem.runtimeStyle.left;
820 // Put in the new values to get a computed value out
821 elem.runtimeStyle.left = elem.currentStyle.left;
822 style.left = ret || 0;
823 ret = style.pixelLeft + "px";
825 // Revert the changed values
827 elem.runtimeStyle.left = rsLeft;
834 clean: function( elems, context, fragment ) {
835 context = context || document;
837 // !context.createElement fails in IE with an error but returns typeof 'object'
838 if ( typeof context.createElement === "undefined" )
839 context = context.ownerDocument || context[0] && context[0].ownerDocument || document;
841 // If a single string is passed in and it's a single tag
842 // just do a createElement and skip the rest
843 if ( !fragment && elems.length === 1 && typeof elems[0] === "string" ) {
844 var match = /^<(\w+)\s*\/?>$/.exec(elems[0]);
846 return [ context.createElement( match[1] ) ];
849 var ret = [], scripts = [], div = context.createElement("div");
851 jQuery.each(elems, function(i, elem){
852 if ( typeof elem === "number" )
858 // Convert html string into DOM nodes
859 if ( typeof elem === "string" ) {
860 // Fix "XHTML"-style tags in all browsers
861 elem = elem.replace(/(<(\w+)[^>]*?)\/>/g, function(all, front, tag){
862 return tag.match(/^(abbr|br|col|img|input|link|meta|param|hr|area|embed)$/i) ?
864 front + "></" + tag + ">";
867 // Trim whitespace, otherwise indexOf won't work as expected
868 var tags = elem.replace(/^\s+/, "").substring(0, 10).toLowerCase();
871 // option or optgroup
872 !tags.indexOf("<opt") &&
873 [ 1, "<select multiple='multiple'>", "</select>" ] ||
875 !tags.indexOf("<leg") &&
876 [ 1, "<fieldset>", "</fieldset>" ] ||
878 tags.match(/^<(thead|tbody|tfoot|colg|cap)/) &&
879 [ 1, "<table>", "</table>" ] ||
881 !tags.indexOf("<tr") &&
882 [ 2, "<table><tbody>", "</tbody></table>" ] ||
884 // <thead> matched above
885 (!tags.indexOf("<td") || !tags.indexOf("<th")) &&
886 [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ] ||
888 !tags.indexOf("<col") &&
889 [ 2, "<table><tbody></tbody><colgroup>", "</colgroup></table>" ] ||
891 // IE can't serialize <link> and <script> tags normally
892 !jQuery.support.htmlSerialize &&
893 [ 1, "div<div>", "</div>" ] ||
897 // Go to html and back, then peel off extra wrappers
898 div.innerHTML = wrap[1] + elem + wrap[2];
900 // Move to the right depth
904 // Remove IE's autoinserted <tbody> from table fragments
905 if ( !jQuery.support.tbody ) {
907 // String was a <table>, *may* have spurious <tbody>
908 var hasBody = /<tbody/i.test(elem),
909 tbody = !tags.indexOf("<table") && !hasBody ?
910 div.firstChild && div.firstChild.childNodes :
912 // String was a bare <thead> or <tfoot>
913 wrap[1] == "<table>" && !hasBody ?
917 for ( var j = tbody.length - 1; j >= 0 ; --j )
918 if ( jQuery.nodeName( tbody[ j ], "tbody" ) && !tbody[ j ].childNodes.length )
919 tbody[ j ].parentNode.removeChild( tbody[ j ] );
923 // IE completely kills leading whitespace when innerHTML is used
924 if ( !jQuery.support.leadingWhitespace && /^\s/.test( elem ) )
925 div.insertBefore( context.createTextNode( elem.match(/^\s*/)[0] ), div.firstChild );
927 elem = jQuery.makeArray( div.childNodes );
933 ret = jQuery.merge( ret, elem );
938 for ( var i = 0; ret[i]; i++ ) {
939 if ( jQuery.nodeName( ret[i], "script" ) && (!ret[i].type || ret[i].type.toLowerCase() === "text/javascript") ) {
940 scripts.push( ret[i].parentNode ? ret[i].parentNode.removeChild( ret[i] ) : ret[i] );
942 if ( ret[i].nodeType === 1 )
943 ret.splice.apply( ret, [i + 1, 0].concat(jQuery.makeArray(ret[i].getElementsByTagName("script"))) );
944 fragment.appendChild( ret[i] );
954 attr: function( elem, name, value ) {
955 // don't set attributes on text and comment nodes
956 if (!elem || elem.nodeType == 3 || elem.nodeType == 8)
959 var notxml = !jQuery.isXMLDoc( elem ),
960 // Whether we are setting (or getting)
961 set = value !== undefined;
963 // Try to normalize/fix the name
964 name = notxml && jQuery.props[ name ] || name;
966 // Only do all the following if this is a node (faster for style)
967 // IE elem.getAttribute passes even for style
968 if ( elem.tagName ) {
970 // These attributes require special treatment
971 var special = /href|src|style/.test( name );
973 // Safari mis-reports the default selected property of a hidden option
974 // Accessing the parent's selectedIndex property fixes it
975 if ( name == "selected" && elem.parentNode )
976 elem.parentNode.selectedIndex;
978 // If applicable, access the attribute via the DOM 0 way
979 if ( name in elem && notxml && !special ) {
981 // We can't allow the type property to be changed (since it causes problems in IE)
982 if ( name == "type" && jQuery.nodeName( elem, "input" ) && elem.parentNode )
983 throw "type property can't be changed";
985 elem[ name ] = value;
988 // browsers index elements by id/name on forms, give priority to attributes.
989 if( jQuery.nodeName( elem, "form" ) && elem.getAttributeNode(name) )
990 return elem.getAttributeNode( name ).nodeValue;
992 // elem.tabIndex doesn't always return the correct value when it hasn't been explicitly set
993 // http://fluidproject.org/blog/2008/01/09/getting-setting-and-removing-tabindex-values-with-javascript/
994 if ( name == "tabIndex" ) {
995 var attributeNode = elem.getAttributeNode( "tabIndex" );
996 return attributeNode && attributeNode.specified
997 ? attributeNode.value
998 : elem.nodeName.match(/(button|input|object|select|textarea)/i)
1000 : elem.nodeName.match(/^(a|area)$/i) && elem.href
1005 return elem[ name ];
1008 if ( !jQuery.support.style && notxml && name == "style" )
1009 return jQuery.attr( elem.style, "cssText", value );
1012 // convert the value to a string (all browsers do this but IE) see #1070
1013 elem.setAttribute( name, "" + value );
1015 var attr = !jQuery.support.hrefNormalized && notxml && special
1016 // Some attributes require a special call on IE
1017 ? elem.getAttribute( name, 2 )
1018 : elem.getAttribute( name );
1020 // Non-existent attributes return null, we normalize to undefined
1021 return attr === null ? undefined : attr;
1024 // elem is actually elem.style ... set the style
1026 // IE uses filters for opacity
1027 if ( !jQuery.support.opacity && name == "opacity" ) {
1029 // IE has trouble with opacity if it does not have layout
1030 // Force it by setting the zoom level
1033 // Set the alpha filter to set the opacity
1034 elem.filter = (elem.filter || "").replace( /alpha\([^)]*\)/, "" ) +
1035 (parseInt( value ) + '' == "NaN" ? "" : "alpha(opacity=" + value * 100 + ")");
1038 return elem.filter && elem.filter.indexOf("opacity=") >= 0 ?
1039 (parseFloat( elem.filter.match(/opacity=([^)]*)/)[1] ) / 100) + '':
1043 name = name.replace(/-([a-z])/ig, function(all, letter){
1044 return letter.toUpperCase();
1048 elem[ name ] = value;
1050 return elem[ name ];
1053 trim: function( text ) {
1054 return (text || "").replace( /^\s+|\s+$/g, "" );
1057 makeArray: function( array ) {
1060 if( array != null ){
1061 var i = array.length;
1062 // The window, strings (and functions) also have 'length'
1063 if( i == null || typeof array === "string" || jQuery.isFunction(array) || array.setInterval )
1067 ret[--i] = array[i];
1073 inArray: function( elem, array ) {
1074 for ( var i = 0, length = array.length; i < length; i++ )
1075 // Use === because on IE, window == document
1076 if ( array[ i ] === elem )
1082 merge: function( first, second ) {
1083 // We have to loop this way because IE & Opera overwrite the length
1084 // expando of getElementsByTagName
1085 var i = 0, elem, pos = first.length;
1086 // Also, we need to make sure that the correct elements are being returned
1087 // (IE returns comment nodes in a '*' query)
1088 if ( !jQuery.support.getAll ) {
1089 while ( (elem = second[ i++ ]) != null )
1090 if ( elem.nodeType != 8 )
1091 first[ pos++ ] = elem;
1094 while ( (elem = second[ i++ ]) != null )
1095 first[ pos++ ] = elem;
1100 unique: function( array ) {
1101 var ret = [], done = {};
1105 for ( var i = 0, length = array.length; i < length; i++ ) {
1106 var id = jQuery.data( array[ i ] );
1108 if ( !done[ id ] ) {
1110 ret.push( array[ i ] );
1121 grep: function( elems, callback, inv ) {
1124 // Go through the array, only saving the items
1125 // that pass the validator function
1126 for ( var i = 0, length = elems.length; i < length; i++ )
1127 if ( !inv != !callback( elems[ i ], i ) )
1128 ret.push( elems[ i ] );
1133 map: function( elems, callback ) {
1136 // Go through the array, translating each of the items to their
1137 // new value (or values).
1138 for ( var i = 0, length = elems.length; i < length; i++ ) {
1139 var value = callback( elems[ i ], i );
1141 if ( value != null )
1142 ret[ ret.length ] = value;
1145 return ret.concat.apply( [], ret );
1149 // Use of jQuery.browser is deprecated.
1150 // It's included for backwards compatibility and plugins,
1151 // although they should work to migrate away.
1153 var userAgent = navigator.userAgent.toLowerCase();
1155 // Figure out what browser is being used
1157 version: (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [0,'0'])[1],
1158 safari: /webkit/.test( userAgent ),
1159 opera: /opera/.test( userAgent ),
1160 msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
1161 mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )
1165 parent: function(elem){return elem.parentNode;},
1166 parents: function(elem){return jQuery.dir(elem,"parentNode");},
1167 next: function(elem){return jQuery.nth(elem,2,"nextSibling");},
1168 prev: function(elem){return jQuery.nth(elem,2,"previousSibling");},
1169 nextAll: function(elem){return jQuery.dir(elem,"nextSibling");},
1170 prevAll: function(elem){return jQuery.dir(elem,"previousSibling");},
1171 siblings: function(elem){return jQuery.sibling(elem.parentNode.firstChild,elem);},
1172 children: function(elem){return jQuery.sibling(elem.firstChild);},
1173 contents: function(elem){return jQuery.nodeName(elem,"iframe")?elem.contentDocument||elem.contentWindow.document:jQuery.makeArray(elem.childNodes);}
1174 }, function(name, fn){
1175 jQuery.fn[ name ] = function( selector ) {
1176 var ret = jQuery.map( this, fn );
1178 if ( selector && typeof selector == "string" )
1179 ret = jQuery.multiFilter( selector, ret );
1181 return this.pushStack( jQuery.unique( ret ), name, selector );
1187 prependTo: "prepend",
1188 insertBefore: "before",
1189 insertAfter: "after",
1190 replaceAll: "replaceWith"
1191 }, function(name, original){
1192 jQuery.fn[ name ] = function() {
1193 var args = arguments;
1195 return this.each(function(){
1196 for ( var i = 0, length = args.length; i < length; i++ )
1197 jQuery( args[ i ] )[ original ]( this );
1203 removeAttr: function( name ) {
1204 jQuery.attr( this, name, "" );
1205 if (this.nodeType == 1)
1206 this.removeAttribute( name );
1209 addClass: function( classNames ) {
1210 jQuery.className.add( this, classNames );
1213 removeClass: function( classNames ) {
1214 jQuery.className.remove( this, classNames );
1217 toggleClass: function( classNames, state ) {
1218 if( typeof state !== "boolean" )
1219 state = !jQuery.className.has( this, classNames );
1220 jQuery.className[ state ? "add" : "remove" ]( this, classNames );
1223 remove: function( selector ) {
1224 if ( !selector || jQuery.filter( selector, [ this ] ).length ) {
1225 // Prevent memory leaks
1226 jQuery( "*", this ).add([this]).each(function(){
1227 jQuery.event.remove(this);
1228 jQuery.removeData(this);
1230 if (this.parentNode)
1231 this.parentNode.removeChild( this );
1236 // Remove element nodes and prevent memory leaks
1237 jQuery( ">*", this ).remove();
1239 // Remove any remaining nodes
1240 while ( this.firstChild )
1241 this.removeChild( this.firstChild );
1243 }, function(name, fn){
1244 jQuery.fn[ name ] = function(){
1245 return this.each( fn, arguments );
1249 // Helper function used by the dimensions and offset modules
1250 function num(elem, prop) {
1251 return elem[0] && parseInt( jQuery.curCSS(elem[0], prop, true), 10 ) || 0;