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 // Map over jQuery in case of overwrite
13 var _jQuery = window.jQuery,
14 // Map over the $ in case of overwrite
17 var jQuery = window.jQuery = window.$ = function( selector, context ) {
18 // The jQuery object is actually just the init constructor 'enhanced'
19 return new jQuery.fn.init( selector, context );
22 // A simple way to check for HTML strings or ID strings
23 // (both of which we optimize for)
24 var quickExpr = /^[^<]*(<(.|\s)+>)[^>]*$|^#([\w-]+)$/,
26 // Is it a simple selector
27 isSimple = /^.[^:#\[\.,]*$/,
29 // Will speed up references to undefined, and allows munging its name.
32 jQuery.fn = jQuery.prototype = {
33 init: function( selector, context ) {
34 // Make sure that a selection was provided
35 selector = selector || document;
37 // Handle $(DOMElement)
38 if ( selector.nodeType ) {
41 this.context = selector;
44 // Handle HTML strings
45 if ( typeof selector === "string" ) {
46 // Are we dealing with HTML string or an ID?
47 var match = quickExpr.exec( selector );
49 // Verify a match, and that no context was specified for #id
50 if ( match && (match[1] || !context) ) {
52 // HANDLE: $(html) -> $(array)
54 selector = jQuery.clean( [ match[1] ], context );
58 var elem = document.getElementById( match[3] );
60 // Make sure an element was located
62 // Handle the case where IE and Opera return items
63 // by name instead of ID
64 if ( elem.id != match[3] )
65 return jQuery().find( selector );
67 // Otherwise, we inject the element directly into the jQuery object
68 var ret = jQuery( elem );
69 ret.context = document;
70 ret.selector = selector;
76 // HANDLE: $(expr, [context])
77 // (which is just equivalent to: $(content).find(expr)
79 return jQuery( context ).find( selector );
81 // HANDLE: $(function)
82 // Shortcut for document ready
83 } else if ( jQuery.isFunction( selector ) )
84 return jQuery( document ).ready( selector );
86 return this.setArray(jQuery.makeArray(selector));
89 // Start with an empty selector
92 // The current version of jQuery being used
95 // The number of elements contained in the matched element set
100 // Get the Nth element in the matched element set OR
101 // Get the whole matched element set as a clean array
102 get: function( num ) {
103 return num === undefined ?
105 // Return a 'clean' array
106 jQuery.makeArray( this ) :
108 // Return just the object
112 // Take an array of elements and push it onto the stack
113 // (returning the new matched element set)
114 pushStack: function( elems, name, selector ) {
115 // Build a new jQuery matched element set
116 var ret = jQuery( elems );
118 // Add the old object onto the stack (as a reference)
119 ret.prevObject = this;
121 ret.context = this.context;
123 if ( name === "find" )
124 ret.selector = this.selector + (this.selector ? " " : "") + selector;
126 ret.selector = this.selector + "." + name + "(" + selector + ")";
128 // Return the newly-formed element set
132 // Force the current matched set of elements to become
133 // the specified array of elements (destroying the stack in the process)
134 // You should use pushStack() in order to do this, but maintain the stack
135 setArray: function( elems ) {
136 // Resetting the length to 0, then using the native Array push
137 // is a super-fast way to populate an object with array-like properties
139 Array.prototype.push.apply( this, elems );
144 // Execute a callback for every element in the matched set.
145 // (You can seed the arguments with an array of args, but this is
146 // only used internally.)
147 each: function( callback, args ) {
148 return jQuery.each( this, callback, args );
151 // Determine the position of an element within
152 // the matched set of elements
153 index: function( elem ) {
154 // Locate the position of the desired element
155 return jQuery.inArray(
156 // If it receives a jQuery object, the first element is used
157 elem && elem.jquery ? elem[0] : elem
161 attr: function( name, value, type ) {
164 // Look for the case where we're accessing a style value
165 if ( typeof name === "string" )
166 if ( value === undefined )
167 return this[0] && jQuery[ type || "attr" ]( this[0], name );
171 options[ name ] = value;
174 // Check to see if we're setting style values
175 return this.each(function(i){
176 // Set all the styles
177 for ( name in options )
182 name, jQuery.prop( this, options[ name ], type, i, name )
187 css: function( key, value ) {
188 // ignore negative width and height values
189 if ( (key == 'width' || key == 'height') && parseFloat(value) < 0 )
191 return this.attr( key, value, "curCSS" );
194 text: function( text ) {
195 if ( typeof text !== "object" && text != null )
196 return this.empty().append( (this[0] && this[0].ownerDocument || document).createTextNode( text ) );
200 jQuery.each( text || this, function(){
201 jQuery.each( this.childNodes, function(){
202 if ( this.nodeType != 8 )
203 ret += this.nodeType != 1 ?
205 jQuery.fn.text( [ this ] );
212 wrapAll: function( html ) {
214 // The elements to wrap the target around
215 jQuery( html, this[0].ownerDocument )
217 .insertBefore( this[0] )
221 while ( elem.firstChild )
222 elem = elem.firstChild;
231 wrapInner: function( html ) {
232 return this.each(function(){
233 jQuery( this ).contents().wrapAll( html );
237 wrap: function( html ) {
238 return this.each(function(){
239 jQuery( this ).wrapAll( html );
244 return this.domManip(arguments, true, function(elem){
245 if (this.nodeType == 1)
246 this.appendChild( elem );
250 prepend: function() {
251 return this.domManip(arguments, true, function(elem){
252 if (this.nodeType == 1)
253 this.insertBefore( elem, this.firstChild );
258 return this.domManip(arguments, false, function(elem){
259 this.parentNode.insertBefore( elem, this );
264 return this.domManip(arguments, false, function(elem){
265 this.parentNode.insertBefore( elem, this.nextSibling );
270 return this.prevObject || jQuery( [] );
273 find: function( selector ) {
274 var elems = jQuery.map(this, function(elem){
275 return jQuery.find( selector, elem );
278 return this.pushStack( /[^+>] [^+>]/.test( selector ) ?
279 jQuery.unique( elems ) :
280 elems, "find", selector );
283 clone: function( events ) {
285 var ret = this.map(function(){
286 if ( !jQuery.support.noCloneEvent && !jQuery.isXMLDoc(this) ) {
287 // IE copies events bound via attachEvent when
288 // using cloneNode. Calling detachEvent on the
289 // clone will also remove the events from the orignal
290 // In order to get around this, we use innerHTML.
291 // Unfortunately, this means some modifications to
292 // attributes in IE that are actually only stored
293 // as properties will not be copied (such as the
294 // the name attribute on an input).
295 var clone = this.cloneNode(true),
296 container = document.createElement("div");
297 container.appendChild(clone);
298 return jQuery.clean([container.innerHTML])[0];
300 return this.cloneNode(true);
303 // Need to set the expando to null on the cloned set if it exists
304 // removeData doesn't work here, IE removes it from the original as well
305 // this is primarily for IE but the data expando shouldn't be copied over in any browser
306 var clone = ret.find("*").andSelf().each(function(){
307 if ( this[ expando ] !== undefined )
308 this[ expando ] = null;
311 // Copy the events from the original to the clone
312 if ( events === true )
313 this.find("*").andSelf().each(function(i){
314 if (this.nodeType == 3)
316 var events = jQuery.data( this, "events" );
318 for ( var type in events )
319 for ( var handler in events[ type ] )
320 jQuery.event.add( clone[ i ], type, events[ type ][ handler ], events[ type ][ handler ].data );
323 // Return the cloned set
327 filter: function( selector ) {
328 return this.pushStack(
329 jQuery.isFunction( selector ) &&
330 jQuery.grep(this, function(elem, i){
331 return selector.call( elem, i );
334 jQuery.multiFilter( selector, jQuery.grep(this, function(elem){
335 return elem.nodeType === 1;
336 }) ), "filter", selector );
339 closest: function( selector ) {
340 return this.map(function(){
342 while ( cur && cur.ownerDocument ) {
343 if ( jQuery(cur).is(selector) )
345 cur = cur.parentNode;
350 not: function( selector ) {
351 if ( typeof selector === "string" )
352 // test special case where just one selector is passed in
353 if ( isSimple.test( selector ) )
354 return this.pushStack( jQuery.multiFilter( selector, this, true ), "not", selector );
356 selector = jQuery.multiFilter( selector, this );
358 var isArrayLike = selector.length && selector[selector.length - 1] !== undefined && !selector.nodeType;
359 return this.filter(function() {
360 return isArrayLike ? jQuery.inArray( this, selector ) < 0 : this != selector;
364 add: function( selector ) {
365 return this.pushStack( jQuery.unique( jQuery.merge(
367 typeof selector === "string" ?
369 jQuery.makeArray( selector )
373 is: function( selector ) {
374 return !!selector && jQuery.multiFilter( selector, this ).length > 0;
377 hasClass: function( selector ) {
378 return !!selector && this.is( "." + selector );
381 val: function( value ) {
382 if ( value === undefined ) {
386 if( jQuery.nodeName( elem, 'option' ) )
387 return (elem.attributes.value || {}).specified ? elem.value : elem.text;
389 // We need to handle select boxes special
390 if ( jQuery.nodeName( elem, "select" ) ) {
391 var index = elem.selectedIndex,
393 options = elem.options,
394 one = elem.type == "select-one";
396 // Nothing was selected
400 // Loop through all the selected options
401 for ( var i = one ? index : 0, max = one ? index + 1 : options.length; i < max; i++ ) {
402 var option = options[ i ];
404 if ( option.selected ) {
405 // Get the specifc value for the option
406 value = jQuery(option).val();
408 // We don't need an array for one selects
412 // Multi-Selects return an array
413 values.push( value );
420 // Everything else, we just grab the value
421 return (elem.value || "").replace(/\r/g, "");
428 if ( typeof value === "number" )
431 return this.each(function(){
432 if ( this.nodeType != 1 )
435 if ( jQuery.isArray(value) && /radio|checkbox/.test( this.type ) )
436 this.checked = (jQuery.inArray(this.value, value) >= 0 ||
437 jQuery.inArray(this.name, value) >= 0);
439 else if ( jQuery.nodeName( this, "select" ) ) {
440 var values = jQuery.makeArray(value);
442 jQuery( "option", this ).each(function(){
443 this.selected = (jQuery.inArray( this.value, values ) >= 0 ||
444 jQuery.inArray( this.text, values ) >= 0);
447 if ( !values.length )
448 this.selectedIndex = -1;
455 html: function( value ) {
456 return value === undefined ?
460 this.empty().append( value );
463 replaceWith: function( value ) {
464 return this.after( value ).remove();
468 return this.slice( i, +i + 1 );
472 return this.pushStack( Array.prototype.slice.apply( this, arguments ),
473 "slice", Array.prototype.slice.call(arguments).join(",") );
476 map: function( callback ) {
477 return this.pushStack( jQuery.map(this, function(elem, i){
478 return callback.call( elem, i, elem );
482 andSelf: function() {
483 return this.add( this.prevObject );
486 domManip: function( args, table, callback ) {
488 var fragment = this[0].ownerDocument.createDocumentFragment(),
489 scripts = jQuery.clean( args, this[0].ownerDocument, fragment ),
490 first = fragment.firstChild,
491 extra = this.length > 1 ? fragment.cloneNode(true) : fragment;
494 for ( var i = 0, l = this.length; i < l; i++ )
495 callback.call( root(this[i], first), i > 0 ? extra.cloneNode(true) : fragment );
498 jQuery.each( scripts, evalScript );
503 function root( elem, cur ) {
504 return table && jQuery.nodeName(elem, "table") && jQuery.nodeName(cur, "tr") ?
505 (elem.getElementsByTagName("tbody")[0] ||
506 elem.appendChild(elem.ownerDocument.createElement("tbody"))) :
512 // Give the init function the jQuery prototype for later instantiation
513 jQuery.fn.init.prototype = jQuery.fn;
515 function evalScript( i, elem ) {
524 jQuery.globalEval( elem.text || elem.textContent || elem.innerHTML || "" );
526 if ( elem.parentNode )
527 elem.parentNode.removeChild( elem );
534 jQuery.extend = jQuery.fn.extend = function() {
535 // copy reference to target object
536 var target = arguments[0] || {}, i = 1, length = arguments.length, deep = false, options;
538 // Handle a deep copy situation
539 if ( typeof target === "boolean" ) {
541 target = arguments[1] || {};
542 // skip the boolean and the target
546 // Handle case when target is a string or something (possible in deep copy)
547 if ( typeof target !== "object" && !jQuery.isFunction(target) )
550 // extend jQuery itself if only one argument is passed
556 for ( ; i < length; i++ )
557 // Only deal with non-null/undefined values
558 if ( (options = arguments[ i ]) != null )
559 // Extend the base object
560 for ( var name in options ) {
561 var src = target[ name ], copy = options[ name ];
563 // Prevent never-ending loop
564 if ( target === copy )
567 // Recurse if we're merging object values
568 if ( deep && copy && typeof copy === "object" && !copy.nodeType )
569 target[ name ] = jQuery.extend( deep,
570 // Never move original objects, clone them
571 src || ( copy.length != null ? [ ] : { } )
574 // Don't bring in undefined values
575 else if ( copy !== undefined )
576 target[ name ] = copy;
580 // Return the modified object
584 // exclude the following css properties to add px
585 var exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i,
587 defaultView = document.defaultView || {},
588 toString = Object.prototype.toString;
591 noConflict: function( deep ) {
595 window.jQuery = _jQuery;
600 // See test/unit/core.js for details concerning isFunction.
601 // Since version 1.3, DOM methods and functions like alert
602 // aren't supported. They return false on IE (#2968).
603 isFunction: function( obj ) {
604 return toString.call(obj) === "[object Function]";
607 isArray: function( obj ) {
608 return toString.call(obj) === "[object Array]";
611 // check if an element is in a (or is an) XML document
612 isXMLDoc: function( elem ) {
613 return elem.documentElement && !elem.body ||
614 elem.tagName && elem.ownerDocument && !elem.ownerDocument.body;
617 // Evalulates a script in a global context
618 globalEval: function( data ) {
619 data = jQuery.trim( data );
622 // Inspired by code by Andrea Giammarchi
623 // http://webreflection.blogspot.com/2007/08/global-scope-evaluation-and-dom.html
624 var head = document.getElementsByTagName("head")[0] || document.documentElement,
625 script = document.createElement("script");
627 script.type = "text/javascript";
628 if ( jQuery.support.scriptEval )
629 script.appendChild( document.createTextNode( data ) );
633 // Use insertBefore instead of appendChild to circumvent an IE6 bug.
634 // This arises when a base node is used (#2709).
635 head.insertBefore( script, head.firstChild );
636 head.removeChild( script );
640 nodeName: function( elem, name ) {
641 return elem.nodeName && elem.nodeName.toUpperCase() == name.toUpperCase();
644 // args is for internal usage only
645 each: function( object, callback, args ) {
646 var name, i = 0, length = object.length;
649 if ( length === undefined ) {
650 for ( name in object )
651 if ( callback.apply( object[ name ], args ) === false )
654 for ( ; i < length; )
655 if ( callback.apply( object[ i++ ], args ) === false )
658 // A special, fast, case for the most common use of each
660 if ( length === undefined ) {
661 for ( name in object )
662 if ( callback.call( object[ name ], name, object[ name ] ) === false )
665 for ( var value = object[0];
666 i < length && callback.call( value, i, value ) !== false; value = object[++i] ){}
672 prop: function( elem, value, type, i, name ) {
673 // Handle executable functions
674 if ( jQuery.isFunction( value ) )
675 value = value.call( elem, i );
677 // Handle passing in a number to a CSS property
678 return typeof value === "number" && type == "curCSS" && !exclude.test( name ) ?
684 // internal only, use addClass("class")
685 add: function( elem, classNames ) {
686 jQuery.each((classNames || "").split(/\s+/), function(i, className){
687 if ( elem.nodeType == 1 && !jQuery.className.has( elem.className, className ) )
688 elem.className += (elem.className ? " " : "") + className;
692 // internal only, use removeClass("class")
693 remove: function( elem, classNames ) {
694 if (elem.nodeType == 1)
695 elem.className = classNames !== undefined ?
696 jQuery.grep(elem.className.split(/\s+/), function(className){
697 return !jQuery.className.has( classNames, className );
702 // internal only, use hasClass("class")
703 has: function( elem, className ) {
704 return jQuery.inArray( className, (elem.className || elem).toString().split(/\s+/) ) > -1;
708 // A method for quickly swapping in/out CSS properties to get correct calculations
709 swap: function( elem, options, callback ) {
711 // Remember the old values, and insert the new ones
712 for ( var name in options ) {
713 old[ name ] = elem.style[ name ];
714 elem.style[ name ] = options[ name ];
717 callback.call( elem );
719 // Revert the old values
720 for ( var name in options )
721 elem.style[ name ] = old[ name ];
724 css: function( elem, name, force ) {
725 if ( name == "width" || name == "height" ) {
726 var val, props = { position: "absolute", visibility: "hidden", display:"block" }, which = name == "width" ? [ "Left", "Right" ] : [ "Top", "Bottom" ];
729 val = name == "width" ? elem.offsetWidth : elem.offsetHeight;
730 var padding = 0, border = 0;
731 jQuery.each( which, function() {
732 padding += parseFloat(jQuery.curCSS( elem, "padding" + this, true)) || 0;
733 border += parseFloat(jQuery.curCSS( elem, "border" + this + "Width", true)) || 0;
735 val -= Math.round(padding + border);
738 if ( jQuery(elem).is(":visible") )
741 jQuery.swap( elem, props, getWH );
743 return Math.max(0, val);
746 return jQuery.curCSS( elem, name, force );
749 curCSS: function( elem, name, force ) {
750 var ret, style = elem.style;
752 // We need to handle opacity special in IE
753 if ( name == "opacity" && !jQuery.support.opacity ) {
754 ret = jQuery.attr( style, "opacity" );
761 // Make sure we're using the right name for getting the float value
762 if ( name.match( /float/i ) )
765 if ( !force && style && style[ name ] )
768 else if ( defaultView.getComputedStyle ) {
770 // Only "float" is needed here
771 if ( name.match( /float/i ) )
774 name = name.replace( /([A-Z])/g, "-$1" ).toLowerCase();
776 var computedStyle = defaultView.getComputedStyle( elem, null );
779 ret = computedStyle.getPropertyValue( name );
781 // We should always get a number back from opacity
782 if ( name == "opacity" && ret == "" )
785 } else if ( elem.currentStyle ) {
786 var camelCase = name.replace(/\-(\w)/g, function(all, letter){
787 return letter.toUpperCase();
790 ret = elem.currentStyle[ name ] || elem.currentStyle[ camelCase ];
792 // From the awesome hack by Dean Edwards
793 // http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291
795 // If we're not dealing with a regular pixel number
796 // but a number that has a weird ending, we need to convert it to pixels
797 if ( !/^\d+(px)?$/i.test( ret ) && /^\d/.test( ret ) ) {
798 // Remember the original values
799 var left = style.left, rsLeft = elem.runtimeStyle.left;
801 // Put in the new values to get a computed value out
802 elem.runtimeStyle.left = elem.currentStyle.left;
803 style.left = ret || 0;
804 ret = style.pixelLeft + "px";
806 // Revert the changed values
808 elem.runtimeStyle.left = rsLeft;
815 clean: function( elems, context, fragment ) {
816 context = context || document;
818 // !context.createElement fails in IE with an error but returns typeof 'object'
819 if ( typeof context.createElement === "undefined" )
820 context = context.ownerDocument || context[0] && context[0].ownerDocument || document;
822 var ret = [], scripts = [], div = context.createElement("div");
824 jQuery.each(elems, function(i, elem){
825 if ( typeof elem === "number" )
831 // Convert html string into DOM nodes
832 if ( typeof elem === "string" ) {
833 // Fix "XHTML"-style tags in all browsers
834 elem = elem.replace(/(<(\w+)[^>]*?)\/>/g, function(all, front, tag){
835 return tag.match(/^(abbr|br|col|img|input|link|meta|param|hr|area|embed)$/i) ?
837 front + "></" + tag + ">";
840 // Trim whitespace, otherwise indexOf won't work as expected
841 var tags = jQuery.trim( elem ).toLowerCase();
844 // option or optgroup
845 !tags.indexOf("<opt") &&
846 [ 1, "<select multiple='multiple'>", "</select>" ] ||
848 !tags.indexOf("<leg") &&
849 [ 1, "<fieldset>", "</fieldset>" ] ||
851 tags.match(/^<(thead|tbody|tfoot|colg|cap)/) &&
852 [ 1, "<table>", "</table>" ] ||
854 !tags.indexOf("<tr") &&
855 [ 2, "<table><tbody>", "</tbody></table>" ] ||
857 // <thead> matched above
858 (!tags.indexOf("<td") || !tags.indexOf("<th")) &&
859 [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ] ||
861 !tags.indexOf("<col") &&
862 [ 2, "<table><tbody></tbody><colgroup>", "</colgroup></table>" ] ||
864 // IE can't serialize <link> and <script> tags normally
865 !jQuery.support.htmlSerialize &&
866 [ 1, "div<div>", "</div>" ] ||
870 // Go to html and back, then peel off extra wrappers
871 div.innerHTML = wrap[1] + elem + wrap[2];
873 // Move to the right depth
877 // Remove IE's autoinserted <tbody> from table fragments
878 if ( !jQuery.support.tbody ) {
880 // String was a <table>, *may* have spurious <tbody>
881 var tbody = !tags.indexOf("<table") && tags.indexOf("<tbody") < 0 ?
882 div.firstChild && div.firstChild.childNodes :
884 // String was a bare <thead> or <tfoot>
885 wrap[1] == "<table>" && tags.indexOf("<tbody") < 0 ?
889 for ( var j = tbody.length - 1; j >= 0 ; --j )
890 if ( jQuery.nodeName( tbody[ j ], "tbody" ) && !tbody[ j ].childNodes.length )
891 tbody[ j ].parentNode.removeChild( tbody[ j ] );
895 // IE completely kills leading whitespace when innerHTML is used
896 if ( !jQuery.support.leadingWhitespace && /^\s/.test( elem ) )
897 div.insertBefore( context.createTextNode( elem.match(/^\s*/)[0] ), div.firstChild );
900 var found = div.getElementsByTagName("script");
902 while ( found.length ) {
903 scripts.push( found[0] );
904 found[0].parentNode.removeChild( found[0] );
908 elem = jQuery.makeArray( div.childNodes );
914 ret = jQuery.merge( ret, elem );
922 for ( var i = 0; ret[i]; i++ ) {
924 if ( jQuery.nodeName( node, "script" ) ) {
925 if( node.parentNode )
926 node.parentNode.removeChild( node );
928 if ( node.nodeType === 1 )
929 ret = jQuery.merge( ret, node.getElementsByTagName("script"));
930 fragment.appendChild( node );
940 attr: function( elem, name, value ) {
941 // don't set attributes on text and comment nodes
942 if (!elem || elem.nodeType == 3 || elem.nodeType == 8)
945 var notxml = !jQuery.isXMLDoc( elem ),
946 // Whether we are setting (or getting)
947 set = value !== undefined;
949 // Try to normalize/fix the name
950 name = notxml && jQuery.props[ name ] || name;
952 // Only do all the following if this is a node (faster for style)
953 // IE elem.getAttribute passes even for style
954 if ( elem.tagName ) {
956 // These attributes require special treatment
957 var special = /href|src|style/.test( name );
959 // Safari mis-reports the default selected property of a hidden option
960 // Accessing the parent's selectedIndex property fixes it
961 if ( name == "selected" )
962 elem.parentNode.selectedIndex;
964 // If applicable, access the attribute via the DOM 0 way
965 if ( name in elem && notxml && !special ) {
967 // We can't allow the type property to be changed (since it causes problems in IE)
968 if ( name == "type" && jQuery.nodeName( elem, "input" ) && elem.parentNode )
969 throw "type property can't be changed";
971 elem[ name ] = value;
974 // browsers index elements by id/name on forms, give priority to attributes.
975 if( jQuery.nodeName( elem, "form" ) && elem.getAttributeNode(name) )
976 return elem.getAttributeNode( name ).nodeValue;
981 if ( !jQuery.support.style && notxml && name == "style" )
982 return jQuery.attr( elem.style, "cssText", value );
985 // convert the value to a string (all browsers do this but IE) see #1070
986 elem.setAttribute( name, "" + value );
988 var attr = !jQuery.support.hrefNormalized && notxml && special
989 // Some attributes require a special call on IE
990 ? elem.getAttribute( name, 2 )
991 : elem.getAttribute( name );
993 // Non-existent attributes return null, we normalize to undefined
994 return attr === null ? undefined : attr;
997 // elem is actually elem.style ... set the style
999 // IE uses filters for opacity
1000 if ( !jQuery.support.opacity && name == "opacity" ) {
1002 // IE has trouble with opacity if it does not have layout
1003 // Force it by setting the zoom level
1006 // Set the alpha filter to set the opacity
1007 elem.filter = (elem.filter || "").replace( /alpha\([^)]*\)/, "" ) +
1008 (parseInt( value ) + '' == "NaN" ? "" : "alpha(opacity=" + value * 100 + ")");
1011 return elem.filter && elem.filter.indexOf("opacity=") >= 0 ?
1012 (parseFloat( elem.filter.match(/opacity=([^)]*)/)[1] ) / 100) + '':
1016 name = name.replace(/-([a-z])/ig, function(all, letter){
1017 return letter.toUpperCase();
1021 elem[ name ] = value;
1023 return elem[ name ];
1026 trim: function( text ) {
1027 return (text || "").replace( /^\s+|\s+$/g, "" );
1030 makeArray: function( array ) {
1033 if( array != null ){
1034 var i = array.length;
1035 // The window, strings (and functions) also have 'length'
1036 if( i == null || typeof array === "string" || jQuery.isFunction(array) || array.setInterval )
1040 ret[--i] = array[i];
1046 inArray: function( elem, array ) {
1047 for ( var i = 0, length = array.length; i < length; i++ )
1048 // Use === because on IE, window == document
1049 if ( array[ i ] === elem )
1055 merge: function( first, second ) {
1056 // We have to loop this way because IE & Opera overwrite the length
1057 // expando of getElementsByTagName
1058 var i = 0, elem, pos = first.length;
1059 // Also, we need to make sure that the correct elements are being returned
1060 // (IE returns comment nodes in a '*' query)
1061 if ( !jQuery.support.getAll ) {
1062 while ( (elem = second[ i++ ]) != null )
1063 if ( elem.nodeType != 8 )
1064 first[ pos++ ] = elem;
1067 while ( (elem = second[ i++ ]) != null )
1068 first[ pos++ ] = elem;
1073 unique: function( array ) {
1074 var ret = [], done = {};
1078 for ( var i = 0, length = array.length; i < length; i++ ) {
1079 var id = jQuery.data( array[ i ] );
1081 if ( !done[ id ] ) {
1083 ret.push( array[ i ] );
1094 grep: function( elems, callback, inv ) {
1097 // Go through the array, only saving the items
1098 // that pass the validator function
1099 for ( var i = 0, length = elems.length; i < length; i++ )
1100 if ( !inv != !callback( elems[ i ], i ) )
1101 ret.push( elems[ i ] );
1106 map: function( elems, callback ) {
1109 // Go through the array, translating each of the items to their
1110 // new value (or values).
1111 for ( var i = 0, length = elems.length; i < length; i++ ) {
1112 var value = callback( elems[ i ], i );
1114 if ( value != null )
1115 ret[ ret.length ] = value;
1118 return ret.concat.apply( [], ret );
1122 // Use of jQuery.browser is deprecated.
1123 // It's included for backwards compatibility and plugins,
1124 // although they should work to migrate away.
1126 var userAgent = navigator.userAgent.toLowerCase();
1128 // Figure out what browser is being used
1130 version: (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [0,'0'])[1],
1131 safari: /webkit/.test( userAgent ),
1132 opera: /opera/.test( userAgent ),
1133 msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
1134 mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )
1137 // Check to see if the W3C box model is being used
1138 jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
1141 parent: function(elem){return elem.parentNode;},
1142 parents: function(elem){return jQuery.dir(elem,"parentNode");},
1143 next: function(elem){return jQuery.nth(elem,2,"nextSibling");},
1144 prev: function(elem){return jQuery.nth(elem,2,"previousSibling");},
1145 nextAll: function(elem){return jQuery.dir(elem,"nextSibling");},
1146 prevAll: function(elem){return jQuery.dir(elem,"previousSibling");},
1147 siblings: function(elem){return jQuery.sibling(elem.parentNode.firstChild,elem);},
1148 children: function(elem){return jQuery.sibling(elem.firstChild);},
1149 contents: function(elem){return jQuery.nodeName(elem,"iframe")?elem.contentDocument||elem.contentWindow.document:jQuery.makeArray(elem.childNodes);}
1150 }, function(name, fn){
1151 jQuery.fn[ name ] = function( selector ) {
1152 var ret = jQuery.map( this, fn );
1154 if ( selector && typeof selector == "string" )
1155 ret = jQuery.multiFilter( selector, ret );
1157 return this.pushStack( jQuery.unique( ret ), name, selector );
1163 prependTo: "prepend",
1164 insertBefore: "before",
1165 insertAfter: "after",
1166 replaceAll: "replaceWith"
1167 }, function(name, original){
1168 jQuery.fn[ name ] = function() {
1169 var args = arguments;
1171 return this.each(function(){
1172 for ( var i = 0, length = args.length; i < length; i++ )
1173 jQuery( args[ i ] )[ original ]( this );
1179 removeAttr: function( name ) {
1180 jQuery.attr( this, name, "" );
1181 if (this.nodeType == 1)
1182 this.removeAttribute( name );
1185 addClass: function( classNames ) {
1186 jQuery.className.add( this, classNames );
1189 removeClass: function( classNames ) {
1190 jQuery.className.remove( this, classNames );
1193 toggleClass: function( classNames, state ) {
1194 if( typeof state !== "boolean" )
1195 state = !jQuery.className.has( this, classNames );
1196 jQuery.className[ state ? "add" : "remove" ]( this, classNames );
1199 remove: function( selector ) {
1200 if ( !selector || jQuery.filter( selector, [ this ] ).length ) {
1201 // Prevent memory leaks
1202 jQuery( "*", this ).add([this]).each(function(){
1203 jQuery.event.remove(this);
1204 jQuery.removeData(this);
1206 if (this.parentNode)
1207 this.parentNode.removeChild( this );
1212 // Remove element nodes and prevent memory leaks
1213 jQuery( ">*", this ).remove();
1215 // Remove any remaining nodes
1216 while ( this.firstChild )
1217 this.removeChild( this.firstChild );
1219 }, function(name, fn){
1220 jQuery.fn[ name ] = function(){
1221 return this.each( fn, arguments );
1225 // Helper function used by the dimensions and offset modules
1226 function num(elem, prop) {
1227 return elem[0] && parseInt( jQuery.curCSS(elem[0], prop, true), 10 ) || 0;