2 // Will speed up references to window, and allows munging its name.
4 // Will speed up references to undefined, and allows munging its name.
6 // Map over jQuery in case of overwrite
7 _jQuery = window.jQuery,
8 // Map over the $ in case of overwrite
11 jQuery = window.jQuery = window.$ = function( selector, context ) {
12 // The jQuery object is actually just the init constructor 'enhanced'
13 return new jQuery.fn.init( selector, context );
16 // A simple way to check for HTML strings or ID strings
17 // (both of which we optimize for)
18 quickExpr = /^[^<]*(<(.|\s)+>)[^>]*$|^#([\w-]+)$/,
19 // Is it a simple selector
20 isSimple = /^.[^:#\[\.,]*$/;
22 jQuery.fn = jQuery.prototype = {
23 init: function( selector, context ) {
24 // Make sure that a selection was provided
25 selector = selector || document;
27 // Handle $(DOMElement)
28 if ( selector.nodeType ) {
31 this.context = selector;
34 // Handle HTML strings
35 if ( typeof selector === "string" ) {
36 // Are we dealing with HTML string or an ID?
37 var match = quickExpr.exec( selector );
39 // Verify a match, and that no context was specified for #id
40 if ( match && (match[1] || !context) ) {
42 // HANDLE: $(html) -> $(array)
44 selector = jQuery.clean( [ match[1] ], context );
48 var elem = document.getElementById( match[3] );
50 // Make sure an element was located
52 // Handle the case where IE and Opera return items
53 // by name instead of ID
54 if ( elem.id != match[3] )
55 return jQuery().find( selector );
57 // Otherwise, we inject the element directly into the jQuery object
58 var ret = jQuery( elem );
59 ret.context = document;
60 ret.selector = selector;
66 // HANDLE: $(expr, [context])
67 // (which is just equivalent to: $(content).find(expr)
69 return jQuery( context ).find( selector );
71 // HANDLE: $(function)
72 // Shortcut for document ready
73 } else if ( jQuery.isFunction( selector ) )
74 return jQuery( document ).ready( selector );
76 // Make sure that old selector state is passed along
77 if ( selector.selector && selector.context ) {
78 this.selector = selector.selector;
79 this.context = selector.context;
82 return this.setArray(jQuery.makeArray(selector));
85 // Start with an empty selector
88 // The current version of jQuery being used
91 // The number of elements contained in the matched element set
96 // Get the Nth element in the matched element set OR
97 // Get the whole matched element set as a clean array
98 get: function( num ) {
99 return num === undefined ?
101 // Return a 'clean' array
102 jQuery.makeArray( this ) :
104 // Return just the object
108 // Take an array of elements and push it onto the stack
109 // (returning the new matched element set)
110 pushStack: function( elems, name, selector ) {
111 // Build a new jQuery matched element set
112 var ret = jQuery( elems );
114 // Add the old object onto the stack (as a reference)
115 ret.prevObject = this;
117 ret.context = this.context;
119 if ( name === "find" )
120 ret.selector = this.selector + (this.selector ? " " : "") + selector;
122 ret.selector = this.selector + "." + name + "(" + selector + ")";
124 // Return the newly-formed element set
128 // Force the current matched set of elements to become
129 // the specified array of elements (destroying the stack in the process)
130 // You should use pushStack() in order to do this, but maintain the stack
131 setArray: function( elems ) {
132 // Resetting the length to 0, then using the native Array push
133 // is a super-fast way to populate an object with array-like properties
135 Array.prototype.push.apply( this, elems );
140 // Execute a callback for every element in the matched set.
141 // (You can seed the arguments with an array of args, but this is
142 // only used internally.)
143 each: function( callback, args ) {
144 return jQuery.each( this, callback, args );
147 // Determine the position of an element within
148 // the matched set of elements
149 index: function( elem ) {
150 // Locate the position of the desired element
151 return jQuery.inArray(
152 // If it receives a jQuery object, the first element is used
153 elem && elem.jquery ? elem[0] : elem
157 attr: function( name, value, type ) {
160 // Look for the case where we're accessing a style value
161 if ( typeof name === "string" )
162 if ( value === undefined )
163 return this[0] && jQuery[ type || "attr" ]( this[0], name );
167 options[ name ] = value;
170 // Check to see if we're setting style values
171 return this.each(function(i){
172 // Set all the styles
173 for ( name in options )
178 name, jQuery.prop( this, options[ name ], type, i, name )
183 css: function( key, value ) {
184 // ignore negative width and height values
185 if ( (key == 'width' || key == 'height') && parseFloat(value) < 0 )
187 return this.attr( key, value, "curCSS" );
190 text: function( text ) {
191 if ( typeof text !== "object" && text != null )
192 return this.empty().append( (this[0] && this[0].ownerDocument || document).createTextNode( text ) );
196 jQuery.each( text || this, function(){
197 jQuery.each( this.childNodes, function(){
198 if ( this.nodeType != 8 )
199 ret += this.nodeType != 1 ?
201 jQuery.fn.text( [ this ] );
208 wrapAll: function( html ) {
210 // The elements to wrap the target around
211 jQuery( html, this[0].ownerDocument )
213 .insertBefore( this[0] )
217 while ( elem.firstChild )
218 elem = elem.firstChild;
227 wrapInner: function( html ) {
228 return this.each(function(){
229 jQuery( this ).contents().wrapAll( html );
233 wrap: function( html ) {
234 return this.each(function(){
235 jQuery( this ).wrapAll( html );
240 return this.domManip(arguments, true, function(elem){
241 if (this.nodeType == 1)
242 this.appendChild( elem );
246 prepend: function() {
247 return this.domManip(arguments, true, function(elem){
248 if (this.nodeType == 1)
249 this.insertBefore( elem, this.firstChild );
254 return this.domManip(arguments, false, function(elem){
255 this.parentNode.insertBefore( elem, this );
260 return this.domManip(arguments, false, function(elem){
261 this.parentNode.insertBefore( elem, this.nextSibling );
266 return this.prevObject || jQuery( [] );
269 // For internal use only.
270 // Behaves like an Array's .push method, not like a jQuery method.
273 find: function( selector ) {
274 if ( this.length === 1 && !/,/.test(selector) ) {
275 var ret = this.pushStack( [], "find", selector );
277 jQuery.find( selector, this[0], ret );
280 var elems = jQuery.map(this, function(elem){
281 return jQuery.find( selector, elem );
284 return this.pushStack( /[^+>] [^+>]/.test( selector ) ?
285 jQuery.unique( elems ) :
286 elems, "find", selector );
290 clone: function( events ) {
292 var ret = this.map(function(){
293 if ( !jQuery.support.noCloneEvent && !jQuery.isXMLDoc(this) ) {
294 // IE copies events bound via attachEvent when
295 // using cloneNode. Calling detachEvent on the
296 // clone will also remove the events from the orignal
297 // In order to get around this, we use innerHTML.
298 // Unfortunately, this means some modifications to
299 // attributes in IE that are actually only stored
300 // as properties will not be copied (such as the
301 // the name attribute on an input).
302 var clone = this.cloneNode(true),
303 container = document.createElement("div");
304 container.appendChild(clone);
305 return jQuery.clean([container.innerHTML])[0];
307 return this.cloneNode(true);
310 // Need to set the expando to null on the cloned set if it exists
311 // removeData doesn't work here, IE removes it from the original as well
312 // this is primarily for IE but the data expando shouldn't be copied over in any browser
313 var clone = ret.find("*").andSelf().each(function(){
314 if ( this[ expando ] !== undefined )
315 this[ expando ] = null;
318 // Copy the events from the original to the clone
319 if ( events === true )
320 this.find("*").andSelf().each(function(i){
321 if (this.nodeType == 3)
323 var events = jQuery.data( this, "events" );
325 for ( var type in events )
326 for ( var handler in events[ type ] )
327 jQuery.event.add( clone[ i ], type, events[ type ][ handler ], events[ type ][ handler ].data );
330 // Return the cloned set
334 filter: function( selector ) {
335 return this.pushStack(
336 jQuery.isFunction( selector ) &&
337 jQuery.grep(this, function(elem, i){
338 return selector.call( elem, i );
341 jQuery.multiFilter( selector, jQuery.grep(this, function(elem){
342 return elem.nodeType === 1;
343 }) ), "filter", selector );
346 closest: function( selector ) {
347 var pos = jQuery.expr.match.POS.test( selector ) ? jQuery(selector) : null;
349 return this.map(function(){
351 while ( cur && cur.ownerDocument ) {
352 if ( pos ? pos.index(cur) > -1 : jQuery(cur).is(selector) )
354 cur = cur.parentNode;
359 not: function( selector ) {
360 if ( typeof selector === "string" )
361 // test special case where just one selector is passed in
362 if ( isSimple.test( selector ) )
363 return this.pushStack( jQuery.multiFilter( selector, this, true ), "not", selector );
365 selector = jQuery.multiFilter( selector, this );
367 var isArrayLike = selector.length && selector[selector.length - 1] !== undefined && !selector.nodeType;
368 return this.filter(function() {
369 return isArrayLike ? jQuery.inArray( this, selector ) < 0 : this != selector;
373 add: function( selector ) {
374 return this.pushStack( jQuery.unique( jQuery.merge(
376 typeof selector === "string" ?
378 jQuery.makeArray( selector )
382 is: function( selector ) {
383 return !!selector && jQuery.multiFilter( selector, this ).length > 0;
386 hasClass: function( selector ) {
387 return !!selector && this.is( "." + selector );
390 val: function( value ) {
391 if ( value === undefined ) {
395 if( jQuery.nodeName( elem, 'option' ) )
396 return (elem.attributes.value || {}).specified ? elem.value : elem.text;
398 // We need to handle select boxes special
399 if ( jQuery.nodeName( elem, "select" ) ) {
400 var index = elem.selectedIndex,
402 options = elem.options,
403 one = elem.type == "select-one";
405 // Nothing was selected
409 // Loop through all the selected options
410 for ( var i = one ? index : 0, max = one ? index + 1 : options.length; i < max; i++ ) {
411 var option = options[ i ];
413 if ( option.selected ) {
414 // Get the specifc value for the option
415 value = jQuery(option).val();
417 // We don't need an array for one selects
421 // Multi-Selects return an array
422 values.push( value );
429 // Everything else, we just grab the value
430 return (elem.value || "").replace(/\r/g, "");
437 if ( typeof value === "number" )
440 return this.each(function(){
441 if ( this.nodeType != 1 )
444 if ( jQuery.isArray(value) && /radio|checkbox/.test( this.type ) )
445 this.checked = (jQuery.inArray(this.value, value) >= 0 ||
446 jQuery.inArray(this.name, value) >= 0);
448 else if ( jQuery.nodeName( this, "select" ) ) {
449 var values = jQuery.makeArray(value);
451 jQuery( "option", this ).each(function(){
452 this.selected = (jQuery.inArray( this.value, values ) >= 0 ||
453 jQuery.inArray( this.text, values ) >= 0);
456 if ( !values.length )
457 this.selectedIndex = -1;
464 html: function( value ) {
465 return value === undefined ?
469 this.empty().append( value );
472 replaceWith: function( value ) {
473 return this.after( value ).remove();
477 return this.slice( i, +i + 1 );
481 return this.pushStack( Array.prototype.slice.apply( this, arguments ),
482 "slice", Array.prototype.slice.call(arguments).join(",") );
485 map: function( callback ) {
486 return this.pushStack( jQuery.map(this, function(elem, i){
487 return callback.call( elem, i, elem );
491 andSelf: function() {
492 return this.add( this.prevObject );
495 domManip: function( args, table, callback ) {
497 var fragment = (this[0].ownerDocument || this[0]).createDocumentFragment(),
498 scripts = jQuery.clean( args, (this[0].ownerDocument || this[0]), fragment ),
499 first = fragment.firstChild,
500 extra = this.length > 1 ? fragment.cloneNode(true) : fragment;
503 for ( var i = 0, l = this.length; i < l; i++ )
504 callback.call( root(this[i], first), i > 0 ? extra.cloneNode(true) : fragment );
507 jQuery.each( scripts, evalScript );
512 function root( elem, cur ) {
513 return table && jQuery.nodeName(elem, "table") && jQuery.nodeName(cur, "tr") ?
514 (elem.getElementsByTagName("tbody")[0] ||
515 elem.appendChild(elem.ownerDocument.createElement("tbody"))) :
521 // Give the init function the jQuery prototype for later instantiation
522 jQuery.fn.init.prototype = jQuery.fn;
524 function evalScript( i, elem ) {
533 jQuery.globalEval( elem.text || elem.textContent || elem.innerHTML || "" );
535 if ( elem.parentNode )
536 elem.parentNode.removeChild( elem );
543 jQuery.extend = jQuery.fn.extend = function() {
544 // copy reference to target object
545 var target = arguments[0] || {}, i = 1, length = arguments.length, deep = false, options;
547 // Handle a deep copy situation
548 if ( typeof target === "boolean" ) {
550 target = arguments[1] || {};
551 // skip the boolean and the target
555 // Handle case when target is a string or something (possible in deep copy)
556 if ( typeof target !== "object" && !jQuery.isFunction(target) )
559 // extend jQuery itself if only one argument is passed
565 for ( ; i < length; i++ )
566 // Only deal with non-null/undefined values
567 if ( (options = arguments[ i ]) != null )
568 // Extend the base object
569 for ( var name in options ) {
570 var src = target[ name ], copy = options[ name ];
572 // Prevent never-ending loop
573 if ( target === copy )
576 // Recurse if we're merging object values
577 if ( deep && copy && typeof copy === "object" && !copy.nodeType )
578 target[ name ] = jQuery.extend( deep,
579 // Never move original objects, clone them
580 src || ( copy.length != null ? [ ] : { } )
583 // Don't bring in undefined values
584 else if ( copy !== undefined )
585 target[ name ] = copy;
589 // Return the modified object
593 // exclude the following css properties to add px
594 var exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i,
596 defaultView = document.defaultView || {},
597 toString = Object.prototype.toString;
600 noConflict: function( deep ) {
604 window.jQuery = _jQuery;
609 // See test/unit/core.js for details concerning isFunction.
610 // Since version 1.3, DOM methods and functions like alert
611 // aren't supported. They return false on IE (#2968).
612 isFunction: function( obj ) {
613 return toString.call(obj) === "[object Function]";
616 isArray: function( obj ) {
617 return toString.call(obj) === "[object Array]";
620 // check if an element is in a (or is an) XML document
621 isXMLDoc: function( elem ) {
622 return elem.documentElement && !elem.body ||
623 elem.tagName && elem.ownerDocument && !elem.ownerDocument.body;
626 // Evalulates a script in a global context
627 globalEval: function( data ) {
628 data = jQuery.trim( data );
631 // Inspired by code by Andrea Giammarchi
632 // http://webreflection.blogspot.com/2007/08/global-scope-evaluation-and-dom.html
633 var head = document.getElementsByTagName("head")[0] || document.documentElement,
634 script = document.createElement("script");
636 script.type = "text/javascript";
637 if ( jQuery.support.scriptEval )
638 script.appendChild( document.createTextNode( data ) );
642 // Use insertBefore instead of appendChild to circumvent an IE6 bug.
643 // This arises when a base node is used (#2709).
644 head.insertBefore( script, head.firstChild );
645 head.removeChild( script );
649 nodeName: function( elem, name ) {
650 return elem.nodeName && elem.nodeName.toUpperCase() == name.toUpperCase();
653 // args is for internal usage only
654 each: function( object, callback, args ) {
655 var name, i = 0, length = object.length;
658 if ( length === undefined ) {
659 for ( name in object )
660 if ( callback.apply( object[ name ], args ) === false )
663 for ( ; i < length; )
664 if ( callback.apply( object[ i++ ], args ) === false )
667 // A special, fast, case for the most common use of each
669 if ( length === undefined ) {
670 for ( name in object )
671 if ( callback.call( object[ name ], name, object[ name ] ) === false )
674 for ( var value = object[0];
675 i < length && callback.call( value, i, value ) !== false; value = object[++i] ){}
681 prop: function( elem, value, type, i, name ) {
682 // Handle executable functions
683 if ( jQuery.isFunction( value ) )
684 value = value.call( elem, i );
686 // Handle passing in a number to a CSS property
687 return typeof value === "number" && type == "curCSS" && !exclude.test( name ) ?
693 // internal only, use addClass("class")
694 add: function( elem, classNames ) {
695 jQuery.each((classNames || "").split(/\s+/), function(i, className){
696 if ( elem.nodeType == 1 && !jQuery.className.has( elem.className, className ) )
697 elem.className += (elem.className ? " " : "") + className;
701 // internal only, use removeClass("class")
702 remove: function( elem, classNames ) {
703 if (elem.nodeType == 1)
704 elem.className = classNames !== undefined ?
705 jQuery.grep(elem.className.split(/\s+/), function(className){
706 return !jQuery.className.has( classNames, className );
711 // internal only, use hasClass("class")
712 has: function( elem, className ) {
713 return jQuery.inArray( className, (elem.className || elem).toString().split(/\s+/) ) > -1;
717 // A method for quickly swapping in/out CSS properties to get correct calculations
718 swap: function( elem, options, callback ) {
720 // Remember the old values, and insert the new ones
721 for ( var name in options ) {
722 old[ name ] = elem.style[ name ];
723 elem.style[ name ] = options[ name ];
726 callback.call( elem );
728 // Revert the old values
729 for ( var name in options )
730 elem.style[ name ] = old[ name ];
733 css: function( elem, name, force ) {
734 if ( name == "width" || name == "height" ) {
735 var val, props = { position: "absolute", visibility: "hidden", display:"block" }, which = name == "width" ? [ "Left", "Right" ] : [ "Top", "Bottom" ];
738 val = name == "width" ? elem.offsetWidth : elem.offsetHeight;
739 var padding = 0, border = 0;
740 jQuery.each( which, function() {
741 padding += parseFloat(jQuery.curCSS( elem, "padding" + this, true)) || 0;
742 border += parseFloat(jQuery.curCSS( elem, "border" + this + "Width", true)) || 0;
744 val -= Math.round(padding + border);
747 if ( jQuery(elem).is(":visible") )
750 jQuery.swap( elem, props, getWH );
752 return Math.max(0, val);
755 return jQuery.curCSS( elem, name, force );
758 curCSS: function( elem, name, force ) {
759 var ret, style = elem.style;
761 // We need to handle opacity special in IE
762 if ( name == "opacity" && !jQuery.support.opacity ) {
763 ret = jQuery.attr( style, "opacity" );
770 // Make sure we're using the right name for getting the float value
771 if ( name.match( /float/i ) )
774 if ( !force && style && style[ name ] )
777 else if ( defaultView.getComputedStyle ) {
779 // Only "float" is needed here
780 if ( name.match( /float/i ) )
783 name = name.replace( /([A-Z])/g, "-$1" ).toLowerCase();
785 var computedStyle = defaultView.getComputedStyle( elem, null );
788 ret = computedStyle.getPropertyValue( name );
790 // We should always get a number back from opacity
791 if ( name == "opacity" && ret == "" )
794 } else if ( elem.currentStyle ) {
795 var camelCase = name.replace(/\-(\w)/g, function(all, letter){
796 return letter.toUpperCase();
799 ret = elem.currentStyle[ name ] || elem.currentStyle[ camelCase ];
801 // From the awesome hack by Dean Edwards
802 // http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291
804 // If we're not dealing with a regular pixel number
805 // but a number that has a weird ending, we need to convert it to pixels
806 if ( !/^\d+(px)?$/i.test( ret ) && /^\d/.test( ret ) ) {
807 // Remember the original values
808 var left = style.left, rsLeft = elem.runtimeStyle.left;
810 // Put in the new values to get a computed value out
811 elem.runtimeStyle.left = elem.currentStyle.left;
812 style.left = ret || 0;
813 ret = style.pixelLeft + "px";
815 // Revert the changed values
817 elem.runtimeStyle.left = rsLeft;
824 clean: function( elems, context, fragment ) {
825 context = context || document;
827 // !context.createElement fails in IE with an error but returns typeof 'object'
828 if ( typeof context.createElement === "undefined" )
829 context = context.ownerDocument || context[0] && context[0].ownerDocument || document;
831 // If a single string is passed in and it's a single tag
832 // just do a createElement and skip the rest
833 if ( !fragment && elems.length === 1 && typeof elems[0] === "string" ) {
834 var match = /^<(\w+)\s*\/?>$/.exec(elems[0]);
836 return [ context.createElement( match[1] ) ];
839 var ret = [], scripts = [], div = context.createElement("div");
841 jQuery.each(elems, function(i, elem){
842 if ( typeof elem === "number" )
848 // Convert html string into DOM nodes
849 if ( typeof elem === "string" ) {
850 // Fix "XHTML"-style tags in all browsers
851 elem = elem.replace(/(<(\w+)[^>]*?)\/>/g, function(all, front, tag){
852 return tag.match(/^(abbr|br|col|img|input|link|meta|param|hr|area|embed)$/i) ?
854 front + "></" + tag + ">";
857 // Trim whitespace, otherwise indexOf won't work as expected
858 var tags = jQuery.trim( elem ).toLowerCase();
861 // option or optgroup
862 !tags.indexOf("<opt") &&
863 [ 1, "<select multiple='multiple'>", "</select>" ] ||
865 !tags.indexOf("<leg") &&
866 [ 1, "<fieldset>", "</fieldset>" ] ||
868 tags.match(/^<(thead|tbody|tfoot|colg|cap)/) &&
869 [ 1, "<table>", "</table>" ] ||
871 !tags.indexOf("<tr") &&
872 [ 2, "<table><tbody>", "</tbody></table>" ] ||
874 // <thead> matched above
875 (!tags.indexOf("<td") || !tags.indexOf("<th")) &&
876 [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ] ||
878 !tags.indexOf("<col") &&
879 [ 2, "<table><tbody></tbody><colgroup>", "</colgroup></table>" ] ||
881 // IE can't serialize <link> and <script> tags normally
882 !jQuery.support.htmlSerialize &&
883 [ 1, "div<div>", "</div>" ] ||
887 // Go to html and back, then peel off extra wrappers
888 div.innerHTML = wrap[1] + elem + wrap[2];
890 // Move to the right depth
894 // Remove IE's autoinserted <tbody> from table fragments
895 if ( !jQuery.support.tbody ) {
897 // String was a <table>, *may* have spurious <tbody>
898 var tbody = !tags.indexOf("<table") && tags.indexOf("<tbody") < 0 ?
899 div.firstChild && div.firstChild.childNodes :
901 // String was a bare <thead> or <tfoot>
902 wrap[1] == "<table>" && tags.indexOf("<tbody") < 0 ?
906 for ( var j = tbody.length - 1; j >= 0 ; --j )
907 if ( jQuery.nodeName( tbody[ j ], "tbody" ) && !tbody[ j ].childNodes.length )
908 tbody[ j ].parentNode.removeChild( tbody[ j ] );
912 // IE completely kills leading whitespace when innerHTML is used
913 if ( !jQuery.support.leadingWhitespace && /^\s/.test( elem ) )
914 div.insertBefore( context.createTextNode( elem.match(/^\s*/)[0] ), div.firstChild );
916 elem = jQuery.makeArray( div.childNodes );
922 ret = jQuery.merge( ret, elem );
927 for ( var i = 0; ret[i]; i++ ) {
928 if ( jQuery.nodeName( ret[i], "script" ) && (!ret[i].type || ret[i].type.toLowerCase() === "text/javascript") ) {
929 scripts.push( ret[i].parentNode ? ret[i].parentNode.removeChild( ret[i] ) : ret[i] );
931 if ( ret[i].nodeType === 1 )
932 ret.splice.apply( ret, [i + 1, 0].concat(jQuery.makeArray(ret[i].getElementsByTagName("script"))) );
933 fragment.appendChild( ret[i] );
943 attr: function( elem, name, value ) {
944 // don't set attributes on text and comment nodes
945 if (!elem || elem.nodeType == 3 || elem.nodeType == 8)
948 var notxml = !jQuery.isXMLDoc( elem ),
949 // Whether we are setting (or getting)
950 set = value !== undefined;
952 // Try to normalize/fix the name
953 name = notxml && jQuery.props[ name ] || name;
955 // Only do all the following if this is a node (faster for style)
956 // IE elem.getAttribute passes even for style
957 if ( elem.tagName ) {
959 // These attributes require special treatment
960 var special = /href|src|style/.test( name );
962 // Safari mis-reports the default selected property of a hidden option
963 // Accessing the parent's selectedIndex property fixes it
964 if ( name == "selected" && elem.parentNode )
965 elem.parentNode.selectedIndex;
967 // If applicable, access the attribute via the DOM 0 way
968 if ( name in elem && notxml && !special ) {
970 // We can't allow the type property to be changed (since it causes problems in IE)
971 if ( name == "type" && jQuery.nodeName( elem, "input" ) && elem.parentNode )
972 throw "type property can't be changed";
974 elem[ name ] = value;
977 // browsers index elements by id/name on forms, give priority to attributes.
978 if( jQuery.nodeName( elem, "form" ) && elem.getAttributeNode(name) )
979 return elem.getAttributeNode( name ).nodeValue;
981 // elem.tabIndex doesn't always return the correct value when it hasn't been explicitly set
982 // http://fluidproject.org/blog/2008/01/09/getting-setting-and-removing-tabindex-values-with-javascript/
983 if ( name == "tabIndex" ) {
984 var attributeNode = elem.getAttributeNode( "tabIndex" );
985 return attributeNode && attributeNode.specified
986 ? attributeNode.value
987 : elem.nodeName.match(/^(a|area|button|input|object|select|textarea)$/i)
995 if ( !jQuery.support.style && notxml && name == "style" )
996 return jQuery.attr( elem.style, "cssText", value );
999 // convert the value to a string (all browsers do this but IE) see #1070
1000 elem.setAttribute( name, "" + value );
1002 var attr = !jQuery.support.hrefNormalized && notxml && special
1003 // Some attributes require a special call on IE
1004 ? elem.getAttribute( name, 2 )
1005 : elem.getAttribute( name );
1007 // Non-existent attributes return null, we normalize to undefined
1008 return attr === null ? undefined : attr;
1011 // elem is actually elem.style ... set the style
1013 // IE uses filters for opacity
1014 if ( !jQuery.support.opacity && name == "opacity" ) {
1016 // IE has trouble with opacity if it does not have layout
1017 // Force it by setting the zoom level
1020 // Set the alpha filter to set the opacity
1021 elem.filter = (elem.filter || "").replace( /alpha\([^)]*\)/, "" ) +
1022 (parseInt( value ) + '' == "NaN" ? "" : "alpha(opacity=" + value * 100 + ")");
1025 return elem.filter && elem.filter.indexOf("opacity=") >= 0 ?
1026 (parseFloat( elem.filter.match(/opacity=([^)]*)/)[1] ) / 100) + '':
1030 name = name.replace(/-([a-z])/ig, function(all, letter){
1031 return letter.toUpperCase();
1035 elem[ name ] = value;
1037 return elem[ name ];
1040 trim: function( text ) {
1041 return (text || "").replace( /^\s+|\s+$/g, "" );
1044 makeArray: function( array ) {
1047 if( array != null ){
1048 var i = array.length;
1049 // The window, strings (and functions) also have 'length'
1050 if( i == null || typeof array === "string" || jQuery.isFunction(array) || array.setInterval )
1054 ret[--i] = array[i];
1060 inArray: function( elem, array ) {
1061 for ( var i = 0, length = array.length; i < length; i++ )
1062 // Use === because on IE, window == document
1063 if ( array[ i ] === elem )
1069 merge: function( first, second ) {
1070 // We have to loop this way because IE & Opera overwrite the length
1071 // expando of getElementsByTagName
1072 var i = 0, elem, pos = first.length;
1073 // Also, we need to make sure that the correct elements are being returned
1074 // (IE returns comment nodes in a '*' query)
1075 if ( !jQuery.support.getAll ) {
1076 while ( (elem = second[ i++ ]) != null )
1077 if ( elem.nodeType != 8 )
1078 first[ pos++ ] = elem;
1081 while ( (elem = second[ i++ ]) != null )
1082 first[ pos++ ] = elem;
1087 unique: function( array ) {
1088 var ret = [], done = {};
1092 for ( var i = 0, length = array.length; i < length; i++ ) {
1093 var id = jQuery.data( array[ i ] );
1095 if ( !done[ id ] ) {
1097 ret.push( array[ i ] );
1108 grep: function( elems, callback, inv ) {
1111 // Go through the array, only saving the items
1112 // that pass the validator function
1113 for ( var i = 0, length = elems.length; i < length; i++ )
1114 if ( !inv != !callback( elems[ i ], i ) )
1115 ret.push( elems[ i ] );
1120 map: function( elems, callback ) {
1123 // Go through the array, translating each of the items to their
1124 // new value (or values).
1125 for ( var i = 0, length = elems.length; i < length; i++ ) {
1126 var value = callback( elems[ i ], i );
1128 if ( value != null )
1129 ret[ ret.length ] = value;
1132 return ret.concat.apply( [], ret );
1136 // Use of jQuery.browser is deprecated.
1137 // It's included for backwards compatibility and plugins,
1138 // although they should work to migrate away.
1140 var userAgent = navigator.userAgent.toLowerCase();
1142 // Figure out what browser is being used
1144 version: (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [0,'0'])[1],
1145 safari: /webkit/.test( userAgent ),
1146 opera: /opera/.test( userAgent ),
1147 msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
1148 mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )
1152 parent: function(elem){return elem.parentNode;},
1153 parents: function(elem){return jQuery.dir(elem,"parentNode");},
1154 next: function(elem){return jQuery.nth(elem,2,"nextSibling");},
1155 prev: function(elem){return jQuery.nth(elem,2,"previousSibling");},
1156 nextAll: function(elem){return jQuery.dir(elem,"nextSibling");},
1157 prevAll: function(elem){return jQuery.dir(elem,"previousSibling");},
1158 siblings: function(elem){return jQuery.sibling(elem.parentNode.firstChild,elem);},
1159 children: function(elem){return jQuery.sibling(elem.firstChild);},
1160 contents: function(elem){return jQuery.nodeName(elem,"iframe")?elem.contentDocument||elem.contentWindow.document:jQuery.makeArray(elem.childNodes);}
1161 }, function(name, fn){
1162 jQuery.fn[ name ] = function( selector ) {
1163 var ret = jQuery.map( this, fn );
1165 if ( selector && typeof selector == "string" )
1166 ret = jQuery.multiFilter( selector, ret );
1168 return this.pushStack( jQuery.unique( ret ), name, selector );
1174 prependTo: "prepend",
1175 insertBefore: "before",
1176 insertAfter: "after",
1177 replaceAll: "replaceWith"
1178 }, function(name, original){
1179 jQuery.fn[ name ] = function() {
1180 var args = arguments;
1182 return this.each(function(){
1183 for ( var i = 0, length = args.length; i < length; i++ )
1184 jQuery( args[ i ] )[ original ]( this );
1190 removeAttr: function( name ) {
1191 jQuery.attr( this, name, "" );
1192 if (this.nodeType == 1)
1193 this.removeAttribute( name );
1196 addClass: function( classNames ) {
1197 jQuery.className.add( this, classNames );
1200 removeClass: function( classNames ) {
1201 jQuery.className.remove( this, classNames );
1204 toggleClass: function( classNames, state ) {
1205 if( typeof state !== "boolean" )
1206 state = !jQuery.className.has( this, classNames );
1207 jQuery.className[ state ? "add" : "remove" ]( this, classNames );
1210 remove: function( selector ) {
1211 if ( !selector || jQuery.filter( selector, [ this ] ).length ) {
1212 // Prevent memory leaks
1213 jQuery( "*", this ).add([this]).each(function(){
1214 jQuery.event.remove(this);
1215 jQuery.removeData(this);
1217 if (this.parentNode)
1218 this.parentNode.removeChild( this );
1223 // Remove element nodes and prevent memory leaks
1224 jQuery( ">*", this ).remove();
1226 // Remove any remaining nodes
1227 while ( this.firstChild )
1228 this.removeChild( this.firstChild );
1230 }, function(name, fn){
1231 jQuery.fn[ name ] = function(){
1232 return this.each( fn, arguments );
1236 // Helper function used by the dimensions and offset modules
1237 function num(elem, prop) {
1238 return elem[0] && parseInt( jQuery.curCSS(elem[0], prop, true), 10 ) || 0;