2 * jQuery @VERSION - New Wave Javascript
4 * Copyright (c) 2008 John Resig (jquery.com)
5 * Dual licensed under the MIT (MIT-LICENSE.txt)
6 * and GPL (GPL-LICENSE.txt) licenses.
12 // Will speed up references to window, and allows munging its name.
15 // Map over jQuery in case of overwrite
16 var _jQuery = window.jQuery,
17 // Map over the $ in case of overwrite
20 var jQuery = window.jQuery = window.$ = function( selector, context ) {
21 // The jQuery object is actually just the init constructor 'enhanced'
22 return new jQuery.fn.init( selector, context );
25 // A simple way to check for HTML strings or ID strings
26 // (both of which we optimize for)
27 var quickExpr = /^[^<]*(<(.|\s)+>)[^>]*$|^#([\w-]+)$/,
29 // Is it a simple selector
30 isSimple = /^.[^:#\[\.,]*$/,
32 // Will speed up references to undefined, and allows munging its name.
35 jQuery.fn = jQuery.prototype = {
36 init: function( selector, context ) {
37 // Make sure that a selection was provided
38 selector = selector || document;
40 // Handle $(DOMElement)
41 if ( selector.nodeType ) {
44 this.context = selector;
47 // Handle HTML strings
48 if ( typeof selector === "string" ) {
49 // Are we dealing with HTML string or an ID?
50 var match = quickExpr.exec( selector );
52 // Verify a match, and that no context was specified for #id
53 if ( match && (match[1] || !context) ) {
55 // HANDLE: $(html) -> $(array)
57 selector = jQuery.clean( [ match[1] ], context );
61 var elem = document.getElementById( match[3] );
63 // Make sure an element was located
65 // Handle the case where IE and Opera return items
66 // by name instead of ID
67 if ( elem.id != match[3] )
68 return jQuery().find( selector );
70 // Otherwise, we inject the element directly into the jQuery object
71 var ret = jQuery( elem );
72 ret.context = document;
73 ret.selector = selector;
79 // HANDLE: $(expr, [context])
80 // (which is just equivalent to: $(content).find(expr)
82 return jQuery( context ).find( selector );
84 // HANDLE: $(function)
85 // Shortcut for document ready
86 } else if ( jQuery.isFunction( selector ) )
87 return jQuery( document ).ready( selector );
89 return this.setArray(jQuery.makeArray(selector));
92 // Start with an empty selector
95 // The current version of jQuery being used
98 // The number of elements contained in the matched element set
103 // Get the Nth element in the matched element set OR
104 // Get the whole matched element set as a clean array
105 get: function( num ) {
106 return num === undefined ?
108 // Return a 'clean' array
109 jQuery.makeArray( this ) :
111 // Return just the object
115 // Take an array of elements and push it onto the stack
116 // (returning the new matched element set)
117 pushStack: function( elems, name, selector ) {
118 // Build a new jQuery matched element set
119 var ret = jQuery( elems );
121 // Add the old object onto the stack (as a reference)
122 ret.prevObject = this;
124 ret.context = this.context;
126 if ( name === "find" )
127 ret.selector = this.selector + (this.selector ? " " : "") + selector;
129 ret.selector = this.selector + "." + name + "(" + selector + ")";
131 // Return the newly-formed element set
135 // Force the current matched set of elements to become
136 // the specified array of elements (destroying the stack in the process)
137 // You should use pushStack() in order to do this, but maintain the stack
138 setArray: function( elems ) {
139 // Resetting the length to 0, then using the native Array push
140 // is a super-fast way to populate an object with array-like properties
142 Array.prototype.push.apply( this, elems );
147 // Execute a callback for every element in the matched set.
148 // (You can seed the arguments with an array of args, but this is
149 // only used internally.)
150 each: function( callback, args ) {
151 return jQuery.each( this, callback, args );
154 // Determine the position of an element within
155 // the matched set of elements
156 index: function( elem ) {
157 // Locate the position of the desired element
158 return jQuery.inArray(
159 // If it receives a jQuery object, the first element is used
160 elem && elem.jquery ? elem[0] : elem
164 attr: function( name, value, type ) {
167 // Look for the case where we're accessing a style value
168 if ( typeof name === "string" )
169 if ( value === undefined )
170 return this[0] && jQuery[ type || "attr" ]( this[0], name );
174 options[ name ] = value;
177 // Check to see if we're setting style values
178 return this.each(function(i){
179 // Set all the styles
180 for ( name in options )
185 name, jQuery.prop( this, options[ name ], type, i, name )
190 css: function( key, value ) {
191 // ignore negative width and height values
192 if ( (key == 'width' || key == 'height') && parseFloat(value) < 0 )
194 return this.attr( key, value, "curCSS" );
197 text: function( text ) {
198 if ( typeof text !== "object" && text != null )
199 return this.empty().append( (this[0] && this[0].ownerDocument || document).createTextNode( text ) );
203 jQuery.each( text || this, function(){
204 jQuery.each( this.childNodes, function(){
205 if ( this.nodeType != 8 )
206 ret += this.nodeType != 1 ?
208 jQuery.fn.text( [ this ] );
215 wrapAll: function( html ) {
217 // The elements to wrap the target around
218 jQuery( html, this[0].ownerDocument )
220 .insertBefore( this[0] )
224 while ( elem.firstChild )
225 elem = elem.firstChild;
234 wrapInner: function( html ) {
235 return this.each(function(){
236 jQuery( this ).contents().wrapAll( html );
240 wrap: function( html ) {
241 return this.each(function(){
242 jQuery( this ).wrapAll( html );
247 return this.domManip(arguments, true, function(elem){
248 if (this.nodeType == 1)
249 this.appendChild( elem );
253 prepend: function() {
254 return this.domManip(arguments, true, function(elem){
255 if (this.nodeType == 1)
256 this.insertBefore( elem, this.firstChild );
261 return this.domManip(arguments, false, function(elem){
262 this.parentNode.insertBefore( elem, this );
267 return this.domManip(arguments, false, function(elem){
268 this.parentNode.insertBefore( elem, this.nextSibling );
273 return this.prevObject || jQuery( [] );
276 find: function( selector ) {
277 var elems = jQuery.map(this, function(elem){
278 return jQuery.find( selector, elem );
281 return this.pushStack( /[^+>] [^+>]/.test( selector ) ?
282 jQuery.unique( elems ) :
283 elems, "find", selector );
286 clone: function( events ) {
288 var ret = this.map(function(){
289 if ( !jQuery.support.noCloneEvent && !jQuery.isXMLDoc(this) ) {
290 // IE copies events bound via attachEvent when
291 // using cloneNode. Calling detachEvent on the
292 // clone will also remove the events from the orignal
293 // In order to get around this, we use innerHTML.
294 // Unfortunately, this means some modifications to
295 // attributes in IE that are actually only stored
296 // as properties will not be copied (such as the
297 // the name attribute on an input).
298 var clone = this.cloneNode(true),
299 container = document.createElement("div");
300 container.appendChild(clone);
301 return jQuery.clean([container.innerHTML])[0];
303 return this.cloneNode(true);
306 // Need to set the expando to null on the cloned set if it exists
307 // removeData doesn't work here, IE removes it from the original as well
308 // this is primarily for IE but the data expando shouldn't be copied over in any browser
309 var clone = ret.find("*").andSelf().each(function(){
310 if ( this[ expando ] !== undefined )
311 this[ expando ] = null;
314 // Copy the events from the original to the clone
315 if ( events === true )
316 this.find("*").andSelf().each(function(i){
317 if (this.nodeType == 3)
319 var events = jQuery.data( this, "events" );
321 for ( var type in events )
322 for ( var handler in events[ type ] )
323 jQuery.event.add( clone[ i ], type, events[ type ][ handler ], events[ type ][ handler ].data );
326 // Return the cloned set
330 filter: function( selector ) {
331 return this.pushStack(
332 jQuery.isFunction( selector ) &&
333 jQuery.grep(this, function(elem, i){
334 return selector.call( elem, i );
337 jQuery.multiFilter( selector, jQuery.grep(this, function(elem){
338 return elem.nodeType === 1;
339 }) ), "filter", selector );
342 closest: function( selector ) {
343 return this.map(function(){
345 while ( cur && cur.ownerDocument ) {
346 if ( jQuery(cur).is(selector) )
348 cur = cur.parentNode;
353 not: function( selector ) {
354 if ( typeof selector === "string" )
355 // test special case where just one selector is passed in
356 if ( isSimple.test( selector ) )
357 return this.pushStack( jQuery.multiFilter( selector, this, true ), "not", selector );
359 selector = jQuery.multiFilter( selector, this );
361 var isArrayLike = selector.length && selector[selector.length - 1] !== undefined && !selector.nodeType;
362 return this.filter(function() {
363 return isArrayLike ? jQuery.inArray( this, selector ) < 0 : this != selector;
367 add: function( selector ) {
368 return this.pushStack( jQuery.unique( jQuery.merge(
370 typeof selector === "string" ?
372 jQuery.makeArray( selector )
376 is: function( selector ) {
377 return !!selector && jQuery.multiFilter( selector, this ).length > 0;
380 hasClass: function( selector ) {
381 return !!selector && this.is( "." + selector );
384 val: function( value ) {
385 if ( value === undefined ) {
389 if( jQuery.nodeName( elem, 'option' ) )
390 return (elem.attributes.value || {}).specified ? elem.value : elem.text;
392 // We need to handle select boxes special
393 if ( jQuery.nodeName( elem, "select" ) ) {
394 var index = elem.selectedIndex,
396 options = elem.options,
397 one = elem.type == "select-one";
399 // Nothing was selected
403 // Loop through all the selected options
404 for ( var i = one ? index : 0, max = one ? index + 1 : options.length; i < max; i++ ) {
405 var option = options[ i ];
407 if ( option.selected ) {
408 // Get the specifc value for the option
409 value = jQuery(option).val();
411 // We don't need an array for one selects
415 // Multi-Selects return an array
416 values.push( value );
423 // Everything else, we just grab the value
424 return (elem.value || "").replace(/\r/g, "");
431 if ( typeof value === "number" )
434 return this.each(function(){
435 if ( this.nodeType != 1 )
438 if ( jQuery.isArray(value) && /radio|checkbox/.test( this.type ) )
439 this.checked = (jQuery.inArray(this.value, value) >= 0 ||
440 jQuery.inArray(this.name, value) >= 0);
442 else if ( jQuery.nodeName( this, "select" ) ) {
443 var values = jQuery.makeArray(value);
445 jQuery( "option", this ).each(function(){
446 this.selected = (jQuery.inArray( this.value, values ) >= 0 ||
447 jQuery.inArray( this.text, values ) >= 0);
450 if ( !values.length )
451 this.selectedIndex = -1;
458 html: function( value ) {
459 return value === undefined ?
463 this.empty().append( value );
466 replaceWith: function( value ) {
467 return this.after( value ).remove();
471 return this.slice( i, +i + 1 );
475 return this.pushStack( Array.prototype.slice.apply( this, arguments ),
476 "slice", Array.prototype.slice.call(arguments).join(",") );
479 map: function( callback ) {
480 return this.pushStack( jQuery.map(this, function(elem, i){
481 return callback.call( elem, i, elem );
485 andSelf: function() {
486 return this.add( this.prevObject );
489 domManip: function( args, table, callback ) {
491 var fragment = this[0].ownerDocument.createDocumentFragment(),
492 scripts = jQuery.clean( args, this[0].ownerDocument, fragment ),
493 first = fragment.firstChild,
494 extra = this.length > 1 ? fragment.cloneNode(true) : fragment;
497 for ( var i = 0, l = this.length; i < l; i++ )
498 callback.call( root(this[i], first), i > 0 ? extra.cloneNode(true) : fragment );
501 jQuery.each( scripts, evalScript );
506 function root( elem, cur ) {
507 return table && jQuery.nodeName(elem, "table") && jQuery.nodeName(cur, "tr") ?
508 (elem.getElementsByTagName("tbody")[0] ||
509 elem.appendChild(elem.ownerDocument.createElement("tbody"))) :
515 // Give the init function the jQuery prototype for later instantiation
516 jQuery.fn.init.prototype = jQuery.fn;
518 function evalScript( i, elem ) {
527 jQuery.globalEval( elem.text || elem.textContent || elem.innerHTML || "" );
529 if ( elem.parentNode )
530 elem.parentNode.removeChild( elem );
537 jQuery.extend = jQuery.fn.extend = function() {
538 // copy reference to target object
539 var target = arguments[0] || {}, i = 1, length = arguments.length, deep = false, options;
541 // Handle a deep copy situation
542 if ( typeof target === "boolean" ) {
544 target = arguments[1] || {};
545 // skip the boolean and the target
549 // Handle case when target is a string or something (possible in deep copy)
550 if ( typeof target !== "object" && !jQuery.isFunction(target) )
553 // extend jQuery itself if only one argument is passed
559 for ( ; i < length; i++ )
560 // Only deal with non-null/undefined values
561 if ( (options = arguments[ i ]) != null )
562 // Extend the base object
563 for ( var name in options ) {
564 var src = target[ name ], copy = options[ name ];
566 // Prevent never-ending loop
567 if ( target === copy )
570 // Recurse if we're merging object values
571 if ( deep && copy && typeof copy === "object" && !copy.nodeType )
572 target[ name ] = jQuery.extend( deep,
573 // Never move original objects, clone them
574 src || ( copy.length != null ? [ ] : { } )
577 // Don't bring in undefined values
578 else if ( copy !== undefined )
579 target[ name ] = copy;
583 // Return the modified object
587 // exclude the following css properties to add px
588 var exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i,
590 defaultView = document.defaultView || {},
591 toString = Object.prototype.toString;
594 noConflict: function( deep ) {
598 window.jQuery = _jQuery;
603 // See test/unit/core.js for details concerning isFunction.
604 // Since version 1.3, DOM methods and functions like alert
605 // aren't supported. They return false on IE (#2968).
606 isFunction: function( obj ) {
607 return toString.call(obj) === "[object Function]";
610 isArray: function( obj ) {
611 return toString.call(obj) === "[object Array]";
614 // check if an element is in a (or is an) XML document
615 isXMLDoc: function( elem ) {
616 return elem.documentElement && !elem.body ||
617 elem.tagName && elem.ownerDocument && !elem.ownerDocument.body;
620 // Evalulates a script in a global context
621 globalEval: function( data ) {
622 data = jQuery.trim( data );
625 // Inspired by code by Andrea Giammarchi
626 // http://webreflection.blogspot.com/2007/08/global-scope-evaluation-and-dom.html
627 var head = document.getElementsByTagName("head")[0] || document.documentElement,
628 script = document.createElement("script");
630 script.type = "text/javascript";
631 if ( jQuery.support.scriptEval )
632 script.appendChild( document.createTextNode( data ) );
636 // Use insertBefore instead of appendChild to circumvent an IE6 bug.
637 // This arises when a base node is used (#2709).
638 head.insertBefore( script, head.firstChild );
639 head.removeChild( script );
643 nodeName: function( elem, name ) {
644 return elem.nodeName && elem.nodeName.toUpperCase() == name.toUpperCase();
647 // args is for internal usage only
648 each: function( object, callback, args ) {
649 var name, i = 0, length = object.length;
652 if ( length === undefined ) {
653 for ( name in object )
654 if ( callback.apply( object[ name ], args ) === false )
657 for ( ; i < length; )
658 if ( callback.apply( object[ i++ ], args ) === false )
661 // A special, fast, case for the most common use of each
663 if ( length === undefined ) {
664 for ( name in object )
665 if ( callback.call( object[ name ], name, object[ name ] ) === false )
668 for ( var value = object[0];
669 i < length && callback.call( value, i, value ) !== false; value = object[++i] ){}
675 prop: function( elem, value, type, i, name ) {
676 // Handle executable functions
677 if ( jQuery.isFunction( value ) )
678 value = value.call( elem, i );
680 // Handle passing in a number to a CSS property
681 return typeof value === "number" && type == "curCSS" && !exclude.test( name ) ?
687 // internal only, use addClass("class")
688 add: function( elem, classNames ) {
689 jQuery.each((classNames || "").split(/\s+/), function(i, className){
690 if ( elem.nodeType == 1 && !jQuery.className.has( elem.className, className ) )
691 elem.className += (elem.className ? " " : "") + className;
695 // internal only, use removeClass("class")
696 remove: function( elem, classNames ) {
697 if (elem.nodeType == 1)
698 elem.className = classNames !== undefined ?
699 jQuery.grep(elem.className.split(/\s+/), function(className){
700 return !jQuery.className.has( classNames, className );
705 // internal only, use hasClass("class")
706 has: function( elem, className ) {
707 return jQuery.inArray( className, (elem.className || elem).toString().split(/\s+/) ) > -1;
711 // A method for quickly swapping in/out CSS properties to get correct calculations
712 swap: function( elem, options, callback ) {
714 // Remember the old values, and insert the new ones
715 for ( var name in options ) {
716 old[ name ] = elem.style[ name ];
717 elem.style[ name ] = options[ name ];
720 callback.call( elem );
722 // Revert the old values
723 for ( var name in options )
724 elem.style[ name ] = old[ name ];
727 css: function( elem, name, force ) {
728 if ( name == "width" || name == "height" ) {
729 var val, props = { position: "absolute", visibility: "hidden", display:"block" }, which = name == "width" ? [ "Left", "Right" ] : [ "Top", "Bottom" ];
732 val = name == "width" ? elem.offsetWidth : elem.offsetHeight;
733 var padding = 0, border = 0;
734 jQuery.each( which, function() {
735 padding += parseFloat(jQuery.curCSS( elem, "padding" + this, true)) || 0;
736 border += parseFloat(jQuery.curCSS( elem, "border" + this + "Width", true)) || 0;
738 val -= Math.round(padding + border);
741 if ( jQuery(elem).is(":visible") )
744 jQuery.swap( elem, props, getWH );
746 return Math.max(0, val);
749 return jQuery.curCSS( elem, name, force );
752 curCSS: function( elem, name, force ) {
753 var ret, style = elem.style;
755 // We need to handle opacity special in IE
756 if ( name == "opacity" && !jQuery.support.opacity ) {
757 ret = jQuery.attr( style, "opacity" );
764 // Make sure we're using the right name for getting the float value
765 if ( name.match( /float/i ) )
768 if ( !force && style && style[ name ] )
771 else if ( defaultView.getComputedStyle ) {
773 // Only "float" is needed here
774 if ( name.match( /float/i ) )
777 name = name.replace( /([A-Z])/g, "-$1" ).toLowerCase();
779 var computedStyle = defaultView.getComputedStyle( elem, null );
782 ret = computedStyle.getPropertyValue( name );
784 // We should always get a number back from opacity
785 if ( name == "opacity" && ret == "" )
788 } else if ( elem.currentStyle ) {
789 var camelCase = name.replace(/\-(\w)/g, function(all, letter){
790 return letter.toUpperCase();
793 ret = elem.currentStyle[ name ] || elem.currentStyle[ camelCase ];
795 // From the awesome hack by Dean Edwards
796 // http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291
798 // If we're not dealing with a regular pixel number
799 // but a number that has a weird ending, we need to convert it to pixels
800 if ( !/^\d+(px)?$/i.test( ret ) && /^\d/.test( ret ) ) {
801 // Remember the original values
802 var left = style.left, rsLeft = elem.runtimeStyle.left;
804 // Put in the new values to get a computed value out
805 elem.runtimeStyle.left = elem.currentStyle.left;
806 style.left = ret || 0;
807 ret = style.pixelLeft + "px";
809 // Revert the changed values
811 elem.runtimeStyle.left = rsLeft;
818 clean: function( elems, context, fragment ) {
819 context = context || document;
821 // !context.createElement fails in IE with an error but returns typeof 'object'
822 if ( typeof context.createElement === "undefined" )
823 context = context.ownerDocument || context[0] && context[0].ownerDocument || document;
825 // If a single string is passed in and it's a single tag
826 // just do a createElement and skip the rest
827 if ( !fragment && elems.length === 1 && typeof elems[0] === "string" ) {
828 var match = /^<(\w+)\s*\/?>$/.exec(elems[0]);
830 return [ context.createElement( match[1] ) ];
833 var ret = [], scripts = [], div = context.createElement("div");
835 jQuery.each(elems, function(i, elem){
836 if ( typeof elem === "number" )
842 // Convert html string into DOM nodes
843 if ( typeof elem === "string" ) {
844 // Fix "XHTML"-style tags in all browsers
845 elem = elem.replace(/(<(\w+)[^>]*?)\/>/g, function(all, front, tag){
846 return tag.match(/^(abbr|br|col|img|input|link|meta|param|hr|area|embed)$/i) ?
848 front + "></" + tag + ">";
851 // Trim whitespace, otherwise indexOf won't work as expected
852 var tags = jQuery.trim( elem ).toLowerCase();
855 // option or optgroup
856 !tags.indexOf("<opt") &&
857 [ 1, "<select multiple='multiple'>", "</select>" ] ||
859 !tags.indexOf("<leg") &&
860 [ 1, "<fieldset>", "</fieldset>" ] ||
862 tags.match(/^<(thead|tbody|tfoot|colg|cap)/) &&
863 [ 1, "<table>", "</table>" ] ||
865 !tags.indexOf("<tr") &&
866 [ 2, "<table><tbody>", "</tbody></table>" ] ||
868 // <thead> matched above
869 (!tags.indexOf("<td") || !tags.indexOf("<th")) &&
870 [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ] ||
872 !tags.indexOf("<col") &&
873 [ 2, "<table><tbody></tbody><colgroup>", "</colgroup></table>" ] ||
875 // IE can't serialize <link> and <script> tags normally
876 !jQuery.support.htmlSerialize &&
877 [ 1, "div<div>", "</div>" ] ||
881 // Go to html and back, then peel off extra wrappers
882 div.innerHTML = wrap[1] + elem + wrap[2];
884 // Move to the right depth
888 // Remove IE's autoinserted <tbody> from table fragments
889 if ( !jQuery.support.tbody ) {
891 // String was a <table>, *may* have spurious <tbody>
892 var tbody = !tags.indexOf("<table") && tags.indexOf("<tbody") < 0 ?
893 div.firstChild && div.firstChild.childNodes :
895 // String was a bare <thead> or <tfoot>
896 wrap[1] == "<table>" && tags.indexOf("<tbody") < 0 ?
900 for ( var j = tbody.length - 1; j >= 0 ; --j )
901 if ( jQuery.nodeName( tbody[ j ], "tbody" ) && !tbody[ j ].childNodes.length )
902 tbody[ j ].parentNode.removeChild( tbody[ j ] );
906 // IE completely kills leading whitespace when innerHTML is used
907 if ( !jQuery.support.leadingWhitespace && /^\s/.test( elem ) )
908 div.insertBefore( context.createTextNode( elem.match(/^\s*/)[0] ), div.firstChild );
911 var found = div.getElementsByTagName("script");
913 while ( found.length ) {
914 scripts.push( found[0] );
915 found[0].parentNode.removeChild( found[0] );
919 elem = jQuery.makeArray( div.childNodes );
925 ret = jQuery.merge( ret, elem );
930 for ( var i = 0; ret[i]; i++ ) {
932 if ( jQuery.nodeName( node, "script" ) ) {
933 if( node.parentNode )
934 node.parentNode.removeChild( node );
936 if ( node.nodeType === 1 )
937 ret = jQuery.merge( ret, node.getElementsByTagName("script"));
938 fragment.appendChild( node );
948 attr: function( elem, name, value ) {
949 // don't set attributes on text and comment nodes
950 if (!elem || elem.nodeType == 3 || elem.nodeType == 8)
953 var notxml = !jQuery.isXMLDoc( elem ),
954 // Whether we are setting (or getting)
955 set = value !== undefined;
957 // Try to normalize/fix the name
958 name = notxml && jQuery.props[ name ] || name;
960 // Only do all the following if this is a node (faster for style)
961 // IE elem.getAttribute passes even for style
962 if ( elem.tagName ) {
964 // These attributes require special treatment
965 var special = /href|src|style/.test( name );
967 // Safari mis-reports the default selected property of a hidden option
968 // Accessing the parent's selectedIndex property fixes it
969 if ( name == "selected" )
970 elem.parentNode.selectedIndex;
972 // If applicable, access the attribute via the DOM 0 way
973 if ( name in elem && notxml && !special ) {
975 // We can't allow the type property to be changed (since it causes problems in IE)
976 if ( name == "type" && jQuery.nodeName( elem, "input" ) && elem.parentNode )
977 throw "type property can't be changed";
979 elem[ name ] = value;
982 // browsers index elements by id/name on forms, give priority to attributes.
983 if( jQuery.nodeName( elem, "form" ) && elem.getAttributeNode(name) )
984 return elem.getAttributeNode( name ).nodeValue;
989 if ( !jQuery.support.style && notxml && name == "style" )
990 return jQuery.attr( elem.style, "cssText", value );
993 // convert the value to a string (all browsers do this but IE) see #1070
994 elem.setAttribute( name, "" + value );
996 var attr = !jQuery.support.hrefNormalized && notxml && special
997 // Some attributes require a special call on IE
998 ? elem.getAttribute( name, 2 )
999 : elem.getAttribute( name );
1001 // Non-existent attributes return null, we normalize to undefined
1002 return attr === null ? undefined : attr;
1005 // elem is actually elem.style ... set the style
1007 // IE uses filters for opacity
1008 if ( !jQuery.support.opacity && name == "opacity" ) {
1010 // IE has trouble with opacity if it does not have layout
1011 // Force it by setting the zoom level
1014 // Set the alpha filter to set the opacity
1015 elem.filter = (elem.filter || "").replace( /alpha\([^)]*\)/, "" ) +
1016 (parseInt( value ) + '' == "NaN" ? "" : "alpha(opacity=" + value * 100 + ")");
1019 return elem.filter && elem.filter.indexOf("opacity=") >= 0 ?
1020 (parseFloat( elem.filter.match(/opacity=([^)]*)/)[1] ) / 100) + '':
1024 name = name.replace(/-([a-z])/ig, function(all, letter){
1025 return letter.toUpperCase();
1029 elem[ name ] = value;
1031 return elem[ name ];
1034 trim: function( text ) {
1035 return (text || "").replace( /^\s+|\s+$/g, "" );
1038 makeArray: function( array ) {
1041 if( array != null ){
1042 var i = array.length;
1043 // The window, strings (and functions) also have 'length'
1044 if( i == null || typeof array === "string" || jQuery.isFunction(array) || array.setInterval )
1048 ret[--i] = array[i];
1054 inArray: function( elem, array ) {
1055 for ( var i = 0, length = array.length; i < length; i++ )
1056 // Use === because on IE, window == document
1057 if ( array[ i ] === elem )
1063 merge: function( first, second ) {
1064 // We have to loop this way because IE & Opera overwrite the length
1065 // expando of getElementsByTagName
1066 var i = 0, elem, pos = first.length;
1067 // Also, we need to make sure that the correct elements are being returned
1068 // (IE returns comment nodes in a '*' query)
1069 if ( !jQuery.support.getAll ) {
1070 while ( (elem = second[ i++ ]) != null )
1071 if ( elem.nodeType != 8 )
1072 first[ pos++ ] = elem;
1075 while ( (elem = second[ i++ ]) != null )
1076 first[ pos++ ] = elem;
1081 unique: function( array ) {
1082 var ret = [], done = {};
1086 for ( var i = 0, length = array.length; i < length; i++ ) {
1087 var id = jQuery.data( array[ i ] );
1089 if ( !done[ id ] ) {
1091 ret.push( array[ i ] );
1102 grep: function( elems, callback, inv ) {
1105 // Go through the array, only saving the items
1106 // that pass the validator function
1107 for ( var i = 0, length = elems.length; i < length; i++ )
1108 if ( !inv != !callback( elems[ i ], i ) )
1109 ret.push( elems[ i ] );
1114 map: function( elems, callback ) {
1117 // Go through the array, translating each of the items to their
1118 // new value (or values).
1119 for ( var i = 0, length = elems.length; i < length; i++ ) {
1120 var value = callback( elems[ i ], i );
1122 if ( value != null )
1123 ret[ ret.length ] = value;
1126 return ret.concat.apply( [], ret );
1130 // Use of jQuery.browser is deprecated.
1131 // It's included for backwards compatibility and plugins,
1132 // although they should work to migrate away.
1134 var userAgent = navigator.userAgent.toLowerCase();
1136 // Figure out what browser is being used
1138 version: (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [0,'0'])[1],
1139 safari: /webkit/.test( userAgent ),
1140 opera: /opera/.test( userAgent ),
1141 msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
1142 mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )
1145 // Check to see if the W3C box model is being used
1146 jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
1149 parent: function(elem){return elem.parentNode;},
1150 parents: function(elem){return jQuery.dir(elem,"parentNode");},
1151 next: function(elem){return jQuery.nth(elem,2,"nextSibling");},
1152 prev: function(elem){return jQuery.nth(elem,2,"previousSibling");},
1153 nextAll: function(elem){return jQuery.dir(elem,"nextSibling");},
1154 prevAll: function(elem){return jQuery.dir(elem,"previousSibling");},
1155 siblings: function(elem){return jQuery.sibling(elem.parentNode.firstChild,elem);},
1156 children: function(elem){return jQuery.sibling(elem.firstChild);},
1157 contents: function(elem){return jQuery.nodeName(elem,"iframe")?elem.contentDocument||elem.contentWindow.document:jQuery.makeArray(elem.childNodes);}
1158 }, function(name, fn){
1159 jQuery.fn[ name ] = function( selector ) {
1160 var ret = jQuery.map( this, fn );
1162 if ( selector && typeof selector == "string" )
1163 ret = jQuery.multiFilter( selector, ret );
1165 return this.pushStack( jQuery.unique( ret ), name, selector );
1171 prependTo: "prepend",
1172 insertBefore: "before",
1173 insertAfter: "after",
1174 replaceAll: "replaceWith"
1175 }, function(name, original){
1176 jQuery.fn[ name ] = function() {
1177 var args = arguments;
1179 return this.each(function(){
1180 for ( var i = 0, length = args.length; i < length; i++ )
1181 jQuery( args[ i ] )[ original ]( this );
1187 removeAttr: function( name ) {
1188 jQuery.attr( this, name, "" );
1189 if (this.nodeType == 1)
1190 this.removeAttribute( name );
1193 addClass: function( classNames ) {
1194 jQuery.className.add( this, classNames );
1197 removeClass: function( classNames ) {
1198 jQuery.className.remove( this, classNames );
1201 toggleClass: function( classNames, state ) {
1202 if( typeof state !== "boolean" )
1203 state = !jQuery.className.has( this, classNames );
1204 jQuery.className[ state ? "add" : "remove" ]( this, classNames );
1207 remove: function( selector ) {
1208 if ( !selector || jQuery.filter( selector, [ this ] ).length ) {
1209 // Prevent memory leaks
1210 jQuery( "*", this ).add([this]).each(function(){
1211 jQuery.event.remove(this);
1212 jQuery.removeData(this);
1214 if (this.parentNode)
1215 this.parentNode.removeChild( this );
1220 // Remove element nodes and prevent memory leaks
1221 jQuery( ">*", this ).remove();
1223 // Remove any remaining nodes
1224 while ( this.firstChild )
1225 this.removeChild( this.firstChild );
1227 }, function(name, fn){
1228 jQuery.fn[ name ] = function(){
1229 return this.each( fn, arguments );
1233 // Helper function used by the dimensions and offset modules
1234 function num(elem, prop) {
1235 return elem[0] && parseInt( jQuery.curCSS(elem[0], prop, true), 10 ) || 0;