2 * jQuery @VERSION - New Wave Javascript
4 * Copyright (c) 2007 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 if ( typeof jQuery != "undefined" )
16 var jQuery = window.jQuery = function(a,c) {
17 // If the context is global, return a new object
18 if ( window == this || !this.init )
19 return new jQuery(a,c);
21 return this.init(a,c);
24 // Map over the $ in case of overwrite
25 if ( typeof $ != "undefined" )
28 // Map the jQuery namespace to the '$' one
31 var quickExpr = /^[^<]*(<(.|\s)+>)[^>]*$|^#(\w+)$/;
33 jQuery.fn = jQuery.prototype = {
35 // Make sure that a selection was provided
38 // Handle HTML strings
39 if ( typeof a == "string" ) {
40 var m = quickExpr.exec(a);
41 if ( m && (m[1] || !c) ) {
42 // HANDLE: $(html) -> $(array)
44 a = jQuery.clean( [ m[1] ], c );
48 var tmp = document.getElementById( m[3] );
50 // Handle the case where IE and Opera return items
51 // by name instead of ID
53 return jQuery().find( a );
65 return new jQuery( c ).find( a );
67 // HANDLE: $(function)
68 // Shortcut for document ready
69 } else if ( jQuery.isFunction(a) )
70 return new jQuery(document)[ jQuery.fn.ready ? "ready" : "load" ]( a );
74 a.constructor == Array && a ||
76 // HANDLE: $(arraylike)
77 // Watch for when an array-like object is passed as the selector
78 (a.jquery || a.length && a != window && !a.nodeType && a[0] != undefined && a[0].nodeType) && jQuery.makeArray( a ) ||
92 get: function( num ) {
93 return num == undefined ?
95 // Return a 'clean' array
96 jQuery.makeArray( this ) :
98 // Return just the object
102 pushStack: function( a ) {
104 ret.prevObject = this;
108 setArray: function( a ) {
110 Array.prototype.push.apply( this, a );
114 each: function( fn, args ) {
115 return jQuery.each( this, fn, args );
118 index: function( obj ) {
120 this.each(function(i){
121 if ( this == obj ) pos = i;
126 attr: function( key, value, type ) {
129 // Look for the case where we're accessing a style value
130 if ( key.constructor == String )
131 if ( value == undefined )
132 return this.length && jQuery[ type || "attr" ]( this[0], key ) || undefined;
138 // Check to see if we're setting style values
139 return this.each(function(index){
140 // Set all the styles
141 for ( var prop in obj )
143 type ? this.style : this,
144 prop, jQuery.prop(this, obj[prop], type, index, prop)
149 css: function( key, value ) {
150 return this.attr( key, value, "curCSS" );
154 if ( typeof e != "object" && e != null )
155 return this.empty().append( document.createTextNode( e ) );
158 jQuery.each( e || this, function(){
159 jQuery.each( this.childNodes, function(){
160 if ( this.nodeType != 8 )
161 t += this.nodeType != 1 ?
162 this.nodeValue : jQuery.fn.text([ this ]);
168 wrapAll: function(html) {
170 // The elements to wrap the target around
171 jQuery(html, this[0].ownerDocument)
173 .insertBefore(this[0])
176 while ( elem.firstChild )
177 elem = elem.firstChild;
185 wrapInner: function(html) {
186 return this.each(function(){
187 jQuery(this).contents().wrapAll(html);
191 wrap: function(html) {
192 return this.each(function(){
193 jQuery(this).wrapAll(html);
198 return this.domManip(arguments, true, 1, function(a){
199 this.appendChild( a );
203 prepend: function() {
204 return this.domManip(arguments, true, -1, function(a){
205 this.insertBefore( a, this.firstChild );
210 return this.domManip(arguments, false, 1, function(a){
211 this.parentNode.insertBefore( a, this );
216 return this.domManip(arguments, false, -1, function(a){
217 this.parentNode.insertBefore( a, this.nextSibling );
222 return this.prevObject || jQuery([]);
226 var data = jQuery.map(this, function(a){ return jQuery.find(t,a); });
227 return this.pushStack( /[^+>] [^+>]/.test( t ) || t.indexOf("..") > -1 ?
228 jQuery.unique( data ) : data );
232 var $this = this.add(this.find("*"));
233 if (jQuery.browser.msie) {
234 // Need to remove events on the element and its descendants
235 $this.each(function() {
237 for (var type in this.$events)
238 this._$events[type] = jQuery.extend({},this.$events[type]);
243 var r = this.pushStack( jQuery.map( this, function(a){
244 return a.cloneNode( true );
247 if (jQuery.browser.msie) {
248 $this.each(function() {
249 // Add the events back to the original and its descendants
250 var events = this._$events;
251 for (var type in events)
252 for (var handler in events[type])
253 jQuery.event.add(this, type, events[type][handler], events[type][handler].data);
254 this._$events = null;
258 // copy form values over
259 var inputs = r.add(r.find('*')).filter('select,input[@type=checkbox]');
260 $this.filter('select,input[@type=checkbox]').each(function(i) {
261 if (this.selectedIndex)
262 inputs[i].selectedIndex = this.selectedIndex;
264 inputs[i].checked = true;
267 // Return the cloned set
271 filter: function(t) {
272 return this.pushStack(
273 jQuery.isFunction( t ) &&
274 jQuery.grep(this, function(el, index){
275 return t.apply(el, [index]);
278 jQuery.multiFilter(t,this) );
282 return this.pushStack(
283 t.constructor == String &&
284 jQuery.multiFilter(t, this, true) ||
286 jQuery.grep(this, function(a) {
287 return ( t.constructor == Array || t.jquery )
288 ? jQuery.inArray( a, t ) < 0
295 return this.pushStack( jQuery.merge(
297 t.constructor == String ?
299 t.length != undefined && (!t.nodeName || t.nodeName == "FORM") ?
305 return expr ? jQuery.multiFilter(expr,this).length > 0 : false;
308 val: function( val ) {
309 return val == undefined ?
310 ( this.length ? this[0].value : null ) :
311 this.attr( "value", val );
314 html: function( val ) {
315 return val == undefined ?
316 ( this.length ? this[0].innerHTML : null ) :
317 this.empty().append( val );
320 replaceWith: function( val ) {
321 return this.after( val ).remove();
325 return this.pushStack( Array.prototype.slice.apply( this, arguments ) );
329 return this.pushStack(jQuery.map( this, function(elem,i){
330 return fn.call( elem, i, elem );
334 domManip: function(args, table, dir, fn){
335 var clone = this.length > 1, a;
337 return this.each(function(){
339 a = jQuery.clean(args, this.ownerDocument);
346 if ( table && jQuery.nodeName(this, "table") && jQuery.nodeName(a[0], "tr") )
347 obj = this.getElementsByTagName("tbody")[0] || this.appendChild(document.createElement("tbody"));
349 jQuery.each( a, function(){
350 if ( jQuery.nodeName(this, "script") ) {
352 jQuery.ajax({ url: this.src, async: false, dataType: "script" });
354 jQuery.globalEval( this.text || this.textContent || this.innerHTML || "" );
356 fn.apply( obj, [ clone ? this.cloneNode(true) : this ] );
362 jQuery.extend = jQuery.fn.extend = function() {
363 // copy reference to target object
364 var target = arguments[0] || {}, a = 1, al = arguments.length, deep = false;
366 // Handle a deep copy situation
367 if ( target.constructor == Boolean ) {
369 target = arguments[1] || {};
372 // extend jQuery itself if only one argument is passed
380 for ( ; a < al; a++ )
381 // Only deal with non-null/undefined values
382 if ( (prop = arguments[a]) != null )
383 // Extend the base object
384 for ( var i in prop ) {
385 // Prevent never-ending loop
386 if ( target == prop[i] )
389 // Recurse if we're merging object values
390 if ( deep && typeof prop[i] == 'object' && target[i] )
391 jQuery.extend( target[i], prop[i] );
393 // Don't bring in undefined values
394 else if ( prop[i] != undefined )
398 // Return the modified object
403 noConflict: function(deep) {
406 window.jQuery = _jQuery;
410 // This may seem like some crazy code, but trust me when I say that this
411 // is the only cross-browser way to do this. --John
412 isFunction: function( fn ) {
413 return !!fn && typeof fn != "string" && !fn.nodeName &&
414 fn.constructor != Array && /function/i.test( fn + "" );
417 // check if an element is in a XML document
418 isXMLDoc: function(elem) {
419 return elem.documentElement && !elem.body ||
420 elem.tagName && elem.ownerDocument && !elem.ownerDocument.body;
423 // Evalulates a script in a global context
424 // Evaluates Async. in Safari 2 :-(
425 globalEval: function( data ) {
426 data = jQuery.trim( data );
428 if ( window.execScript )
429 window.execScript( data );
430 else if ( jQuery.browser.safari )
431 // safari doesn't provide a synchronous global eval
432 window.setTimeout( data, 0 );
434 eval.call( window, data );
438 nodeName: function( elem, name ) {
439 return elem.nodeName && elem.nodeName.toUpperCase() == name.toUpperCase();
442 // args is for internal usage only
443 each: function( obj, fn, args ) {
445 if ( obj.length == undefined )
447 fn.apply( obj[i], args );
449 for ( var i = 0, ol = obj.length; i < ol; i++ )
450 if ( fn.apply( obj[i], args ) === false ) break;
452 // A special, fast, case for the most common use of each
454 if ( obj.length == undefined )
456 fn.call( obj[i], i, obj[i] );
458 for ( var i = 0, ol = obj.length, val = obj[0];
459 i < ol && fn.call(val,i,val) !== false; val = obj[++i] ){}
465 prop: function(elem, value, type, index, prop){
466 // Handle executable functions
467 if ( jQuery.isFunction( value ) )
468 value = value.call( elem, [index] );
470 // exclude the following css properties to add px
471 var exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i;
473 // Handle passing in a number to a CSS property
474 return value && value.constructor == Number && type == "curCSS" && !exclude.test(prop) ?
480 // internal only, use addClass("class")
481 add: function( elem, c ){
482 jQuery.each( (c || "").split(/\s+/), function(i, cur){
483 if ( !jQuery.className.has( elem.className, cur ) )
484 elem.className += ( elem.className ? " " : "" ) + cur;
488 // internal only, use removeClass("class")
489 remove: function( elem, c ){
490 elem.className = c != undefined ?
491 jQuery.grep( elem.className.split(/\s+/), function(cur){
492 return !jQuery.className.has( c, cur );
496 // internal only, use is(".class")
497 has: function( t, c ) {
498 return jQuery.inArray( c, (t.className || t).toString().split(/\s+/) ) > -1;
502 swap: function(e,o,f) {
504 e.style["old"+i] = e.style[i];
509 e.style[i] = e.style["old"+i];
513 if ( p == "height" || p == "width" ) {
514 var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"];
516 jQuery.each( d, function(){
517 old["padding" + this] = 0;
518 old["border" + this + "Width"] = 0;
521 jQuery.swap( e, old, function() {
522 if ( jQuery(e).is(':visible') ) {
523 oHeight = e.offsetHeight;
524 oWidth = e.offsetWidth;
526 e = jQuery(e.cloneNode(true))
527 .find(":radio").removeAttr("checked").end()
529 visibility: "hidden", position: "absolute", display: "block", right: "0", left: "0"
530 }).appendTo(e.parentNode)[0];
532 var parPos = jQuery.css(e.parentNode,"position") || "static";
533 if ( parPos == "static" )
534 e.parentNode.style.position = "relative";
536 oHeight = e.clientHeight;
537 oWidth = e.clientWidth;
539 if ( parPos == "static" )
540 e.parentNode.style.position = "static";
542 e.parentNode.removeChild(e);
546 return p == "height" ? oHeight : oWidth;
549 return jQuery.curCSS( e, p );
552 curCSS: function(elem, prop, force) {
553 var ret, stack = [], swap = [];
555 // A helper method for determining if an element's values are broken
557 if ( !jQuery.browser.safari )
560 var ret = document.defaultView.getComputedStyle(a,null);
561 return !ret || ret.getPropertyValue("color") == "";
564 if (prop == "opacity" && jQuery.browser.msie) {
565 ret = jQuery.attr(elem.style, "opacity");
566 return ret == "" ? "1" : ret;
569 if (prop.match(/float/i))
572 if (!force && elem.style[prop])
573 ret = elem.style[prop];
575 else if (document.defaultView && document.defaultView.getComputedStyle) {
577 if (prop.match(/float/i))
580 prop = prop.replace(/([A-Z])/g,"-$1").toLowerCase();
581 var cur = document.defaultView.getComputedStyle(elem, null);
583 if ( cur && !color(elem) )
584 ret = cur.getPropertyValue(prop);
586 // If the element isn't reporting its values properly in Safari
587 // then some display: none elements are involved
589 // Locate all of the parent display: none elements
590 for ( var a = elem; a && color(a); a = a.parentNode )
593 // Go through and make them visible, but in reverse
594 // (It would be better if we knew the exact display type that they had)
595 for ( a = 0; a < stack.length; a++ )
596 if ( color(stack[a]) ) {
597 swap[a] = stack[a].style.display;
598 stack[a].style.display = "block";
601 // Since we flip the display style, we have to handle that
602 // one special, otherwise get the value
603 ret = prop == "display" && swap[stack.length-1] != null ?
605 document.defaultView.getComputedStyle(elem,null).getPropertyValue(prop) || "";
607 // Finally, revert the display styles back
608 for ( a = 0; a < swap.length; a++ )
609 if ( swap[a] != null )
610 stack[a].style.display = swap[a];
613 if ( prop == "opacity" && ret == "" )
616 } else if (elem.currentStyle) {
617 var newProp = prop.replace(/\-(\w)/g,function(m,c){return c.toUpperCase();});
618 ret = elem.currentStyle[prop] || elem.currentStyle[newProp];
624 clean: function(a, doc) {
626 doc = doc || document;
628 jQuery.each( a, function(i,arg){
631 if ( arg.constructor == Number )
632 arg = arg.toString();
634 // Convert html string into DOM nodes
635 if ( typeof arg == "string" ) {
636 // Trim whitespace, otherwise indexOf won't work as expected
637 var s = jQuery.trim(arg).toLowerCase(), div = doc.createElement("div"), tb = [];
640 // option or optgroup
641 !s.indexOf("<opt") &&
642 [1, "<select>", "</select>"] ||
644 !s.indexOf("<leg") &&
645 [1, "<fieldset>", "</fieldset>"] ||
647 s.match(/^<(thead|tbody|tfoot|colg|cap)/) &&
648 [1, "<table>", "</table>"] ||
651 [2, "<table><tbody>", "</tbody></table>"] ||
653 // <thead> matched above
654 (!s.indexOf("<td") || !s.indexOf("<th")) &&
655 [3, "<table><tbody><tr>", "</tr></tbody></table>"] ||
657 !s.indexOf("<col") &&
658 [2, "<table><tbody></tbody><colgroup>", "</colgroup></table>"] ||
660 // IE can't serialize <link> and <script> tags normally
661 jQuery.browser.msie &&
662 [1, "div<div>", "</div>"] ||
666 // Go to html and back, then peel off extra wrappers
667 div.innerHTML = wrap[1] + arg + wrap[2];
669 // Move to the right depth
673 // Remove IE's autoinserted <tbody> from table fragments
674 if ( jQuery.browser.msie ) {
676 // String was a <table>, *may* have spurious <tbody>
677 if ( !s.indexOf("<table") && s.indexOf("<tbody") < 0 )
678 tb = div.firstChild && div.firstChild.childNodes;
680 // String was a bare <thead> or <tfoot>
681 else if ( wrap[1] == "<table>" && s.indexOf("<tbody") < 0 )
684 for ( var n = tb.length-1; n >= 0 ; --n )
685 if ( jQuery.nodeName(tb[n], "tbody") && !tb[n].childNodes.length )
686 tb[n].parentNode.removeChild(tb[n]);
688 // IE completely kills leading whitespace when innerHTML is used
689 if ( /^\s/.test(arg) )
690 div.insertBefore( doc.createTextNode( arg.match(/^\s*/)[0] ), div.firstChild );
694 arg = jQuery.makeArray( div.childNodes );
697 if ( 0 === arg.length && (!jQuery.nodeName(arg, "form") && !jQuery.nodeName(arg, "select")) )
700 if ( arg[0] == undefined || jQuery.nodeName(arg, "form") || arg.options )
703 r = jQuery.merge( r, arg );
710 attr: function(elem, name, value){
711 var fix = jQuery.isXMLDoc(elem) ? {} : jQuery.props;
713 // Safari mis-reports the default selected property of a hidden option
714 // Accessing the parent's selectedIndex property fixes it
715 if ( name == "selected" && jQuery.browser.safari )
716 elem.parentNode.selectedIndex;
718 // Certain attributes only work when accessed via the old DOM 0 way
720 if ( value != undefined ) elem[fix[name]] = value;
721 return elem[fix[name]];
722 } else if ( jQuery.browser.msie && name == "style" )
723 return jQuery.attr( elem.style, "cssText", value );
725 else if ( value == undefined && jQuery.browser.msie && jQuery.nodeName(elem, "form") && (name == "action" || name == "method") )
726 return elem.getAttributeNode(name).nodeValue;
728 // IE elem.getAttribute passes even for style
729 else if ( elem.tagName ) {
731 if ( value != undefined ) elem.setAttribute( name, value );
732 if ( jQuery.browser.msie && /href|src/.test(name) && !jQuery.isXMLDoc(elem) )
733 return elem.getAttribute( name, 2 );
734 return elem.getAttribute( name );
736 // elem is actually elem.style ... set the style
738 // IE actually uses filters for opacity
739 if ( name == "opacity" && jQuery.browser.msie ) {
740 if ( value != undefined ) {
741 // IE has trouble with opacity if it does not have layout
742 // Force it by setting the zoom level
745 // Set the alpha filter to set the opacity
746 elem.filter = (elem.filter || "").replace(/alpha\([^)]*\)/,"") +
747 (parseFloat(value).toString() == "NaN" ? "" : "alpha(opacity=" + value * 100 + ")");
751 (parseFloat( elem.filter.match(/opacity=([^)]*)/)[1] ) / 100).toString() : "";
753 name = name.replace(/-([a-z])/ig,function(z,b){return b.toUpperCase();});
754 if ( value != undefined ) elem[name] = value;
760 return (t||"").replace(/^\s+|\s+$/g, "");
763 makeArray: function( a ) {
766 // Need to use typeof to fight Safari childNodes crashes
767 if ( typeof a != "array" )
768 for ( var i = 0, al = a.length; i < al; i++ )
776 inArray: function( b, a ) {
777 for ( var i = 0, al = a.length; i < al; i++ )
783 merge: function(first, second) {
784 // We have to loop this way because IE & Opera overwrite the length
785 // expando of getElementsByTagName
787 // Also, we need to make sure that the correct elements are being returned
788 // (IE returns comment nodes in a '*' query)
789 if ( jQuery.browser.msie ) {
790 for ( var i = 0; second[i]; i++ )
791 if ( second[i].nodeType != 8 )
792 first.push(second[i]);
794 for ( var i = 0; second[i]; i++ )
795 first.push(second[i]);
800 unique: function(first) {
801 var r = [], num = jQuery.mergeNum++;
804 for ( var i = 0, fl = first.length; i < fl; i++ )
805 if ( num != first[i].mergeNum ) {
806 first[i].mergeNum = num;
818 grep: function(elems, fn, inv) {
819 // If a string is passed in for the function, make a function
820 // for it (a handy shortcut)
821 if ( typeof fn == "string" )
822 fn = eval("false||function(a,i){return " + fn + "}");
826 // Go through the array, only saving the items
827 // that pass the validator function
828 for ( var i = 0, el = elems.length; i < el; i++ )
829 if ( !inv && fn(elems[i],i) || inv && !fn(elems[i],i) )
830 result.push( elems[i] );
835 map: function(elems, fn) {
836 // If a string is passed in for the function, make a function
837 // for it (a handy shortcut)
838 if ( typeof fn == "string" )
839 fn = eval("false||function(a){return " + fn + "}");
843 // Go through the array, translating each of the items to their
844 // new value (or values).
845 for ( var i = 0, el = elems.length; i < el; i++ ) {
846 var val = fn(elems[i],i);
848 if ( val !== null && val != undefined ) {
849 if ( val.constructor != Array ) val = [val];
850 result = result.concat( val );
858 var userAgent = navigator.userAgent.toLowerCase();
860 // Figure out what browser is being used
862 version: (userAgent.match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/) || [])[1],
863 safari: /webkit/.test(userAgent),
864 opera: /opera/.test(userAgent),
865 msie: /msie/.test(userAgent) && !/opera/.test(userAgent),
866 mozilla: /mozilla/.test(userAgent) && !/(compatible|webkit)/.test(userAgent)
869 var styleFloat = jQuery.browser.msie ? "styleFloat" : "cssFloat";
872 // Check to see if the W3C box model is being used
873 boxModel: !jQuery.browser.msie || document.compatMode == "CSS1Compat",
875 styleFloat: jQuery.browser.msie ? "styleFloat" : "cssFloat",
879 "class": "className",
881 cssFloat: styleFloat,
882 styleFloat: styleFloat,
883 innerHTML: "innerHTML",
884 className: "className",
886 disabled: "disabled",
888 readonly: "readOnly",
889 selected: "selected",
890 maxlength: "maxLength"
895 parent: "a.parentNode",
896 parents: "jQuery.parents(a)",
897 next: "jQuery.nth(a,2,'nextSibling')",
898 prev: "jQuery.nth(a,2,'previousSibling')",
899 siblings: "jQuery.sibling(a.parentNode.firstChild,a)",
900 children: "jQuery.sibling(a.firstChild)",
901 contents: "jQuery.nodeName(a,'iframe')?a.contentDocument||a.contentWindow.document:jQuery.makeArray(a.childNodes)"
903 jQuery.fn[ i ] = function(a) {
904 var ret = jQuery.map(this,n);
905 if ( a && typeof a == "string" )
906 ret = jQuery.multiFilter(a,ret);
907 return this.pushStack( jQuery.unique(ret) );
913 prependTo: "prepend",
914 insertBefore: "before",
915 insertAfter: "after",
916 replaceAll: "replaceWith"
918 jQuery.fn[ i ] = function(){
920 return this.each(function(){
921 for ( var j = 0, al = a.length; j < al; j++ )
922 jQuery(a[j])[n]( this );
928 removeAttr: function( key ) {
929 jQuery.attr( this, key, "" );
930 this.removeAttribute( key );
932 addClass: function(c){
933 jQuery.className.add(this,c);
935 removeClass: function(c){
936 jQuery.className.remove(this,c);
938 toggleClass: function( c ){
939 jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this, c);
942 if ( !a || jQuery.filter( a, [this] ).r.length )
943 this.parentNode.removeChild( this );
946 while ( this.firstChild )
947 this.removeChild( this.firstChild );
950 jQuery.fn[ i ] = function() {
951 return this.each( n, arguments );
955 jQuery.each( [ "height", "width" ], function(i,n){
956 jQuery.fn[ n ] = function(h) {
957 return h == undefined ?
958 ( this.length ? jQuery.css( this[0], n ) : null ) :
959 this.css( n, h.constructor == String ? h : h + "px" );