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 return this.setArray(jQuery.makeArray(selector));
79 // Start with an empty selector
82 // The current version of jQuery being used
85 // The number of elements contained in the matched element set
90 // Get the Nth element in the matched element set OR
91 // Get the whole matched element set as a clean array
92 get: function( num ) {
93 return num === undefined ?
95 // Return a 'clean' array
96 jQuery.makeArray( this ) :
98 // Return just the object
102 // Take an array of elements and push it onto the stack
103 // (returning the new matched element set)
104 pushStack: function( elems, name, selector ) {
105 // Build a new jQuery matched element set
106 var ret = jQuery( elems );
108 // Add the old object onto the stack (as a reference)
109 ret.prevObject = this;
111 ret.context = this.context;
113 if ( name === "find" )
114 ret.selector = this.selector + (this.selector ? " " : "") + selector;
116 ret.selector = this.selector + "." + name + "(" + selector + ")";
118 // Return the newly-formed element set
122 // Force the current matched set of elements to become
123 // the specified array of elements (destroying the stack in the process)
124 // You should use pushStack() in order to do this, but maintain the stack
125 setArray: function( elems ) {
126 // Resetting the length to 0, then using the native Array push
127 // is a super-fast way to populate an object with array-like properties
129 Array.prototype.push.apply( this, elems );
134 // Execute a callback for every element in the matched set.
135 // (You can seed the arguments with an array of args, but this is
136 // only used internally.)
137 each: function( callback, args ) {
138 return jQuery.each( this, callback, args );
141 // Determine the position of an element within
142 // the matched set of elements
143 index: function( elem ) {
144 // Locate the position of the desired element
145 return jQuery.inArray(
146 // If it receives a jQuery object, the first element is used
147 elem && elem.jquery ? elem[0] : elem
151 attr: function( name, value, type ) {
154 // Look for the case where we're accessing a style value
155 if ( typeof name === "string" )
156 if ( value === undefined )
157 return this[0] && jQuery[ type || "attr" ]( this[0], name );
161 options[ name ] = value;
164 // Check to see if we're setting style values
165 return this.each(function(i){
166 // Set all the styles
167 for ( name in options )
172 name, jQuery.prop( this, options[ name ], type, i, name )
177 css: function( key, value ) {
178 // ignore negative width and height values
179 if ( (key == 'width' || key == 'height') && parseFloat(value) < 0 )
181 return this.attr( key, value, "curCSS" );
184 text: function( text ) {
185 if ( typeof text !== "object" && text != null )
186 return this.empty().append( (this[0] && this[0].ownerDocument || document).createTextNode( text ) );
190 jQuery.each( text || this, function(){
191 jQuery.each( this.childNodes, function(){
192 if ( this.nodeType != 8 )
193 ret += this.nodeType != 1 ?
195 jQuery.fn.text( [ this ] );
202 wrapAll: function( html ) {
204 // The elements to wrap the target around
205 jQuery( html, this[0].ownerDocument )
207 .insertBefore( this[0] )
211 while ( elem.firstChild )
212 elem = elem.firstChild;
221 wrapInner: function( html ) {
222 return this.each(function(){
223 jQuery( this ).contents().wrapAll( html );
227 wrap: function( html ) {
228 return this.each(function(){
229 jQuery( this ).wrapAll( html );
234 return this.domManip(arguments, true, function(elem){
235 if (this.nodeType == 1)
236 this.appendChild( elem );
240 prepend: function() {
241 return this.domManip(arguments, true, function(elem){
242 if (this.nodeType == 1)
243 this.insertBefore( elem, this.firstChild );
248 return this.domManip(arguments, false, function(elem){
249 this.parentNode.insertBefore( elem, this );
254 return this.domManip(arguments, false, function(elem){
255 this.parentNode.insertBefore( elem, this.nextSibling );
260 return this.prevObject || jQuery( [] );
265 find: function( selector ) {
266 if ( this.length === 1 && !/,/.test(selector) ) {
267 var ret = this.pushStack( [], "find", selector );
269 jQuery.find( selector, this[0], ret );
272 var elems = jQuery.map(this, function(elem){
273 return jQuery.find( selector, elem );
276 return this.pushStack( /[^+>] [^+>]/.test( selector ) ?
277 jQuery.unique( elems ) :
278 elems, "find", selector );
282 clone: function( events ) {
284 var ret = this.map(function(){
285 if ( !jQuery.support.noCloneEvent && !jQuery.isXMLDoc(this) ) {
286 // IE copies events bound via attachEvent when
287 // using cloneNode. Calling detachEvent on the
288 // clone will also remove the events from the orignal
289 // In order to get around this, we use innerHTML.
290 // Unfortunately, this means some modifications to
291 // attributes in IE that are actually only stored
292 // as properties will not be copied (such as the
293 // the name attribute on an input).
294 var clone = this.cloneNode(true),
295 container = document.createElement("div");
296 container.appendChild(clone);
297 return jQuery.clean([container.innerHTML])[0];
299 return this.cloneNode(true);
302 // Need to set the expando to null on the cloned set if it exists
303 // removeData doesn't work here, IE removes it from the original as well
304 // this is primarily for IE but the data expando shouldn't be copied over in any browser
305 var clone = ret.find("*").andSelf().each(function(){
306 if ( this[ expando ] !== undefined )
307 this[ expando ] = null;
310 // Copy the events from the original to the clone
311 if ( events === true )
312 this.find("*").andSelf().each(function(i){
313 if (this.nodeType == 3)
315 var events = jQuery.data( this, "events" );
317 for ( var type in events )
318 for ( var handler in events[ type ] )
319 jQuery.event.add( clone[ i ], type, events[ type ][ handler ], events[ type ][ handler ].data );
322 // Return the cloned set
326 filter: function( selector ) {
327 return this.pushStack(
328 jQuery.isFunction( selector ) &&
329 jQuery.grep(this, function(elem, i){
330 return selector.call( elem, i );
333 jQuery.multiFilter( selector, jQuery.grep(this, function(elem){
334 return elem.nodeType === 1;
335 }) ), "filter", selector );
338 closest: function( selector ) {
339 return this.map(function(){
341 while ( cur && cur.ownerDocument ) {
342 if ( jQuery(cur).is(selector) )
344 cur = cur.parentNode;
349 not: function( selector ) {
350 if ( typeof selector === "string" )
351 // test special case where just one selector is passed in
352 if ( isSimple.test( selector ) )
353 return this.pushStack( jQuery.multiFilter( selector, this, true ), "not", selector );
355 selector = jQuery.multiFilter( selector, this );
357 var isArrayLike = selector.length && selector[selector.length - 1] !== undefined && !selector.nodeType;
358 return this.filter(function() {
359 return isArrayLike ? jQuery.inArray( this, selector ) < 0 : this != selector;
363 add: function( selector ) {
364 return this.pushStack( jQuery.unique( jQuery.merge(
366 typeof selector === "string" ?
368 jQuery.makeArray( selector )
372 is: function( selector ) {
373 return !!selector && jQuery.multiFilter( selector, this ).length > 0;
376 hasClass: function( selector ) {
377 return !!selector && this.is( "." + selector );
380 val: function( value ) {
381 if ( value === undefined ) {
385 if( jQuery.nodeName( elem, 'option' ) )
386 return (elem.attributes.value || {}).specified ? elem.value : elem.text;
388 // We need to handle select boxes special
389 if ( jQuery.nodeName( elem, "select" ) ) {
390 var index = elem.selectedIndex,
392 options = elem.options,
393 one = elem.type == "select-one";
395 // Nothing was selected
399 // Loop through all the selected options
400 for ( var i = one ? index : 0, max = one ? index + 1 : options.length; i < max; i++ ) {
401 var option = options[ i ];
403 if ( option.selected ) {
404 // Get the specifc value for the option
405 value = jQuery(option).val();
407 // We don't need an array for one selects
411 // Multi-Selects return an array
412 values.push( value );
419 // Everything else, we just grab the value
420 return (elem.value || "").replace(/\r/g, "");
427 if ( typeof value === "number" )
430 return this.each(function(){
431 if ( this.nodeType != 1 )
434 if ( jQuery.isArray(value) && /radio|checkbox/.test( this.type ) )
435 this.checked = (jQuery.inArray(this.value, value) >= 0 ||
436 jQuery.inArray(this.name, value) >= 0);
438 else if ( jQuery.nodeName( this, "select" ) ) {
439 var values = jQuery.makeArray(value);
441 jQuery( "option", this ).each(function(){
442 this.selected = (jQuery.inArray( this.value, values ) >= 0 ||
443 jQuery.inArray( this.text, values ) >= 0);
446 if ( !values.length )
447 this.selectedIndex = -1;
454 html: function( value ) {
455 return value === undefined ?
459 this.empty().append( value );
462 replaceWith: function( value ) {
463 return this.after( value ).remove();
467 return this.slice( i, +i + 1 );
471 return this.pushStack( Array.prototype.slice.apply( this, arguments ),
472 "slice", Array.prototype.slice.call(arguments).join(",") );
475 map: function( callback ) {
476 return this.pushStack( jQuery.map(this, function(elem, i){
477 return callback.call( elem, i, elem );
481 andSelf: function() {
482 return this.add( this.prevObject );
485 domManip: function( args, table, callback ) {
487 var fragment = (this[0].ownerDocument || this[0]).createDocumentFragment(),
488 scripts = jQuery.clean( args, (this[0].ownerDocument || this[0]), fragment ),
489 first = fragment.firstChild,
490 extra = this.length > 1 ? fragment.cloneNode(true) : fragment;
493 for ( var i = 0, l = this.length; i < l; i++ )
494 callback.call( root(this[i], first), i > 0 ? extra.cloneNode(true) : fragment );
497 jQuery.each( scripts, evalScript );
502 function root( elem, cur ) {
503 return table && jQuery.nodeName(elem, "table") && jQuery.nodeName(cur, "tr") ?
504 (elem.getElementsByTagName("tbody")[0] ||
505 elem.appendChild(elem.ownerDocument.createElement("tbody"))) :
511 // Give the init function the jQuery prototype for later instantiation
512 jQuery.fn.init.prototype = jQuery.fn;
514 function evalScript( i, elem ) {
523 jQuery.globalEval( elem.text || elem.textContent || elem.innerHTML || "" );
525 if ( elem.parentNode )
526 elem.parentNode.removeChild( elem );
533 jQuery.extend = jQuery.fn.extend = function() {
534 // copy reference to target object
535 var target = arguments[0] || {}, i = 1, length = arguments.length, deep = false, options;
537 // Handle a deep copy situation
538 if ( typeof target === "boolean" ) {
540 target = arguments[1] || {};
541 // skip the boolean and the target
545 // Handle case when target is a string or something (possible in deep copy)
546 if ( typeof target !== "object" && !jQuery.isFunction(target) )
549 // extend jQuery itself if only one argument is passed
555 for ( ; i < length; i++ )
556 // Only deal with non-null/undefined values
557 if ( (options = arguments[ i ]) != null )
558 // Extend the base object
559 for ( var name in options ) {
560 var src = target[ name ], copy = options[ name ];
562 // Prevent never-ending loop
563 if ( target === copy )
566 // Recurse if we're merging object values
567 if ( deep && copy && typeof copy === "object" && !copy.nodeType )
568 target[ name ] = jQuery.extend( deep,
569 // Never move original objects, clone them
570 src || ( copy.length != null ? [ ] : { } )
573 // Don't bring in undefined values
574 else if ( copy !== undefined )
575 target[ name ] = copy;
579 // Return the modified object
583 // exclude the following css properties to add px
584 var exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i,
586 defaultView = document.defaultView || {},
587 toString = Object.prototype.toString;
590 noConflict: function( deep ) {
594 window.jQuery = _jQuery;
599 // See test/unit/core.js for details concerning isFunction.
600 // Since version 1.3, DOM methods and functions like alert
601 // aren't supported. They return false on IE (#2968).
602 isFunction: function( obj ) {
603 return toString.call(obj) === "[object Function]";
606 isArray: function( obj ) {
607 return toString.call(obj) === "[object Array]";
610 // check if an element is in a (or is an) XML document
611 isXMLDoc: function( elem ) {
612 return elem.documentElement && !elem.body ||
613 elem.tagName && elem.ownerDocument && !elem.ownerDocument.body;
616 // Evalulates a script in a global context
617 globalEval: function( data ) {
618 data = jQuery.trim( data );
621 // Inspired by code by Andrea Giammarchi
622 // http://webreflection.blogspot.com/2007/08/global-scope-evaluation-and-dom.html
623 var head = document.getElementsByTagName("head")[0] || document.documentElement,
624 script = document.createElement("script");
626 script.type = "text/javascript";
627 if ( jQuery.support.scriptEval )
628 script.appendChild( document.createTextNode( data ) );
632 // Use insertBefore instead of appendChild to circumvent an IE6 bug.
633 // This arises when a base node is used (#2709).
634 head.insertBefore( script, head.firstChild );
635 head.removeChild( script );
639 nodeName: function( elem, name ) {
640 return elem.nodeName && elem.nodeName.toUpperCase() == name.toUpperCase();
643 // args is for internal usage only
644 each: function( object, callback, args ) {
645 var name, i = 0, length = object.length;
648 if ( length === undefined ) {
649 for ( name in object )
650 if ( callback.apply( object[ name ], args ) === false )
653 for ( ; i < length; )
654 if ( callback.apply( object[ i++ ], args ) === false )
657 // A special, fast, case for the most common use of each
659 if ( length === undefined ) {
660 for ( name in object )
661 if ( callback.call( object[ name ], name, object[ name ] ) === false )
664 for ( var value = object[0];
665 i < length && callback.call( value, i, value ) !== false; value = object[++i] ){}
671 prop: function( elem, value, type, i, name ) {
672 // Handle executable functions
673 if ( jQuery.isFunction( value ) )
674 value = value.call( elem, i );
676 // Handle passing in a number to a CSS property
677 return typeof value === "number" && type == "curCSS" && !exclude.test( name ) ?
683 // internal only, use addClass("class")
684 add: function( elem, classNames ) {
685 jQuery.each((classNames || "").split(/\s+/), function(i, className){
686 if ( elem.nodeType == 1 && !jQuery.className.has( elem.className, className ) )
687 elem.className += (elem.className ? " " : "") + className;
691 // internal only, use removeClass("class")
692 remove: function( elem, classNames ) {
693 if (elem.nodeType == 1)
694 elem.className = classNames !== undefined ?
695 jQuery.grep(elem.className.split(/\s+/), function(className){
696 return !jQuery.className.has( classNames, className );
701 // internal only, use hasClass("class")
702 has: function( elem, className ) {
703 return jQuery.inArray( className, (elem.className || elem).toString().split(/\s+/) ) > -1;
707 // A method for quickly swapping in/out CSS properties to get correct calculations
708 swap: function( elem, options, callback ) {
710 // Remember the old values, and insert the new ones
711 for ( var name in options ) {
712 old[ name ] = elem.style[ name ];
713 elem.style[ name ] = options[ name ];
716 callback.call( elem );
718 // Revert the old values
719 for ( var name in options )
720 elem.style[ name ] = old[ name ];
723 css: function( elem, name, force ) {
724 if ( name == "width" || name == "height" ) {
725 var val, props = { position: "absolute", visibility: "hidden", display:"block" }, which = name == "width" ? [ "Left", "Right" ] : [ "Top", "Bottom" ];
728 val = name == "width" ? elem.offsetWidth : elem.offsetHeight;
729 var padding = 0, border = 0;
730 jQuery.each( which, function() {
731 padding += parseFloat(jQuery.curCSS( elem, "padding" + this, true)) || 0;
732 border += parseFloat(jQuery.curCSS( elem, "border" + this + "Width", true)) || 0;
734 val -= Math.round(padding + border);
737 if ( jQuery(elem).is(":visible") )
740 jQuery.swap( elem, props, getWH );
742 return Math.max(0, val);
745 return jQuery.curCSS( elem, name, force );
748 curCSS: function( elem, name, force ) {
749 var ret, style = elem.style;
751 // We need to handle opacity special in IE
752 if ( name == "opacity" && !jQuery.support.opacity ) {
753 ret = jQuery.attr( style, "opacity" );
760 // Make sure we're using the right name for getting the float value
761 if ( name.match( /float/i ) )
764 if ( !force && style && style[ name ] )
767 else if ( defaultView.getComputedStyle ) {
769 // Only "float" is needed here
770 if ( name.match( /float/i ) )
773 name = name.replace( /([A-Z])/g, "-$1" ).toLowerCase();
775 var computedStyle = defaultView.getComputedStyle( elem, null );
778 ret = computedStyle.getPropertyValue( name );
780 // We should always get a number back from opacity
781 if ( name == "opacity" && ret == "" )
784 } else if ( elem.currentStyle ) {
785 var camelCase = name.replace(/\-(\w)/g, function(all, letter){
786 return letter.toUpperCase();
789 ret = elem.currentStyle[ name ] || elem.currentStyle[ camelCase ];
791 // From the awesome hack by Dean Edwards
792 // http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291
794 // If we're not dealing with a regular pixel number
795 // but a number that has a weird ending, we need to convert it to pixels
796 if ( !/^\d+(px)?$/i.test( ret ) && /^\d/.test( ret ) ) {
797 // Remember the original values
798 var left = style.left, rsLeft = elem.runtimeStyle.left;
800 // Put in the new values to get a computed value out
801 elem.runtimeStyle.left = elem.currentStyle.left;
802 style.left = ret || 0;
803 ret = style.pixelLeft + "px";
805 // Revert the changed values
807 elem.runtimeStyle.left = rsLeft;
814 clean: function( elems, context, fragment ) {
815 context = context || document;
817 // !context.createElement fails in IE with an error but returns typeof 'object'
818 if ( typeof context.createElement === "undefined" )
819 context = context.ownerDocument || context[0] && context[0].ownerDocument || document;
821 // If a single string is passed in and it's a single tag
822 // just do a createElement and skip the rest
823 if ( !fragment && elems.length === 1 && typeof elems[0] === "string" ) {
824 var match = /^<(\w+)\s*\/?>$/.exec(elems[0]);
826 return [ context.createElement( match[1] ) ];
829 var ret = [], scripts = [], div = context.createElement("div");
831 jQuery.each(elems, function(i, elem){
832 if ( typeof elem === "number" )
838 // Convert html string into DOM nodes
839 if ( typeof elem === "string" ) {
840 // Fix "XHTML"-style tags in all browsers
841 elem = elem.replace(/(<(\w+)[^>]*?)\/>/g, function(all, front, tag){
842 return tag.match(/^(abbr|br|col|img|input|link|meta|param|hr|area|embed)$/i) ?
844 front + "></" + tag + ">";
847 // Trim whitespace, otherwise indexOf won't work as expected
848 var tags = jQuery.trim( elem ).toLowerCase();
851 // option or optgroup
852 !tags.indexOf("<opt") &&
853 [ 1, "<select multiple='multiple'>", "</select>" ] ||
855 !tags.indexOf("<leg") &&
856 [ 1, "<fieldset>", "</fieldset>" ] ||
858 tags.match(/^<(thead|tbody|tfoot|colg|cap)/) &&
859 [ 1, "<table>", "</table>" ] ||
861 !tags.indexOf("<tr") &&
862 [ 2, "<table><tbody>", "</tbody></table>" ] ||
864 // <thead> matched above
865 (!tags.indexOf("<td") || !tags.indexOf("<th")) &&
866 [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ] ||
868 !tags.indexOf("<col") &&
869 [ 2, "<table><tbody></tbody><colgroup>", "</colgroup></table>" ] ||
871 // IE can't serialize <link> and <script> tags normally
872 !jQuery.support.htmlSerialize &&
873 [ 1, "div<div>", "</div>" ] ||
877 // Go to html and back, then peel off extra wrappers
878 div.innerHTML = wrap[1] + elem + wrap[2];
880 // Move to the right depth
884 // Remove IE's autoinserted <tbody> from table fragments
885 if ( !jQuery.support.tbody ) {
887 // String was a <table>, *may* have spurious <tbody>
888 var tbody = !tags.indexOf("<table") && tags.indexOf("<tbody") < 0 ?
889 div.firstChild && div.firstChild.childNodes :
891 // String was a bare <thead> or <tfoot>
892 wrap[1] == "<table>" && tags.indexOf("<tbody") < 0 ?
896 for ( var j = tbody.length - 1; j >= 0 ; --j )
897 if ( jQuery.nodeName( tbody[ j ], "tbody" ) && !tbody[ j ].childNodes.length )
898 tbody[ j ].parentNode.removeChild( tbody[ j ] );
902 // IE completely kills leading whitespace when innerHTML is used
903 if ( !jQuery.support.leadingWhitespace && /^\s/.test( elem ) )
904 div.insertBefore( context.createTextNode( elem.match(/^\s*/)[0] ), div.firstChild );
906 elem = jQuery.makeArray( div.childNodes );
912 ret = jQuery.merge( ret, elem );
917 for ( var i = 0; ret[i]; i++ ) {
918 if ( jQuery.nodeName( ret[i], "script" ) ) {
919 scripts.push( ret[i].parentNode.removeChild( ret[i] ) );
921 if ( ret[i].nodeType === 1 )
922 ret.splice.apply( ret, [i + 1, 0].concat(jQuery.makeArray(ret[i].getElementsByTagName("script"))) );
923 fragment.appendChild( ret[i] );
933 attr: function( elem, name, value ) {
934 // don't set attributes on text and comment nodes
935 if (!elem || elem.nodeType == 3 || elem.nodeType == 8)
938 var notxml = !jQuery.isXMLDoc( elem ),
939 // Whether we are setting (or getting)
940 set = value !== undefined;
942 // Try to normalize/fix the name
943 name = notxml && jQuery.props[ name ] || name;
945 // Only do all the following if this is a node (faster for style)
946 // IE elem.getAttribute passes even for style
947 if ( elem.tagName ) {
949 // These attributes require special treatment
950 var special = /href|src|style/.test( name );
952 // Safari mis-reports the default selected property of a hidden option
953 // Accessing the parent's selectedIndex property fixes it
954 if ( name == "selected" )
955 elem.parentNode.selectedIndex;
957 // If applicable, access the attribute via the DOM 0 way
958 if ( name in elem && notxml && !special ) {
960 // We can't allow the type property to be changed (since it causes problems in IE)
961 if ( name == "type" && jQuery.nodeName( elem, "input" ) && elem.parentNode )
962 throw "type property can't be changed";
964 elem[ name ] = value;
967 // browsers index elements by id/name on forms, give priority to attributes.
968 if( jQuery.nodeName( elem, "form" ) && elem.getAttributeNode(name) )
969 return elem.getAttributeNode( name ).nodeValue;
971 // elem.tabIndex doesn't always return the correct value when it hasn't been explicitly set
972 // http://fluidproject.org/blog/2008/01/09/getting-setting-and-removing-tabindex-values-with-javascript/
973 if ( name == "tabIndex" ) {
974 var attributeNode = elem.getAttributeNode( "tabIndex" );
975 return attributeNode && attributeNode.specified
976 ? attributeNode.value
977 : elem.nodeName.match(/^(a|area|button|input|object|select|textarea)$/i)
985 if ( !jQuery.support.style && notxml && name == "style" )
986 return jQuery.attr( elem.style, "cssText", value );
989 // convert the value to a string (all browsers do this but IE) see #1070
990 elem.setAttribute( name, "" + value );
992 var attr = !jQuery.support.hrefNormalized && notxml && special
993 // Some attributes require a special call on IE
994 ? elem.getAttribute( name, 2 )
995 : elem.getAttribute( name );
997 // Non-existent attributes return null, we normalize to undefined
998 return attr === null ? undefined : attr;
1001 // elem is actually elem.style ... set the style
1003 // IE uses filters for opacity
1004 if ( !jQuery.support.opacity && name == "opacity" ) {
1006 // IE has trouble with opacity if it does not have layout
1007 // Force it by setting the zoom level
1010 // Set the alpha filter to set the opacity
1011 elem.filter = (elem.filter || "").replace( /alpha\([^)]*\)/, "" ) +
1012 (parseInt( value ) + '' == "NaN" ? "" : "alpha(opacity=" + value * 100 + ")");
1015 return elem.filter && elem.filter.indexOf("opacity=") >= 0 ?
1016 (parseFloat( elem.filter.match(/opacity=([^)]*)/)[1] ) / 100) + '':
1020 name = name.replace(/-([a-z])/ig, function(all, letter){
1021 return letter.toUpperCase();
1025 elem[ name ] = value;
1027 return elem[ name ];
1030 trim: function( text ) {
1031 return (text || "").replace( /^\s+|\s+$/g, "" );
1034 makeArray: function( array ) {
1037 if( array != null ){
1038 var i = array.length;
1039 // The window, strings (and functions) also have 'length'
1040 if( i == null || typeof array === "string" || jQuery.isFunction(array) || array.setInterval )
1044 ret[--i] = array[i];
1050 inArray: function( elem, array ) {
1051 for ( var i = 0, length = array.length; i < length; i++ )
1052 // Use === because on IE, window == document
1053 if ( array[ i ] === elem )
1059 merge: function( first, second ) {
1060 // We have to loop this way because IE & Opera overwrite the length
1061 // expando of getElementsByTagName
1062 var i = 0, elem, pos = first.length;
1063 // Also, we need to make sure that the correct elements are being returned
1064 // (IE returns comment nodes in a '*' query)
1065 if ( !jQuery.support.getAll ) {
1066 while ( (elem = second[ i++ ]) != null )
1067 if ( elem.nodeType != 8 )
1068 first[ pos++ ] = elem;
1071 while ( (elem = second[ i++ ]) != null )
1072 first[ pos++ ] = elem;
1077 unique: function( array ) {
1078 var ret = [], done = {};
1082 for ( var i = 0, length = array.length; i < length; i++ ) {
1083 var id = jQuery.data( array[ i ] );
1085 if ( !done[ id ] ) {
1087 ret.push( array[ i ] );
1098 grep: function( elems, callback, inv ) {
1101 // Go through the array, only saving the items
1102 // that pass the validator function
1103 for ( var i = 0, length = elems.length; i < length; i++ )
1104 if ( !inv != !callback( elems[ i ], i ) )
1105 ret.push( elems[ i ] );
1110 map: function( elems, callback ) {
1113 // Go through the array, translating each of the items to their
1114 // new value (or values).
1115 for ( var i = 0, length = elems.length; i < length; i++ ) {
1116 var value = callback( elems[ i ], i );
1118 if ( value != null )
1119 ret[ ret.length ] = value;
1122 return ret.concat.apply( [], ret );
1126 // Use of jQuery.browser is deprecated.
1127 // It's included for backwards compatibility and plugins,
1128 // although they should work to migrate away.
1130 var userAgent = navigator.userAgent.toLowerCase();
1132 // Figure out what browser is being used
1134 version: (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [0,'0'])[1],
1135 safari: /webkit/.test( userAgent ),
1136 opera: /opera/.test( userAgent ),
1137 msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
1138 mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )
1141 // Check to see if the W3C box model is being used
1142 jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
1145 parent: function(elem){return elem.parentNode;},
1146 parents: function(elem){return jQuery.dir(elem,"parentNode");},
1147 next: function(elem){return jQuery.nth(elem,2,"nextSibling");},
1148 prev: function(elem){return jQuery.nth(elem,2,"previousSibling");},
1149 nextAll: function(elem){return jQuery.dir(elem,"nextSibling");},
1150 prevAll: function(elem){return jQuery.dir(elem,"previousSibling");},
1151 siblings: function(elem){return jQuery.sibling(elem.parentNode.firstChild,elem);},
1152 children: function(elem){return jQuery.sibling(elem.firstChild);},
1153 contents: function(elem){return jQuery.nodeName(elem,"iframe")?elem.contentDocument||elem.contentWindow.document:jQuery.makeArray(elem.childNodes);}
1154 }, function(name, fn){
1155 jQuery.fn[ name ] = function( selector ) {
1156 var ret = jQuery.map( this, fn );
1158 if ( selector && typeof selector == "string" )
1159 ret = jQuery.multiFilter( selector, ret );
1161 return this.pushStack( jQuery.unique( ret ), name, selector );
1167 prependTo: "prepend",
1168 insertBefore: "before",
1169 insertAfter: "after",
1170 replaceAll: "replaceWith"
1171 }, function(name, original){
1172 jQuery.fn[ name ] = function() {
1173 var args = arguments;
1175 return this.each(function(){
1176 for ( var i = 0, length = args.length; i < length; i++ )
1177 jQuery( args[ i ] )[ original ]( this );
1183 removeAttr: function( name ) {
1184 jQuery.attr( this, name, "" );
1185 if (this.nodeType == 1)
1186 this.removeAttribute( name );
1189 addClass: function( classNames ) {
1190 jQuery.className.add( this, classNames );
1193 removeClass: function( classNames ) {
1194 jQuery.className.remove( this, classNames );
1197 toggleClass: function( classNames, state ) {
1198 if( typeof state !== "boolean" )
1199 state = !jQuery.className.has( this, classNames );
1200 jQuery.className[ state ? "add" : "remove" ]( this, classNames );
1203 remove: function( selector ) {
1204 if ( !selector || jQuery.filter( selector, [ this ] ).length ) {
1205 // Prevent memory leaks
1206 jQuery( "*", this ).add([this]).each(function(){
1207 jQuery.event.remove(this);
1208 jQuery.removeData(this);
1210 if (this.parentNode)
1211 this.parentNode.removeChild( this );
1216 // Remove element nodes and prevent memory leaks
1217 jQuery( ">*", this ).remove();
1219 // Remove any remaining nodes
1220 while ( this.firstChild )
1221 this.removeChild( this.firstChild );
1223 }, function(name, fn){
1224 jQuery.fn[ name ] = function(){
1225 return this.each( fn, arguments );
1229 // Helper function used by the dimensions and offset modules
1230 function num(elem, prop) {
1231 return elem[0] && parseInt( jQuery.curCSS(elem[0], prop, true), 10 ) || 0;