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( [] );
263 find: function( selector ) {
264 if ( this.length === 1 ) {
265 return this.pushStack( jQuery.find( selector, this[0] ), "find", selector );
267 var elems = jQuery.map(this, function(elem){
268 return jQuery.find( selector, elem );
271 return this.pushStack( /[^+>] [^+>]/.test( selector ) ?
272 jQuery.unique( elems ) :
273 elems, "find", selector );
277 clone: function( events ) {
279 var ret = this.map(function(){
280 if ( !jQuery.support.noCloneEvent && !jQuery.isXMLDoc(this) ) {
281 // IE copies events bound via attachEvent when
282 // using cloneNode. Calling detachEvent on the
283 // clone will also remove the events from the orignal
284 // In order to get around this, we use innerHTML.
285 // Unfortunately, this means some modifications to
286 // attributes in IE that are actually only stored
287 // as properties will not be copied (such as the
288 // the name attribute on an input).
289 var clone = this.cloneNode(true),
290 container = document.createElement("div");
291 container.appendChild(clone);
292 return jQuery.clean([container.innerHTML])[0];
294 return this.cloneNode(true);
297 // Need to set the expando to null on the cloned set if it exists
298 // removeData doesn't work here, IE removes it from the original as well
299 // this is primarily for IE but the data expando shouldn't be copied over in any browser
300 var clone = ret.find("*").andSelf().each(function(){
301 if ( this[ expando ] !== undefined )
302 this[ expando ] = null;
305 // Copy the events from the original to the clone
306 if ( events === true )
307 this.find("*").andSelf().each(function(i){
308 if (this.nodeType == 3)
310 var events = jQuery.data( this, "events" );
312 for ( var type in events )
313 for ( var handler in events[ type ] )
314 jQuery.event.add( clone[ i ], type, events[ type ][ handler ], events[ type ][ handler ].data );
317 // Return the cloned set
321 filter: function( selector ) {
322 return this.pushStack(
323 jQuery.isFunction( selector ) &&
324 jQuery.grep(this, function(elem, i){
325 return selector.call( elem, i );
328 jQuery.multiFilter( selector, jQuery.grep(this, function(elem){
329 return elem.nodeType === 1;
330 }) ), "filter", selector );
333 closest: function( selector ) {
334 return this.map(function(){
336 while ( cur && cur.ownerDocument ) {
337 if ( jQuery(cur).is(selector) )
339 cur = cur.parentNode;
344 not: function( selector ) {
345 if ( typeof selector === "string" )
346 // test special case where just one selector is passed in
347 if ( isSimple.test( selector ) )
348 return this.pushStack( jQuery.multiFilter( selector, this, true ), "not", selector );
350 selector = jQuery.multiFilter( selector, this );
352 var isArrayLike = selector.length && selector[selector.length - 1] !== undefined && !selector.nodeType;
353 return this.filter(function() {
354 return isArrayLike ? jQuery.inArray( this, selector ) < 0 : this != selector;
358 add: function( selector ) {
359 return this.pushStack( jQuery.unique( jQuery.merge(
361 typeof selector === "string" ?
363 jQuery.makeArray( selector )
367 is: function( selector ) {
368 return !!selector && jQuery.multiFilter( selector, this ).length > 0;
371 hasClass: function( selector ) {
372 return !!selector && this.is( "." + selector );
375 val: function( value ) {
376 if ( value === undefined ) {
380 if( jQuery.nodeName( elem, 'option' ) )
381 return (elem.attributes.value || {}).specified ? elem.value : elem.text;
383 // We need to handle select boxes special
384 if ( jQuery.nodeName( elem, "select" ) ) {
385 var index = elem.selectedIndex,
387 options = elem.options,
388 one = elem.type == "select-one";
390 // Nothing was selected
394 // Loop through all the selected options
395 for ( var i = one ? index : 0, max = one ? index + 1 : options.length; i < max; i++ ) {
396 var option = options[ i ];
398 if ( option.selected ) {
399 // Get the specifc value for the option
400 value = jQuery(option).val();
402 // We don't need an array for one selects
406 // Multi-Selects return an array
407 values.push( value );
414 // Everything else, we just grab the value
415 return (elem.value || "").replace(/\r/g, "");
422 if ( typeof value === "number" )
425 return this.each(function(){
426 if ( this.nodeType != 1 )
429 if ( jQuery.isArray(value) && /radio|checkbox/.test( this.type ) )
430 this.checked = (jQuery.inArray(this.value, value) >= 0 ||
431 jQuery.inArray(this.name, value) >= 0);
433 else if ( jQuery.nodeName( this, "select" ) ) {
434 var values = jQuery.makeArray(value);
436 jQuery( "option", this ).each(function(){
437 this.selected = (jQuery.inArray( this.value, values ) >= 0 ||
438 jQuery.inArray( this.text, values ) >= 0);
441 if ( !values.length )
442 this.selectedIndex = -1;
449 html: function( value ) {
450 return value === undefined ?
454 this.empty().append( value );
457 replaceWith: function( value ) {
458 return this.after( value ).remove();
462 return this.slice( i, +i + 1 );
466 return this.pushStack( Array.prototype.slice.apply( this, arguments ),
467 "slice", Array.prototype.slice.call(arguments).join(",") );
470 map: function( callback ) {
471 return this.pushStack( jQuery.map(this, function(elem, i){
472 return callback.call( elem, i, elem );
476 andSelf: function() {
477 return this.add( this.prevObject );
480 domManip: function( args, table, callback ) {
482 var fragment = (this[0].ownerDocument || this[0]).createDocumentFragment(),
483 scripts = jQuery.clean( args, (this[0].ownerDocument || this[0]), fragment ),
484 first = fragment.firstChild,
485 extra = this.length > 1 ? fragment.cloneNode(true) : fragment;
488 for ( var i = 0, l = this.length; i < l; i++ )
489 callback.call( root(this[i], first), i > 0 ? extra.cloneNode(true) : fragment );
492 jQuery.each( scripts, evalScript );
497 function root( elem, cur ) {
498 return table && jQuery.nodeName(elem, "table") && jQuery.nodeName(cur, "tr") ?
499 (elem.getElementsByTagName("tbody")[0] ||
500 elem.appendChild(elem.ownerDocument.createElement("tbody"))) :
506 // Give the init function the jQuery prototype for later instantiation
507 jQuery.fn.init.prototype = jQuery.fn;
509 function evalScript( i, elem ) {
518 jQuery.globalEval( elem.text || elem.textContent || elem.innerHTML || "" );
520 if ( elem.parentNode )
521 elem.parentNode.removeChild( elem );
528 jQuery.extend = jQuery.fn.extend = function() {
529 // copy reference to target object
530 var target = arguments[0] || {}, i = 1, length = arguments.length, deep = false, options;
532 // Handle a deep copy situation
533 if ( typeof target === "boolean" ) {
535 target = arguments[1] || {};
536 // skip the boolean and the target
540 // Handle case when target is a string or something (possible in deep copy)
541 if ( typeof target !== "object" && !jQuery.isFunction(target) )
544 // extend jQuery itself if only one argument is passed
550 for ( ; i < length; i++ )
551 // Only deal with non-null/undefined values
552 if ( (options = arguments[ i ]) != null )
553 // Extend the base object
554 for ( var name in options ) {
555 var src = target[ name ], copy = options[ name ];
557 // Prevent never-ending loop
558 if ( target === copy )
561 // Recurse if we're merging object values
562 if ( deep && copy && typeof copy === "object" && !copy.nodeType )
563 target[ name ] = jQuery.extend( deep,
564 // Never move original objects, clone them
565 src || ( copy.length != null ? [ ] : { } )
568 // Don't bring in undefined values
569 else if ( copy !== undefined )
570 target[ name ] = copy;
574 // Return the modified object
578 // exclude the following css properties to add px
579 var exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i,
581 defaultView = document.defaultView || {},
582 toString = Object.prototype.toString;
585 noConflict: function( deep ) {
589 window.jQuery = _jQuery;
594 // See test/unit/core.js for details concerning isFunction.
595 // Since version 1.3, DOM methods and functions like alert
596 // aren't supported. They return false on IE (#2968).
597 isFunction: function( obj ) {
598 return toString.call(obj) === "[object Function]";
601 isArray: function( obj ) {
602 return toString.call(obj) === "[object Array]";
605 // check if an element is in a (or is an) XML document
606 isXMLDoc: function( elem ) {
607 return elem.documentElement && !elem.body ||
608 elem.tagName && elem.ownerDocument && !elem.ownerDocument.body;
611 // Evalulates a script in a global context
612 globalEval: function( data ) {
613 data = jQuery.trim( data );
616 // Inspired by code by Andrea Giammarchi
617 // http://webreflection.blogspot.com/2007/08/global-scope-evaluation-and-dom.html
618 var head = document.getElementsByTagName("head")[0] || document.documentElement,
619 script = document.createElement("script");
621 script.type = "text/javascript";
622 if ( jQuery.support.scriptEval )
623 script.appendChild( document.createTextNode( data ) );
627 // Use insertBefore instead of appendChild to circumvent an IE6 bug.
628 // This arises when a base node is used (#2709).
629 head.insertBefore( script, head.firstChild );
630 head.removeChild( script );
634 nodeName: function( elem, name ) {
635 return elem.nodeName && elem.nodeName.toUpperCase() == name.toUpperCase();
638 // args is for internal usage only
639 each: function( object, callback, args ) {
640 var name, i = 0, length = object.length;
643 if ( length === undefined ) {
644 for ( name in object )
645 if ( callback.apply( object[ name ], args ) === false )
648 for ( ; i < length; )
649 if ( callback.apply( object[ i++ ], args ) === false )
652 // A special, fast, case for the most common use of each
654 if ( length === undefined ) {
655 for ( name in object )
656 if ( callback.call( object[ name ], name, object[ name ] ) === false )
659 for ( var value = object[0];
660 i < length && callback.call( value, i, value ) !== false; value = object[++i] ){}
666 prop: function( elem, value, type, i, name ) {
667 // Handle executable functions
668 if ( jQuery.isFunction( value ) )
669 value = value.call( elem, i );
671 // Handle passing in a number to a CSS property
672 return typeof value === "number" && type == "curCSS" && !exclude.test( name ) ?
678 // internal only, use addClass("class")
679 add: function( elem, classNames ) {
680 jQuery.each((classNames || "").split(/\s+/), function(i, className){
681 if ( elem.nodeType == 1 && !jQuery.className.has( elem.className, className ) )
682 elem.className += (elem.className ? " " : "") + className;
686 // internal only, use removeClass("class")
687 remove: function( elem, classNames ) {
688 if (elem.nodeType == 1)
689 elem.className = classNames !== undefined ?
690 jQuery.grep(elem.className.split(/\s+/), function(className){
691 return !jQuery.className.has( classNames, className );
696 // internal only, use hasClass("class")
697 has: function( elem, className ) {
698 return jQuery.inArray( className, (elem.className || elem).toString().split(/\s+/) ) > -1;
702 // A method for quickly swapping in/out CSS properties to get correct calculations
703 swap: function( elem, options, callback ) {
705 // Remember the old values, and insert the new ones
706 for ( var name in options ) {
707 old[ name ] = elem.style[ name ];
708 elem.style[ name ] = options[ name ];
711 callback.call( elem );
713 // Revert the old values
714 for ( var name in options )
715 elem.style[ name ] = old[ name ];
718 css: function( elem, name, force ) {
719 if ( name == "width" || name == "height" ) {
720 var val, props = { position: "absolute", visibility: "hidden", display:"block" }, which = name == "width" ? [ "Left", "Right" ] : [ "Top", "Bottom" ];
723 val = name == "width" ? elem.offsetWidth : elem.offsetHeight;
724 var padding = 0, border = 0;
725 jQuery.each( which, function() {
726 padding += parseFloat(jQuery.curCSS( elem, "padding" + this, true)) || 0;
727 border += parseFloat(jQuery.curCSS( elem, "border" + this + "Width", true)) || 0;
729 val -= Math.round(padding + border);
732 if ( jQuery(elem).is(":visible") )
735 jQuery.swap( elem, props, getWH );
737 return Math.max(0, val);
740 return jQuery.curCSS( elem, name, force );
743 curCSS: function( elem, name, force ) {
744 var ret, style = elem.style;
746 // We need to handle opacity special in IE
747 if ( name == "opacity" && !jQuery.support.opacity ) {
748 ret = jQuery.attr( style, "opacity" );
755 // Make sure we're using the right name for getting the float value
756 if ( name.match( /float/i ) )
759 if ( !force && style && style[ name ] )
762 else if ( defaultView.getComputedStyle ) {
764 // Only "float" is needed here
765 if ( name.match( /float/i ) )
768 name = name.replace( /([A-Z])/g, "-$1" ).toLowerCase();
770 var computedStyle = defaultView.getComputedStyle( elem, null );
773 ret = computedStyle.getPropertyValue( name );
775 // We should always get a number back from opacity
776 if ( name == "opacity" && ret == "" )
779 } else if ( elem.currentStyle ) {
780 var camelCase = name.replace(/\-(\w)/g, function(all, letter){
781 return letter.toUpperCase();
784 ret = elem.currentStyle[ name ] || elem.currentStyle[ camelCase ];
786 // From the awesome hack by Dean Edwards
787 // http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291
789 // If we're not dealing with a regular pixel number
790 // but a number that has a weird ending, we need to convert it to pixels
791 if ( !/^\d+(px)?$/i.test( ret ) && /^\d/.test( ret ) ) {
792 // Remember the original values
793 var left = style.left, rsLeft = elem.runtimeStyle.left;
795 // Put in the new values to get a computed value out
796 elem.runtimeStyle.left = elem.currentStyle.left;
797 style.left = ret || 0;
798 ret = style.pixelLeft + "px";
800 // Revert the changed values
802 elem.runtimeStyle.left = rsLeft;
809 clean: function( elems, context, fragment ) {
810 context = context || document;
812 // !context.createElement fails in IE with an error but returns typeof 'object'
813 if ( typeof context.createElement === "undefined" )
814 context = context.ownerDocument || context[0] && context[0].ownerDocument || document;
816 // If a single string is passed in and it's a single tag
817 // just do a createElement and skip the rest
818 if ( !fragment && elems.length === 1 && typeof elems[0] === "string" ) {
819 var match = /^<(\w+)\s*\/?>$/.exec(elems[0]);
821 return [ context.createElement( match[1] ) ];
824 var ret = [], scripts = [], div = context.createElement("div");
826 jQuery.each(elems, function(i, elem){
827 if ( typeof elem === "number" )
833 // Convert html string into DOM nodes
834 if ( typeof elem === "string" ) {
835 // Fix "XHTML"-style tags in all browsers
836 elem = elem.replace(/(<(\w+)[^>]*?)\/>/g, function(all, front, tag){
837 return tag.match(/^(abbr|br|col|img|input|link|meta|param|hr|area|embed)$/i) ?
839 front + "></" + tag + ">";
842 // Trim whitespace, otherwise indexOf won't work as expected
843 var tags = jQuery.trim( elem ).toLowerCase();
846 // option or optgroup
847 !tags.indexOf("<opt") &&
848 [ 1, "<select multiple='multiple'>", "</select>" ] ||
850 !tags.indexOf("<leg") &&
851 [ 1, "<fieldset>", "</fieldset>" ] ||
853 tags.match(/^<(thead|tbody|tfoot|colg|cap)/) &&
854 [ 1, "<table>", "</table>" ] ||
856 !tags.indexOf("<tr") &&
857 [ 2, "<table><tbody>", "</tbody></table>" ] ||
859 // <thead> matched above
860 (!tags.indexOf("<td") || !tags.indexOf("<th")) &&
861 [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ] ||
863 !tags.indexOf("<col") &&
864 [ 2, "<table><tbody></tbody><colgroup>", "</colgroup></table>" ] ||
866 // IE can't serialize <link> and <script> tags normally
867 !jQuery.support.htmlSerialize &&
868 [ 1, "div<div>", "</div>" ] ||
872 // Go to html and back, then peel off extra wrappers
873 div.innerHTML = wrap[1] + elem + wrap[2];
875 // Move to the right depth
879 // Remove IE's autoinserted <tbody> from table fragments
880 if ( !jQuery.support.tbody ) {
882 // String was a <table>, *may* have spurious <tbody>
883 var tbody = !tags.indexOf("<table") && tags.indexOf("<tbody") < 0 ?
884 div.firstChild && div.firstChild.childNodes :
886 // String was a bare <thead> or <tfoot>
887 wrap[1] == "<table>" && tags.indexOf("<tbody") < 0 ?
891 for ( var j = tbody.length - 1; j >= 0 ; --j )
892 if ( jQuery.nodeName( tbody[ j ], "tbody" ) && !tbody[ j ].childNodes.length )
893 tbody[ j ].parentNode.removeChild( tbody[ j ] );
897 // IE completely kills leading whitespace when innerHTML is used
898 if ( !jQuery.support.leadingWhitespace && /^\s/.test( elem ) )
899 div.insertBefore( context.createTextNode( elem.match(/^\s*/)[0] ), div.firstChild );
901 elem = jQuery.makeArray( div.childNodes );
907 ret = jQuery.merge( ret, elem );
912 for ( var i = 0; ret[i]; i++ ) {
913 if ( jQuery.nodeName( ret[i], "script" ) ) {
914 scripts.push( ret[i].parentNode.removeChild( ret[i] ) );
916 if ( ret[i].nodeType === 1 )
917 ret.splice.apply( ret, [i + 1, 0].concat(jQuery.makeArray(ret[i].getElementsByTagName("script"))) );
918 fragment.appendChild( ret[i] );
928 attr: function( elem, name, value ) {
929 // don't set attributes on text and comment nodes
930 if (!elem || elem.nodeType == 3 || elem.nodeType == 8)
933 var notxml = !jQuery.isXMLDoc( elem ),
934 // Whether we are setting (or getting)
935 set = value !== undefined;
937 // Try to normalize/fix the name
938 name = notxml && jQuery.props[ name ] || name;
940 // Only do all the following if this is a node (faster for style)
941 // IE elem.getAttribute passes even for style
942 if ( elem.tagName ) {
944 // These attributes require special treatment
945 var special = /href|src|style/.test( name );
947 // Safari mis-reports the default selected property of a hidden option
948 // Accessing the parent's selectedIndex property fixes it
949 if ( name == "selected" )
950 elem.parentNode.selectedIndex;
952 // If applicable, access the attribute via the DOM 0 way
953 if ( name in elem && notxml && !special ) {
955 // We can't allow the type property to be changed (since it causes problems in IE)
956 if ( name == "type" && jQuery.nodeName( elem, "input" ) && elem.parentNode )
957 throw "type property can't be changed";
959 elem[ name ] = value;
962 // browsers index elements by id/name on forms, give priority to attributes.
963 if( jQuery.nodeName( elem, "form" ) && elem.getAttributeNode(name) )
964 return elem.getAttributeNode( name ).nodeValue;
966 // elem.tabindex doesn't always return the correct value
967 // http://fluidproject.org/blog/2008/01/09/getting-setting-and-removing-tabindex-values-with-javascript/
968 if ( name == jQuery.props.tabindex ) {
969 var attributeNode = elem.getAttributeNode(jQuery.props.tabindex);
970 return attributeNode && attributeNode.specified && attributeNode.value || undefined;
976 if ( !jQuery.support.style && notxml && name == "style" )
977 return jQuery.attr( elem.style, "cssText", value );
980 // convert the value to a string (all browsers do this but IE) see #1070
981 elem.setAttribute( name, "" + value );
983 var attr = !jQuery.support.hrefNormalized && notxml && special
984 // Some attributes require a special call on IE
985 ? elem.getAttribute( name, 2 )
986 : elem.getAttribute( name );
988 // Non-existent attributes return null, we normalize to undefined
989 return attr === null ? undefined : attr;
992 // elem is actually elem.style ... set the style
994 // IE uses filters for opacity
995 if ( !jQuery.support.opacity && name == "opacity" ) {
997 // IE has trouble with opacity if it does not have layout
998 // Force it by setting the zoom level
1001 // Set the alpha filter to set the opacity
1002 elem.filter = (elem.filter || "").replace( /alpha\([^)]*\)/, "" ) +
1003 (parseInt( value ) + '' == "NaN" ? "" : "alpha(opacity=" + value * 100 + ")");
1006 return elem.filter && elem.filter.indexOf("opacity=") >= 0 ?
1007 (parseFloat( elem.filter.match(/opacity=([^)]*)/)[1] ) / 100) + '':
1011 name = name.replace(/-([a-z])/ig, function(all, letter){
1012 return letter.toUpperCase();
1016 elem[ name ] = value;
1018 return elem[ name ];
1021 trim: function( text ) {
1022 return (text || "").replace( /^\s+|\s+$/g, "" );
1025 makeArray: function( array ) {
1028 if( array != null ){
1029 var i = array.length;
1030 // The window, strings (and functions) also have 'length'
1031 if( i == null || typeof array === "string" || jQuery.isFunction(array) || array.setInterval )
1035 ret[--i] = array[i];
1041 inArray: function( elem, array ) {
1042 for ( var i = 0, length = array.length; i < length; i++ )
1043 // Use === because on IE, window == document
1044 if ( array[ i ] === elem )
1050 merge: function( first, second ) {
1051 // We have to loop this way because IE & Opera overwrite the length
1052 // expando of getElementsByTagName
1053 var i = 0, elem, pos = first.length;
1054 // Also, we need to make sure that the correct elements are being returned
1055 // (IE returns comment nodes in a '*' query)
1056 if ( !jQuery.support.getAll ) {
1057 while ( (elem = second[ i++ ]) != null )
1058 if ( elem.nodeType != 8 )
1059 first[ pos++ ] = elem;
1062 while ( (elem = second[ i++ ]) != null )
1063 first[ pos++ ] = elem;
1068 unique: function( array ) {
1069 var ret = [], done = {};
1073 for ( var i = 0, length = array.length; i < length; i++ ) {
1074 var id = jQuery.data( array[ i ] );
1076 if ( !done[ id ] ) {
1078 ret.push( array[ i ] );
1089 grep: function( elems, callback, inv ) {
1092 // Go through the array, only saving the items
1093 // that pass the validator function
1094 for ( var i = 0, length = elems.length; i < length; i++ )
1095 if ( !inv != !callback( elems[ i ], i ) )
1096 ret.push( elems[ i ] );
1101 map: function( elems, callback ) {
1104 // Go through the array, translating each of the items to their
1105 // new value (or values).
1106 for ( var i = 0, length = elems.length; i < length; i++ ) {
1107 var value = callback( elems[ i ], i );
1109 if ( value != null )
1110 ret[ ret.length ] = value;
1113 return ret.concat.apply( [], ret );
1117 // Use of jQuery.browser is deprecated.
1118 // It's included for backwards compatibility and plugins,
1119 // although they should work to migrate away.
1121 var userAgent = navigator.userAgent.toLowerCase();
1123 // Figure out what browser is being used
1125 version: (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [0,'0'])[1],
1126 safari: /webkit/.test( userAgent ),
1127 opera: /opera/.test( userAgent ),
1128 msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
1129 mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )
1132 // Check to see if the W3C box model is being used
1133 jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
1136 parent: function(elem){return elem.parentNode;},
1137 parents: function(elem){return jQuery.dir(elem,"parentNode");},
1138 next: function(elem){return jQuery.nth(elem,2,"nextSibling");},
1139 prev: function(elem){return jQuery.nth(elem,2,"previousSibling");},
1140 nextAll: function(elem){return jQuery.dir(elem,"nextSibling");},
1141 prevAll: function(elem){return jQuery.dir(elem,"previousSibling");},
1142 siblings: function(elem){return jQuery.sibling(elem.parentNode.firstChild,elem);},
1143 children: function(elem){return jQuery.sibling(elem.firstChild);},
1144 contents: function(elem){return jQuery.nodeName(elem,"iframe")?elem.contentDocument||elem.contentWindow.document:jQuery.makeArray(elem.childNodes);}
1145 }, function(name, fn){
1146 jQuery.fn[ name ] = function( selector ) {
1147 var ret = jQuery.map( this, fn );
1149 if ( selector && typeof selector == "string" )
1150 ret = jQuery.multiFilter( selector, ret );
1152 return this.pushStack( jQuery.unique( ret ), name, selector );
1158 prependTo: "prepend",
1159 insertBefore: "before",
1160 insertAfter: "after",
1161 replaceAll: "replaceWith"
1162 }, function(name, original){
1163 jQuery.fn[ name ] = function() {
1164 var args = arguments;
1166 return this.each(function(){
1167 for ( var i = 0, length = args.length; i < length; i++ )
1168 jQuery( args[ i ] )[ original ]( this );
1174 removeAttr: function( name ) {
1175 jQuery.attr( this, name, "" );
1176 if (this.nodeType == 1)
1177 this.removeAttribute( name );
1180 addClass: function( classNames ) {
1181 jQuery.className.add( this, classNames );
1184 removeClass: function( classNames ) {
1185 jQuery.className.remove( this, classNames );
1188 toggleClass: function( classNames, state ) {
1189 if( typeof state !== "boolean" )
1190 state = !jQuery.className.has( this, classNames );
1191 jQuery.className[ state ? "add" : "remove" ]( this, classNames );
1194 remove: function( selector ) {
1195 if ( !selector || jQuery.filter( selector, [ this ] ).length ) {
1196 // Prevent memory leaks
1197 jQuery( "*", this ).add([this]).each(function(){
1198 jQuery.event.remove(this);
1199 jQuery.removeData(this);
1201 if (this.parentNode)
1202 this.parentNode.removeChild( this );
1207 // Remove element nodes and prevent memory leaks
1208 jQuery( ">*", this ).remove();
1210 // Remove any remaining nodes
1211 while ( this.firstChild )
1212 this.removeChild( this.firstChild );
1214 }, function(name, fn){
1215 jQuery.fn[ name ] = function(){
1216 return this.each( fn, arguments );
1220 // Helper function used by the dimensions and offset modules
1221 function num(elem, prop) {
1222 return elem[0] && parseInt( jQuery.curCSS(elem[0], prop, true), 10 ) || 0;