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.
13 // Will speed up references to window, and allows munging its name.
15 // Will speed up references to undefined, and allows munging its name.
17 // Map over jQuery in case of overwrite
18 _jQuery = window.jQuery,
19 // Map over the $ in case of overwrite
22 jQuery = window.jQuery = window.$ = function( selector, context ) {
23 // The jQuery object is actually just the init constructor 'enhanced'
24 return new jQuery.fn.init( selector, context );
27 // A simple way to check for HTML strings or ID strings
28 // (both of which we optimize for)
29 quickExpr = /^[^<]*(<(.|\s)+>)[^>]*$|^#([\w-]+)$/,
30 // Is it a simple selector
31 isSimple = /^.[^:#\[\.,]*$/;
33 jQuery.fn = jQuery.prototype = {
34 init: function( selector, context ) {
35 // Make sure that a selection was provided
36 selector = selector || document;
38 // Handle $(DOMElement)
39 if ( selector.nodeType ) {
42 this.context = selector;
45 // Handle HTML strings
46 if ( typeof selector === "string" ) {
47 // Are we dealing with HTML string or an ID?
48 var match = quickExpr.exec( selector );
50 // Verify a match, and that no context was specified for #id
51 if ( match && (match[1] || !context) ) {
53 // HANDLE: $(html) -> $(array)
55 selector = jQuery.clean( [ match[1] ], context );
59 var elem = document.getElementById( match[3] );
61 // Make sure an element was located
63 // Handle the case where IE and Opera return items
64 // by name instead of ID
65 if ( elem.id != match[3] )
66 return jQuery().find( selector );
68 // Otherwise, we inject the element directly into the jQuery object
69 var ret = jQuery( elem );
70 ret.context = document;
71 ret.selector = selector;
77 // HANDLE: $(expr, [context])
78 // (which is just equivalent to: $(content).find(expr)
80 return jQuery( context ).find( selector );
82 // HANDLE: $(function)
83 // Shortcut for document ready
84 } else if ( jQuery.isFunction( selector ) )
85 return jQuery( document ).ready( selector );
87 return this.setArray(jQuery.makeArray(selector));
90 // Start with an empty selector
93 // The current version of jQuery being used
96 // The number of elements contained in the matched element set
101 // Get the Nth element in the matched element set OR
102 // Get the whole matched element set as a clean array
103 get: function( num ) {
104 return num === undefined ?
106 // Return a 'clean' array
107 jQuery.makeArray( this ) :
109 // Return just the object
113 // Take an array of elements and push it onto the stack
114 // (returning the new matched element set)
115 pushStack: function( elems, name, selector ) {
116 // Build a new jQuery matched element set
117 var ret = jQuery( elems );
119 // Add the old object onto the stack (as a reference)
120 ret.prevObject = this;
122 ret.context = this.context;
124 if ( name === "find" )
125 ret.selector = this.selector + (this.selector ? " " : "") + selector;
127 ret.selector = this.selector + "." + name + "(" + selector + ")";
129 // Return the newly-formed element set
133 // Force the current matched set of elements to become
134 // the specified array of elements (destroying the stack in the process)
135 // You should use pushStack() in order to do this, but maintain the stack
136 setArray: function( elems ) {
137 // Resetting the length to 0, then using the native Array push
138 // is a super-fast way to populate an object with array-like properties
140 Array.prototype.push.apply( this, elems );
145 // Execute a callback for every element in the matched set.
146 // (You can seed the arguments with an array of args, but this is
147 // only used internally.)
148 each: function( callback, args ) {
149 return jQuery.each( this, callback, args );
152 // Determine the position of an element within
153 // the matched set of elements
154 index: function( elem ) {
155 // Locate the position of the desired element
156 return jQuery.inArray(
157 // If it receives a jQuery object, the first element is used
158 elem && elem.jquery ? elem[0] : elem
162 attr: function( name, value, type ) {
165 // Look for the case where we're accessing a style value
166 if ( typeof name === "string" )
167 if ( value === undefined )
168 return this[0] && jQuery[ type || "attr" ]( this[0], name );
172 options[ name ] = value;
175 // Check to see if we're setting style values
176 return this.each(function(i){
177 // Set all the styles
178 for ( name in options )
183 name, jQuery.prop( this, options[ name ], type, i, name )
188 css: function( key, value ) {
189 // ignore negative width and height values
190 if ( (key == 'width' || key == 'height') && parseFloat(value) < 0 )
192 return this.attr( key, value, "curCSS" );
195 text: function( text ) {
196 if ( typeof text !== "object" && text != null )
197 return this.empty().append( (this[0] && this[0].ownerDocument || document).createTextNode( text ) );
201 jQuery.each( text || this, function(){
202 jQuery.each( this.childNodes, function(){
203 if ( this.nodeType != 8 )
204 ret += this.nodeType != 1 ?
206 jQuery.fn.text( [ this ] );
213 wrapAll: function( html ) {
215 // The elements to wrap the target around
216 jQuery( html, this[0].ownerDocument )
218 .insertBefore( this[0] )
222 while ( elem.firstChild )
223 elem = elem.firstChild;
232 wrapInner: function( html ) {
233 return this.each(function(){
234 jQuery( this ).contents().wrapAll( html );
238 wrap: function( html ) {
239 return this.each(function(){
240 jQuery( this ).wrapAll( html );
245 return this.domManip(arguments, true, function(elem){
246 if (this.nodeType == 1)
247 this.appendChild( elem );
251 prepend: function() {
252 return this.domManip(arguments, true, function(elem){
253 if (this.nodeType == 1)
254 this.insertBefore( elem, this.firstChild );
259 return this.domManip(arguments, false, function(elem){
260 this.parentNode.insertBefore( elem, this );
265 return this.domManip(arguments, false, function(elem){
266 this.parentNode.insertBefore( elem, this.nextSibling );
271 return this.prevObject || jQuery( [] );
274 find: function( selector ) {
275 var elems = jQuery.map(this, function(elem){
276 return jQuery.find( selector, elem );
279 return this.pushStack( /[^+>] [^+>]/.test( selector ) ?
280 jQuery.unique( elems ) :
281 elems, "find", selector );
284 clone: function( events ) {
286 var ret = this.map(function(){
287 if ( !jQuery.support.noCloneEvent && !jQuery.isXMLDoc(this) ) {
288 // IE copies events bound via attachEvent when
289 // using cloneNode. Calling detachEvent on the
290 // clone will also remove the events from the orignal
291 // In order to get around this, we use innerHTML.
292 // Unfortunately, this means some modifications to
293 // attributes in IE that are actually only stored
294 // as properties will not be copied (such as the
295 // the name attribute on an input).
296 var clone = this.cloneNode(true),
297 container = document.createElement("div");
298 container.appendChild(clone);
299 return jQuery.clean([container.innerHTML])[0];
301 return this.cloneNode(true);
304 // Need to set the expando to null on the cloned set if it exists
305 // removeData doesn't work here, IE removes it from the original as well
306 // this is primarily for IE but the data expando shouldn't be copied over in any browser
307 var clone = ret.find("*").andSelf().each(function(){
308 if ( this[ expando ] !== undefined )
309 this[ expando ] = null;
312 // Copy the events from the original to the clone
313 if ( events === true )
314 this.find("*").andSelf().each(function(i){
315 if (this.nodeType == 3)
317 var events = jQuery.data( this, "events" );
319 for ( var type in events )
320 for ( var handler in events[ type ] )
321 jQuery.event.add( clone[ i ], type, events[ type ][ handler ], events[ type ][ handler ].data );
324 // Return the cloned set
328 filter: function( selector ) {
329 return this.pushStack(
330 jQuery.isFunction( selector ) &&
331 jQuery.grep(this, function(elem, i){
332 return selector.call( elem, i );
335 jQuery.multiFilter( selector, jQuery.grep(this, function(elem){
336 return elem.nodeType === 1;
337 }) ), "filter", selector );
340 closest: function( selector ) {
341 return this.map(function(){
343 while ( cur && cur.ownerDocument ) {
344 if ( jQuery(cur).is(selector) )
346 cur = cur.parentNode;
351 not: function( selector ) {
352 if ( typeof selector === "string" )
353 // test special case where just one selector is passed in
354 if ( isSimple.test( selector ) )
355 return this.pushStack( jQuery.multiFilter( selector, this, true ), "not", selector );
357 selector = jQuery.multiFilter( selector, this );
359 var isArrayLike = selector.length && selector[selector.length - 1] !== undefined && !selector.nodeType;
360 return this.filter(function() {
361 return isArrayLike ? jQuery.inArray( this, selector ) < 0 : this != selector;
365 add: function( selector ) {
366 return this.pushStack( jQuery.unique( jQuery.merge(
368 typeof selector === "string" ?
370 jQuery.makeArray( selector )
374 is: function( selector ) {
375 return !!selector && jQuery.multiFilter( selector, this ).length > 0;
378 hasClass: function( selector ) {
379 return !!selector && this.is( "." + selector );
382 val: function( value ) {
383 if ( value === undefined ) {
387 if( jQuery.nodeName( elem, 'option' ) )
388 return (elem.attributes.value || {}).specified ? elem.value : elem.text;
390 // We need to handle select boxes special
391 if ( jQuery.nodeName( elem, "select" ) ) {
392 var index = elem.selectedIndex,
394 options = elem.options,
395 one = elem.type == "select-one";
397 // Nothing was selected
401 // Loop through all the selected options
402 for ( var i = one ? index : 0, max = one ? index + 1 : options.length; i < max; i++ ) {
403 var option = options[ i ];
405 if ( option.selected ) {
406 // Get the specifc value for the option
407 value = jQuery(option).val();
409 // We don't need an array for one selects
413 // Multi-Selects return an array
414 values.push( value );
421 // Everything else, we just grab the value
422 return (elem.value || "").replace(/\r/g, "");
429 if ( typeof value === "number" )
432 return this.each(function(){
433 if ( this.nodeType != 1 )
436 if ( jQuery.isArray(value) && /radio|checkbox/.test( this.type ) )
437 this.checked = (jQuery.inArray(this.value, value) >= 0 ||
438 jQuery.inArray(this.name, value) >= 0);
440 else if ( jQuery.nodeName( this, "select" ) ) {
441 var values = jQuery.makeArray(value);
443 jQuery( "option", this ).each(function(){
444 this.selected = (jQuery.inArray( this.value, values ) >= 0 ||
445 jQuery.inArray( this.text, values ) >= 0);
448 if ( !values.length )
449 this.selectedIndex = -1;
456 html: function( value ) {
457 return value === undefined ?
461 this.empty().append( value );
464 replaceWith: function( value ) {
465 return this.after( value ).remove();
469 return this.slice( i, +i + 1 );
473 return this.pushStack( Array.prototype.slice.apply( this, arguments ),
474 "slice", Array.prototype.slice.call(arguments).join(",") );
477 map: function( callback ) {
478 return this.pushStack( jQuery.map(this, function(elem, i){
479 return callback.call( elem, i, elem );
483 andSelf: function() {
484 return this.add( this.prevObject );
487 domManip: function( args, table, callback ) {
489 var fragment = this[0].ownerDocument.createDocumentFragment(),
490 scripts = jQuery.clean( args, this[0].ownerDocument, fragment ),
491 first = fragment.firstChild,
492 extra = this.length > 1 ? fragment.cloneNode(true) : fragment;
495 for ( var i = 0, l = this.length; i < l; i++ )
496 callback.call( root(this[i], first), i > 0 ? extra.cloneNode(true) : fragment );
499 jQuery.each( scripts, evalScript );
504 function root( elem, cur ) {
505 return table && jQuery.nodeName(elem, "table") && jQuery.nodeName(cur, "tr") ?
506 (elem.getElementsByTagName("tbody")[0] ||
507 elem.appendChild(elem.ownerDocument.createElement("tbody"))) :
513 // Give the init function the jQuery prototype for later instantiation
514 jQuery.fn.init.prototype = jQuery.fn;
516 function evalScript( i, elem ) {
525 jQuery.globalEval( elem.text || elem.textContent || elem.innerHTML || "" );
527 if ( elem.parentNode )
528 elem.parentNode.removeChild( elem );
535 jQuery.extend = jQuery.fn.extend = function() {
536 // copy reference to target object
537 var target = arguments[0] || {}, i = 1, length = arguments.length, deep = false, options;
539 // Handle a deep copy situation
540 if ( typeof target === "boolean" ) {
542 target = arguments[1] || {};
543 // skip the boolean and the target
547 // Handle case when target is a string or something (possible in deep copy)
548 if ( typeof target !== "object" && !jQuery.isFunction(target) )
551 // extend jQuery itself if only one argument is passed
557 for ( ; i < length; i++ )
558 // Only deal with non-null/undefined values
559 if ( (options = arguments[ i ]) != null )
560 // Extend the base object
561 for ( var name in options ) {
562 var src = target[ name ], copy = options[ name ];
564 // Prevent never-ending loop
565 if ( target === copy )
568 // Recurse if we're merging object values
569 if ( deep && copy && typeof copy === "object" && !copy.nodeType )
570 target[ name ] = jQuery.extend( deep,
571 // Never move original objects, clone them
572 src || ( copy.length != null ? [ ] : { } )
575 // Don't bring in undefined values
576 else if ( copy !== undefined )
577 target[ name ] = copy;
581 // Return the modified object
585 // exclude the following css properties to add px
586 var exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i,
588 defaultView = document.defaultView || {},
589 toString = Object.prototype.toString;
592 noConflict: function( deep ) {
596 window.jQuery = _jQuery;
601 // See test/unit/core.js for details concerning isFunction.
602 // Since version 1.3, DOM methods and functions like alert
603 // aren't supported. They return false on IE (#2968).
604 isFunction: function( obj ) {
605 return toString.call(obj) === "[object Function]";
608 isArray: function( obj ) {
609 return toString.call(obj) === "[object Array]";
612 // check if an element is in a (or is an) XML document
613 isXMLDoc: function( elem ) {
614 return elem.documentElement && !elem.body ||
615 elem.tagName && elem.ownerDocument && !elem.ownerDocument.body;
618 // Evalulates a script in a global context
619 globalEval: function( data ) {
620 data = jQuery.trim( data );
623 // Inspired by code by Andrea Giammarchi
624 // http://webreflection.blogspot.com/2007/08/global-scope-evaluation-and-dom.html
625 var head = document.getElementsByTagName("head")[0] || document.documentElement,
626 script = document.createElement("script");
628 script.type = "text/javascript";
629 if ( jQuery.support.scriptEval )
630 script.appendChild( document.createTextNode( data ) );
634 // Use insertBefore instead of appendChild to circumvent an IE6 bug.
635 // This arises when a base node is used (#2709).
636 head.insertBefore( script, head.firstChild );
637 head.removeChild( script );
641 nodeName: function( elem, name ) {
642 return elem.nodeName && elem.nodeName.toUpperCase() == name.toUpperCase();
645 // args is for internal usage only
646 each: function( object, callback, args ) {
647 var name, i = 0, length = object.length;
650 if ( length === undefined ) {
651 for ( name in object )
652 if ( callback.apply( object[ name ], args ) === false )
655 for ( ; i < length; )
656 if ( callback.apply( object[ i++ ], args ) === false )
659 // A special, fast, case for the most common use of each
661 if ( length === undefined ) {
662 for ( name in object )
663 if ( callback.call( object[ name ], name, object[ name ] ) === false )
666 for ( var value = object[0];
667 i < length && callback.call( value, i, value ) !== false; value = object[++i] ){}
673 prop: function( elem, value, type, i, name ) {
674 // Handle executable functions
675 if ( jQuery.isFunction( value ) )
676 value = value.call( elem, i );
678 // Handle passing in a number to a CSS property
679 return typeof value === "number" && type == "curCSS" && !exclude.test( name ) ?
685 // internal only, use addClass("class")
686 add: function( elem, classNames ) {
687 jQuery.each((classNames || "").split(/\s+/), function(i, className){
688 if ( elem.nodeType == 1 && !jQuery.className.has( elem.className, className ) )
689 elem.className += (elem.className ? " " : "") + className;
693 // internal only, use removeClass("class")
694 remove: function( elem, classNames ) {
695 if (elem.nodeType == 1)
696 elem.className = classNames !== undefined ?
697 jQuery.grep(elem.className.split(/\s+/), function(className){
698 return !jQuery.className.has( classNames, className );
703 // internal only, use hasClass("class")
704 has: function( elem, className ) {
705 return jQuery.inArray( className, (elem.className || elem).toString().split(/\s+/) ) > -1;
709 // A method for quickly swapping in/out CSS properties to get correct calculations
710 swap: function( elem, options, callback ) {
712 // Remember the old values, and insert the new ones
713 for ( var name in options ) {
714 old[ name ] = elem.style[ name ];
715 elem.style[ name ] = options[ name ];
718 callback.call( elem );
720 // Revert the old values
721 for ( var name in options )
722 elem.style[ name ] = old[ name ];
725 css: function( elem, name, force ) {
726 if ( name == "width" || name == "height" ) {
727 var val, props = { position: "absolute", visibility: "hidden", display:"block" }, which = name == "width" ? [ "Left", "Right" ] : [ "Top", "Bottom" ];
730 val = name == "width" ? elem.offsetWidth : elem.offsetHeight;
731 var padding = 0, border = 0;
732 jQuery.each( which, function() {
733 padding += parseFloat(jQuery.curCSS( elem, "padding" + this, true)) || 0;
734 border += parseFloat(jQuery.curCSS( elem, "border" + this + "Width", true)) || 0;
736 val -= Math.round(padding + border);
739 if ( jQuery(elem).is(":visible") )
742 jQuery.swap( elem, props, getWH );
744 return Math.max(0, val);
747 return jQuery.curCSS( elem, name, force );
750 curCSS: function( elem, name, force ) {
751 var ret, style = elem.style;
753 // We need to handle opacity special in IE
754 if ( name == "opacity" && !jQuery.support.opacity ) {
755 ret = jQuery.attr( style, "opacity" );
762 // Make sure we're using the right name for getting the float value
763 if ( name.match( /float/i ) )
766 if ( !force && style && style[ name ] )
769 else if ( defaultView.getComputedStyle ) {
771 // Only "float" is needed here
772 if ( name.match( /float/i ) )
775 name = name.replace( /([A-Z])/g, "-$1" ).toLowerCase();
777 var computedStyle = defaultView.getComputedStyle( elem, null );
780 ret = computedStyle.getPropertyValue( name );
782 // We should always get a number back from opacity
783 if ( name == "opacity" && ret == "" )
786 } else if ( elem.currentStyle ) {
787 var camelCase = name.replace(/\-(\w)/g, function(all, letter){
788 return letter.toUpperCase();
791 ret = elem.currentStyle[ name ] || elem.currentStyle[ camelCase ];
793 // From the awesome hack by Dean Edwards
794 // http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291
796 // If we're not dealing with a regular pixel number
797 // but a number that has a weird ending, we need to convert it to pixels
798 if ( !/^\d+(px)?$/i.test( ret ) && /^\d/.test( ret ) ) {
799 // Remember the original values
800 var left = style.left, rsLeft = elem.runtimeStyle.left;
802 // Put in the new values to get a computed value out
803 elem.runtimeStyle.left = elem.currentStyle.left;
804 style.left = ret || 0;
805 ret = style.pixelLeft + "px";
807 // Revert the changed values
809 elem.runtimeStyle.left = rsLeft;
816 clean: function( elems, context, fragment ) {
817 context = context || document;
819 // !context.createElement fails in IE with an error but returns typeof 'object'
820 if ( typeof context.createElement === "undefined" )
821 context = context.ownerDocument || context[0] && context[0].ownerDocument || document;
823 // If a single string is passed in and it's a single tag
824 // just do a createElement and skip the rest
825 if ( !fragment && elems.length === 1 && typeof elems[0] === "string" ) {
826 var match = /^<(\w+)\s*\/?>$/.exec(elems[0]);
828 return [ context.createElement( match[1] ) ];
831 var ret = [], scripts = [], div = context.createElement("div");
833 jQuery.each(elems, function(i, elem){
834 if ( typeof elem === "number" )
840 // Convert html string into DOM nodes
841 if ( typeof elem === "string" ) {
842 // Fix "XHTML"-style tags in all browsers
843 elem = elem.replace(/(<(\w+)[^>]*?)\/>/g, function(all, front, tag){
844 return tag.match(/^(abbr|br|col|img|input|link|meta|param|hr|area|embed)$/i) ?
846 front + "></" + tag + ">";
849 // Trim whitespace, otherwise indexOf won't work as expected
850 var tags = jQuery.trim( elem ).toLowerCase();
853 // option or optgroup
854 !tags.indexOf("<opt") &&
855 [ 1, "<select multiple='multiple'>", "</select>" ] ||
857 !tags.indexOf("<leg") &&
858 [ 1, "<fieldset>", "</fieldset>" ] ||
860 tags.match(/^<(thead|tbody|tfoot|colg|cap)/) &&
861 [ 1, "<table>", "</table>" ] ||
863 !tags.indexOf("<tr") &&
864 [ 2, "<table><tbody>", "</tbody></table>" ] ||
866 // <thead> matched above
867 (!tags.indexOf("<td") || !tags.indexOf("<th")) &&
868 [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ] ||
870 !tags.indexOf("<col") &&
871 [ 2, "<table><tbody></tbody><colgroup>", "</colgroup></table>" ] ||
873 // IE can't serialize <link> and <script> tags normally
874 !jQuery.support.htmlSerialize &&
875 [ 1, "div<div>", "</div>" ] ||
879 // Go to html and back, then peel off extra wrappers
880 div.innerHTML = wrap[1] + elem + wrap[2];
882 // Move to the right depth
886 // Remove IE's autoinserted <tbody> from table fragments
887 if ( !jQuery.support.tbody ) {
889 // String was a <table>, *may* have spurious <tbody>
890 var tbody = !tags.indexOf("<table") && tags.indexOf("<tbody") < 0 ?
891 div.firstChild && div.firstChild.childNodes :
893 // String was a bare <thead> or <tfoot>
894 wrap[1] == "<table>" && tags.indexOf("<tbody") < 0 ?
898 for ( var j = tbody.length - 1; j >= 0 ; --j )
899 if ( jQuery.nodeName( tbody[ j ], "tbody" ) && !tbody[ j ].childNodes.length )
900 tbody[ j ].parentNode.removeChild( tbody[ j ] );
904 // IE completely kills leading whitespace when innerHTML is used
905 if ( !jQuery.support.leadingWhitespace && /^\s/.test( elem ) )
906 div.insertBefore( context.createTextNode( elem.match(/^\s*/)[0] ), div.firstChild );
909 var found = div.getElementsByTagName("script");
911 while ( found.length ) {
912 scripts.push( found[0] );
913 found[0].parentNode.removeChild( found[0] );
917 elem = jQuery.makeArray( div.childNodes );
923 ret = jQuery.merge( ret, elem );
928 for ( var i = 0; ret[i]; i++ ) {
930 if ( jQuery.nodeName( node, "script" ) ) {
931 if( node.parentNode )
932 node.parentNode.removeChild( node );
934 if ( node.nodeType === 1 )
935 ret = jQuery.merge( ret, node.getElementsByTagName("script"));
936 fragment.appendChild( node );
946 attr: function( elem, name, value ) {
947 // don't set attributes on text and comment nodes
948 if (!elem || elem.nodeType == 3 || elem.nodeType == 8)
951 var notxml = !jQuery.isXMLDoc( elem ),
952 // Whether we are setting (or getting)
953 set = value !== undefined;
955 // Try to normalize/fix the name
956 name = notxml && jQuery.props[ name ] || name;
958 // Only do all the following if this is a node (faster for style)
959 // IE elem.getAttribute passes even for style
960 if ( elem.tagName ) {
962 // These attributes require special treatment
963 var special = /href|src|style/.test( name );
965 // Safari mis-reports the default selected property of a hidden option
966 // Accessing the parent's selectedIndex property fixes it
967 if ( name == "selected" )
968 elem.parentNode.selectedIndex;
970 // If applicable, access the attribute via the DOM 0 way
971 if ( name in elem && notxml && !special ) {
973 // We can't allow the type property to be changed (since it causes problems in IE)
974 if ( name == "type" && jQuery.nodeName( elem, "input" ) && elem.parentNode )
975 throw "type property can't be changed";
977 elem[ name ] = value;
980 // browsers index elements by id/name on forms, give priority to attributes.
981 if( jQuery.nodeName( elem, "form" ) && elem.getAttributeNode(name) )
982 return elem.getAttributeNode( name ).nodeValue;
987 if ( !jQuery.support.style && notxml && name == "style" )
988 return jQuery.attr( elem.style, "cssText", value );
991 // convert the value to a string (all browsers do this but IE) see #1070
992 elem.setAttribute( name, "" + value );
994 var attr = !jQuery.support.hrefNormalized && notxml && special
995 // Some attributes require a special call on IE
996 ? elem.getAttribute( name, 2 )
997 : elem.getAttribute( name );
999 // Non-existent attributes return null, we normalize to undefined
1000 return attr === null ? undefined : attr;
1003 // elem is actually elem.style ... set the style
1005 // IE uses filters for opacity
1006 if ( !jQuery.support.opacity && name == "opacity" ) {
1008 // IE has trouble with opacity if it does not have layout
1009 // Force it by setting the zoom level
1012 // Set the alpha filter to set the opacity
1013 elem.filter = (elem.filter || "").replace( /alpha\([^)]*\)/, "" ) +
1014 (parseInt( value ) + '' == "NaN" ? "" : "alpha(opacity=" + value * 100 + ")");
1017 return elem.filter && elem.filter.indexOf("opacity=") >= 0 ?
1018 (parseFloat( elem.filter.match(/opacity=([^)]*)/)[1] ) / 100) + '':
1022 name = name.replace(/-([a-z])/ig, function(all, letter){
1023 return letter.toUpperCase();
1027 elem[ name ] = value;
1029 return elem[ name ];
1032 trim: function( text ) {
1033 return (text || "").replace( /^\s+|\s+$/g, "" );
1036 makeArray: function( array ) {
1039 if( array != null ){
1040 var i = array.length;
1041 // The window, strings (and functions) also have 'length'
1042 if( i == null || typeof array === "string" || jQuery.isFunction(array) || array.setInterval )
1046 ret[--i] = array[i];
1052 inArray: function( elem, array ) {
1053 for ( var i = 0, length = array.length; i < length; i++ )
1054 // Use === because on IE, window == document
1055 if ( array[ i ] === elem )
1061 merge: function( first, second ) {
1062 // We have to loop this way because IE & Opera overwrite the length
1063 // expando of getElementsByTagName
1064 var i = 0, elem, pos = first.length;
1065 // Also, we need to make sure that the correct elements are being returned
1066 // (IE returns comment nodes in a '*' query)
1067 if ( !jQuery.support.getAll ) {
1068 while ( (elem = second[ i++ ]) != null )
1069 if ( elem.nodeType != 8 )
1070 first[ pos++ ] = elem;
1073 while ( (elem = second[ i++ ]) != null )
1074 first[ pos++ ] = elem;
1079 unique: function( array ) {
1080 var ret = [], done = {};
1084 for ( var i = 0, length = array.length; i < length; i++ ) {
1085 var id = jQuery.data( array[ i ] );
1087 if ( !done[ id ] ) {
1089 ret.push( array[ i ] );
1100 grep: function( elems, callback, inv ) {
1103 // Go through the array, only saving the items
1104 // that pass the validator function
1105 for ( var i = 0, length = elems.length; i < length; i++ )
1106 if ( !inv != !callback( elems[ i ], i ) )
1107 ret.push( elems[ i ] );
1112 map: function( elems, callback ) {
1115 // Go through the array, translating each of the items to their
1116 // new value (or values).
1117 for ( var i = 0, length = elems.length; i < length; i++ ) {
1118 var value = callback( elems[ i ], i );
1120 if ( value != null )
1121 ret[ ret.length ] = value;
1124 return ret.concat.apply( [], ret );
1128 // Use of jQuery.browser is deprecated.
1129 // It's included for backwards compatibility and plugins,
1130 // although they should work to migrate away.
1132 var userAgent = navigator.userAgent.toLowerCase();
1134 // Figure out what browser is being used
1136 version: (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [0,'0'])[1],
1137 safari: /webkit/.test( userAgent ),
1138 opera: /opera/.test( userAgent ),
1139 msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
1140 mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )
1143 // Check to see if the W3C box model is being used
1144 jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
1147 parent: function(elem){return elem.parentNode;},
1148 parents: function(elem){return jQuery.dir(elem,"parentNode");},
1149 next: function(elem){return jQuery.nth(elem,2,"nextSibling");},
1150 prev: function(elem){return jQuery.nth(elem,2,"previousSibling");},
1151 nextAll: function(elem){return jQuery.dir(elem,"nextSibling");},
1152 prevAll: function(elem){return jQuery.dir(elem,"previousSibling");},
1153 siblings: function(elem){return jQuery.sibling(elem.parentNode.firstChild,elem);},
1154 children: function(elem){return jQuery.sibling(elem.firstChild);},
1155 contents: function(elem){return jQuery.nodeName(elem,"iframe")?elem.contentDocument||elem.contentWindow.document:jQuery.makeArray(elem.childNodes);}
1156 }, function(name, fn){
1157 jQuery.fn[ name ] = function( selector ) {
1158 var ret = jQuery.map( this, fn );
1160 if ( selector && typeof selector == "string" )
1161 ret = jQuery.multiFilter( selector, ret );
1163 return this.pushStack( jQuery.unique( ret ), name, selector );
1169 prependTo: "prepend",
1170 insertBefore: "before",
1171 insertAfter: "after",
1172 replaceAll: "replaceWith"
1173 }, function(name, original){
1174 jQuery.fn[ name ] = function() {
1175 var args = arguments;
1177 return this.each(function(){
1178 for ( var i = 0, length = args.length; i < length; i++ )
1179 jQuery( args[ i ] )[ original ]( this );
1185 removeAttr: function( name ) {
1186 jQuery.attr( this, name, "" );
1187 if (this.nodeType == 1)
1188 this.removeAttribute( name );
1191 addClass: function( classNames ) {
1192 jQuery.className.add( this, classNames );
1195 removeClass: function( classNames ) {
1196 jQuery.className.remove( this, classNames );
1199 toggleClass: function( classNames, state ) {
1200 if( typeof state !== "boolean" )
1201 state = !jQuery.className.has( this, classNames );
1202 jQuery.className[ state ? "add" : "remove" ]( this, classNames );
1205 remove: function( selector ) {
1206 if ( !selector || jQuery.filter( selector, [ this ] ).length ) {
1207 // Prevent memory leaks
1208 jQuery( "*", this ).add([this]).each(function(){
1209 jQuery.event.remove(this);
1210 jQuery.removeData(this);
1212 if (this.parentNode)
1213 this.parentNode.removeChild( this );
1218 // Remove element nodes and prevent memory leaks
1219 jQuery( ">*", this ).remove();
1221 // Remove any remaining nodes
1222 while ( this.firstChild )
1223 this.removeChild( this.firstChild );
1225 }, function(name, fn){
1226 jQuery.fn[ name ] = function(){
1227 return this.each( fn, arguments );
1231 // Helper function used by the dimensions and offset modules
1232 function num(elem, prop) {
1233 return elem[0] && parseInt( jQuery.curCSS(elem[0], prop, true), 10 ) || 0;