4 * Copyright (c) 2006 John Resig (jquery.com)
5 * Licensed under the MIT License:
6 * http://www.opensource.org/licenses/mit-license.php
12 // Global undefined variable
13 window.undefined = window.undefined;
16 * Create a new jQuery Object
19 function jQuery(a,c) {
21 return new jQuery(a,c);
23 this.cur = jQuery.Select(
24 a || jQuery.context || document,
25 c && c.jquery && c.get(0) || c
30 * The jQuery query object.
34 jQuery.fn = jQuery.prototype = {
36 * The current SVN version of jQuery.
44 * The number of elements currently matched.
49 return this.get().length;
53 * Access the elements matched. If a number is provided,
54 * the Nth element is returned, otherwise, an array of all
55 * matched items is returned.
57 * @type Array,DOMElement
60 return num == undefined ? this.cur : this.cur[num];
64 for ( var i = 0; i < this.size(); i++ )
65 f.apply( this.get(i), [i] );
69 return this.each(function(){
72 jQuery.attr(this,j,a[j]);
74 jQuery.attr(this,a,b);
78 return h == undefined && this.size() ?
79 this.get(0).innerHTML : this.set( "innerHTML", h );
82 return h == undefined && this.size() ?
83 this.get(0).value : this.set( "value", h );
88 for ( var j = 0; j < e.length; j++ )
89 for ( var i = 0; i < e[j].childNodes.length; i++ )
90 t += e[j].childNodes[i].nodeType != 1 ?
91 e[j].childNodes[i].nodeValue :
92 jQuery.fn.text(e[j].childNodes[i].childNodes);
97 return a.constructor != String || b ?
101 jQuery.attr(this.style,j,a[j]);
103 jQuery.attr(this.style,a,b);
104 }) : jQuery.css( this.get(0), a );
107 return this.each(function(){
108 var d = jQuery.css(this,"display");
109 if ( !d || d == "none" )
116 return this.each(function(){
117 this.style.display = this.oldblock ? this.oldblock : "";
118 if ( jQuery.css(this,"display") == "none" )
119 this.style.display = "block";
123 return this.each(function(){
124 this.oldblock = jQuery.css(this,"display");
125 if ( this.oldblock == "none" )
126 this.oldblock = "block";
127 this.style.display = "none";
130 addClass: function(c) {
131 return this.each(function(){
132 jQuery.className.add(this,c);
135 removeClass: function(c) {
136 return this.each(function(){
137 jQuery.className.remove(this,c);
141 toggleClass: function(c) {
142 return this.each(function(){
143 if (jQuery.hasWord(this,c))
144 jQuery.className.remove(this,c);
146 jQuery.className.add(this,c);
150 this.each(function(){this.parentNode.removeChild( this );});
151 return this.pushStack( [] );
155 var a = jQuery.clean(arguments);
156 return this.each(function(){
157 var b = a[0].cloneNode(true);
158 this.parentNode.insertBefore( b, this );
159 while ( b.firstChild )
161 b.appendChild( this );
166 var clone = this.size() > 1;
167 var a = jQuery.clean(arguments);
168 return this.domManip(function(){
169 for ( var i = 0; i < a.length; i++ )
170 this.appendChild( clone ? a[i].cloneNode(true) : a[i] );
174 appendTo: function() {
176 return this.each(function(){
177 for ( var i = 0; i < a.length; i++ )
178 $(a[i]).append( this );
182 prepend: function() {
183 var clone = this.size() > 1;
184 var a = jQuery.clean(arguments);
185 return this.domManip(function(){
186 for ( var i = a.length - 1; i >= 0; i-- )
187 this.insertBefore( clone ? a[i].cloneNode(true) : a[i], this.firstChild );
192 var clone = this.size() > 1;
193 var a = jQuery.clean(arguments);
194 return this.each(function(){
195 for ( var i = 0; i < a.length; i++ )
196 this.parentNode.insertBefore( clone ? a[i].cloneNode(true) : a[i], this );
201 var clone = this.size() > 1;
202 var a = jQuery.clean(arguments);
203 return this.each(function(){
204 for ( var i = a.length - 1; i >= 0; i-- )
205 this.parentNode.insertBefore( clone ? a[i].cloneNode(true) : a[i], this.nextSibling );
210 return this.each(function(){
211 while ( this.firstChild )
212 this.removeChild( this.firstChild );
216 bind: function(t,f) {
217 return this.each(function(){jQuery.event.add(this,t,f);});
219 unbind: function(t,f) {
220 return this.each(function(){jQuery.event.remove(this,t,f);});
222 trigger: function(t) {
223 return this.each(function(){jQuery.event.trigger(this,t);});
226 pushStack: function(a) {
227 if ( !this.stack ) this.stack = [];
228 this.stack.unshift( this.cur );
229 if ( a ) this.cur = a;
235 this.each(function(){
236 ret = jQuery.merge( ret, jQuery.Select(t,this) );
238 this.pushStack( ret );
243 this.cur = this.stack.shift();
247 parent: function(a) {
248 var ret = jQuery.map(this.cur,"d.parentNode");
249 if ( a ) ret = jQuery.filter(a,ret).r;
250 return this.pushStack(ret);
253 parents: function(a) {
254 var ret = jQuery.map(this.cur,jQuery.parents);
255 if ( a ) ret = jQuery.filter(a,ret).r;
256 return this.pushStack(ret);
259 siblings: function(a) {
260 // Incorrect, need to exclude current element
261 var ret = jQuery.map(this.cur,jQuery.sibling);
262 if ( a ) ret = jQuery.filter(a,ret).r;
263 return this.pushStack(ret);
266 filter: function(t) {
267 return this.pushStack( jQuery.filter(t,this.cur).r );
270 return this.pushStack( t.constructor == String ?
271 jQuery.filter(t,this.cur,false).r :
272 jQuery.grep(this.cur,function(a){ return a != t; }) );
275 return this.pushStack( jQuery.merge( this.cur, t.constructor == String ?
276 jQuery.Select(t) : t.constructor == Array ? t : [t] ) );
280 * A wrapper function for each() to be used by append and prepend.
281 * Handles cases where you're trying to modify the inner contents of
282 * a table, when you actually need to work with the tbody.
285 * @param {String} expr The expression with which to filter
289 return jQuery.filter(expr,this.cur).r.length > 0;
293 * A wrapper function for each() to be used by append and prepend.
294 * Handles cases where you're trying to modify the inner contents of
295 * a table, when you actually need to work with the tbody.
299 * @param {Function} fn The function doing the DOM manipulation.
302 domManip: function(fn){
303 return this.each(function(){
306 if ( this.nodeName == "TABLE" ) {
307 var tbody = this.getElementsByTagName("tbody");
309 if ( !tbody.length ) {
310 obj = document.createElement("tbody");
311 this.appendChild( obj );
323 if (jQuery.hasWord(o,c)) return;
324 o.className += ( o.className ? " " : "" ) + c;
326 remove: function(o,c){
327 o.className = !c ? "" :
329 new RegExp("(^|\\s*\\b[^-])"+c+"($|\\b(?=[^-]))", "g"), "");
334 var b = navigator.userAgent.toLowerCase();
336 // Figure out what browser is being used
338 ( /webkit/.test(b) && "safari" ) ||
339 ( /opera/.test(b) && "opera" ) ||
340 ( /msie/.test(b) && "msie" ) ||
341 ( !/compatible/.test(b) && "mozilla" ) ||
344 // Check to see if the W3C box model is being used
345 jQuery.boxModel = ( jQuery.browser != "msie" || document.compatMode == "CSS1Compat" );
348 jQuery.css = function(e,p) {
349 // Adapted from Prototype 1.4.0
350 if ( p == "height" || p == "width" ) {
352 // Handle extra width/height provided by the W3C box model
353 var ph = (!jQuery.boxModel ? 0 :
354 jQuery.css(e,"paddingTop") + jQuery.css(e,"paddingBottom") +
355 jQuery.css(e,"borderTopWidth") + jQuery.css(e,"borderBottomWidth")) || 0;
357 var pw = (!jQuery.boxModel ? 0 :
358 jQuery.css(e,"paddingLeft") + jQuery.css(e,"paddingRight") +
359 jQuery.css(e,"borderLeftWidth") + jQuery.css(e,"borderRightWidth")) || 0;
363 if (jQuery.css(e,"display") != 'none') {
364 oHeight = e.offsetHeight || parseInt(e.style.height) || 0;
365 oWidth = e.offsetWidth || parseInt(e.style.width) || 0;
368 var ov = els.visibility;
369 var op = els.position;
370 var od = els.display;
371 els.visibility = "hidden";
372 els.position = "absolute";
374 oHeight = e.clientHeight || parseInt(e.style.height);
375 oWidth = e.clientWidth || parseInt(e.style.width);
381 return p == "height" ?
382 (oHeight - ph < 0 ? 0 : oHeight - ph) :
383 (oWidth - pw < 0 ? 0 : oWidth - pw);
390 else if (e.currentStyle)
391 r = e.currentStyle[p];
392 else if (document.defaultView && document.defaultView.getComputedStyle) {
393 p = p.replace(/([A-Z])/g,"-$1").toLowerCase();
394 var s = document.defaultView.getComputedStyle(e,"");
395 r = s ? s.getPropertyValue(p) : null;
398 return /top|right|left|bottom/i.test(p) ? parseFloat( r ) : r;
401 jQuery.clean = function(a) {
403 for ( var i = 0; i < a.length; i++ ) {
404 if ( a[i].constructor == String ) {
406 if ( !a[i].indexOf("<tr") ) {
408 a[i] = "<table>" + a[i] + "</table>";
409 } else if ( !a[i].indexOf("<td") || !a[i].indexOf("<th") ) {
411 a[i] = "<table><tbody><tr>" + a[i] + "</tr></tbody></table>";
414 var div = document.createElement("div");
415 div.innerHTML = a[i];
418 div = div.firstChild.firstChild;
419 if ( td ) div = div.firstChild;
422 for ( var j = 0; j < div.childNodes.length; j++ )
423 r[r.length] = div.childNodes[j];
424 } else if ( a[i].length && !a[i].nodeType )
425 for ( var k = 0; k < a[i].length; k++ )
426 r[r.length] = a[i][k];
427 else if ( a[i] !== null )
429 a[i].nodeType ? a[i] : document.createTextNode(a[i].toString());
435 "": "m[2]== '*'||a.nodeName.toUpperCase()==m[2].toUpperCase()",
436 "#": "a.getAttribute('id')&&a.getAttribute('id')==m[2]",
443 last: "i==r.length-1",
446 "first-child": "jQuery.sibling(a,0).cur",
447 "nth-child": "(m[3]=='even'?jQuery.sibling(a,m[3]).n%2==0:(m[3]=='odd'?jQuery.sibling(a,m[3]).n%2==1:jQuery.sibling(a,m[3]).cur))",
448 "last-child": "jQuery.sibling(a,0,true).cur",
449 "nth-last-child": "jQuery.sibling(a,m[3],true).cur",
450 "first-of-type": "jQuery.ofType(a,0)",
451 "nth-of-type": "jQuery.ofType(a,m[3])",
452 "last-of-type": "jQuery.ofType(a,0,true)",
453 "nth-last-of-type": "jQuery.ofType(a,m[3],true)",
454 "only-of-type": "jQuery.ofType(a)==1",
455 "only-child": "jQuery.sibling(a).length==1",
456 parent: "a.childNodes.length",
457 empty: "!a.childNodes.length",
458 root: "a==(a.ownerDocument||document).documentElement",
459 contains: "(a.innerText||a.innerHTML).indexOf(m[3])!=-1",
460 visible: "(!a.type||a.type!='hidden')&&(jQuery.css(a,'display')!= 'none'&&jQuery.css(a,'visibility')!= 'hidden')",
461 hidden: "(a.type&&a.type == 'hidden')||jQuery.css(a,'display')=='none'||jQuery.css(a,'visibility')== 'hidden'",
462 enabled: "a.disabled==false",
463 disabled: "a.disabled",
466 ".": "jQuery.hasWord(a,m[2])",
468 "=": "jQuery.attr(a,m[3])==m[4]",
469 "!=": "jQuery.attr(a,m[3])!=m[4]",
470 "~=": "jQuery.hasWord(jQuery.attr(a,m[3]),m[4])",
471 "|=": "!jQuery.attr(a,m[3]).indexOf(m[4])",
472 "^=": "!jQuery.attr(a,m[3]).indexOf(m[4])",
473 "$=": "jQuery.attr(a,m[3]).substr( jQuery.attr(a,m[3]).length - m[4].length,m[4].length )==m[4]",
474 "*=": "jQuery.attr(a,m[3]).indexOf(m[4])>=0",
475 "": "m[3]=='*'?a.attributes.length>0:jQuery.attr(a,m[3])"
477 "[": "jQuery.Select(m[2],a).length"
481 "\\.\\.|/\\.\\.", "a.parentNode",
482 ">|/", "jQuery.sibling(a.firstChild)",
483 "\\+", "jQuery.sibling(a).next",
486 var s = jQuery.sibling(a);
488 for ( var i = s.n; i < s.length; i++ )
494 jQuery.Select = function( t, context ) {
495 context = context || jQuery.context || document;
496 if ( t.constructor != String ) return [t];
498 if ( !t.indexOf("//") ) {
499 context = context.documentElement;
500 t = t.substr(2,t.length);
501 } else if ( !t.indexOf("/") ) {
502 context = context.documentElement;
503 t = t.substr(1,t.length);
504 // FIX Assume the root element is right :(
505 if ( t.indexOf("/") >= 1 )
506 t = t.substr(t.indexOf("/"),t.length);
513 while ( t.length > 0 && last != t ) {
517 t = jQuery.cleanSpaces(t).replace( /^\/\//i, "" );
519 var foundToken = false;
521 for ( var i = 0; i < jQuery.token.length; i += 2 ) {
522 var re = new RegExp("^(" + jQuery.token[i] + ")");
526 r = ret = jQuery.map( ret, jQuery.token[i+1] );
527 t = jQuery.cleanSpaces( t.replace( re, "" ) );
534 if ( !t.indexOf(",") || !t.indexOf("|") ) {
535 if ( ret[0] == context ) ret.shift();
536 done = jQuery.merge( done, ret );
538 t = " " + t.substr(1,t.length);
540 var re2 = /^([#.]?)([a-z0-9\\*_-]*)/i;
544 // Ummm, should make this work in all XML docs
545 var oid = document.getElementById(m[2]);
546 r = ret = oid ? [oid] : [];
547 t = t.replace( re2, "" );
549 if ( !m[2] || m[1] == "." ) m[2] = "*";
551 for ( var i = 0; i < ret.length; i++ )
554 jQuery.getAll(ret[i]) :
555 ret[i].getElementsByTagName(m[2])
563 var val = jQuery.filter(t,r);
565 t = jQuery.cleanSpaces(val.t);
569 if ( ret && ret[0] == context ) ret.shift();
570 done = jQuery.merge( done, ret );
575 jQuery.getAll = function(o,r) {
577 var s = o.childNodes;
578 for ( var i = 0; i < s.length; i++ )
579 if ( s[i].nodeType == 1 ) {
581 jQuery.getAll( s[i], r );
586 jQuery.attr = function(o,a,v){
587 if ( a && a.constructor == String ) {
590 "class": "className",
593 a = (fix[a] && fix[a].replace && fix[a]) || a;
594 var r = /-([a-z])/ig;
595 a = a.replace(r,function(z,b){return b.toUpperCase();});
596 if ( v != undefined ) {
598 if ( o.setAttribute && a != "disabled" )
601 return o[a] || o.getAttribute(a) || "";
606 jQuery.filter = function(t,r,not) {
609 g = function(a,f) {return jQuery.grep(a,f,true);};
611 while ( t && t.match(/^[:\\.#\\[a-zA-Z\\*]/) ) {
612 var re = /^\[ *@([a-z0-9*()_-]+) *([~!|*$^=]*) *'?"?([^'"]*)'?"? *\]/i;
616 m = ["", "@", m[2], m[1], m[3]];
618 re = /^(\[) *([^\]]*) *\]/i;
622 re = /^(:)([a-z0-9*_-]*)\( *["']?([^ \)'"]*)['"]? *\)/i;
626 re = /^([:\.#]*)([a-z0-9*_-]*)/i;
631 t = t.replace( re, "" );
633 if ( m[1] == ":" && m[2] == "not" )
634 r = jQuery.filter(m[3],r,false).r;
638 if ( jQuery.g[m[1]].constructor == String )
640 else if ( jQuery.g[m[1]][m[2]] )
641 f = jQuery.g[m[1]][m[2]];
644 eval("f = function(a,i){return " + f + "}");
650 return { r: r, t: t };
653 jQuery.parents = function(a){
655 var c = a.parentNode;
656 while ( c && c != document ) {
663 jQuery.cleanSpaces = function(t){
664 return t.replace(/^\s+|\s+$/g, "");
667 jQuery.ofType = function(a,n,e) {
668 var t = jQuery.grep(jQuery.sibling(a),function(b){ return b.nodeName == a.nodeName; });
669 if ( e ) n = t.length - n - 1;
670 return n != undefined ? t[n] == a : t.length;
673 jQuery.sibling = function(a,n,e) {
675 var tmp = a.parentNode.childNodes;
676 for ( var i = 0; i < tmp.length; i++ ) {
677 if ( tmp[i].nodeType == 1 )
678 type[type.length] = tmp[i];
680 type.n = type.length - 1;
682 if ( e ) n = type.length - n - 1;
683 type.cur = ( type[n] == a );
684 type.prev = ( type.n > 0 ? type[type.n - 1] : null );
685 type.next = ( type.n < type.length - 1 ? type[type.n + 1] : null );
689 jQuery.hasWord = function(e,a) {
690 if ( e == undefined ) return;
691 if ( e.className ) e = e.className;
692 return new RegExp("(^|\\s)" + a + "(\\s|$)").test(e);
695 jQuery.merge = function(a,b) {
697 for ( var k = 0; k < b.length; k++ ) d[k] = b[k];
699 for ( var i = 0; i < a.length; i++ ) {
701 for ( var j = 0; j < b.length; j++ )
704 if ( c ) d[d.length] = a[i];
710 jQuery.grep = function(a,f,s) {
711 if ( f.constructor == String )
712 f = new Function("a","i","return " + f);
715 for ( var i = 0; i < a.length; i++ )
716 if ( (!s && f(a[i],i)) || (s && !f(a[i],i)) )
721 jQuery.map = function(a,f) {
722 if ( f.constructor == String )
723 f = new Function("a","return " + f);
726 for ( var i = 0; i < a.length; i++ ) {
729 if ( t.constructor != Array ) t = [t];
730 r = jQuery.merge( t, r );
738 // Bind an event to an element
739 // Original by Dean Edwards
740 add: function(element, type, handler) {
741 // For whatever reason, IE has trouble passing the window object
742 // around, causing it to be cloned in the process
743 if ( jQuery.browser == "msie" && element.setInterval != undefined )
746 if (!handler.guid) handler.guid = jQuery.event.guid++;
747 if (!element.events) element.events = {};
748 var handlers = element.events[type];
750 handlers = element.events[type] = {};
751 if (element["on" + type])
752 handlers[0] = element["on" + type];
754 handlers[handler.guid] = handler;
755 element["on" + type] = jQuery.event.handle;
760 // Detach an event or set of events from an element
761 remove: function(element, type, handler) {
763 if (type && element.events[type])
765 delete element.events[type][handler.guid];
767 for ( var i in element.events[type] )
768 delete element.events[type][i];
770 for ( var j in element.events )
771 jQuery.event.remove( element, j );
774 trigger: function(element,type,data) {
775 data = data || [ jQuery.event.fix({ type: type }) ];
776 if ( element && element["on" + type] )
777 element["on" + type].apply( element, data );
780 handle: function(event) {
781 if ( !event && !window.event ) return;
783 var returnValue = true, handlers = [];
784 event = event || jQuery.event.fix(window.event);
786 for ( var j in this.events[event.type] )
787 handlers[handlers.length] = this.events[event.type][j];
789 for ( var i = 0; i < handlers.length; i++ ) {
790 if ( handlers[i].constructor == Function ) {
791 this.handleEvent = handlers[i];
792 if (this.handleEvent(event) === false) {
793 event.preventDefault();
794 event.stopPropagation();
802 fix: function(event) {
803 event.preventDefault = function() {
804 this.returnValue = false;
807 event.stopPropagation = function() {
808 this.cancelBubble = true;