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 selector === undefined ?
15 new jQuery.fn.init( selector, context );
18 // A simple way to check for HTML strings or ID strings
19 // (both of which we optimize for)
20 quickExpr = /^[^<]*(<(.|\s)+>)[^>]*$|^#([\w-]+)$/,
21 // Is it a simple selector
22 isSimple = /^.[^:#\[\.,]*$/;
24 jQuery.fn = jQuery.prototype = {
25 init: function( selector, context ) {
26 // Handle $("") or $(null)
32 // Handle $(DOMElement)
33 if ( selector.nodeType ) {
36 this.context = selector;
40 // Handle HTML strings
41 if ( typeof selector === "string" ) {
42 // Are we dealing with HTML string or an ID?
43 var match = quickExpr.exec( selector );
45 // Verify a match, and that no context was specified for #id
46 if ( match && (match[1] || !context) ) {
48 // HANDLE: $(html) -> $(array)
50 selector = jQuery.clean( [ match[1] ], context );
54 var elem = document.getElementById( match[3] );
56 // Handle the case where IE and Opera return items
57 // by name instead of ID
58 if ( elem && elem.id != match[3] ) {
59 return rootjQuery.find( selector );
62 // Otherwise, we inject the element directly into the jQuery object
63 var ret = jQuery( elem || null );
64 ret.context = document;
65 ret.selector = selector;
69 // HANDLE: $(expr, $(...))
70 } else if ( !context || context.jquery ) {
71 return (context || rootjQuery).find( selector );
73 // HANDLE: $(expr, context)
74 // (which is just equivalent to: $(context).find(expr)
76 return jQuery( context ).find( selector );
79 // HANDLE: $(function)
80 // Shortcut for document ready
81 } else if ( jQuery.isFunction( selector ) ) {
82 return rootjQuery.ready( selector );
85 // Make sure that old selector state is passed along
86 if ( selector.selector && selector.context ) {
87 this.selector = selector.selector;
88 this.context = selector.context;
91 return this.setArray(jQuery.isArray( selector ) ?
93 jQuery.makeArray(selector));
96 // Start with an empty selector
99 // The current version of jQuery being used
102 // The number of elements contained in the matched element set
107 // Get the Nth element in the matched element set OR
108 // Get the whole matched element set as a clean array
109 get: function( num ) {
110 return num === undefined ?
112 // Return a 'clean' array
113 Array.prototype.slice.call( this ) :
115 // Return just the object
119 // Take an array of elements and push it onto the stack
120 // (returning the new matched element set)
121 pushStack: function( elems, name, selector ) {
122 // Build a new jQuery matched element set
123 var ret = jQuery( elems || null );
125 // Add the old object onto the stack (as a reference)
126 ret.prevObject = this;
128 ret.context = this.context;
130 if ( name === "find" )
131 ret.selector = this.selector + (this.selector ? " " : "") + selector;
133 ret.selector = this.selector + "." + name + "(" + selector + ")";
135 // Return the newly-formed element set
139 // Force the current matched set of elements to become
140 // the specified array of elements (destroying the stack in the process)
141 // You should use pushStack() in order to do this, but maintain the stack
142 setArray: function( elems ) {
143 // Resetting the length to 0, then using the native Array push
144 // is a super-fast way to populate an object with array-like properties
146 Array.prototype.push.apply( this, elems );
151 // Execute a callback for every element in the matched set.
152 // (You can seed the arguments with an array of args, but this is
153 // only used internally.)
154 each: function( callback, args ) {
155 return jQuery.each( this, callback, args );
158 // Determine the position of an element within
159 // the matched set of elements
160 index: function( elem ) {
161 // Locate the position of the desired element
162 return jQuery.inArray(
163 // If it receives a jQuery object, the first element is used
164 elem && elem.jquery ? elem[0] : elem
168 attr: function( name, value, type ) {
169 var options = name, isFunction = jQuery.isFunction( value );
171 // Look for the case where we're accessing a style value
172 if ( typeof name === "string" ) {
173 if ( value === undefined ) {
175 jQuery[ type || "attr" ]( this[0], name ) :
180 options[ name ] = value;
184 // Check to see if we're setting style values
185 for ( var i = 0, l = this.length; i < l; i++ ) {
188 // Set all the styles
189 for ( var prop in options ) {
190 value = options[prop];
193 value = value.call( elem, i );
196 if ( typeof value === "number" && type === "curCSS" && !exclude.test(prop) ) {
197 value = value + "px";
200 jQuery.attr( type ? elem.style : elem, prop, value );
207 css: function( key, value ) {
208 // ignore negative width and height values
209 if ( (key == 'width' || key == 'height') && parseFloat(value) < 0 )
211 return this.attr( key, value, "curCSS" );
214 text: function( text ) {
215 if ( typeof text !== "object" && text != null )
216 return this.empty().append( (this[0] && this[0].ownerDocument || document).createTextNode( text ) );
220 jQuery.each( text || this, function(){
221 jQuery.each( this.childNodes, function(){
222 if ( this.nodeType != 8 )
223 ret += this.nodeType != 1 ?
225 jQuery.fn.text( [ this ] );
232 wrapAll: function( html ) {
234 // The elements to wrap the target around
235 var wrap = jQuery( html, this[0].ownerDocument ).clone();
237 if ( this[0].parentNode )
238 wrap.insertBefore( this[0] );
243 while ( elem.firstChild )
244 elem = elem.firstChild;
253 wrapInner: function( html ) {
254 return this.each(function(){
255 jQuery( this ).contents().wrapAll( html );
259 wrap: function( html ) {
260 return this.each(function(){
261 jQuery( this ).wrapAll( html );
266 return this.domManip(arguments, true, function(elem){
267 if (this.nodeType == 1)
268 this.appendChild( elem );
272 prepend: function() {
273 return this.domManip(arguments, true, function(elem){
274 if (this.nodeType == 1)
275 this.insertBefore( elem, this.firstChild );
280 return this.domManip(arguments, false, function(elem){
281 this.parentNode.insertBefore( elem, this );
286 return this.domManip(arguments, false, function(elem){
287 this.parentNode.insertBefore( elem, this.nextSibling );
292 return this.prevObject || jQuery(null);
295 // For internal use only.
296 // Behaves like an Array's method, not like a jQuery method.
301 find: function( selector ) {
302 var ret = this.pushStack( "", "find", selector ), length = 0;
304 for ( var i = 0, l = this.length; i < l; i++ ) {
306 jQuery.find( selector, this[i], ret );
309 // Make sure that the results are unique
310 for ( var n = length; n < ret.length; n++ ) {
311 for ( var r = 0; r < length; r++ ) {
312 if ( ret[r] === ret[n] ) {
324 clone: function( events ) {
326 var ret = this.map(function(){
327 if ( !jQuery.support.noCloneEvent && !jQuery.isXMLDoc(this) ) {
328 // IE copies events bound via attachEvent when
329 // using cloneNode. Calling detachEvent on the
330 // clone will also remove the events from the orignal
331 // In order to get around this, we use innerHTML.
332 // Unfortunately, this means some modifications to
333 // attributes in IE that are actually only stored
334 // as properties will not be copied (such as the
335 // the name attribute on an input).
336 var html = this.outerHTML;
338 var div = this.ownerDocument.createElement("div");
339 div.appendChild( this.cloneNode(true) );
340 html = div.innerHTML;
343 return jQuery.clean([html.replace(/ jQuery\d+="(?:\d+|null)"/g, "").replace(/^\s*/, "")])[0];
345 return this.cloneNode(true);
348 // Copy the events from the original to the clone
349 if ( events === true ) {
350 var orig = this.find("*").andSelf(), i = 0;
352 ret.find("*").andSelf().each(function(){
353 if ( this.nodeName !== orig[i].nodeName )
356 var events = jQuery.data( orig[i], "events" );
358 for ( var type in events ) {
359 for ( var handler in events[ type ] ) {
360 jQuery.event.add( this, type, events[ type ][ handler ], events[ type ][ handler ].data );
368 // Return the cloned set
372 filter: function( selector ) {
373 return this.pushStack(
374 jQuery.isFunction( selector ) &&
375 jQuery.grep(this, function(elem, i){
376 return selector.call( elem, i );
379 jQuery.multiFilter( selector, jQuery.grep(this, function(elem){
380 return elem.nodeType === 1;
381 }) ), "filter", selector );
384 closest: function( selector ) {
385 var pos = jQuery.expr.match.POS.test( selector ) ? jQuery(selector) : null,
388 return this.map(function(){
390 while ( cur && cur.ownerDocument ) {
391 if ( pos ? pos.index(cur) > -1 : jQuery(cur).is(selector) ) {
392 jQuery.data(cur, "closest", closer);
395 cur = cur.parentNode;
401 not: function( selector ) {
402 if ( typeof selector === "string" )
403 // test special case where just one selector is passed in
404 if ( isSimple.test( selector ) )
405 return this.pushStack( jQuery.multiFilter( selector, this, true ), "not", selector );
407 selector = jQuery.multiFilter( selector, this );
409 var isArrayLike = selector.length && selector[selector.length - 1] !== undefined && !selector.nodeType;
410 return this.filter(function() {
411 return isArrayLike ? jQuery.inArray( this, selector ) < 0 : this != selector;
415 add: function( selector ) {
416 return this.pushStack( jQuery.unique( jQuery.merge(
418 typeof selector === "string" ?
420 jQuery.makeArray( selector )
424 is: function( selector ) {
425 return !!selector && jQuery.multiFilter( selector, this ).length > 0;
428 hasClass: function( selector ) {
429 return !!selector && this.is( "." + selector );
432 val: function( value ) {
433 if ( value === undefined ) {
437 if( jQuery.nodeName( elem, 'option' ) )
438 return (elem.attributes.value || {}).specified ? elem.value : elem.text;
440 // We need to handle select boxes special
441 if ( jQuery.nodeName( elem, "select" ) ) {
442 var index = elem.selectedIndex,
444 options = elem.options,
445 one = elem.type == "select-one";
447 // Nothing was selected
451 // Loop through all the selected options
452 for ( var i = one ? index : 0, max = one ? index + 1 : options.length; i < max; i++ ) {
453 var option = options[ i ];
455 if ( option.selected ) {
456 // Get the specifc value for the option
457 value = jQuery(option).val();
459 // We don't need an array for one selects
463 // Multi-Selects return an array
464 values.push( value );
471 // Everything else, we just grab the value
472 return (elem.value || "").replace(/\r/g, "");
479 if ( typeof value === "number" )
482 return this.each(function(){
483 if ( this.nodeType != 1 )
486 if ( jQuery.isArray(value) && /radio|checkbox/.test( this.type ) )
487 this.checked = (jQuery.inArray(this.value, value) >= 0 ||
488 jQuery.inArray(this.name, value) >= 0);
490 else if ( jQuery.nodeName( this, "select" ) ) {
491 var values = jQuery.makeArray(value);
493 jQuery( "option", this ).each(function(){
494 this.selected = (jQuery.inArray( this.value, values ) >= 0 ||
495 jQuery.inArray( this.text, values ) >= 0);
498 if ( !values.length )
499 this.selectedIndex = -1;
506 html: function( value ) {
507 return value === undefined ?
509 this[0].innerHTML.replace(/ jQuery\d+="(?:\d+|null)"/g, "") :
511 this.empty().append( value );
514 replaceWith: function( value ) {
515 return this.after( value ).remove();
519 return this.slice( i, +i + 1 );
523 return this.pushStack( Array.prototype.slice.apply( this, arguments ),
524 "slice", Array.prototype.slice.call(arguments).join(",") );
527 map: function( callback ) {
528 return this.pushStack( jQuery.map(this, function(elem, i){
529 return callback.call( elem, i, elem );
533 andSelf: function() {
534 return this.add( this.prevObject );
537 domManip: function( args, table, callback ) {
539 var fragment = (this[0].ownerDocument || this[0]).createDocumentFragment(),
540 scripts = jQuery.clean( args, (this[0].ownerDocument || this[0]), fragment ),
541 first = fragment.firstChild;
544 for ( var i = 0, l = this.length; i < l; i++ )
545 callback.call( root(this[i], first), this.length > 1 || i > 0 ?
546 fragment.cloneNode(true) : fragment );
549 jQuery.each( scripts, evalScript );
554 function root( elem, cur ) {
555 return table && jQuery.nodeName(elem, "table") && jQuery.nodeName(cur, "tr") ?
556 (elem.getElementsByTagName("tbody")[0] ||
557 elem.appendChild(elem.ownerDocument.createElement("tbody"))) :
563 // Give the init function the jQuery prototype for later instantiation
564 jQuery.fn.init.prototype = jQuery.fn;
566 function evalScript( i, elem ) {
575 jQuery.globalEval( elem.text || elem.textContent || elem.innerHTML || "" );
577 if ( elem.parentNode )
578 elem.parentNode.removeChild( elem );
585 jQuery.extend = jQuery.fn.extend = function() {
586 // copy reference to target object
587 var target = arguments[0] || {}, i = 1, length = arguments.length, deep = false, options;
589 // Handle a deep copy situation
590 if ( typeof target === "boolean" ) {
592 target = arguments[1] || {};
593 // skip the boolean and the target
597 // Handle case when target is a string or something (possible in deep copy)
598 if ( typeof target !== "object" && !jQuery.isFunction(target) )
601 // extend jQuery itself if only one argument is passed
607 for ( ; i < length; i++ )
608 // Only deal with non-null/undefined values
609 if ( (options = arguments[ i ]) != null )
610 // Extend the base object
611 for ( var name in options ) {
612 var src = target[ name ], copy = options[ name ];
614 // Prevent never-ending loop
615 if ( target === copy )
618 // Recurse if we're merging object values
619 if ( deep && copy && typeof copy === "object" && !copy.nodeType )
620 target[ name ] = jQuery.extend( deep,
621 // Never move original objects, clone them
622 src || ( copy.length != null ? [ ] : { } )
625 // Don't bring in undefined values
626 else if ( copy !== undefined )
627 target[ name ] = copy;
631 // Return the modified object
635 // exclude the following css properties to add px
636 var exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i,
638 defaultView = document.defaultView || {},
639 toString = Object.prototype.toString;
642 noConflict: function( deep ) {
646 window.jQuery = _jQuery;
651 // See test/unit/core.js for details concerning isFunction.
652 // Since version 1.3, DOM methods and functions like alert
653 // aren't supported. They return false on IE (#2968).
654 isFunction: function( obj ) {
655 return toString.call(obj) === "[object Function]";
658 isArray: function( obj ) {
659 return toString.call(obj) === "[object Array]";
662 // check if an element is in a (or is an) XML document
663 isXMLDoc: function( elem ) {
664 return elem.nodeType === 9 && elem.documentElement.nodeName !== "HTML" ||
665 !!elem.ownerDocument && elem.ownerDocument.documentElement.nodeName !== "HTML";
668 // Evalulates a script in a global context
669 globalEval: function( data ) {
670 if ( data && /\S/.test(data) ) {
671 // Inspired by code by Andrea Giammarchi
672 // http://webreflection.blogspot.com/2007/08/global-scope-evaluation-and-dom.html
673 var head = document.getElementsByTagName("head")[0] || document.documentElement,
674 script = document.createElement("script");
676 script.type = "text/javascript";
677 if ( jQuery.support.scriptEval )
678 script.appendChild( document.createTextNode( data ) );
682 // Use insertBefore instead of appendChild to circumvent an IE6 bug.
683 // This arises when a base node is used (#2709).
684 head.insertBefore( script, head.firstChild );
685 head.removeChild( script );
689 nodeName: function( elem, name ) {
690 return elem.nodeName && elem.nodeName.toUpperCase() == name.toUpperCase();
693 // args is for internal usage only
694 each: function( object, callback, args ) {
695 var name, i = 0, length = object.length;
698 if ( length === undefined ) {
699 for ( name in object )
700 if ( callback.apply( object[ name ], args ) === false )
703 for ( ; i < length; )
704 if ( callback.apply( object[ i++ ], args ) === false )
707 // A special, fast, case for the most common use of each
709 if ( length === undefined ) {
710 for ( name in object )
711 if ( callback.call( object[ name ], name, object[ name ] ) === false )
714 for ( var value = object[0];
715 i < length && callback.call( value, i, value ) !== false; value = object[++i] ){}
722 // internal only, use addClass("class")
723 add: function( elem, classNames ) {
724 jQuery.each((classNames || "").split(/\s+/), function(i, className){
725 if ( elem.nodeType == 1 && !jQuery.className.has( elem.className, className ) )
726 elem.className += (elem.className ? " " : "") + className;
730 // internal only, use removeClass("class")
731 remove: function( elem, classNames ) {
732 if (elem.nodeType == 1)
733 elem.className = classNames !== undefined ?
734 jQuery.grep(elem.className.split(/\s+/), function(className){
735 return !jQuery.className.has( classNames, className );
740 // internal only, use hasClass("class")
741 has: function( elem, className ) {
742 return elem && jQuery.inArray( className, (elem.className || elem).toString().split(/\s+/) ) > -1;
746 // A method for quickly swapping in/out CSS properties to get correct calculations
747 swap: function( elem, options, callback ) {
749 // Remember the old values, and insert the new ones
750 for ( var name in options ) {
751 old[ name ] = elem.style[ name ];
752 elem.style[ name ] = options[ name ];
755 callback.call( elem );
757 // Revert the old values
758 for ( var name in options )
759 elem.style[ name ] = old[ name ];
762 css: function( elem, name, force, extra ) {
763 if ( name == "width" || name == "height" ) {
764 var val, props = { position: "absolute", visibility: "hidden", display:"block" }, which = name == "width" ? [ "Left", "Right" ] : [ "Top", "Bottom" ];
767 val = name == "width" ? elem.offsetWidth : elem.offsetHeight;
769 if ( extra === "border" )
772 jQuery.each( which, function() {
774 val -= parseFloat(jQuery.curCSS( elem, "padding" + this, true)) || 0;
775 if ( extra === "margin" )
776 val += parseFloat(jQuery.curCSS( elem, "margin" + this, true)) || 0;
778 val -= parseFloat(jQuery.curCSS( elem, "border" + this + "Width", true)) || 0;
782 if ( elem.offsetWidth !== 0 )
785 jQuery.swap( elem, props, getWH );
787 return Math.max(0, Math.round(val));
790 return jQuery.curCSS( elem, name, force );
793 curCSS: function( elem, name, force ) {
794 var ret, style = elem.style;
796 // We need to handle opacity special in IE
797 if ( name == "opacity" && !jQuery.support.opacity ) {
798 ret = jQuery.attr( style, "opacity" );
805 // Make sure we're using the right name for getting the float value
806 if ( name.match( /float/i ) )
809 if ( !force && style && style[ name ] )
812 else if ( defaultView.getComputedStyle ) {
814 // Only "float" is needed here
815 if ( name.match( /float/i ) )
818 name = name.replace( /([A-Z])/g, "-$1" ).toLowerCase();
820 var computedStyle = defaultView.getComputedStyle( elem, null );
823 ret = computedStyle.getPropertyValue( name );
825 // We should always get a number back from opacity
826 if ( name == "opacity" && ret == "" )
829 } else if ( elem.currentStyle ) {
830 var camelCase = name.replace(/\-(\w)/g, function(all, letter){
831 return letter.toUpperCase();
834 ret = elem.currentStyle[ name ] || elem.currentStyle[ camelCase ];
836 // From the awesome hack by Dean Edwards
837 // http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291
839 // If we're not dealing with a regular pixel number
840 // but a number that has a weird ending, we need to convert it to pixels
841 if ( !/^\d+(px)?$/i.test( ret ) && /^\d/.test( ret ) ) {
842 // Remember the original values
843 var left = style.left, rsLeft = elem.runtimeStyle.left;
845 // Put in the new values to get a computed value out
846 elem.runtimeStyle.left = elem.currentStyle.left;
847 style.left = ret || 0;
848 ret = style.pixelLeft + "px";
850 // Revert the changed values
852 elem.runtimeStyle.left = rsLeft;
859 clean: function( elems, context, fragment ) {
860 context = context || document;
862 // !context.createElement fails in IE with an error but returns typeof 'object'
863 if ( typeof context.createElement === "undefined" )
864 context = context.ownerDocument || context[0] && context[0].ownerDocument || document;
866 // If a single string is passed in and it's a single tag
867 // just do a createElement and skip the rest
868 if ( !fragment && elems.length === 1 && typeof elems[0] === "string" ) {
869 var match = /^<(\w+)\s*\/?>$/.exec(elems[0]);
871 return [ context.createElement( match[1] ) ];
874 var ret = [], scripts = [], div = context.createElement("div");
876 jQuery.each(elems, function(i, elem){
877 if ( typeof elem === "number" )
883 // Convert html string into DOM nodes
884 if ( typeof elem === "string" ) {
885 // Fix "XHTML"-style tags in all browsers
886 elem = elem.replace(/(<(\w+)[^>]*?)\/>/g, function(all, front, tag){
887 return tag.match(/^(abbr|br|col|img|input|link|meta|param|hr|area|embed)$/i) ?
889 front + "></" + tag + ">";
892 // Trim whitespace, otherwise indexOf won't work as expected
893 var tags = elem.replace(/^\s+/, "").substring(0, 10).toLowerCase();
896 // option or optgroup
897 !tags.indexOf("<opt") &&
898 [ 1, "<select multiple='multiple'>", "</select>" ] ||
900 !tags.indexOf("<leg") &&
901 [ 1, "<fieldset>", "</fieldset>" ] ||
903 tags.match(/^<(thead|tbody|tfoot|colg|cap)/) &&
904 [ 1, "<table>", "</table>" ] ||
906 !tags.indexOf("<tr") &&
907 [ 2, "<table><tbody>", "</tbody></table>" ] ||
909 // <thead> matched above
910 (!tags.indexOf("<td") || !tags.indexOf("<th")) &&
911 [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ] ||
913 !tags.indexOf("<col") &&
914 [ 2, "<table><tbody></tbody><colgroup>", "</colgroup></table>" ] ||
916 // IE can't serialize <link> and <script> tags normally
917 !jQuery.support.htmlSerialize &&
918 [ 1, "div<div>", "</div>" ] ||
922 // Go to html and back, then peel off extra wrappers
923 div.innerHTML = wrap[1] + elem + wrap[2];
925 // Move to the right depth
929 // Remove IE's autoinserted <tbody> from table fragments
930 if ( !jQuery.support.tbody ) {
932 // String was a <table>, *may* have spurious <tbody>
933 var hasBody = /<tbody/i.test(elem),
934 tbody = !tags.indexOf("<table") && !hasBody ?
935 div.firstChild && div.firstChild.childNodes :
937 // String was a bare <thead> or <tfoot>
938 wrap[1] == "<table>" && !hasBody ?
942 for ( var j = tbody.length - 1; j >= 0 ; --j )
943 if ( jQuery.nodeName( tbody[ j ], "tbody" ) && !tbody[ j ].childNodes.length )
944 tbody[ j ].parentNode.removeChild( tbody[ j ] );
948 // IE completely kills leading whitespace when innerHTML is used
949 if ( !jQuery.support.leadingWhitespace && /^\s/.test( elem ) )
950 div.insertBefore( context.createTextNode( elem.match(/^\s*/)[0] ), div.firstChild );
952 elem = jQuery.makeArray( div.childNodes );
958 ret = jQuery.merge( ret, elem );
963 for ( var i = 0; ret[i]; i++ ) {
964 if ( jQuery.nodeName( ret[i], "script" ) && (!ret[i].type || ret[i].type.toLowerCase() === "text/javascript") ) {
965 scripts.push( ret[i].parentNode ? ret[i].parentNode.removeChild( ret[i] ) : ret[i] );
967 if ( ret[i].nodeType === 1 )
968 ret.splice.apply( ret, [i + 1, 0].concat(jQuery.makeArray(ret[i].getElementsByTagName("script"))) );
969 fragment.appendChild( ret[i] );
979 attr: function( elem, name, value ) {
980 // don't set attributes on text and comment nodes
981 if (!elem || elem.nodeType == 3 || elem.nodeType == 8)
984 var notxml = !elem.tagName || !jQuery.isXMLDoc( elem ),
985 // Whether we are setting (or getting)
986 set = value !== undefined;
988 // Try to normalize/fix the name
989 name = notxml && jQuery.props[ name ] || name;
991 // Only do all the following if this is a node (faster for style)
992 // IE elem.getAttribute passes even for style
993 if ( elem.tagName ) {
995 // These attributes require special treatment
996 var special = /href|src|style/.test( name );
998 // Safari mis-reports the default selected property of a hidden option
999 // Accessing the parent's selectedIndex property fixes it
1000 if ( name == "selected" && elem.parentNode )
1001 elem.parentNode.selectedIndex;
1003 // If applicable, access the attribute via the DOM 0 way
1004 if ( name in elem && notxml && !special ) {
1006 // We can't allow the type property to be changed (since it causes problems in IE)
1007 if ( name == "type" && jQuery.nodeName( elem, "input" ) && elem.parentNode )
1008 throw "type property can't be changed";
1010 elem[ name ] = value;
1013 // browsers index elements by id/name on forms, give priority to attributes.
1014 if( jQuery.nodeName( elem, "form" ) && elem.getAttributeNode(name) )
1015 return elem.getAttributeNode( name ).nodeValue;
1017 // elem.tabIndex doesn't always return the correct value when it hasn't been explicitly set
1018 // http://fluidproject.org/blog/2008/01/09/getting-setting-and-removing-tabindex-values-with-javascript/
1019 if ( name == "tabIndex" ) {
1020 var attributeNode = elem.getAttributeNode( "tabIndex" );
1021 return attributeNode && attributeNode.specified
1022 ? attributeNode.value
1023 : elem.nodeName.match(/(button|input|object|select|textarea)/i)
1025 : elem.nodeName.match(/^(a|area)$/i) && elem.href
1030 return elem[ name ];
1033 if ( !jQuery.support.style && notxml && name == "style" )
1034 return jQuery.attr( elem.style, "cssText", value );
1037 // convert the value to a string (all browsers do this but IE) see #1070
1038 elem.setAttribute( name, "" + value );
1040 var attr = !jQuery.support.hrefNormalized && notxml && special
1041 // Some attributes require a special call on IE
1042 ? elem.getAttribute( name, 2 )
1043 : elem.getAttribute( name );
1045 // Non-existent attributes return null, we normalize to undefined
1046 return attr === null ? undefined : attr;
1049 // elem is actually elem.style ... set the style
1051 // IE uses filters for opacity
1052 if ( !jQuery.support.opacity && name == "opacity" ) {
1054 // IE has trouble with opacity if it does not have layout
1055 // Force it by setting the zoom level
1058 // Set the alpha filter to set the opacity
1059 elem.filter = (elem.filter || "").replace( /alpha\([^)]*\)/, "" ) +
1060 (parseInt( value ) + '' == "NaN" ? "" : "alpha(opacity=" + value * 100 + ")");
1063 return elem.filter && elem.filter.indexOf("opacity=") >= 0 ?
1064 (parseFloat( elem.filter.match(/opacity=([^)]*)/)[1] ) / 100) + '':
1068 name = name.replace(/-([a-z])/ig, function(all, letter){
1069 return letter.toUpperCase();
1073 elem[ name ] = value;
1075 return elem[ name ];
1078 trim: function( text ) {
1079 return (text || "").replace( /^\s+|\s+$/g, "" );
1082 makeArray: function( array ) {
1085 if( array != null ){
1086 var i = array.length;
1087 // The window, strings (and functions) also have 'length'
1088 if( i == null || typeof array === "string" || jQuery.isFunction(array) || array.setInterval )
1092 ret[--i] = array[i];
1098 inArray: function( elem, array ) {
1099 for ( var i = 0, length = array.length; i < length; i++ )
1100 // Use === because on IE, window == document
1101 if ( array[ i ] === elem )
1107 merge: function( first, second ) {
1108 // We have to loop this way because IE & Opera overwrite the length
1109 // expando of getElementsByTagName
1110 var i = 0, elem, pos = first.length;
1111 // Also, we need to make sure that the correct elements are being returned
1112 // (IE returns comment nodes in a '*' query)
1113 if ( !jQuery.support.getAll ) {
1114 while ( (elem = second[ i++ ]) != null )
1115 if ( elem.nodeType != 8 )
1116 first[ pos++ ] = elem;
1119 while ( (elem = second[ i++ ]) != null )
1120 first[ pos++ ] = elem;
1125 unique: function( array ) {
1126 var ret = [], done = {};
1130 for ( var i = 0, length = array.length; i < length; i++ ) {
1131 var id = jQuery.data( array[ i ] );
1133 if ( !done[ id ] ) {
1135 ret.push( array[ i ] );
1146 grep: function( elems, callback, inv ) {
1149 // Go through the array, only saving the items
1150 // that pass the validator function
1151 for ( var i = 0, length = elems.length; i < length; i++ )
1152 if ( !inv != !callback( elems[ i ], i ) )
1153 ret.push( elems[ i ] );
1158 map: function( elems, callback ) {
1161 // Go through the array, translating each of the items to their
1162 // new value (or values).
1163 for ( var i = 0, length = elems.length; i < length; i++ ) {
1164 var value = callback( elems[ i ], i );
1166 if ( value != null )
1167 ret[ ret.length ] = value;
1170 return ret.concat.apply( [], ret );
1174 // All jQuery objects should point back to these
1175 var rootjQuery = jQuery(document);
1177 // Use of jQuery.browser is deprecated.
1178 // It's included for backwards compatibility and plugins,
1179 // although they should work to migrate away.
1181 var userAgent = navigator.userAgent.toLowerCase();
1183 // Figure out what browser is being used
1185 version: (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [0,'0'])[1],
1186 safari: /webkit/.test( userAgent ),
1187 opera: /opera/.test( userAgent ),
1188 msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
1189 mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )
1193 parent: function(elem){return elem.parentNode;},
1194 parents: function(elem){return jQuery.dir(elem,"parentNode");},
1195 next: function(elem){return jQuery.nth(elem,2,"nextSibling");},
1196 prev: function(elem){return jQuery.nth(elem,2,"previousSibling");},
1197 nextAll: function(elem){return jQuery.dir(elem,"nextSibling");},
1198 prevAll: function(elem){return jQuery.dir(elem,"previousSibling");},
1199 siblings: function(elem){return jQuery.sibling(elem.parentNode.firstChild,elem);},
1200 children: function(elem){return jQuery.sibling(elem.firstChild);},
1201 contents: function(elem){return jQuery.nodeName(elem,"iframe")?elem.contentDocument||elem.contentWindow.document:jQuery.makeArray(elem.childNodes);}
1202 }, function(name, fn){
1203 jQuery.fn[ name ] = function( selector ) {
1204 var ret = jQuery.map( this, fn );
1206 if ( selector && typeof selector == "string" )
1207 ret = jQuery.multiFilter( selector, ret );
1209 return this.pushStack( jQuery.unique( ret ), name, selector );
1215 prependTo: "prepend",
1216 insertBefore: "before",
1217 insertAfter: "after",
1218 replaceAll: "replaceWith"
1219 }, function(name, original){
1220 jQuery.fn[ name ] = function( selector ) {
1221 var ret = [], insert = jQuery( selector );
1223 for ( var i = 0, l = insert.length; i < l; i++ ) {
1224 var elems = (i > 0 ? this.clone(true) : this).get();
1225 jQuery.fn[ original ].apply( jQuery(insert[i]), elems );
1226 ret = ret.concat( elems );
1229 return this.pushStack( ret, name, selector );
1234 removeAttr: function( name ) {
1235 jQuery.attr( this, name, "" );
1236 if (this.nodeType == 1)
1237 this.removeAttribute( name );
1240 addClass: function( classNames ) {
1241 jQuery.className.add( this, classNames );
1244 removeClass: function( classNames ) {
1245 jQuery.className.remove( this, classNames );
1248 toggleClass: function( classNames, state ) {
1249 if( typeof state !== "boolean" )
1250 state = !jQuery.className.has( this, classNames );
1251 jQuery.className[ state ? "add" : "remove" ]( this, classNames );
1254 remove: function( selector ) {
1255 if ( !selector || jQuery.multiFilter( selector, [ this ] ).length ) {
1256 if ( this.nodeType === 1 ) {
1257 cleanData( this.getElementsByTagName("*") );
1258 cleanData( [this] );
1261 if ( this.parentNode ) {
1262 this.parentNode.removeChild( this );
1268 // Remove element nodes and prevent memory leaks
1269 if ( this.nodeType === 1 ) {
1270 cleanData( this.getElementsByTagName("*") );
1273 // Remove any remaining nodes
1274 while ( this.firstChild ) {
1275 this.removeChild( this.firstChild );
1278 }, function(name, fn){
1279 jQuery.fn[ name ] = function(){
1280 return this.each( fn, arguments );
1284 function cleanData( elems ) {
1285 for ( var i = 0, l = elems.length; i < l; i++ ) {
1286 var id = elems[i][expando];
1288 delete jQuery.cache[ id ];