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: $(content).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 find: function( selector ) {
296 var ret = this.pushStack( "", "find", selector ), length = 0,
297 splice = Array.prototype.splice;
299 for ( var i = 0, l = this.length; i < l; i++ ) {
301 jQuery.find( selector, this[i], ret );
304 // Make sure that the results are unique
305 for ( var n = length; n < ret.length; n++ ) {
306 for ( var r = 0; r < length; r++ ) {
307 if ( ret[r] === ret[n] ) {
308 splice.call(ret, n--, 1);
319 clone: function( events ) {
321 var ret = this.map(function(){
322 if ( !jQuery.support.noCloneEvent && !jQuery.isXMLDoc(this) ) {
323 // IE copies events bound via attachEvent when
324 // using cloneNode. Calling detachEvent on the
325 // clone will also remove the events from the orignal
326 // In order to get around this, we use innerHTML.
327 // Unfortunately, this means some modifications to
328 // attributes in IE that are actually only stored
329 // as properties will not be copied (such as the
330 // the name attribute on an input).
331 var html = this.outerHTML;
333 var div = this.ownerDocument.createElement("div");
334 div.appendChild( this.cloneNode(true) );
335 html = div.innerHTML;
338 return jQuery.clean([html.replace(/ jQuery\d+="(?:\d+|null)"/g, "").replace(/^\s*/, "")])[0];
340 return this.cloneNode(true);
343 // Copy the events from the original to the clone
344 if ( events === true ) {
345 var orig = this.find("*").andSelf(), i = 0;
347 ret.find("*").andSelf().each(function(){
348 if ( this.nodeName !== orig[i].nodeName )
351 var events = jQuery.data( orig[i], "events" );
353 for ( var type in events ) {
354 for ( var handler in events[ type ] ) {
355 jQuery.event.add( this, type, events[ type ][ handler ], events[ type ][ handler ].data );
363 // Return the cloned set
367 filter: function( selector ) {
368 return this.pushStack(
369 jQuery.isFunction( selector ) &&
370 jQuery.grep(this, function(elem, i){
371 return selector.call( elem, i );
374 jQuery.multiFilter( selector, jQuery.grep(this, function(elem){
375 return elem.nodeType === 1;
376 }) ), "filter", selector );
379 closest: function( selector ) {
380 var pos = jQuery.expr.match.POS.test( selector ) ? jQuery(selector) : null,
383 return this.map(function(){
385 while ( cur && cur.ownerDocument ) {
386 if ( pos ? pos.index(cur) > -1 : jQuery(cur).is(selector) ) {
387 jQuery.data(cur, "closest", closer);
390 cur = cur.parentNode;
396 not: function( selector ) {
397 if ( typeof selector === "string" )
398 // test special case where just one selector is passed in
399 if ( isSimple.test( selector ) )
400 return this.pushStack( jQuery.multiFilter( selector, this, true ), "not", selector );
402 selector = jQuery.multiFilter( selector, this );
404 var isArrayLike = selector.length && selector[selector.length - 1] !== undefined && !selector.nodeType;
405 return this.filter(function() {
406 return isArrayLike ? jQuery.inArray( this, selector ) < 0 : this != selector;
410 add: function( selector ) {
411 return this.pushStack( jQuery.unique( jQuery.merge(
413 typeof selector === "string" ?
415 jQuery.makeArray( selector )
419 is: function( selector ) {
420 return !!selector && jQuery.multiFilter( selector, this ).length > 0;
423 hasClass: function( selector ) {
424 return !!selector && this.is( "." + selector );
427 val: function( value ) {
428 if ( value === undefined ) {
432 if( jQuery.nodeName( elem, 'option' ) )
433 return (elem.attributes.value || {}).specified ? elem.value : elem.text;
435 // We need to handle select boxes special
436 if ( jQuery.nodeName( elem, "select" ) ) {
437 var index = elem.selectedIndex,
439 options = elem.options,
440 one = elem.type == "select-one";
442 // Nothing was selected
446 // Loop through all the selected options
447 for ( var i = one ? index : 0, max = one ? index + 1 : options.length; i < max; i++ ) {
448 var option = options[ i ];
450 if ( option.selected ) {
451 // Get the specifc value for the option
452 value = jQuery(option).val();
454 // We don't need an array for one selects
458 // Multi-Selects return an array
459 values.push( value );
466 // Everything else, we just grab the value
467 return (elem.value || "").replace(/\r/g, "");
474 if ( typeof value === "number" )
477 return this.each(function(){
478 if ( this.nodeType != 1 )
481 if ( jQuery.isArray(value) && /radio|checkbox/.test( this.type ) )
482 this.checked = (jQuery.inArray(this.value, value) >= 0 ||
483 jQuery.inArray(this.name, value) >= 0);
485 else if ( jQuery.nodeName( this, "select" ) ) {
486 var values = jQuery.makeArray(value);
488 jQuery( "option", this ).each(function(){
489 this.selected = (jQuery.inArray( this.value, values ) >= 0 ||
490 jQuery.inArray( this.text, values ) >= 0);
493 if ( !values.length )
494 this.selectedIndex = -1;
501 html: function( value ) {
502 return value === undefined ?
504 this[0].innerHTML.replace(/ jQuery\d+="(?:\d+|null)"/g, "") :
506 this.empty().append( value );
509 replaceWith: function( value ) {
510 return this.after( value ).remove();
514 return this.slice( i, +i + 1 );
518 return this.pushStack( Array.prototype.slice.apply( this, arguments ),
519 "slice", Array.prototype.slice.call(arguments).join(",") );
522 map: function( callback ) {
523 return this.pushStack( jQuery.map(this, function(elem, i){
524 return callback.call( elem, i, elem );
528 andSelf: function() {
529 return this.add( this.prevObject );
532 domManip: function( args, table, callback ) {
534 var fragment = (this[0].ownerDocument || this[0]).createDocumentFragment(),
535 scripts = jQuery.clean( args, (this[0].ownerDocument || this[0]), fragment ),
536 first = fragment.firstChild;
539 for ( var i = 0, l = this.length; i < l; i++ )
540 callback.call( root(this[i], first), this.length > 1 || i > 0 ?
541 fragment.cloneNode(true) : fragment );
544 jQuery.each( scripts, evalScript );
549 function root( elem, cur ) {
550 return table && jQuery.nodeName(elem, "table") && jQuery.nodeName(cur, "tr") ?
551 (elem.getElementsByTagName("tbody")[0] ||
552 elem.appendChild(elem.ownerDocument.createElement("tbody"))) :
558 // Give the init function the jQuery prototype for later instantiation
559 jQuery.fn.init.prototype = jQuery.fn;
561 function evalScript( i, elem ) {
570 jQuery.globalEval( elem.text || elem.textContent || elem.innerHTML || "" );
572 if ( elem.parentNode )
573 elem.parentNode.removeChild( elem );
580 jQuery.extend = jQuery.fn.extend = function() {
581 // copy reference to target object
582 var target = arguments[0] || {}, i = 1, length = arguments.length, deep = false, options;
584 // Handle a deep copy situation
585 if ( typeof target === "boolean" ) {
587 target = arguments[1] || {};
588 // skip the boolean and the target
592 // Handle case when target is a string or something (possible in deep copy)
593 if ( typeof target !== "object" && !jQuery.isFunction(target) )
596 // extend jQuery itself if only one argument is passed
602 for ( ; i < length; i++ )
603 // Only deal with non-null/undefined values
604 if ( (options = arguments[ i ]) != null )
605 // Extend the base object
606 for ( var name in options ) {
607 var src = target[ name ], copy = options[ name ];
609 // Prevent never-ending loop
610 if ( target === copy )
613 // Recurse if we're merging object values
614 if ( deep && copy && typeof copy === "object" && !copy.nodeType )
615 target[ name ] = jQuery.extend( deep,
616 // Never move original objects, clone them
617 src || ( copy.length != null ? [ ] : { } )
620 // Don't bring in undefined values
621 else if ( copy !== undefined )
622 target[ name ] = copy;
626 // Return the modified object
630 // exclude the following css properties to add px
631 var exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i,
633 defaultView = document.defaultView || {},
634 toString = Object.prototype.toString;
637 noConflict: function( deep ) {
641 window.jQuery = _jQuery;
646 // See test/unit/core.js for details concerning isFunction.
647 // Since version 1.3, DOM methods and functions like alert
648 // aren't supported. They return false on IE (#2968).
649 isFunction: function( obj ) {
650 return toString.call(obj) === "[object Function]";
653 isArray: function( obj ) {
654 return toString.call(obj) === "[object Array]";
657 // check if an element is in a (or is an) XML document
658 isXMLDoc: function( elem ) {
659 return elem.nodeType === 9 && elem.documentElement.nodeName !== "HTML" ||
660 !!elem.ownerDocument && elem.ownerDocument.documentElement.nodeName !== "HTML";
663 // Evalulates a script in a global context
664 globalEval: function( data ) {
665 if ( data && /\S/.test(data) ) {
666 // Inspired by code by Andrea Giammarchi
667 // http://webreflection.blogspot.com/2007/08/global-scope-evaluation-and-dom.html
668 var head = document.getElementsByTagName("head")[0] || document.documentElement,
669 script = document.createElement("script");
671 script.type = "text/javascript";
672 if ( jQuery.support.scriptEval )
673 script.appendChild( document.createTextNode( data ) );
677 // Use insertBefore instead of appendChild to circumvent an IE6 bug.
678 // This arises when a base node is used (#2709).
679 head.insertBefore( script, head.firstChild );
680 head.removeChild( script );
684 nodeName: function( elem, name ) {
685 return elem.nodeName && elem.nodeName.toUpperCase() == name.toUpperCase();
688 // args is for internal usage only
689 each: function( object, callback, args ) {
690 var name, i = 0, length = object.length;
693 if ( length === undefined ) {
694 for ( name in object )
695 if ( callback.apply( object[ name ], args ) === false )
698 for ( ; i < length; )
699 if ( callback.apply( object[ i++ ], args ) === false )
702 // A special, fast, case for the most common use of each
704 if ( length === undefined ) {
705 for ( name in object )
706 if ( callback.call( object[ name ], name, object[ name ] ) === false )
709 for ( var value = object[0];
710 i < length && callback.call( value, i, value ) !== false; value = object[++i] ){}
717 // internal only, use addClass("class")
718 add: function( elem, classNames ) {
719 jQuery.each((classNames || "").split(/\s+/), function(i, className){
720 if ( elem.nodeType == 1 && !jQuery.className.has( elem.className, className ) )
721 elem.className += (elem.className ? " " : "") + className;
725 // internal only, use removeClass("class")
726 remove: function( elem, classNames ) {
727 if (elem.nodeType == 1)
728 elem.className = classNames !== undefined ?
729 jQuery.grep(elem.className.split(/\s+/), function(className){
730 return !jQuery.className.has( classNames, className );
735 // internal only, use hasClass("class")
736 has: function( elem, className ) {
737 return elem && jQuery.inArray( className, (elem.className || elem).toString().split(/\s+/) ) > -1;
741 // A method for quickly swapping in/out CSS properties to get correct calculations
742 swap: function( elem, options, callback ) {
744 // Remember the old values, and insert the new ones
745 for ( var name in options ) {
746 old[ name ] = elem.style[ name ];
747 elem.style[ name ] = options[ name ];
750 callback.call( elem );
752 // Revert the old values
753 for ( var name in options )
754 elem.style[ name ] = old[ name ];
757 css: function( elem, name, force, extra ) {
758 if ( name == "width" || name == "height" ) {
759 var val, props = { position: "absolute", visibility: "hidden", display:"block" }, which = name == "width" ? [ "Left", "Right" ] : [ "Top", "Bottom" ];
762 val = name == "width" ? elem.offsetWidth : elem.offsetHeight;
764 if ( extra === "border" )
767 jQuery.each( which, function() {
769 val -= parseFloat(jQuery.curCSS( elem, "padding" + this, true)) || 0;
770 if ( extra === "margin" )
771 val += parseFloat(jQuery.curCSS( elem, "margin" + this, true)) || 0;
773 val -= parseFloat(jQuery.curCSS( elem, "border" + this + "Width", true)) || 0;
777 if ( elem.offsetWidth !== 0 )
780 jQuery.swap( elem, props, getWH );
782 return Math.max(0, Math.round(val));
785 return jQuery.curCSS( elem, name, force );
788 curCSS: function( elem, name, force ) {
789 var ret, style = elem.style;
791 // We need to handle opacity special in IE
792 if ( name == "opacity" && !jQuery.support.opacity ) {
793 ret = jQuery.attr( style, "opacity" );
800 // Make sure we're using the right name for getting the float value
801 if ( name.match( /float/i ) )
804 if ( !force && style && style[ name ] )
807 else if ( defaultView.getComputedStyle ) {
809 // Only "float" is needed here
810 if ( name.match( /float/i ) )
813 name = name.replace( /([A-Z])/g, "-$1" ).toLowerCase();
815 var computedStyle = defaultView.getComputedStyle( elem, null );
818 ret = computedStyle.getPropertyValue( name );
820 // We should always get a number back from opacity
821 if ( name == "opacity" && ret == "" )
824 } else if ( elem.currentStyle ) {
825 var camelCase = name.replace(/\-(\w)/g, function(all, letter){
826 return letter.toUpperCase();
829 ret = elem.currentStyle[ name ] || elem.currentStyle[ camelCase ];
831 // From the awesome hack by Dean Edwards
832 // http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291
834 // If we're not dealing with a regular pixel number
835 // but a number that has a weird ending, we need to convert it to pixels
836 if ( !/^\d+(px)?$/i.test( ret ) && /^\d/.test( ret ) ) {
837 // Remember the original values
838 var left = style.left, rsLeft = elem.runtimeStyle.left;
840 // Put in the new values to get a computed value out
841 elem.runtimeStyle.left = elem.currentStyle.left;
842 style.left = ret || 0;
843 ret = style.pixelLeft + "px";
845 // Revert the changed values
847 elem.runtimeStyle.left = rsLeft;
854 clean: function( elems, context, fragment ) {
855 context = context || document;
857 // !context.createElement fails in IE with an error but returns typeof 'object'
858 if ( typeof context.createElement === "undefined" )
859 context = context.ownerDocument || context[0] && context[0].ownerDocument || document;
861 // If a single string is passed in and it's a single tag
862 // just do a createElement and skip the rest
863 if ( !fragment && elems.length === 1 && typeof elems[0] === "string" ) {
864 var match = /^<(\w+)\s*\/?>$/.exec(elems[0]);
866 return [ context.createElement( match[1] ) ];
869 var ret = [], scripts = [], div = context.createElement("div");
871 jQuery.each(elems, function(i, elem){
872 if ( typeof elem === "number" )
878 // Convert html string into DOM nodes
879 if ( typeof elem === "string" ) {
880 // Fix "XHTML"-style tags in all browsers
881 elem = elem.replace(/(<(\w+)[^>]*?)\/>/g, function(all, front, tag){
882 return tag.match(/^(abbr|br|col|img|input|link|meta|param|hr|area|embed)$/i) ?
884 front + "></" + tag + ">";
887 // Trim whitespace, otherwise indexOf won't work as expected
888 var tags = elem.replace(/^\s+/, "").substring(0, 10).toLowerCase();
891 // option or optgroup
892 !tags.indexOf("<opt") &&
893 [ 1, "<select multiple='multiple'>", "</select>" ] ||
895 !tags.indexOf("<leg") &&
896 [ 1, "<fieldset>", "</fieldset>" ] ||
898 tags.match(/^<(thead|tbody|tfoot|colg|cap)/) &&
899 [ 1, "<table>", "</table>" ] ||
901 !tags.indexOf("<tr") &&
902 [ 2, "<table><tbody>", "</tbody></table>" ] ||
904 // <thead> matched above
905 (!tags.indexOf("<td") || !tags.indexOf("<th")) &&
906 [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ] ||
908 !tags.indexOf("<col") &&
909 [ 2, "<table><tbody></tbody><colgroup>", "</colgroup></table>" ] ||
911 // IE can't serialize <link> and <script> tags normally
912 !jQuery.support.htmlSerialize &&
913 [ 1, "div<div>", "</div>" ] ||
917 // Go to html and back, then peel off extra wrappers
918 div.innerHTML = wrap[1] + elem + wrap[2];
920 // Move to the right depth
924 // Remove IE's autoinserted <tbody> from table fragments
925 if ( !jQuery.support.tbody ) {
927 // String was a <table>, *may* have spurious <tbody>
928 var hasBody = /<tbody/i.test(elem),
929 tbody = !tags.indexOf("<table") && !hasBody ?
930 div.firstChild && div.firstChild.childNodes :
932 // String was a bare <thead> or <tfoot>
933 wrap[1] == "<table>" && !hasBody ?
937 for ( var j = tbody.length - 1; j >= 0 ; --j )
938 if ( jQuery.nodeName( tbody[ j ], "tbody" ) && !tbody[ j ].childNodes.length )
939 tbody[ j ].parentNode.removeChild( tbody[ j ] );
943 // IE completely kills leading whitespace when innerHTML is used
944 if ( !jQuery.support.leadingWhitespace && /^\s/.test( elem ) )
945 div.insertBefore( context.createTextNode( elem.match(/^\s*/)[0] ), div.firstChild );
947 elem = jQuery.makeArray( div.childNodes );
953 ret = jQuery.merge( ret, elem );
958 for ( var i = 0; ret[i]; i++ ) {
959 if ( jQuery.nodeName( ret[i], "script" ) && (!ret[i].type || ret[i].type.toLowerCase() === "text/javascript") ) {
960 scripts.push( ret[i].parentNode ? ret[i].parentNode.removeChild( ret[i] ) : ret[i] );
962 if ( ret[i].nodeType === 1 )
963 ret.splice.apply( ret, [i + 1, 0].concat(jQuery.makeArray(ret[i].getElementsByTagName("script"))) );
964 fragment.appendChild( ret[i] );
974 attr: function( elem, name, value ) {
975 // don't set attributes on text and comment nodes
976 if (!elem || elem.nodeType == 3 || elem.nodeType == 8)
979 var notxml = !elem.tagName || !jQuery.isXMLDoc( elem ),
980 // Whether we are setting (or getting)
981 set = value !== undefined;
983 // Try to normalize/fix the name
984 name = notxml && jQuery.props[ name ] || name;
986 // Only do all the following if this is a node (faster for style)
987 // IE elem.getAttribute passes even for style
988 if ( elem.tagName ) {
990 // These attributes require special treatment
991 var special = /href|src|style/.test( name );
993 // Safari mis-reports the default selected property of a hidden option
994 // Accessing the parent's selectedIndex property fixes it
995 if ( name == "selected" && elem.parentNode )
996 elem.parentNode.selectedIndex;
998 // If applicable, access the attribute via the DOM 0 way
999 if ( name in elem && notxml && !special ) {
1001 // We can't allow the type property to be changed (since it causes problems in IE)
1002 if ( name == "type" && jQuery.nodeName( elem, "input" ) && elem.parentNode )
1003 throw "type property can't be changed";
1005 elem[ name ] = value;
1008 // browsers index elements by id/name on forms, give priority to attributes.
1009 if( jQuery.nodeName( elem, "form" ) && elem.getAttributeNode(name) )
1010 return elem.getAttributeNode( name ).nodeValue;
1012 // elem.tabIndex doesn't always return the correct value when it hasn't been explicitly set
1013 // http://fluidproject.org/blog/2008/01/09/getting-setting-and-removing-tabindex-values-with-javascript/
1014 if ( name == "tabIndex" ) {
1015 var attributeNode = elem.getAttributeNode( "tabIndex" );
1016 return attributeNode && attributeNode.specified
1017 ? attributeNode.value
1018 : elem.nodeName.match(/(button|input|object|select|textarea)/i)
1020 : elem.nodeName.match(/^(a|area)$/i) && elem.href
1025 return elem[ name ];
1028 if ( !jQuery.support.style && notxml && name == "style" )
1029 return jQuery.attr( elem.style, "cssText", value );
1032 // convert the value to a string (all browsers do this but IE) see #1070
1033 elem.setAttribute( name, "" + value );
1035 var attr = !jQuery.support.hrefNormalized && notxml && special
1036 // Some attributes require a special call on IE
1037 ? elem.getAttribute( name, 2 )
1038 : elem.getAttribute( name );
1040 // Non-existent attributes return null, we normalize to undefined
1041 return attr === null ? undefined : attr;
1044 // elem is actually elem.style ... set the style
1046 // IE uses filters for opacity
1047 if ( !jQuery.support.opacity && name == "opacity" ) {
1049 // IE has trouble with opacity if it does not have layout
1050 // Force it by setting the zoom level
1053 // Set the alpha filter to set the opacity
1054 elem.filter = (elem.filter || "").replace( /alpha\([^)]*\)/, "" ) +
1055 (parseInt( value ) + '' == "NaN" ? "" : "alpha(opacity=" + value * 100 + ")");
1058 return elem.filter && elem.filter.indexOf("opacity=") >= 0 ?
1059 (parseFloat( elem.filter.match(/opacity=([^)]*)/)[1] ) / 100) + '':
1063 name = name.replace(/-([a-z])/ig, function(all, letter){
1064 return letter.toUpperCase();
1068 elem[ name ] = value;
1070 return elem[ name ];
1073 trim: function( text ) {
1074 return (text || "").replace( /^\s+|\s+$/g, "" );
1077 makeArray: function( array ) {
1080 if( array != null ){
1081 var i = array.length;
1082 // The window, strings (and functions) also have 'length'
1083 if( i == null || typeof array === "string" || jQuery.isFunction(array) || array.setInterval )
1087 ret[--i] = array[i];
1093 inArray: function( elem, array ) {
1094 for ( var i = 0, length = array.length; i < length; i++ )
1095 // Use === because on IE, window == document
1096 if ( array[ i ] === elem )
1102 merge: function( first, second ) {
1103 // We have to loop this way because IE & Opera overwrite the length
1104 // expando of getElementsByTagName
1105 var i = 0, elem, pos = first.length;
1106 // Also, we need to make sure that the correct elements are being returned
1107 // (IE returns comment nodes in a '*' query)
1108 if ( !jQuery.support.getAll ) {
1109 while ( (elem = second[ i++ ]) != null )
1110 if ( elem.nodeType != 8 )
1111 first[ pos++ ] = elem;
1114 while ( (elem = second[ i++ ]) != null )
1115 first[ pos++ ] = elem;
1120 unique: function( array ) {
1121 var ret = [], done = {};
1125 for ( var i = 0, length = array.length; i < length; i++ ) {
1126 var id = jQuery.data( array[ i ] );
1128 if ( !done[ id ] ) {
1130 ret.push( array[ i ] );
1141 grep: function( elems, callback, inv ) {
1144 // Go through the array, only saving the items
1145 // that pass the validator function
1146 for ( var i = 0, length = elems.length; i < length; i++ )
1147 if ( !inv != !callback( elems[ i ], i ) )
1148 ret.push( elems[ i ] );
1153 map: function( elems, callback ) {
1156 // Go through the array, translating each of the items to their
1157 // new value (or values).
1158 for ( var i = 0, length = elems.length; i < length; i++ ) {
1159 var value = callback( elems[ i ], i );
1161 if ( value != null )
1162 ret[ ret.length ] = value;
1165 return ret.concat.apply( [], ret );
1169 // All jQuery objects should point back to these
1170 var rootjQuery = jQuery(document);
1172 // Use of jQuery.browser is deprecated.
1173 // It's included for backwards compatibility and plugins,
1174 // although they should work to migrate away.
1176 var userAgent = navigator.userAgent.toLowerCase();
1178 // Figure out what browser is being used
1180 version: (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [0,'0'])[1],
1181 safari: /webkit/.test( userAgent ),
1182 opera: /opera/.test( userAgent ),
1183 msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
1184 mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )
1188 parent: function(elem){return elem.parentNode;},
1189 parents: function(elem){return jQuery.dir(elem,"parentNode");},
1190 next: function(elem){return jQuery.nth(elem,2,"nextSibling");},
1191 prev: function(elem){return jQuery.nth(elem,2,"previousSibling");},
1192 nextAll: function(elem){return jQuery.dir(elem,"nextSibling");},
1193 prevAll: function(elem){return jQuery.dir(elem,"previousSibling");},
1194 siblings: function(elem){return jQuery.sibling(elem.parentNode.firstChild,elem);},
1195 children: function(elem){return jQuery.sibling(elem.firstChild);},
1196 contents: function(elem){return jQuery.nodeName(elem,"iframe")?elem.contentDocument||elem.contentWindow.document:jQuery.makeArray(elem.childNodes);}
1197 }, function(name, fn){
1198 jQuery.fn[ name ] = function( selector ) {
1199 var ret = jQuery.map( this, fn );
1201 if ( selector && typeof selector == "string" )
1202 ret = jQuery.multiFilter( selector, ret );
1204 return this.pushStack( jQuery.unique( ret ), name, selector );
1210 prependTo: "prepend",
1211 insertBefore: "before",
1212 insertAfter: "after",
1213 replaceAll: "replaceWith"
1214 }, function(name, original){
1215 jQuery.fn[ name ] = function( selector ) {
1216 var ret = [], insert = jQuery( selector );
1218 for ( var i = 0, l = insert.length; i < l; i++ ) {
1219 var elems = (i > 0 ? this.clone(true) : this).get();
1220 jQuery.fn[ original ].apply( jQuery(insert[i]), elems );
1221 ret = ret.concat( elems );
1224 return this.pushStack( ret, name, selector );
1229 removeAttr: function( name ) {
1230 jQuery.attr( this, name, "" );
1231 if (this.nodeType == 1)
1232 this.removeAttribute( name );
1235 addClass: function( classNames ) {
1236 jQuery.className.add( this, classNames );
1239 removeClass: function( classNames ) {
1240 jQuery.className.remove( this, classNames );
1243 toggleClass: function( classNames, state ) {
1244 if( typeof state !== "boolean" )
1245 state = !jQuery.className.has( this, classNames );
1246 jQuery.className[ state ? "add" : "remove" ]( this, classNames );
1249 remove: function( selector ) {
1250 if ( !selector || jQuery.multiFilter( selector, [ this ] ).length ) {
1251 if ( this.nodeType === 1 ) {
1252 cleanData( this.getElementsByTagName("*") );
1253 cleanData( [this] );
1256 if ( this.parentNode ) {
1257 this.parentNode.removeChild( this );
1263 // Remove element nodes and prevent memory leaks
1264 if ( this.nodeType === 1 ) {
1265 cleanData( this.getElementsByTagName("*") );
1268 // Remove any remaining nodes
1269 while ( this.firstChild ) {
1270 this.removeChild( this.firstChild );
1273 }, function(name, fn){
1274 jQuery.fn[ name ] = function(){
1275 return this.each( fn, arguments );
1279 function cleanData( elems ) {
1280 for ( var i = 0, l = elems.length; i < l; i++ ) {
1281 var id = elems[i][expando];
1283 delete jQuery.cache[ id ];
1288 // Helper function used by the dimensions and offset modules
1289 function num(elem, prop) {
1290 return elem[0] && parseInt( jQuery.curCSS(elem[0], prop, true), 10 ) || 0;