3 * jQuery 1.2.1 - New Wave Javascript
5 * Copyright (c) 2007 John Resig (jquery.com)
6 * Dual licensed under the MIT (MIT-LICENSE.txt)
7 * and GPL (GPL-LICENSE.txt) licenses.
9 * $Date: 2007-09-16 23:42:06 -0400 (Sun, 16 Sep 2007) $
13 // Map over jQuery in case of overwrite
14 if ( typeof jQuery != "undefined" )
17 var jQuery = window.jQuery = function(selector, context) {
18 // If the context is a namespace object, return a new object
19 return this instanceof jQuery ?
20 this.init(selector, context) :
21 new jQuery(selector, context);
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 = {
34 init: function(selector, context) {
35 // Make sure that a selection was provided
36 selector = selector || document;
38 // Handle HTML strings
39 if ( typeof selector == "string" ) {
40 var m = quickExpr.exec(selector);
41 if ( m && (m[1] || !context) ) {
42 // HANDLE: $(html) -> $(array)
44 selector = jQuery.clean( [ m[1] ], context );
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( selector );
65 return new jQuery( context ).find( selector );
67 // HANDLE: $(function)
68 // Shortcut for document ready
69 } else if ( jQuery.isFunction(selector) )
70 return new jQuery(document)[ jQuery.fn.ready ? "ready" : "load" ]( selector );
74 selector.constructor == Array && selector ||
76 // HANDLE: $(arraylike)
77 // Watch for when an array-like object is passed as the selector
78 (selector.jquery || selector.length && selector != window && !selector.nodeType && selector[0] != undefined && selector[0].nodeType) && jQuery.makeArray( selector ) ||
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 );
231 clone: function(events) {
233 var ret = this.map(function(){
234 return this.outerHTML ? jQuery(this.outerHTML)[0] : this.cloneNode(true);
237 // Need to set the expando to null on the cloned set if it exists
238 // removeData doesn't work here, IE removes it from the original as well
239 // this is primarily for IE but the data expando shouldn't be copied over in any browser
240 var clone = ret.find("*").andSelf().each(function(){
241 if ( this[ expando ] != undefined )
242 this[ expando ] = null;
245 // Copy the events from the original to the clone
247 this.find("*").andSelf().each(function(i) {
248 var events = jQuery.data(this, "events");
249 for ( var type in events )
250 for ( var handler in events[type] )
251 jQuery.event.add(clone[i], type, events[type][handler], events[type][handler].data);
254 // Return the cloned set
258 filter: function(t) {
259 return this.pushStack(
260 jQuery.isFunction( t ) &&
261 jQuery.grep(this, function(el, index){
262 return t.apply(el, [index]);
265 jQuery.multiFilter(t,this) );
269 return this.pushStack(
270 t.constructor == String &&
271 jQuery.multiFilter(t, this, true) ||
273 jQuery.grep(this, function(a) {
274 return ( t.constructor == Array || t.jquery )
275 ? jQuery.inArray( a, t ) < 0
282 return this.pushStack( jQuery.merge(
284 t.constructor == String ?
286 t.length != undefined && (!t.nodeName || jQuery.nodeName(t, "form")) ?
292 return expr ? jQuery.multiFilter(expr,this).length > 0 : false;
295 hasClass: function(expr) {
296 return this.is("." + expr);
299 val: function( val ) {
300 if ( val == undefined ) {
304 // We need to handle select boxes special
305 if ( jQuery.nodeName(elem, "select") ) {
306 var index = elem.selectedIndex,
308 options = elem.options,
309 one = elem.type == "select-one";
311 // Nothing was selected
315 // Loop through all the selected options
316 for ( var i = one ? index : 0, max = one ? index + 1 : options.length; i < max; i++ ) {
317 var option = options[i];
318 if ( option.selected ) {
319 // Get the specifc value for the option
320 var val = jQuery.browser.msie && !option.attributes["value"].specified ? option.text : option.value;
322 // We don't need an array for one selects
326 // Multi-Selects return an array
333 // Everything else, we just grab the value
335 return this[0].value.replace(/\r/g, "");
338 return this.each(function(){
339 if ( val.constructor == Array && /radio|checkbox/.test(this.type) )
340 this.checked = (jQuery.inArray(this.value, val) >= 0 ||
341 jQuery.inArray(this.name, val) >= 0);
342 else if ( jQuery.nodeName(this, "select") ) {
343 var tmp = val.constructor == Array ? val : [val];
345 jQuery("option", this).each(function(){
346 this.selected = (jQuery.inArray(this.value, tmp) >= 0 ||
347 jQuery.inArray(this.text, tmp) >= 0);
351 this.selectedIndex = -1;
357 html: function( val ) {
358 return val == undefined ?
359 ( this.length ? this[0].innerHTML : null ) :
360 this.empty().append( val );
363 replaceWith: function( val ) {
364 return this.after( val ).remove();
368 return this.slice(i, i+1);
372 return this.pushStack( Array.prototype.slice.apply( this, arguments ) );
376 return this.pushStack(jQuery.map( this, function(elem,i){
377 return fn.call( elem, i, elem );
381 andSelf: function() {
382 return this.add( this.prevObject );
385 domManip: function(args, table, dir, fn) {
386 var clone = this.length > 1, a;
388 return this.each(function(){
390 a = jQuery.clean(args, this.ownerDocument);
397 if ( table && jQuery.nodeName(this, "table") && jQuery.nodeName(a[0], "tr") )
398 obj = this.getElementsByTagName("tbody")[0] || this.appendChild(document.createElement("tbody"));
400 jQuery.each( a, function(){
401 var elem = clone ? this.cloneNode(true) : this;
402 if ( !evalScript(0, elem) )
403 fn.call( obj, elem );
409 function evalScript(i, elem){
410 var script = jQuery.nodeName(elem, "script");
414 jQuery.ajax({ url: elem.src, async: false, dataType: "script" });
416 jQuery.globalEval( elem.text || elem.textContent || elem.innerHTML || "" );
418 if ( elem.parentNode )
419 elem.parentNode.removeChild(elem);
421 } else if ( elem.nodeType == 1 )
422 jQuery("script", elem).each(evalScript);
427 jQuery.extend = jQuery.fn.extend = function() {
428 // copy reference to target object
429 var target = arguments[0] || {}, a = 1, al = arguments.length, deep = false;
431 // Handle a deep copy situation
432 if ( target.constructor == Boolean ) {
434 target = arguments[1] || {};
437 // extend jQuery itself if only one argument is passed
445 for ( ; a < al; a++ )
446 // Only deal with non-null/undefined values
447 if ( (prop = arguments[a]) != null )
448 // Extend the base object
449 for ( var i in prop ) {
450 // Prevent never-ending loop
451 if ( target == prop[i] )
454 // Recurse if we're merging object values
455 if ( deep && typeof prop[i] == 'object' && target[i] )
456 jQuery.extend( target[i], prop[i] );
458 // Don't bring in undefined values
459 else if ( prop[i] != undefined )
463 // Return the modified object
467 var expando = "jQuery" + (new Date()).getTime(), uuid = 0, win = {};
470 noConflict: function(deep) {
473 window.jQuery = _jQuery;
477 // This may seem like some crazy code, but trust me when I say that this
478 // is the only cross-browser way to do this. --John
479 isFunction: function( fn ) {
480 return !!fn && typeof fn != "string" && !fn.nodeName &&
481 fn.constructor != Array && /function/i.test( fn + "" );
484 // check if an element is in a XML document
485 isXMLDoc: function(elem) {
486 return elem.documentElement && !elem.body ||
487 elem.tagName && elem.ownerDocument && !elem.ownerDocument.body;
490 // Evalulates a script in a global context
491 // Evaluates Async. in Safari 2 :-(
492 globalEval: function( data ) {
493 data = jQuery.trim( data );
495 if ( window.execScript )
496 window.execScript( data );
497 else if ( jQuery.browser.safari )
498 // safari doesn't provide a synchronous global eval
499 window.setTimeout( data, 0 );
501 eval.call( window, data );
505 nodeName: function( elem, name ) {
506 return elem.nodeName && elem.nodeName.toUpperCase() == name.toUpperCase();
511 data: function( elem, name, data ) {
512 elem = elem == window ? win : elem;
514 var id = elem[ expando ];
516 // Compute a unique ID for the element
518 id = elem[ expando ] = ++uuid;
520 // Only generate the data cache if we're
521 // trying to access or manipulate it
522 if ( name && !jQuery.cache[ id ] )
523 jQuery.cache[ id ] = {};
525 // Prevent overriding the named cache with undefined values
526 if ( data != undefined )
527 jQuery.cache[ id ][ name ] = data;
529 // Return the named cache data, or the ID for the element
530 return name ? jQuery.cache[ id ][ name ] : id;
533 removeData: function( elem, name ) {
534 elem = elem == window ? win : elem;
536 var id = elem[ expando ];
538 // If we want to remove a specific section of the element's data
540 if ( jQuery.cache[ id ] ) {
541 // Remove the section of cache data
542 delete jQuery.cache[ id ][ name ];
544 // If we've removed all the data, remove the element's cache
546 for ( name in jQuery.cache[ id ] ) break;
548 jQuery.removeData( elem );
551 // Otherwise, we want to remove all of the element's data
553 // Clean up the element expando
555 delete elem[ expando ];
557 // IE has trouble directly removing the expando
558 // but it's ok with using removeAttribute
559 if ( elem.removeAttribute )
560 elem.removeAttribute( expando );
563 // Completely remove the data cache
564 delete jQuery.cache[ id ];
568 // args is for internal usage only
569 each: function( obj, fn, args ) {
571 if ( obj.length == undefined )
573 fn.apply( obj[i], args );
575 for ( var i = 0, ol = obj.length; i < ol; i++ )
576 if ( fn.apply( obj[i], args ) === false ) break;
578 // A special, fast, case for the most common use of each
580 if ( obj.length == undefined )
582 fn.call( obj[i], i, obj[i] );
584 for ( var i = 0, ol = obj.length, val = obj[0];
585 i < ol && fn.call(val,i,val) !== false; val = obj[++i] ){}
591 prop: function(elem, value, type, index, prop){
592 // Handle executable functions
593 if ( jQuery.isFunction( value ) )
594 value = value.call( elem, [index] );
596 // exclude the following css properties to add px
597 var exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i;
599 // Handle passing in a number to a CSS property
600 return value && value.constructor == Number && type == "curCSS" && !exclude.test(prop) ?
606 // internal only, use addClass("class")
607 add: function( elem, c ){
608 jQuery.each( (c || "").split(/\s+/), function(i, cur){
609 if ( !jQuery.className.has( elem.className, cur ) )
610 elem.className += ( elem.className ? " " : "" ) + cur;
614 // internal only, use removeClass("class")
615 remove: function( elem, c ){
616 elem.className = c != undefined ?
617 jQuery.grep( elem.className.split(/\s+/), function(cur){
618 return !jQuery.className.has( c, cur );
622 // internal only, use is(".class")
623 has: function( t, c ) {
624 return jQuery.inArray( c, (t.className || t).toString().split(/\s+/) ) > -1;
628 swap: function(e,o,f) {
630 e.style["old"+i] = e.style[i];
635 e.style[i] = e.style["old"+i];
639 if ( p == "height" || p == "width" ) {
640 var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"];
642 jQuery.each( d, function(){
643 old["padding" + this] = 0;
644 old["border" + this + "Width"] = 0;
647 jQuery.swap( e, old, function() {
648 if ( jQuery(e).is(':visible') ) {
649 oHeight = e.offsetHeight;
650 oWidth = e.offsetWidth;
652 e = jQuery(e.cloneNode(true))
653 .find(":radio").removeAttr("checked").end()
655 visibility: "hidden", position: "absolute", display: "block", right: "0", left: "0"
656 }).appendTo(e.parentNode)[0];
658 var parPos = jQuery.css(e.parentNode,"position") || "static";
659 if ( parPos == "static" )
660 e.parentNode.style.position = "relative";
662 oHeight = e.clientHeight;
663 oWidth = e.clientWidth;
665 if ( parPos == "static" )
666 e.parentNode.style.position = "static";
668 e.parentNode.removeChild(e);
672 return p == "height" ? oHeight : oWidth;
675 return jQuery.curCSS( e, p );
678 curCSS: function(elem, prop, force) {
679 var ret, stack = [], swap = [];
681 // A helper method for determining if an element's values are broken
683 if ( !jQuery.browser.safari )
686 var ret = document.defaultView.getComputedStyle(a,null);
687 return !ret || ret.getPropertyValue("color") == "";
690 if (prop == "opacity" && jQuery.browser.msie) {
691 ret = jQuery.attr(elem.style, "opacity");
692 return ret == "" ? "1" : ret;
695 if (prop.match(/float/i))
698 if (!force && elem.style[prop])
699 ret = elem.style[prop];
701 else if (document.defaultView && document.defaultView.getComputedStyle) {
703 if (prop.match(/float/i))
706 prop = prop.replace(/([A-Z])/g,"-$1").toLowerCase();
707 var cur = document.defaultView.getComputedStyle(elem, null);
709 if ( cur && !color(elem) )
710 ret = cur.getPropertyValue(prop);
712 // If the element isn't reporting its values properly in Safari
713 // then some display: none elements are involved
715 // Locate all of the parent display: none elements
716 for ( var a = elem; a && color(a); a = a.parentNode )
719 // Go through and make them visible, but in reverse
720 // (It would be better if we knew the exact display type that they had)
721 for ( a = 0; a < stack.length; a++ )
722 if ( color(stack[a]) ) {
723 swap[a] = stack[a].style.display;
724 stack[a].style.display = "block";
727 // Since we flip the display style, we have to handle that
728 // one special, otherwise get the value
729 ret = prop == "display" && swap[stack.length-1] != null ?
731 document.defaultView.getComputedStyle(elem,null).getPropertyValue(prop) || "";
733 // Finally, revert the display styles back
734 for ( a = 0; a < swap.length; a++ )
735 if ( swap[a] != null )
736 stack[a].style.display = swap[a];
739 if ( prop == "opacity" && ret == "" )
742 } else if (elem.currentStyle) {
743 var newProp = prop.replace(/\-(\w)/g,function(m,c){return c.toUpperCase();});
744 ret = elem.currentStyle[prop] || elem.currentStyle[newProp];
746 // From the awesome hack by Dean Edwards
747 // http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291
749 // If we're not dealing with a regular pixel number
750 // but a number that has a weird ending, we need to convert it to pixels
751 if ( !/^\d+(px)?$/i.test(ret) && /^\d/.test(ret) ) {
752 var style = elem.style.left;
753 var runtimeStyle = elem.runtimeStyle.left;
754 elem.runtimeStyle.left = elem.currentStyle.left;
755 elem.style.left = ret || 0;
756 ret = elem.style.pixelLeft + "px";
757 elem.style.left = style;
758 elem.runtimeStyle.left = runtimeStyle;
765 clean: function(a, doc) {
767 doc = doc || document;
769 jQuery.each( a, function(i,arg){
772 if ( arg.constructor == Number )
773 arg = arg.toString();
775 // Convert html string into DOM nodes
776 if ( typeof arg == "string" ) {
777 // Fix "XHTML"-style tags in all browsers
778 arg = arg.replace(/(<(\w+)[^>]*?)\/>/g, function(m, all, tag){
779 return tag.match(/^(abbr|br|col|img|input|link|meta|param|hr|area)$/i)? m : all+"></"+tag+">";
782 // Trim whitespace, otherwise indexOf won't work as expected
783 var s = jQuery.trim(arg).toLowerCase(), div = doc.createElement("div"), tb = [];
786 // option or optgroup
787 !s.indexOf("<opt") &&
788 [1, "<select>", "</select>"] ||
790 !s.indexOf("<leg") &&
791 [1, "<fieldset>", "</fieldset>"] ||
793 s.match(/^<(thead|tbody|tfoot|colg|cap)/) &&
794 [1, "<table>", "</table>"] ||
797 [2, "<table><tbody>", "</tbody></table>"] ||
799 // <thead> matched above
800 (!s.indexOf("<td") || !s.indexOf("<th")) &&
801 [3, "<table><tbody><tr>", "</tr></tbody></table>"] ||
803 !s.indexOf("<col") &&
804 [2, "<table><tbody></tbody><colgroup>", "</colgroup></table>"] ||
806 // IE can't serialize <link> and <script> tags normally
807 jQuery.browser.msie &&
808 [1, "div<div>", "</div>"] ||
812 // Go to html and back, then peel off extra wrappers
813 div.innerHTML = wrap[1] + arg + wrap[2];
815 // Move to the right depth
819 // Remove IE's autoinserted <tbody> from table fragments
820 if ( jQuery.browser.msie ) {
822 // String was a <table>, *may* have spurious <tbody>
823 if ( !s.indexOf("<table") && s.indexOf("<tbody") < 0 )
824 tb = div.firstChild && div.firstChild.childNodes;
826 // String was a bare <thead> or <tfoot>
827 else if ( wrap[1] == "<table>" && s.indexOf("<tbody") < 0 )
830 for ( var n = tb.length-1; n >= 0 ; --n )
831 if ( jQuery.nodeName(tb[n], "tbody") && !tb[n].childNodes.length )
832 tb[n].parentNode.removeChild(tb[n]);
834 // IE completely kills leading whitespace when innerHTML is used
835 if ( /^\s/.test(arg) )
836 div.insertBefore( doc.createTextNode( arg.match(/^\s*/)[0] ), div.firstChild );
840 arg = jQuery.makeArray( div.childNodes );
843 if ( 0 === arg.length && (!jQuery.nodeName(arg, "form") && !jQuery.nodeName(arg, "select")) )
846 if ( arg[0] == undefined || jQuery.nodeName(arg, "form") || arg.options )
849 r = jQuery.merge( r, arg );
856 attr: function(elem, name, value){
857 var fix = jQuery.isXMLDoc(elem) ? {} : jQuery.props;
859 // Safari mis-reports the default selected property of a hidden option
860 // Accessing the parent's selectedIndex property fixes it
861 if ( name == "selected" && jQuery.browser.safari )
862 elem.parentNode.selectedIndex;
864 // Certain attributes only work when accessed via the old DOM 0 way
866 if ( value != undefined ) elem[fix[name]] = value;
867 return elem[fix[name]];
868 } else if ( jQuery.browser.msie && name == "style" )
869 return jQuery.attr( elem.style, "cssText", value );
871 else if ( value == undefined && jQuery.browser.msie && jQuery.nodeName(elem, "form") && (name == "action" || name == "method") )
872 return elem.getAttributeNode(name).nodeValue;
874 // IE elem.getAttribute passes even for style
875 else if ( elem.tagName ) {
877 if ( value != undefined ) {
878 if ( name == "type" && jQuery.nodeName(elem,"input") && elem.parentNode )
879 throw "type property can't be changed";
880 elem.setAttribute( name, value );
883 if ( jQuery.browser.msie && /href|src/.test(name) && !jQuery.isXMLDoc(elem) )
884 return elem.getAttribute( name, 2 );
886 return elem.getAttribute( name );
888 // elem is actually elem.style ... set the style
890 // IE actually uses filters for opacity
891 if ( name == "opacity" && jQuery.browser.msie ) {
892 if ( value != undefined ) {
893 // IE has trouble with opacity if it does not have layout
894 // Force it by setting the zoom level
897 // Set the alpha filter to set the opacity
898 elem.filter = (elem.filter || "").replace(/alpha\([^)]*\)/,"") +
899 (parseFloat(value).toString() == "NaN" ? "" : "alpha(opacity=" + value * 100 + ")");
903 (parseFloat( elem.filter.match(/opacity=([^)]*)/)[1] ) / 100).toString() : "";
905 name = name.replace(/-([a-z])/ig,function(z,b){return b.toUpperCase();});
906 if ( value != undefined ) elem[name] = value;
912 return (t||"").replace(/^\s+|\s+$/g, "");
915 makeArray: function( a ) {
918 // Need to use typeof to fight Safari childNodes crashes
919 if ( typeof a != "array" )
920 for ( var i = 0, al = a.length; i < al; i++ )
928 inArray: function( b, a ) {
929 for ( var i = 0, al = a.length; i < al; i++ )
935 merge: function(first, second) {
936 // We have to loop this way because IE & Opera overwrite the length
937 // expando of getElementsByTagName
939 // Also, we need to make sure that the correct elements are being returned
940 // (IE returns comment nodes in a '*' query)
941 if ( jQuery.browser.msie ) {
942 for ( var i = 0; second[i]; i++ )
943 if ( second[i].nodeType != 8 )
944 first.push(second[i]);
946 for ( var i = 0; second[i]; i++ )
947 first.push(second[i]);
952 unique: function(first) {
953 var r = [], done = {};
956 for ( var i = 0, fl = first.length; i < fl; i++ ) {
957 var id = jQuery.data(first[i]);
970 grep: function(elems, fn, inv) {
971 // If a string is passed in for the function, make a function
972 // for it (a handy shortcut)
973 if ( typeof fn == "string" )
974 fn = eval("false||function(a,i){return " + fn + "}");
978 // Go through the array, only saving the items
979 // that pass the validator function
980 for ( var i = 0, el = elems.length; i < el; i++ )
981 if ( !inv && fn(elems[i],i) || inv && !fn(elems[i],i) )
982 result.push( elems[i] );
987 map: function(elems, fn) {
988 // If a string is passed in for the function, make a function
989 // for it (a handy shortcut)
990 if ( typeof fn == "string" )
991 fn = eval("false||function(a){return " + fn + "}");
995 // Go through the array, translating each of the items to their
996 // new value (or values).
997 for ( var i = 0, el = elems.length; i < el; i++ ) {
998 var val = fn(elems[i],i);
1000 if ( val !== null && val != undefined ) {
1001 if ( val.constructor != Array ) val = [val];
1002 result = result.concat( val );
1010 var userAgent = navigator.userAgent.toLowerCase();
1012 // Figure out what browser is being used
1014 version: (userAgent.match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/) || [])[1],
1015 safari: /webkit/.test(userAgent),
1016 opera: /opera/.test(userAgent),
1017 msie: /msie/.test(userAgent) && !/opera/.test(userAgent),
1018 mozilla: /mozilla/.test(userAgent) && !/(compatible|webkit)/.test(userAgent)
1021 var styleFloat = jQuery.browser.msie ? "styleFloat" : "cssFloat";
1024 // Check to see if the W3C box model is being used
1025 boxModel: !jQuery.browser.msie || document.compatMode == "CSS1Compat",
1027 styleFloat: jQuery.browser.msie ? "styleFloat" : "cssFloat",
1031 "class": "className",
1032 "float": styleFloat,
1033 cssFloat: styleFloat,
1034 styleFloat: styleFloat,
1035 innerHTML: "innerHTML",
1036 className: "className",
1038 disabled: "disabled",
1040 readonly: "readOnly",
1041 selected: "selected",
1042 maxlength: "maxLength"
1047 parent: "a.parentNode",
1048 parents: "jQuery.dir(a,'parentNode')",
1049 next: "jQuery.nth(a,2,'nextSibling')",
1050 prev: "jQuery.nth(a,2,'previousSibling')",
1051 nextAll: "jQuery.dir(a,'nextSibling')",
1052 prevAll: "jQuery.dir(a,'previousSibling')",
1053 siblings: "jQuery.sibling(a.parentNode.firstChild,a)",
1054 children: "jQuery.sibling(a.firstChild)",
1055 contents: "jQuery.nodeName(a,'iframe')?a.contentDocument||a.contentWindow.document:jQuery.makeArray(a.childNodes)"
1057 jQuery.fn[ i ] = function(a) {
1058 var ret = jQuery.map(this,n);
1059 if ( a && typeof a == "string" )
1060 ret = jQuery.multiFilter(a,ret);
1061 return this.pushStack( jQuery.unique(ret) );
1067 prependTo: "prepend",
1068 insertBefore: "before",
1069 insertAfter: "after",
1070 replaceAll: "replaceWith"
1072 jQuery.fn[ i ] = function(){
1074 return this.each(function(){
1075 for ( var j = 0, al = a.length; j < al; j++ )
1076 jQuery(a[j])[n]( this );
1082 removeAttr: function( key ) {
1083 jQuery.attr( this, key, "" );
1084 this.removeAttribute( key );
1086 addClass: function(c){
1087 jQuery.className.add(this,c);
1089 removeClass: function(c){
1090 jQuery.className.remove(this,c);
1092 toggleClass: function( c ){
1093 jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this, c);
1095 remove: function(a){
1096 if ( !a || jQuery.filter( a, [this] ).r.length ) {
1097 jQuery.removeData( this );
1098 this.parentNode.removeChild( this );
1102 // Clean up the cache
1103 jQuery("*", this).each(function(){ jQuery.removeData(this); });
1105 while ( this.firstChild )
1106 this.removeChild( this.firstChild );
1109 jQuery.fn[ i ] = function() {
1110 return this.each( n, arguments );
1114 jQuery.each( [ "Height", "Width" ], function(i,name){
1115 var n = name.toLowerCase();
1117 jQuery.fn[ n ] = function(h) {
1118 return this[0] == window ?
1119 jQuery.browser.safari && self["inner" + name] ||
1120 jQuery.boxModel && Math.max(document.documentElement["client" + name], document.body["client" + name]) ||
1121 document.body["client" + name] :
1123 this[0] == document ?
1124 Math.max( document.body["scroll" + name], document.body["offset" + name] ) :
1127 ( this.length ? jQuery.css( this[0], n ) : null ) :
1128 this.css( n, h.constructor == String ? h : h + "px" );
1132 var chars = jQuery.browser.safari && parseInt(jQuery.browser.version) < 417 ?
1133 "(?:[\\w*_-]|\\\\.)" :
1134 "(?:[\\w\u0128-\uFFFF*_-]|\\\\.)",
1135 quickChild = new RegExp("^>\\s*(" + chars + "+)"),
1136 quickID = new RegExp("^(" + chars + "+)(#)(" + chars + "+)"),
1137 quickClass = new RegExp("^([#.]?)(" + chars + "*)");
1141 "": "m[2]=='*'||jQuery.nodeName(a,m[2])",
1142 "#": "a.getAttribute('id')==m[2]",
1150 last: "i==r.length-1",
1155 "first-child": "a.parentNode.getElementsByTagName('*')[0]==a",
1156 "last-child": "jQuery.nth(a.parentNode.lastChild,1,'previousSibling')==a",
1157 "only-child": "!jQuery.nth(a.parentNode.lastChild,2,'previousSibling')",
1160 parent: "a.firstChild",
1161 empty: "!a.firstChild",
1164 contains: "(a.textContent||a.innerText||jQuery(a).text()||'').indexOf(m[3])>=0",
1167 visible: '"hidden"!=a.type&&jQuery.css(a,"display")!="none"&&jQuery.css(a,"visibility")!="hidden"',
1168 hidden: '"hidden"==a.type||jQuery.css(a,"display")=="none"||jQuery.css(a,"visibility")=="hidden"',
1171 enabled: "!a.disabled",
1172 disabled: "a.disabled",
1173 checked: "a.checked",
1174 selected: "a.selected||jQuery.attr(a,'selected')",
1177 text: "'text'==a.type",
1178 radio: "'radio'==a.type",
1179 checkbox: "'checkbox'==a.type",
1180 file: "'file'==a.type",
1181 password: "'password'==a.type",
1182 submit: "'submit'==a.type",
1183 image: "'image'==a.type",
1184 reset: "'reset'==a.type",
1185 button: '"button"==a.type||jQuery.nodeName(a,"button")',
1186 input: "/input|select|textarea|button/i.test(a.nodeName)",
1189 has: "jQuery.find(m[3],a).length",
1192 header: "/h\\d/i.test(a.nodeName)",
1195 animated: "jQuery.grep(jQuery.timers,function(fn){return a==fn.elem;}).length"
1199 // The regular expressions that power the parsing engine
1201 // Match: [@value='test'], [@foo]
1202 /^(\[) *@?([\w-]+) *([!*$^~=]*) *('?"?)(.*?)\4 *\]/,
1204 // Match: :contains('foo')
1205 /^(:)([\w-]+)\("?'?(.*?(\(.*?\))?[^(]*?)"?'?\)/,
1207 // Match: :even, :last-chlid, #id, .class
1208 new RegExp("^([:.#]*)(" + chars + "+)")
1211 multiFilter: function( expr, elems, not ) {
1214 while ( expr && expr != old ) {
1216 var f = jQuery.filter( expr, elems, not );
1217 expr = f.t.replace(/^\s*,\s*/, "" );
1218 cur = not ? elems = f.r : jQuery.merge( cur, f.r );
1224 find: function( t, context ) {
1225 // Quickly handle non-string expressions
1226 if ( typeof t != "string" )
1229 // Make sure that the context is a DOM Element
1230 if ( context && !context.nodeType )
1233 // Set the correct context (if none is provided)
1234 context = context || document;
1236 // Initialize the search
1237 var ret = [context], done = [], last;
1239 // Continue while a selector expression exists, and while
1240 // we're no longer looping upon ourselves
1241 while ( t && last != t ) {
1247 var foundToken = false;
1249 // An attempt at speeding up child selectors that
1250 // point to a specific element tag
1251 var re = quickChild;
1255 var nodeName = m[1].toUpperCase();
1257 // Perform our own iteration and filter
1258 for ( var i = 0; ret[i]; i++ )
1259 for ( var c = ret[i].firstChild; c; c = c.nextSibling )
1260 if ( c.nodeType == 1 && (nodeName == "*" || c.nodeName.toUpperCase() == nodeName.toUpperCase()) )
1264 t = t.replace( re, "" );
1265 if ( t.indexOf(" ") == 0 ) continue;
1268 re = /^([>+~])\s*(\w*)/i;
1270 if ( (m = re.exec(t)) != null ) {
1273 var nodeName = m[2], merge = {};
1276 for ( var j = 0, rl = ret.length; j < rl; j++ ) {
1277 var n = m == "~" || m == "+" ? ret[j].nextSibling : ret[j].firstChild;
1278 for ( ; n; n = n.nextSibling )
1279 if ( n.nodeType == 1 ) {
1280 var id = jQuery.data(n);
1282 if ( m == "~" && merge[id] ) break;
1284 if (!nodeName || n.nodeName.toUpperCase() == nodeName.toUpperCase() ) {
1285 if ( m == "~" ) merge[id] = true;
1289 if ( m == "+" ) break;
1295 // And remove the token
1296 t = jQuery.trim( t.replace( re, "" ) );
1301 // See if there's still an expression, and that we haven't already
1303 if ( t && !foundToken ) {
1304 // Handle multiple expressions
1305 if ( !t.indexOf(",") ) {
1306 // Clean the result set
1307 if ( context == ret[0] ) ret.shift();
1309 // Merge the result sets
1310 done = jQuery.merge( done, ret );
1312 // Reset the context
1313 r = ret = [context];
1315 // Touch up the selector string
1316 t = " " + t.substr(1,t.length);
1319 // Optimize for the case nodeName#idName
1321 var m = re2.exec(t);
1323 // Re-organize the results, so that they're consistent
1325 m = [ 0, m[2], m[3], m[1] ];
1328 // Otherwise, do a traditional filter check for
1329 // ID, class, and element selectors
1334 m[2] = m[2].replace(/\\/g, "");
1336 var elem = ret[ret.length-1];
1338 // Try to do a global search by ID, where we can
1339 if ( m[1] == "#" && elem && elem.getElementById && !jQuery.isXMLDoc(elem) ) {
1340 // Optimization for HTML document case
1341 var oid = elem.getElementById(m[2]);
1343 // Do a quick check for the existence of the actual ID attribute
1344 // to avoid selecting by the name attribute in IE
1345 // also check to insure id is a string to avoid selecting an element with the name of 'id' inside a form
1346 if ( (jQuery.browser.msie||jQuery.browser.opera) && oid && typeof oid.id == "string" && oid.id != m[2] )
1347 oid = jQuery('[@id="'+m[2]+'"]', elem)[0];
1349 // Do a quick check for node name (where applicable) so
1350 // that div#foo searches will be really fast
1351 ret = r = oid && (!m[3] || jQuery.nodeName(oid, m[3])) ? [oid] : [];
1353 // We need to find all descendant elements
1354 for ( var i = 0; ret[i]; i++ ) {
1355 // Grab the tag name being searched for
1356 var tag = m[1] == "#" && m[3] ? m[3] : m[1] != "" || m[0] == "" ? "*" : m[2];
1358 // Handle IE7 being really dumb about <object>s
1359 if ( tag == "*" && ret[i].nodeName.toLowerCase() == "object" )
1362 r = jQuery.merge( r, ret[i].getElementsByTagName( tag ));
1365 // It's faster to filter by class and be done with it
1367 r = jQuery.classFilter( r, m[2] );
1369 // Same with ID filtering
1370 if ( m[1] == "#" ) {
1373 // Try to find the element with the ID
1374 for ( var i = 0; r[i]; i++ )
1375 if ( r[i].getAttribute("id") == m[2] ) {
1386 t = t.replace( re2, "" );
1391 // If a selector string still exists
1393 // Attempt to filter it
1394 var val = jQuery.filter(t,r);
1396 t = jQuery.trim(val.t);
1400 // An error occurred with the selector;
1401 // just return an empty set instead
1405 // Remove the root context
1406 if ( ret && context == ret[0] )
1409 // And combine the results
1410 done = jQuery.merge( done, ret );
1415 classFilter: function(r,m,not){
1418 for ( var i = 0; r[i]; i++ ) {
1419 var pass = (" " + r[i].className + " ").indexOf( m ) >= 0;
1420 if ( !not && pass || not && !pass )
1426 filter: function(t,r,not) {
1429 // Look for common filter expressions
1430 while ( t && t != last ) {
1433 var p = jQuery.parse, m;
1435 for ( var i = 0; p[i]; i++ ) {
1439 // Remove what we just matched
1440 t = t.substring( m[0].length );
1442 m[2] = m[2].replace(/\\/g, "");
1450 // :not() is a special case that can be optimized by
1451 // keeping it out of the expression list
1452 if ( m[1] == ":" && m[2] == "not" )
1453 r = jQuery.filter(m[3], r, true).r;
1455 // We can get a big speed boost by filtering by class here
1456 else if ( m[1] == "." )
1457 r = jQuery.classFilter(r, m[2], not);
1459 else if ( m[1] == "[" ) {
1460 var tmp = [], type = m[3];
1462 for ( var i = 0, rl = r.length; i < rl; i++ ) {
1463 var a = r[i], z = a[ jQuery.props[m[2]] || m[2] ];
1465 if ( z == null || /href|src|selected/.test(m[2]) )
1466 z = jQuery.attr(a,m[2]) || '';
1468 if ( (type == "" && !!z ||
1469 type == "=" && z == m[5] ||
1470 type == "!=" && z != m[5] ||
1471 type == "^=" && z && !z.indexOf(m[5]) ||
1472 type == "$=" && z.substr(z.length - m[5].length) == m[5] ||
1473 (type == "*=" || type == "~=") && z.indexOf(m[5]) >= 0) ^ not )
1479 // We can get a speed boost by handling nth-child here
1480 } else if ( m[1] == ":" && m[2] == "nth-child" ) {
1481 var merge = {}, tmp = [],
1482 test = /(\d*)n\+?(\d*)/.exec(
1483 m[3] == "even" && "2n" || m[3] == "odd" && "2n+1" ||
1484 !/\D/.test(m[3]) && "n+" + m[3] || m[3]),
1485 first = (test[1] || 1) - 0, last = test[2] - 0;
1487 for ( var i = 0, rl = r.length; i < rl; i++ ) {
1488 var node = r[i], parentNode = node.parentNode, id = jQuery.data(parentNode);
1493 for ( var n = parentNode.firstChild; n; n = n.nextSibling )
1494 if ( n.nodeType == 1 )
1503 if ( last == 0 || node.nodeIndex == last )
1505 } else if ( (node.nodeIndex + last) % first == 0 )
1514 // Otherwise, find the expression to execute
1516 var f = jQuery.expr[m[1]];
1517 if ( typeof f != "string" )
1518 f = jQuery.expr[m[1]][m[2]];
1520 // Build a custom macro to enclose it
1521 f = eval("false||function(a,i){return " + f + "}");
1523 // Execute it against the current filter
1524 r = jQuery.grep( r, f, not );
1528 // Return an array of filtered elements (r)
1529 // and the modified expression string (t)
1530 return { r: r, t: t };
1533 dir: function( elem, dir ){
1535 var cur = elem[dir];
1536 while ( cur && cur != document ) {
1537 if ( cur.nodeType == 1 )
1538 matched.push( cur );
1544 nth: function(cur,result,dir,elem){
1545 result = result || 1;
1548 for ( ; cur; cur = cur[dir] )
1549 if ( cur.nodeType == 1 && ++num == result )
1555 sibling: function( n, elem ) {
1558 for ( ; n; n = n.nextSibling ) {
1559 if ( n.nodeType == 1 && (!elem || n != elem) )
1567 * A number of helper functions used for managing events.
1568 * Many of the ideas behind this code orignated from
1569 * Dean Edwards' addEvent library.
1573 // Bind an event to an element
1574 // Original by Dean Edwards
1575 add: function(element, type, handler, data) {
1576 // For whatever reason, IE has trouble passing the window object
1577 // around, causing it to be cloned in the process
1578 if ( jQuery.browser.msie && element.setInterval != undefined )
1581 // Make sure that the function being executed has a unique ID
1582 if ( !handler.guid )
1583 handler.guid = this.guid++;
1585 // if data is passed, bind to handler
1586 if( data != undefined ) {
1587 // Create temporary function pointer to original handler
1590 // Create unique handler function, wrapped around original handler
1591 handler = function() {
1592 // Pass arguments and context to original handler
1593 return fn.apply(this, arguments);
1596 // Store data in unique handler
1597 handler.data = data;
1599 // Set the guid of unique handler to the same of original handler, so it can be removed
1600 handler.guid = fn.guid;
1603 // Namespaced event handlers
1604 var parts = type.split(".");
1606 handler.type = parts[1];
1608 // Init the element's event structure
1609 var events = jQuery.data(element, "events") || jQuery.data(element, "events", {});
1611 var handle = jQuery.data(element, "handle", function(){
1612 // returned undefined or false
1615 // Handle the second event of a trigger and when
1616 // an event is called after a page has unloaded
1617 if ( typeof jQuery == "undefined" || jQuery.event.triggered )
1620 val = jQuery.event.handle.apply(element, arguments);
1625 // Get the current list of functions bound to this event
1626 var handlers = events[type];
1628 // Init the event handler queue
1630 handlers = events[type] = {};
1632 // And bind the global event handler to the element
1633 if (element.addEventListener)
1634 element.addEventListener(type, handle, false);
1636 element.attachEvent("on" + type, handle);
1639 // Add the function to the element's handler list
1640 handlers[handler.guid] = handler;
1642 // Keep track of which events have been used, for global triggering
1643 this.global[type] = true;
1649 // Detach an event or set of events from an element
1650 remove: function(element, type, handler) {
1651 var events = jQuery.data(element, "events"), ret, index;
1653 // Namespaced event handlers
1654 if ( typeof type == "string" ) {
1655 var parts = type.split(".");
1660 // type is actually an event object here
1661 if ( type && type.type ) {
1662 handler = type.handler;
1667 for ( type in events )
1668 this.remove( element, type );
1670 } else if ( events[type] ) {
1671 // remove the given handler for the given type
1673 delete events[type][handler.guid];
1675 // remove all handlers for the given type
1677 for ( handler in events[type] )
1678 // Handle the removal of namespaced events
1679 if ( !parts[1] || events[type][handler].type == parts[1] )
1680 delete events[type][handler];
1682 // remove generic event handler if no more handlers exist
1683 for ( ret in events[type] ) break;
1685 if (element.removeEventListener)
1686 element.removeEventListener(type, jQuery.data(element, "handle"), false);
1688 element.detachEvent("on" + type, jQuery.data(element, "handle"));
1690 delete events[type];
1694 // Remove the expando if it's no longer used
1695 for ( ret in events ) break;
1697 jQuery.removeData( element, "events" );
1698 jQuery.removeData( element, "handle" );
1703 trigger: function(type, data, element, donative, extra) {
1704 // Clone the incoming data, if any
1705 data = jQuery.makeArray(data || []);
1707 // Handle a global trigger
1709 // Only trigger if we've ever bound an event for it
1710 if ( this.global[type] )
1711 jQuery("*").add([window, document]).trigger(type, data);
1713 // Handle triggering a single element
1715 var val, ret, fn = jQuery.isFunction( element[ type ] || null ),
1716 // Check to see if we need to provide a fake event, or not
1717 evt = !data[0] || !data[0].preventDefault;
1719 // Pass along a fake event
1721 data.unshift( this.fix({ type: type, target: element }) );
1723 // Enforce the right trigger type
1724 data[0].type = type;
1726 // Trigger the event
1727 if ( jQuery.isFunction( jQuery.data(element, "handle") ) )
1728 val = jQuery.data(element, "handle").apply( element, data );
1730 // Handle triggering native .onfoo handlers
1731 if ( !fn && element["on"+type] && element["on"+type].apply( element, data ) === false )
1734 // Extra functions don't get the custom event object
1738 // Handle triggering of extra function
1739 if ( extra && extra.apply( element, data ) === false )
1742 // Trigger the native events (except for clicks on links)
1743 if ( fn && donative !== false && val !== false && !(jQuery.nodeName(element, 'a') && type == "click") ) {
1744 this.triggered = true;
1748 this.triggered = false;
1754 handle: function(event) {
1755 // returned undefined or false
1758 // Empty object is for triggered events with no data
1759 event = jQuery.event.fix( event || window.event || {} );
1761 // Namespaced event handlers
1762 var parts = event.type.split(".");
1763 event.type = parts[0];
1765 var c = jQuery.data(this, "events") && jQuery.data(this, "events")[event.type], args = Array.prototype.slice.call( arguments, 1 );
1766 args.unshift( event );
1768 for ( var j in c ) {
1769 // Pass in a reference to the handler function itself
1770 // So that we can later remove it
1771 args[0].handler = c[j];
1772 args[0].data = c[j].data;
1774 // Filter the functions by class
1775 if ( !parts[1] || c[j].type == parts[1] ) {
1776 var tmp = c[j].apply( this, args );
1778 if ( val !== false )
1781 if ( tmp === false ) {
1782 event.preventDefault();
1783 event.stopPropagation();
1788 // Clean up added properties in IE to prevent memory leak
1789 if (jQuery.browser.msie)
1790 event.target = event.preventDefault = event.stopPropagation =
1791 event.handler = event.data = null;
1796 fix: function(event) {
1797 // store a copy of the original event object
1798 // and clone to set read-only properties
1799 var originalEvent = event;
1800 event = jQuery.extend({}, originalEvent);
1802 // add preventDefault and stopPropagation since
1803 // they will not work on the clone
1804 event.preventDefault = function() {
1805 // if preventDefault exists run it on the original event
1806 if (originalEvent.preventDefault)
1807 originalEvent.preventDefault();
1808 // otherwise set the returnValue property of the original event to false (IE)
1809 originalEvent.returnValue = false;
1811 event.stopPropagation = function() {
1812 // if stopPropagation exists run it on the original event
1813 if (originalEvent.stopPropagation)
1814 originalEvent.stopPropagation();
1815 // otherwise set the cancelBubble property of the original event to true (IE)
1816 originalEvent.cancelBubble = true;
1819 // Fix target property, if necessary
1820 if ( !event.target && event.srcElement )
1821 event.target = event.srcElement;
1823 // check if target is a textnode (safari)
1824 if (jQuery.browser.safari && event.target.nodeType == 3)
1825 event.target = originalEvent.target.parentNode;
1827 // Add relatedTarget, if necessary
1828 if ( !event.relatedTarget && event.fromElement )
1829 event.relatedTarget = event.fromElement == event.target ? event.toElement : event.fromElement;
1831 // Calculate pageX/Y if missing and clientX/Y available
1832 if ( event.pageX == null && event.clientX != null ) {
1833 var e = document.documentElement, b = document.body;
1834 event.pageX = event.clientX + (e && e.scrollLeft || b.scrollLeft || 0);
1835 event.pageY = event.clientY + (e && e.scrollTop || b.scrollTop || 0);
1838 // Add which for key events
1839 if ( !event.which && (event.charCode || event.keyCode) )
1840 event.which = event.charCode || event.keyCode;
1842 // Add metaKey to non-Mac browsers (use ctrl for PC's and Meta for Macs)
1843 if ( !event.metaKey && event.ctrlKey )
1844 event.metaKey = event.ctrlKey;
1846 // Add which for click: 1 == left; 2 == middle; 3 == right
1847 // Note: button is not normalized, so don't use it
1848 if ( !event.which && event.button )
1849 event.which = (event.button & 1 ? 1 : ( event.button & 2 ? 3 : ( event.button & 4 ? 2 : 0 ) ));
1856 bind: function( type, data, fn ) {
1857 return type == "unload" ? this.one(type, data, fn) : this.each(function(){
1858 jQuery.event.add( this, type, fn || data, fn && data );
1862 one: function( type, data, fn ) {
1863 return this.each(function(){
1864 jQuery.event.add( this, type, function(event) {
1865 jQuery(this).unbind(event);
1866 return (fn || data).apply( this, arguments);
1871 unbind: function( type, fn ) {
1872 return this.each(function(){
1873 jQuery.event.remove( this, type, fn );
1877 trigger: function( type, data, fn ) {
1878 return this.each(function(){
1879 jQuery.event.trigger( type, data, this, true, fn );
1883 triggerHandler: function( type, data, fn ) {
1885 return jQuery.event.trigger( type, data, this[0], false, fn );
1888 toggle: function() {
1889 // Save reference to arguments for access in closure
1892 return this.click(function(e) {
1893 // Figure out which function to execute
1894 this.lastToggle = 0 == this.lastToggle ? 1 : 0;
1896 // Make sure that clicks stop
1899 // and execute the function
1900 return a[this.lastToggle].apply( this, [e] ) || false;
1904 hover: function(f,g) {
1906 // A private function for handling mouse 'hovering'
1907 function handleHover(e) {
1908 // Check if mouse(over|out) are still within the same parent element
1909 var p = e.relatedTarget;
1911 // Traverse up the tree
1912 while ( p && p != this ) try { p = p.parentNode; } catch(e) { p = this; };
1914 // If we actually just moused on to a sub-element, ignore it
1915 if ( p == this ) return false;
1917 // Execute the right function
1918 return (e.type == "mouseover" ? f : g).apply(this, [e]);
1921 // Bind the function to the two event listeners
1922 return this.mouseover(handleHover).mouseout(handleHover);
1925 ready: function(f) {
1926 // Attach the listeners
1929 // If the DOM is already ready
1930 if ( jQuery.isReady )
1931 // Execute the function immediately
1932 f.apply( document, [jQuery] );
1934 // Otherwise, remember the function for later
1936 // Add the function to the wait list
1937 jQuery.readyList.push( function() { return f.apply(this, [jQuery]); } );
1945 * All the code that makes DOM Ready work nicely.
1950 // Handle when the DOM is ready
1952 // Make sure that the DOM is not already loaded
1953 if ( !jQuery.isReady ) {
1954 // Remember that the DOM is ready
1955 jQuery.isReady = true;
1957 // If there are functions bound, to execute
1958 if ( jQuery.readyList ) {
1959 // Execute all of them
1960 jQuery.each( jQuery.readyList, function(){
1961 this.apply( document );
1964 // Reset the list of functions
1965 jQuery.readyList = null;
1967 // Remove event listener to avoid memory leak
1968 if ( jQuery.browser.mozilla || jQuery.browser.opera )
1969 document.removeEventListener( "DOMContentLoaded", jQuery.ready, false );
1971 // Remove script element used by IE hack
1972 if( !window.frames.length ) // don't remove if frames are present (#1187)
1973 jQuery(window).load(function(){ jQuery("#__ie_init").remove(); });
1978 jQuery.each( ("blur,focus,load,resize,scroll,unload,click,dblclick," +
1979 "mousedown,mouseup,mousemove,mouseover,mouseout,change,select," +
1980 "submit,keydown,keypress,keyup,error").split(","), function(i,o){
1982 // Handle event binding
1983 jQuery.fn[o] = function(f){
1984 return f ? this.bind(o, f) : this.trigger(o);
1988 var readyBound = false;
1990 function bindReady(){
1991 if ( readyBound ) return;
1994 // If Mozilla is used
1995 if ( jQuery.browser.mozilla || jQuery.browser.opera )
1996 // Use the handy event callback
1997 document.addEventListener( "DOMContentLoaded", jQuery.ready, false );
1999 // If IE is used, use the excellent hack by Matthias Miller
2000 // http://www.outofhanwell.com/blog/index.php?title=the_window_onload_problem_revisited
2001 else if ( jQuery.browser.msie ) {
2003 // Only works if you document.write() it
2004 document.write("<scr" + "ipt id=__ie_init defer=true " +
2005 "src=//:><\/script>");
2007 // Use the defer script hack
2008 var script = document.getElementById("__ie_init");
2010 // script does not exist if jQuery is loaded dynamically
2012 script.onreadystatechange = function() {
2013 if ( this.readyState != "complete" ) return;
2017 // Clear from memory
2020 // If Safari is used
2021 } else if ( jQuery.browser.safari )
2022 // Continually check to see if the document.readyState is valid
2023 jQuery.safariTimer = setInterval(function(){
2024 // loaded and complete are both valid states
2025 if ( document.readyState == "loaded" ||
2026 document.readyState == "complete" ) {
2028 // If either one are found, remove the timer
2029 clearInterval( jQuery.safariTimer );
2030 jQuery.safariTimer = null;
2032 // and execute any waiting functions
2037 // A fallback to window.onload, that will always work
2038 jQuery.event.add( window, "load", jQuery.ready );
2041 load: function( url, params, callback ) {
2042 if ( jQuery.isFunction( url ) )
2043 return this.bind("load", url);
2045 var off = url.indexOf(" ");
2047 var selector = url.slice(off, url.length);
2048 url = url.slice(0, off);
2051 callback = callback || function(){};
2053 // Default to a GET request
2056 // If the second parameter was provided
2058 // If it's a function
2059 if ( jQuery.isFunction( params ) ) {
2060 // We assume that it's the callback
2064 // Otherwise, build a param string
2066 params = jQuery.param( params );
2072 // Request the remote document
2077 complete: function(res, status){
2078 // If successful, inject the HTML into all the matched elements
2079 if ( status == "success" || status == "notmodified" )
2080 // See if a selector was specified
2081 self.html( selector ?
2082 // Create a dummy div to hold the results
2084 // inject the contents of the document in, removing the scripts
2085 // to avoid any 'Permission Denied' errors in IE
2086 .append(res.responseText.replace(/<script(.|\s)*?\/script>/g, ""))
2088 // Locate the specified elements
2091 // If not, just inject the full result
2094 // Add delay to account for Safari's delay in globalEval
2095 setTimeout(function(){
2096 self.each( callback, [res.responseText, status, res] );
2103 serialize: function() {
2104 return jQuery.param(this.serializeArray());
2106 serializeArray: function() {
2107 return this.map(function(){
2108 return jQuery.nodeName(this, "form") ?
2109 jQuery.makeArray(this.elements) : this;
2112 return this.name && !this.disabled &&
2113 (this.checked || /select|textarea/i.test(this.nodeName) ||
2114 /text|hidden|password/i.test(this.type));
2116 .map(function(i, elem){
2117 var val = jQuery(this).val();
2118 return val == null ? null :
2119 val.constructor == Array ?
2120 jQuery.map( val, function(val, i){
2121 return {name: elem.name, value: val};
2123 {name: elem.name, value: val};
2128 // Attach a bunch of functions for handling common AJAX events
2129 jQuery.each( "ajaxStart,ajaxStop,ajaxComplete,ajaxError,ajaxSuccess,ajaxSend".split(","), function(i,o){
2130 jQuery.fn[o] = function(f){
2131 return this.bind(o, f);
2135 var jsc = (new Date).getTime();
2138 get: function( url, data, callback, type ) {
2139 // shift arguments if data argument was ommited
2140 if ( jQuery.isFunction( data ) ) {
2145 return jQuery.ajax({
2154 getScript: function( url, callback ) {
2155 return jQuery.get(url, null, callback, "script");
2158 getJSON: function( url, data, callback ) {
2159 return jQuery.get(url, data, callback, "json");
2162 post: function( url, data, callback, type ) {
2163 if ( jQuery.isFunction( data ) ) {
2168 return jQuery.ajax({
2177 ajaxSetup: function( settings ) {
2178 jQuery.extend( jQuery.ajaxSettings, settings );
2185 contentType: "application/x-www-form-urlencoded",
2191 // Last-Modified header cache for next request
2194 ajax: function( s ) {
2195 var jsonp, jsre = /=(\?|%3F)/g, status, data;
2197 // Extend the settings, but re-extend 's' so that it can be
2198 // checked again later (in the test suite, specifically)
2199 s = jQuery.extend(true, s, jQuery.extend(true, {}, jQuery.ajaxSettings, s));
2201 // convert data if not already a string
2202 if ( s.data && s.processData && typeof s.data != "string" )
2203 s.data = jQuery.param(s.data);
2205 // Handle JSONP Parameter Callbacks
2206 if ( s.dataType == "jsonp" ) {
2207 if ( s.type.toLowerCase() == "get" ) {
2208 if ( !s.url.match(jsre) )
2209 s.url += (s.url.match(/\?/) ? "&" : "?") + (s.jsonp || "callback") + "=?";
2210 } else if ( !s.data || !s.data.match(jsre) )
2211 s.data = (s.data ? s.data + "&" : "") + (s.jsonp || "callback") + "=?";
2212 s.dataType = "json";
2215 // Build temporary JSONP function
2216 if ( s.dataType == "json" && (s.data && s.data.match(jsre) || s.url.match(jsre)) ) {
2217 jsonp = "jsonp" + jsc++;
2219 // Replace the =? sequence both in the query string and the data
2221 s.data = s.data.replace(jsre, "=" + jsonp);
2222 s.url = s.url.replace(jsre, "=" + jsonp);
2224 // We need to make sure
2225 // that a JSONP style response is executed properly
2226 s.dataType = "script";
2228 // Handle JSONP-style loading
2229 window[ jsonp ] = function(tmp){
2234 window[ jsonp ] = undefined;
2235 try{ delete window[ jsonp ]; } catch(e){}
2239 if ( s.dataType == "script" && s.cache == null )
2242 if ( s.cache === false && s.type.toLowerCase() == "get" )
2243 s.url += (s.url.match(/\?/) ? "&" : "?") + "_=" + (new Date()).getTime();
2245 // If data is available, append data to url for get requests
2246 if ( s.data && s.type.toLowerCase() == "get" ) {
2247 s.url += (s.url.match(/\?/) ? "&" : "?") + s.data;
2249 // IE likes to send both get and post data, prevent this
2253 // Watch for a new set of requests
2254 if ( s.global && ! jQuery.active++ )
2255 jQuery.event.trigger( "ajaxStart" );
2257 // If we're requesting a remote document
2258 // and trying to load JSON or Script
2259 if ( !s.url.indexOf("http") && s.dataType == "script" ) {
2260 var head = document.getElementsByTagName("head")[0];
2261 var script = document.createElement("script");
2264 // Handle Script loading
2265 if ( !jsonp && (s.success || s.complete) ) {
2268 // Attach handlers for all browsers
2269 script.onload = script.onreadystatechange = function(){
2270 if ( !done && (!this.readyState ||
2271 this.readyState == "loaded" || this.readyState == "complete") ) {
2275 head.removeChild( script );
2280 head.appendChild(script);
2282 // We handle everything using the script element injection
2286 var requestDone = false;
2288 // Create the request object; Microsoft failed to properly
2289 // implement the XMLHttpRequest in IE7, so we use the ActiveXObject when it is available
2290 var xml = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
2293 xml.open(s.type, s.url, s.async);
2295 // Set the correct header, if data is being sent
2297 xml.setRequestHeader("Content-Type", s.contentType);
2299 // Set the If-Modified-Since header, if ifModified mode.
2301 xml.setRequestHeader("If-Modified-Since",
2302 jQuery.lastModified[s.url] || "Thu, 01 Jan 1970 00:00:00 GMT" );
2304 // Set header so the called script knows that it's an XMLHttpRequest
2305 xml.setRequestHeader("X-Requested-With", "XMLHttpRequest");
2307 // Allow custom headers/mimetypes
2312 jQuery.event.trigger("ajaxSend", [xml, s]);
2314 // Wait for a response to come back
2315 var onreadystatechange = function(isTimeout){
2316 // The transfer is complete and the data is available, or the request timed out
2317 if ( !requestDone && xml && (xml.readyState == 4 || isTimeout == "timeout") ) {
2320 // clear poll interval
2322 clearInterval(ival);
2326 status = isTimeout == "timeout" && "timeout" ||
2327 !jQuery.httpSuccess( xml ) && "error" ||
2328 s.ifModified && jQuery.httpNotModified( xml, s.url ) && "notmodified" ||
2331 if ( status == "success" ) {
2332 // Watch for, and catch, XML document parse errors
2334 // process the data (runs the xml through httpData regardless of callback)
2335 data = jQuery.httpData( xml, s.dataType );
2337 status = "parsererror";
2341 // Make sure that the request was successful or notmodified
2342 if ( status == "success" ) {
2343 // Cache Last-Modified header, if ifModified mode.
2346 modRes = xml.getResponseHeader("Last-Modified");
2347 } catch(e) {} // swallow exception thrown by FF if header is not available
2349 if ( s.ifModified && modRes )
2350 jQuery.lastModified[s.url] = modRes;
2352 // JSONP handles its own success callback
2356 jQuery.handleError(s, xml, status);
2358 // Fire the complete handlers
2361 // Stop memory leaks
2368 // don't attach the handler to the request, just poll it instead
2369 var ival = setInterval(onreadystatechange, 13);
2372 if ( s.timeout > 0 )
2373 setTimeout(function(){
2374 // Check to see if the request is still happening
2376 // Cancel the request
2380 onreadystatechange( "timeout" );
2389 jQuery.handleError(s, xml, null, e);
2392 // firefox 1.5 doesn't fire statechange for sync requests
2394 onreadystatechange();
2396 // return XMLHttpRequest to allow aborting the request etc.
2400 // If a local callback was specified, fire it and pass it the data
2402 s.success( data, status );
2404 // Fire the global callback
2406 jQuery.event.trigger( "ajaxSuccess", [xml, s] );
2409 function complete(){
2412 s.complete(xml, status);
2414 // The request was completed
2416 jQuery.event.trigger( "ajaxComplete", [xml, s] );
2418 // Handle the global AJAX counter
2419 if ( s.global && ! --jQuery.active )
2420 jQuery.event.trigger( "ajaxStop" );
2424 handleError: function( s, xml, status, e ) {
2425 // If a local callback was specified, fire it
2426 if ( s.error ) s.error( xml, status, e );
2428 // Fire the global callback
2430 jQuery.event.trigger( "ajaxError", [xml, s, e] );
2433 // Counter for holding the number of active queries
2436 // Determines if an XMLHttpRequest was successful or not
2437 httpSuccess: function( r ) {
2439 return !r.status && location.protocol == "file:" ||
2440 ( r.status >= 200 && r.status < 300 ) || r.status == 304 ||
2441 jQuery.browser.safari && r.status == undefined;
2446 // Determines if an XMLHttpRequest returns NotModified
2447 httpNotModified: function( xml, url ) {
2449 var xmlRes = xml.getResponseHeader("Last-Modified");
2451 // Firefox always returns 200. check Last-Modified date
2452 return xml.status == 304 || xmlRes == jQuery.lastModified[url] ||
2453 jQuery.browser.safari && xml.status == undefined;
2458 httpData: function( r, type ) {
2459 var ct = r.getResponseHeader("content-type");
2460 var xml = type == "xml" || !type && ct && ct.indexOf("xml") >= 0;
2461 var data = xml ? r.responseXML : r.responseText;
2463 if ( xml && data.documentElement.tagName == "parsererror" )
2464 throw "parsererror";
2466 // If the type is "script", eval it in global context
2467 if ( type == "script" )
2468 jQuery.globalEval( data );
2470 // Get the JavaScript object, if JSON is used.
2471 if ( type == "json" )
2472 data = eval("(" + data + ")");
2477 // Serialize an array of form elements or a set of
2478 // key/values into a query string
2479 param: function( a ) {
2482 // If an array was passed in, assume that it is an array
2484 if ( a.constructor == Array || a.jquery )
2485 // Serialize the form elements
2486 jQuery.each( a, function(){
2487 s.push( encodeURIComponent(this.name) + "=" + encodeURIComponent( this.value ) );
2490 // Otherwise, assume that it's an object of key/value pairs
2492 // Serialize the key/values
2494 // If the value is an array then the key names need to be repeated
2495 if ( a[j] && a[j].constructor == Array )
2496 jQuery.each( a[j], function(){
2497 s.push( encodeURIComponent(j) + "=" + encodeURIComponent( this ) );
2500 s.push( encodeURIComponent(j) + "=" + encodeURIComponent( a[j] ) );
2502 // Return the resulting serialization
2503 return s.join("&").replace(/%20/g, "+");
2508 show: function(speed,callback){
2511 height: "show", width: "show", opacity: "show"
2512 }, speed, callback) :
2514 this.filter(":hidden").each(function(){
2515 this.style.display = this.oldblock ? this.oldblock : "";
2516 if ( jQuery.css(this,"display") == "none" )
2517 this.style.display = "block";
2521 hide: function(speed,callback){
2524 height: "hide", width: "hide", opacity: "hide"
2525 }, speed, callback) :
2527 this.filter(":visible").each(function(){
2528 this.oldblock = this.oldblock || jQuery.css(this,"display");
2529 if ( this.oldblock == "none" )
2530 this.oldblock = "block";
2531 this.style.display = "none";
2535 // Save the old toggle function
2536 _toggle: jQuery.fn.toggle,
2538 toggle: function( fn, fn2 ){
2539 return jQuery.isFunction(fn) && jQuery.isFunction(fn2) ?
2540 this._toggle( fn, fn2 ) :
2543 height: "toggle", width: "toggle", opacity: "toggle"
2545 this.each(function(){
2546 jQuery(this)[ jQuery(this).is(":hidden") ? "show" : "hide" ]();
2550 slideDown: function(speed,callback){
2551 return this.animate({height: "show"}, speed, callback);
2554 slideUp: function(speed,callback){
2555 return this.animate({height: "hide"}, speed, callback);
2558 slideToggle: function(speed, callback){
2559 return this.animate({height: "toggle"}, speed, callback);
2562 fadeIn: function(speed, callback){
2563 return this.animate({opacity: "show"}, speed, callback);
2566 fadeOut: function(speed, callback){
2567 return this.animate({opacity: "hide"}, speed, callback);
2570 fadeTo: function(speed,to,callback){
2571 return this.animate({opacity: to}, speed, callback);
2574 animate: function( prop, speed, easing, callback ) {
2575 var opt = jQuery.speed(speed, easing, callback);
2577 return this[ opt.queue === false ? "each" : "queue" ](function(){
2578 opt = jQuery.extend({}, opt);
2579 var hidden = jQuery(this).is(":hidden"), self = this;
2581 for ( var p in prop ) {
2582 if ( prop[p] == "hide" && hidden || prop[p] == "show" && !hidden )
2583 return jQuery.isFunction(opt.complete) && opt.complete.apply(this);
2585 if ( p == "height" || p == "width" ) {
2586 // Store display property
2587 opt.display = jQuery.css(this, "display");
2589 // Make sure that nothing sneaks out
2590 opt.overflow = this.style.overflow;
2594 if ( opt.overflow != null )
2595 this.style.overflow = "hidden";
2597 opt.curAnim = jQuery.extend({}, prop);
2599 jQuery.each( prop, function(name, val){
2600 var e = new jQuery.fx( self, opt, name );
2602 if ( /toggle|show|hide/.test(val) )
2603 e[ val == "toggle" ? hidden ? "show" : "hide" : val ]( prop );
2605 var parts = val.toString().match(/^([+-]=)?([\d+-.]+)(.*)$/),
2606 start = e.cur(true) || 0;
2609 var end = parseFloat(parts[2]),
2610 unit = parts[3] || "px";
2612 // We need to compute starting value
2613 if ( unit != "px" ) {
2614 self.style[ name ] = (end || 1) + unit;
2615 start = ((end || 1) / e.cur(true)) * start;
2616 self.style[ name ] = start + unit;
2619 // If a +=/-= token was provided, we're doing a relative animation
2621 end = ((parts[1] == "-=" ? -1 : 1) * end) + start;
2623 e.custom( start, end, unit );
2625 e.custom( start, val, "" );
2629 // For JS strict compliance
2634 queue: function(type, fn){
2635 if ( jQuery.isFunction(type) ) {
2640 if ( !type || (typeof type == "string" && !fn) )
2641 return queue( this[0], type );
2643 return this.each(function(){
2644 if ( fn.constructor == Array )
2645 queue(this, type, fn);
2647 queue(this, type).push( fn );
2649 if ( queue(this, type).length == 1 )
2656 var timers = jQuery.timers;
2658 return this.each(function(){
2659 for ( var i = 0; i < timers.length; i++ )
2660 if ( timers[i].elem == this )
2661 timers.splice(i--, 1);
2667 var queue = function( elem, type, array ) {
2671 var q = jQuery.data( elem, type + "queue" );
2674 q = jQuery.data( elem, type + "queue",
2675 array ? jQuery.makeArray(array) : [] );
2680 jQuery.fn.dequeue = function(type){
2681 type = type || "fx";
2683 return this.each(function(){
2684 var q = queue(this, type);
2695 speed: function(speed, easing, fn) {
2696 var opt = speed && speed.constructor == Object ? speed : {
2697 complete: fn || !fn && easing ||
2698 jQuery.isFunction( speed ) && speed,
2700 easing: fn && easing || easing && easing.constructor != Function && easing
2703 opt.duration = (opt.duration && opt.duration.constructor == Number ?
2705 { slow: 600, fast: 200 }[opt.duration]) || 400;
2708 opt.old = opt.complete;
2709 opt.complete = function(){
2710 jQuery(this).dequeue();
2711 if ( jQuery.isFunction( opt.old ) )
2712 opt.old.apply( this );
2719 linear: function( p, n, firstNum, diff ) {
2720 return firstNum + diff * p;
2722 swing: function( p, n, firstNum, diff ) {
2723 return ((-Math.cos(p*Math.PI)/2) + 0.5) * diff + firstNum;
2729 fx: function( elem, options, prop ){
2730 this.options = options;
2734 if ( !options.orig )
2740 jQuery.fx.prototype = {
2742 // Simple function for setting a style value
2744 if ( this.options.step )
2745 this.options.step.apply( this.elem, [ this.now, this ] );
2747 (jQuery.fx.step[this.prop] || jQuery.fx.step._default)( this );
2749 // Set display property to block for height/width animations
2750 if ( this.prop == "height" || this.prop == "width" )
2751 this.elem.style.display = "block";
2754 // Get the current size
2755 cur: function(force){
2756 if ( this.elem[this.prop] != null && this.elem.style[this.prop] == null )
2757 return this.elem[ this.prop ];
2759 var r = parseFloat(jQuery.curCSS(this.elem, this.prop, force));
2760 return r && r > -10000 ? r : parseFloat(jQuery.css(this.elem, this.prop)) || 0;
2763 // Start an animation from one number to another
2764 custom: function(from, to, unit){
2765 this.startTime = (new Date()).getTime();
2768 this.unit = unit || this.unit || "px";
2769 this.now = this.start;
2770 this.pos = this.state = 0;
2780 jQuery.timers.push(t);
2782 if ( jQuery.timers.length == 1 ) {
2783 var timer = setInterval(function(){
2784 var timers = jQuery.timers;
2786 for ( var i = 0; i < timers.length; i++ )
2788 timers.splice(i--, 1);
2790 if ( !timers.length )
2791 clearInterval( timer );
2796 // Simple 'show' function
2798 // Remember where we started, so that we can go back to it later
2799 this.options.orig[this.prop] = jQuery.attr( this.elem.style, this.prop );
2800 this.options.show = true;
2802 // Begin the animation
2803 this.custom(0, this.cur());
2805 // Make sure that we start at a small width/height to avoid any
2807 if ( this.prop == "width" || this.prop == "height" )
2808 this.elem.style[this.prop] = "1px";
2810 // Start by showing the element
2811 jQuery(this.elem).show();
2814 // Simple 'hide' function
2816 // Remember where we started, so that we can go back to it later
2817 this.options.orig[this.prop] = jQuery.attr( this.elem.style, this.prop );
2818 this.options.hide = true;
2820 // Begin the animation
2821 this.custom(this.cur(), 0);
2824 // Each step of an animation
2826 var t = (new Date()).getTime();
2828 if ( t > this.options.duration + this.startTime ) {
2829 this.now = this.end;
2830 this.pos = this.state = 1;
2833 this.options.curAnim[ this.prop ] = true;
2836 for ( var i in this.options.curAnim )
2837 if ( this.options.curAnim[i] !== true )
2841 if ( this.options.display != null ) {
2842 // Reset the overflow
2843 this.elem.style.overflow = this.options.overflow;
2845 // Reset the display
2846 this.elem.style.display = this.options.display;
2847 if ( jQuery.css(this.elem, "display") == "none" )
2848 this.elem.style.display = "block";
2851 // Hide the element if the "hide" operation was done
2852 if ( this.options.hide )
2853 this.elem.style.display = "none";
2855 // Reset the properties, if the item has been hidden or shown
2856 if ( this.options.hide || this.options.show )
2857 for ( var p in this.options.curAnim )
2858 jQuery.attr(this.elem.style, p, this.options.orig[p]);
2861 // If a callback was provided, execute it
2862 if ( done && jQuery.isFunction( this.options.complete ) )
2863 // Execute the complete function
2864 this.options.complete.apply( this.elem );
2868 var n = t - this.startTime;
2869 this.state = n / this.options.duration;
2871 // Perform the easing function, defaults to swing
2872 this.pos = jQuery.easing[this.options.easing || (jQuery.easing.swing ? "swing" : "linear")](this.state, n, 0, 1, this.options.duration);
2873 this.now = this.start + ((this.end - this.start) * this.pos);
2875 // Perform the next step of the animation
2885 scrollLeft: function(fx){
2886 fx.elem.scrollLeft = fx.now;
2889 scrollTop: function(fx){
2890 fx.elem.scrollTop = fx.now;
2893 opacity: function(fx){
2894 jQuery.attr(fx.elem.style, "opacity", fx.now);
2897 _default: function(fx){
2898 fx.elem.style[ fx.prop ] = fx.now + fx.unit;
2901 // The Offset Method
2902 // Originally By Brandon Aaron, part of the Dimension Plugin
2903 // http://jquery.com/plugins/project/dimensions
2904 jQuery.fn.offset = function() {
2905 var left = 0, top = 0, elem = this[0], results;
2907 if ( elem ) with ( jQuery.browser ) {
2908 var absolute = jQuery.css(elem, "position") == "absolute",
2909 parent = elem.parentNode,
2910 offsetParent = elem.offsetParent,
2911 doc = elem.ownerDocument,
2912 safari2 = safari && parseInt(version) < 522;
2914 // Use getBoundingClientRect if available
2915 if ( elem.getBoundingClientRect ) {
2916 box = elem.getBoundingClientRect();
2918 // Add the document scroll offsets
2920 box.left + Math.max(doc.documentElement.scrollLeft, doc.body.scrollLeft),
2921 box.top + Math.max(doc.documentElement.scrollTop, doc.body.scrollTop)
2924 // IE adds the HTML element's border, by default it is medium which is 2px
2925 // IE 6 and IE 7 quirks mode the border width is overwritable by the following css html { border: 0; }
2926 // IE 7 standards mode, the border is always 2px
2928 var border = jQuery("html").css("borderWidth");
2929 border = (border == "medium" || jQuery.boxModel && parseInt(version) >= 7) && 2 || border;
2930 add( -border, -border );
2933 // Otherwise loop through the offsetParents and parentNodes
2936 // Initial element offsets
2937 add( elem.offsetLeft, elem.offsetTop );
2939 // Get parent offsets
2940 while ( offsetParent ) {
2941 // Add offsetParent offsets
2942 add( offsetParent.offsetLeft, offsetParent.offsetTop );
2944 // Mozilla and Safari > 2 does not include the border on offset parents
2945 // However Mozilla adds the border for table cells
2946 if ( mozilla && /^t[d|h]$/i.test(parent.tagName) || !safari2 )
2947 border( offsetParent );
2949 // Safari <= 2 doubles body offsets with an absolutely positioned element or parent
2950 if ( safari2 && !absolute && jQuery.css(offsetParent, "position") == "absolute" )
2953 // Get next offsetParent
2954 offsetParent = offsetParent.offsetParent;
2957 // Get parent scroll offsets
2958 while ( parent.tagName && !/^body|html$/i.test(parent.tagName) ) {
2959 // Work around opera inline/table scrollLeft/Top bug
2960 if ( !/^inline|table-row.*$/i.test(jQuery.css(parent, "display")) )
2961 // Subtract parent scroll offsets
2962 add( -parent.scrollLeft, -parent.scrollTop );
2964 // Mozilla does not add the border for a parent that has overflow != visible
2965 if ( mozilla && jQuery.css(parent, "overflow") != "visible" )
2969 parent = parent.parentNode;
2972 // Safari doubles body offsets with an absolutely positioned element or parent
2973 if ( safari2 && absolute )
2974 add( -doc.body.offsetLeft, -doc.body.offsetTop );
2977 // Return an object with top and left properties
2978 results = { top: top, left: left };
2983 function border(elem) {
2984 add( jQuery.css(elem, "borderLeftWidth"), jQuery.css(elem, "borderTopWidth") );
2987 function add(l, t) {
2988 left += parseInt(l) || 0;
2989 top += parseInt(t) || 0;