475ca5608e9f324adac89a183d2306786d730568
[jquery.git] / jquery / jquery.js
1 /*
2  * jQuery (http://jquery.com/)
3  * By John Resig (http://ejohn.org/)
4  * Under an Attribution, Share Alike License
5  *
6  * $Date: $
7  * $Rev: $
8  */
9
10 function $(a,c) {
11         var $a = a || $.context || document;
12         var $c = c && c.$jquery && c.get(0) || c;
13         
14         // Since we're using Prototype's $ function,
15         // be nice and have backwards compatability
16         if ( typeof Prototype != "undefined" ) {
17                 if ( $a.constructor == String ) {
18                         var re = new RegExp( "[^a-zA-Z0-9_-]" );
19                         if ( !re.test($a) ) {
20                                 $c = $c && $c.documentElement || document;
21                                 if ( $c.getElementsByTagName($a).length == 0 ) {
22                                         var obj = $c.getElementById($a);
23                                         if ( obj != null ) return obj;
24                                 }
25                         }
26                 } else if ( $a.constructor == Array ) {
27                         return $.map( $a, function(b){
28                                 if ( b.constructor == String )
29                                         return document.getElementById(b);
30                                 return b;
31                         });
32                 }
33         }
34
35         // Load Dynamic Function List
36         var self = {
37                 cur: $.Select($a,$c),
38                 $jquery: "$Rev$",
39                 
40                 // The only two getters
41                 size: function() {return this.get().length},
42                 get: function(i) {
43                         return i == null ? this.cur : this.cur[i];
44                 },
45                 
46                 each: function(f) {
47                         for ( var i = 0; i < this.size(); i++ )
48                                 $.apply( this.get(i), f, [i] );
49                         return this;
50                 },
51                 set: function(a,b) {
52                         return this.each(function(){
53                                 if ( b == null )
54                                         for ( var j in a )
55                                                 $.attr(this,j,a[j]);
56                                 else
57                                         $.attr(this,a,b);
58                         });
59                 },
60                 html: function(h) {
61                         return h == null && this.size() ?
62         this.get(0).innerHTML : this.set( "innerHTML", h );
63                 },
64                 val: function(h) {
65                         return h == null && this.size() ?
66         this.get(0).value : this.set( "value", h );
67                 },
68                 
69                 css: function(a,b) {
70                         return this.each(function(){
71                                 if ( !b )
72                                         for ( var j in a )
73                                                 $.attr(this.style,j,a[j]);
74                                 else
75                                         $.attr(this.style,a,b);
76                         });
77                 },
78                 toggle: function() {
79                         return this.each(function(){
80                                 var d = $.getCSS(this,"display");
81                                 if ( d == "none" || d == '' )
82                                         $(this).show();
83                                 else
84                                         $(this).hide();
85                         });
86                 },
87                 show: function(a) {
88                         return this.each(function(){
89                                 this.style.display = this.$$oldblock ? this.$$oldblock : '';
90                                 if ( $.getCSS(this,"display") == "none" ) this.style.display = 'block';
91                         });
92                 },
93                 hide: function(a) {
94                         return this.each(function(){
95                                 this.$$oldblock = $.getCSS(this,"display");
96                                 if ( this.$$oldblock == "none" ) this.$$oldblock = 'block';
97                                 this.style.display = 'none';
98                         });
99                 },
100                 addClass: function(c) {
101                         return this.each(function(){
102                                 if ($.hasWord(this,c)) return;
103                                 this.className += ( this.className.length > 0 ? " " : "" ) + c;
104                         });
105                 },
106                 removeClass: function(c) {
107                         return this.each(function(){
108                                 this.className = c == null ? '' :
109                                         this.className.replace(
110                                                 new RegExp('(^|\\s*\\b[^-])'+c+'($|\\b(?=[^-]))', 'g'), '');
111                         });
112                 },
113                 // TODO: Optomize
114                 toggleClass: function(c) {
115                         return this.each(function(){
116                                 if ($.hasWord(this,c))
117                                         this.className = 
118                                                 this.className.replace(
119                                                         new RegExp('(\\s*\\b[^-])'+c+'($|\\b(?=[^-]))', 'g'), '');
120                                 else
121                                         this.className += ( this.className.length > 0 ? " " : "" ) + c;
122                         });
123                 },
124                 remove: function() {
125                         this.each(function(){this.parentNode.removeChild( this );});
126                         this.cur = [];
127                         return this;
128                 },
129                 
130                 wrap: function() {
131                         var a = $.clean(arguments);
132                         return this.each(function(){
133                                 var b = a[0].cloneNode(true);
134                                 this.parentNode.insertBefore( b, this );
135                                 while ( b.firstChild ) b = b.firstChild;
136                                 b.appendChild( this );
137                         });
138                 },
139                 
140                 append: function() {
141       var clone = this.size() > 1;
142                         var a = $.clean(arguments);
143                         return this.each(function(){
144                                 for ( var i in a )
145                                   this.appendChild( clone ? a[i].cloneNode(true) : a[i] );
146                         });
147                 },
148
149                 appendTo: function() {
150                         var a = arguments;
151                         return this.each(function(){
152                                 for ( var i = 0; i < a.length; i++ )
153                                         $(a[i]).append( this );
154                         });
155                 },
156                 
157                 prepend: function() {
158       var clone = this.size() > 1;
159                         var a = $.clean(arguments);
160                         return this.each(function(){
161                                 for ( var i = a.length - 1; i >= 0; i-- )
162                                         this.insertBefore( clone ? a[i].cloneNode(true) : a[i], this.firstChild );
163                         });
164                 },
165                 
166                 before: function() {
167       var clone = this.size() > 1;
168                         var a = $.clean(arguments);
169                         return this.each(function(){
170                                 for ( var i in a )
171                                         this.parentNode.insertBefore( clone ? a[i].cloneNode(true) : a[i], this );
172                         });
173                 },
174                 
175                 after: function() {
176       var clone = this.size() > 1;
177                         var a = $.clean(arguments);
178                         return this.each(function(){
179                                 for ( var i = a.length - 1; i >= 0; i-- )
180                                         this.parentNode.insertBefore( clone ? a[i].cloneNode(true) : a[i], this.nextSibling );
181                         });
182                 },
183
184                 empty: function() {
185                         return this.each(function(){
186                                 while ( this.firstChild )
187                                         this.removeChild( this.firstChild );
188                         });
189                 },
190                 
191                 bind: function(t,f) {
192                         return this.each(function(){addEvent(this,t,f);});
193                 },
194                 unbind: function(t,f) {
195                         return this.each(function(){removeEvent(this,t,f);});
196                 },
197                 trigger: function(t) {
198                         return this.each(function(){triggerEvent(this,t);});
199                 },
200                 
201                 find: function(t) {
202                         var old = [], ret = [];
203                         this.each(function(){
204                                 old[old.length] = this;
205                                 ret = $.merge( ret, $.Select(t,this) );
206                         });
207                         this.old = old;
208                         this.cur = ret;
209                         return this;
210                 },
211                 end: function() {
212                         this.cur = this.old;
213                         return this;
214                 },
215                 
216                 parent: function(a) {
217                         if ( a == null ) a = 1;
218                         this.cur = $.map(this.cur,function(d){
219                                 var b = $.parents(d);
220                                 if ( a == 0 )
221                                         return b;
222                                 else if ( a.constructor == String ) {
223                                         var c = $.filter(a,b);
224                                         return c.length > 0 ? c[0] : null;
225                                 } else
226                                         return b.length >= a ? b[a-1] : null;
227                         });
228                         return this;
229                 },
230                 
231                 parents: function(a) {
232                         return this;
233                 },
234                 
235                 filter: function(t) {
236                         this.cur = $.filter(t,this.cur).r;
237                         return this;
238                 },
239                 not: function(t) {
240                         this.cur = t.constructor == String ?
241                                 $.filter(t,this.cur,false).r :
242                                 $.grep(this.cur,function(a){return a != t;});
243                         return this;
244                 },
245                 add: function(t) {
246                         this.cur = $.merge( this.cur, t.constructor == String ?
247                                 $.Select(t) : t.constructor == Array ? t : [t] );
248                         return this;
249                 },
250                 is: function(t) {
251                         return $.filter(t,this.cur).r.length > 0;
252                 },
253                 isNot: function(t) {
254                         return !this.s(t);
255                 }
256         };
257         
258         // TODO: Remove need to return this
259         for ( var i in $.fn ) {
260                 if ( self[i] != null )
261                         self["_"+i] = self[i];
262                 self[i] = $.fn[i];
263         }
264         
265         if ( typeof Prototype != "undefined" && $a.constructor != String ) {
266                 if ( $c ) $a = self.get();
267                 for ( var i in self ) {(function(j){
268                         try {
269                                 if ( $a[j] == null ) {
270                                         $a[j] = function() {
271                                                 return $.apply(self,self[j],arguments);
272                                         };
273                                 }
274                         } catch(e) {}
275                 })(i);}
276                 return $a;
277         }
278         
279         return self;
280 }
281
282 $.apply = function(o,f,a) {
283         a = a || [];
284         if ( f.apply )
285                 return f.apply( o, a );
286   else {
287                 var p = [];
288                 for (var i = 0; i < a.length; i++)
289                         p[i] = 'a['+i+']';
290                 o.$$exec = this;
291                 var r = eval('o.$$exec(' + p.join(',') + ')');
292                 o.$$exec = null;
293                 return r;
294         }
295 };
296
297 $.getCSS = function(e,p) {
298         // Adapted from Prototype 1.4.0
299         if ( p == 'height' || p == 'width' ) {
300     if ($.getCSS(e,"display") != 'none')
301                         return p == 'height' ?
302                                 e.offsetHeight || parseInt(e.style.height) : 
303                                 e.offsetWidth || parseInt(e.style.width);
304     var els = e.style;
305     var ov = els.visibility;
306     var op = els.position;
307                 var od = els.display;
308     els.visibility = 'hidden';
309     els.position = 'absolute';
310     els.display = '';
311                 var oHeight = e.clientHeight || parseInt(e.style.height);
312     var oWidth = e.clientWidth || parseInt(e.style.width);
313     els.display = od;
314     els.position = op;
315     els.visibility = ov;
316                 return p == 'height' ? oHeight : oWidth;
317   }
318         
319   if (e.style[p])
320     return e.style[p];
321   else if (e.currentStyle)
322     return e.currentStyle[p];
323   else if (document.defaultView && document.defaultView.getComputedStyle) {
324     p = p.replace(/([A-Z])/g,"-$1");
325     p = p.toLowerCase();
326     var s = document.defaultView.getComputedStyle(e,"");
327     var r = s ? s.getPropertyValue(p) : p;
328                 return r;
329   } else
330     return null;
331 };
332 $.css = $.getCSS;
333
334 $.clean = function(a) {
335         var r = [];
336         for ( var i = 0; i < a.length; i++ )
337                 if ( a[i].constructor == String ) {
338                         var div = document.createElement("div");
339                         div.innerHTML = a[i];
340                         for ( var j = 0; j < div.childNodes.length; j++ )
341                                 r[r.length] = div.childNodes[j];
342                 } else if ( a[i].length )
343                         for ( var j = 0; j < a[i].length; j++ )
344                                 r[r.length] = a[i][j];
345                 else if ( a[i] != null )
346                         r[r.length] = 
347                                 a[i].nodeType ? a[i] : document.createTextNode(a[i].toString());
348         return r;
349 };
350
351 $.g = {
352         '': "m[2] == '*' || a.nodeName.toUpperCase() == m[2].toUpperCase()",
353         '#': "a.id == m[2]",
354         ':': {
355                 lt: "i < m[3]-0",
356                 gt: "i > m[3]-0",
357                 nth: "m[3] - 0 == i",
358                 eq: "m[3] - 0 == i",
359                 first: "i == 0",
360                 last: "i == r.length - 1",
361                 even: "i % 2 == 0",
362                 odd: "i % 2 == 1",
363                 "first-child": "$.sibling(a,0).cur",
364                 "nth-child": "(m[3] == 'even'?$.sibling(a,m[3]).n % 2 == 0 :(m[3] == 'odd'?$.sibling(a,m[3]).n % 2 == 1:$.sibling(a,m[3]).cur))",
365                 "last-child": "$.sibling(a,0,true).cur",
366                 "nth-last-child": "$.sibling(a,m[3],true).cur",
367                 "first-of-type": "$.ofType(a,0)",
368                 "nth-of-type": "$.ofType(a,m[3])",
369                 "last-of-type": "$.ofType(a,0,true)",
370                 "nth-last-of-type": "$.ofType(a,m[3],true)",
371                 "only-of-type": "$.ofType(a) == 1",
372                 "only-child": "$.sibling(a).length == 1",
373                 parent: "a.childNodes.length > 0",
374                 empty: "a.childNodes.length == 0",
375                 root: "a == ( a.ownerDocument ? a.ownerDocument : document ).documentElement",
376                 contains: "(a.innerText || a.innerHTML).indexOf(m[3]) != -1",
377                 visible: "(!a.type || a.type != 'hidden') && ($.getCSS(a,'display') != 'none' && $.getCSS(a,'visibility') != 'hidden')",
378                 hidden: "(a.type && a.type == 'hidden') || $.getCSS(a,'display') == 'none' || $.getCSS(a,'visibility') == 'hidden'",
379                 enabled: "a.disabled == false",
380                 disabled: "a.disabled",
381                 checked: "a.checked"
382         },
383         // TODO: Write getAttribute helper
384         ".": "$.hasWord(a.className||a.getAttribute('class'),m[2])",
385         "@": {
386                 "=": "$.attr(a,m[3]) == m[4]",
387                 "!=": "$.attr(a,m[3]) != m[4]",
388                 "~=": "$.hasWord($.attr(a,m[3]),m[4])",
389                 "|=": "$.attr(a,m[3]).indexOf(m[4]) == 0",
390                 "^=": "$.attr(a,m[3]).indexOf(m[4]) == 0",
391                 "$=": "$.attr(a,m[3]).substr( $.attr(a,m[3]).length - m[4].length, m[4].length ) == m[4]",
392                 "*=": "$.attr(a,m[3]).indexOf(m[4]) >= 0",
393                 "": "m[3] == '*' ? a.attributes.length > 0 : $.attr(a,m[3])"
394         },
395         "[": "$.Select(m[2],a).length > 0"
396 };
397
398 $.fn = {};
399
400 $.Select = function( t, context ) {
401         context = context || $.context || document;
402         if ( t.constructor != String ) return [t];
403         
404         if ( t.indexOf("//") == 0 ) {
405                 context = context.documentElement;
406                 t = t.substr(2,t.length);
407         } else if ( t.indexOf("/") == 0 ) {
408                 context = context.documentElement;
409                 t = t.substr(1,t.length);
410                 // FIX Assume the root element is right :(
411                 if ( t.indexOf('/') )
412                         t = t.substr(t.indexOf('/'),t.length);
413         }
414         
415         var ret = [context];
416   var done = [];
417         var last = null;
418   
419   while ( t.length > 0 && last != t ) {
420     var r = [];
421                 last = t;
422     
423     t = $.cleanSpaces(t);
424     
425     var re = new RegExp( "^//", "i" );
426     t = t.replace( re, "" );
427
428     if ( t.indexOf('..') == 0 || t.indexOf('/..') == 0 ) {
429                         if ( t.indexOf('/') == 0 )
430                                 t = t.substr(1,t.length);
431       r = $.map( ret, function(a){ return a.parentNode; } );
432                         t = t.substr(2,t.length);
433                         t = $.cleanSpaces(t);
434     } else if ( t.indexOf('>') == 0 || t.indexOf('/') == 0 ) {
435       r = $.map( ret, function(a){ return ( a.childNodes.length > 0 ? $.sibling( a.firstChild ) : null ); } );
436                         t = t.substr(1,t.length);
437                         t = $.cleanSpaces(t);
438     } else if ( t.indexOf('+') == 0 ) {
439       r = $.map( ret, function(a){ return $.sibling(a).next; } );
440                         t = t.substr(1,t.length);
441                         t = $.cleanSpaces(t);
442     } else if ( t.indexOf('~') == 0 ) {
443       r = $.map( ret, function(a){
444         var r = [];
445         var s = $.sibling(a);
446         if ( s.n > 0 )
447           for ( var i = s.n; i < s.length; i++ )
448             r[r.length] = s[i];
449         return r;
450       } );
451                         t = t.substr(1,t.length);
452                         t = $.cleanSpaces(t);
453     } else if ( t.indexOf(',') == 0 || t.indexOf('|') == 0 ) {
454       if ( ret[0] == context ) ret.shift();
455       done = $.merge( done, ret );
456       r = ret = [context];
457                         t = " " + t.substr(1,t.length);
458     } else {
459       var re = new RegExp( "^([#.]?)([a-z0-9\\*_-]*)", "i" );
460       var m = re.exec(t);
461                         
462                         if ( m[1] == "#" ) { // Ummm, should make this work in all XML docs
463                                 var oid = document.getElementById(m[2]);
464                                 r = oid ? [oid] : [];
465         t = t.replace( re, "" );
466                         } else {
467                           if ( m[2] == "" || m[1] == "." ) m[2] = "*";
468
469                           for ( var i = 0; i < ret.length; i++ ) {
470                                   var o = ret[i];
471                                   if ( o ) {
472                                           switch( m[2] ) {
473                                                   case '*':
474                                                           r = $.merge( $.getAll(o), r );
475                                                   break;
476                                                   case 'text': case 'radio': case 'checkbox': case 'hidden':
477                                                   case 'button': case 'submit': case 'image': case 'password':
478                                                   case 'reset': case 'file':
479                                                           r = $.merge( $.grep( $.tag(o,"input"), 
480                                                                                   function(a){ return a.type == m[2] }), r );
481                                                   break;
482                                                   case 'input':
483                                                           r = $.merge( $.tag(o,"input"), r );
484                                                           r = $.merge( $.tag(o,"select"), r );
485                                                           r = $.merge( $.tag(o,"textarea"), r );
486                                                   break;
487                                                   default:
488                                                           r = $.merge( r, $.tag(o,m[2]) );
489                                                   break;
490                                           }
491                                   }
492                           }
493                         }
494     }
495
496                 var val = $.filter(t,r);
497                 ret = r = val.r;
498                 t = $.cleanSpaces(val.t);
499   }
500
501   if ( ret && ret[0] == context ) ret.shift();
502   done = $.merge( done, ret );
503   return done;
504 };
505
506 $.tag = function(a,b){
507   return a && typeof a.getElementsByTagName != "undefined" ?
508     a.getElementsByTagName( b ) : [];
509 };
510
511 $.attr = function(o,a,v){
512   if ( a && a.constructor == String ) {
513     var fix = {
514       'for': 'htmlFor',
515       'text': 'cssText',
516       'class': 'className',
517       'float': 'cssFloat'
518     };
519     a = (fix[a] && fix[a].replace && fix[a]) || a;
520     var r = new RegExp("-([a-z])","ig");
521     a = a.replace(r,function(z,b){return b.toUpperCase();});
522     if ( v != null ) {
523       o[a] = v;
524       if ( o.setAttribute ) o.setAttribute(a,v);
525     } 
526     return o[a] || o.getAttribute(a) || '';
527   } else return '';
528 };
529
530 $.filter = function(t,r,not) {
531         var g = $.grep;
532         if ( not == false ) var g = function(a,f) {return $.grep(a,f,true);};
533         
534         while ( t.length > 0 && t.match(/^[:\\.#\\[a-zA-Z\\*]/) ) {
535                 var re = new RegExp( "^\\[ *@([a-z0-9\\(\\)_-]+) *([~!\\|\\*$^=]*) *'?\"?([^'\"]*)'?\"? *\\]", "i" );
536                 var m = re.exec(t);
537                 
538                 if ( m != null ) {
539                         m = ['', '@', m[2], m[1], m[3]];
540                 } else {
541                         var re = new RegExp( "^(\\[) *([^\\]]*) *\\]", "i" );
542                         var m = re.exec(t);
543                         
544                         if ( m == null ) {
545                                 var re = new RegExp( "^(:)([a-z0-9\\*_-]*)\\( *[\"']?([^ \\)'\"]*)['\"]? *\\)", "i" );
546                                 var m = re.exec(t);
547                                 
548                                 if ( m == null ) {
549                                         var re = new RegExp( "^([:\\.#]*)([a-z0-9\\*_-]*)", "i" );
550                                         var m = re.exec(t);
551                                 }
552                         }
553                 }
554                 t = t.replace( re, "" );
555                 
556                 if ( m[1] == ":" && m[2] == "not" )
557                         r = $.filter(m[3],r,false).r;
558                 else {
559                         if ( $.g[m[1]].constructor == String )
560                                 var f = $.g[m[1]];
561                         else if ( $.g[m[1]][m[2]] )
562                                 var f = $.g[m[1]][m[2]];
563                                                 
564                         if ( f != null ) {
565                                 eval("f = function(a,i){return " + f + "}");
566                                 r = g( r, f );
567                         }
568                 }
569         }
570         return { r: r, t: t };
571 };
572
573 $.parents = function(a){
574         var b = [];
575         var c = a.parentNode;
576         while ( c != null && c != c.documentElement ) {
577                 b[b.length] = c;
578                 c = c.parentNode;
579         }
580         return b;
581 };
582
583 $.cleanSpaces = function(t){return t.replace(/^\s+|\s+$/g, '')};
584
585 $.ofType = function(a,n,e) {
586   var t = $.grep($.sibling(a),function(b){return b.nodeName == a.nodeName});
587   if ( e ) n = t.length - n - 1;
588   return n != null ? t[n] == a : t.length;
589 };
590
591 $.sibling = function(a,n,e) {
592   var type = [];
593   var tmp = a.parentNode.childNodes;
594   for ( var i = 0; i < tmp.length; i++ ) {
595     if ( tmp[i].nodeType == 1 )
596       type[type.length] = tmp[i];
597     if ( tmp[i] == a )
598       type.n = type.length - 1;
599   }
600   if ( e ) n = type.length - n - 1;
601   type.cur = ( type[n] == a );
602   type.prev = ( type.n > 0 ? type[type.n - 1] : null );
603   type.next = ( type.n < type.length - 1 ? type[type.n + 1] : null );
604   return type;
605 };
606
607 $.hasWord = function(e,a) {
608   if ( e == null ) return false;
609   if ( e.className != null ) e = e.className;
610   return new RegExp("(^|\\s)" + a + "(\\s|$)").test(e)
611 };
612
613 $.getAll = function(o,r) {
614         r = r || [];
615         var s = o.childNodes;
616         for ( var i = 0; i < s.length; i++ ) {
617                 if ( s[i].nodeType == 1 ) {
618                         r[r.length] = s[i];
619                         $.getAll( s[i], r );
620                 }
621         }
622         return r;
623 };
624
625 $.merge = function(a,b) {
626         var d = [];
627         for ( var j = 0; j < b.length; j++ )
628                 d[j] = b[j];
629         
630   for ( var i = 0; i < a.length; i++ ) {
631     var c = true;
632     for ( var j = 0; j < b.length; j++ )
633       if ( a[i] == b[j] )
634         c = false;
635                 if ( c )
636                         d[d.length] = a[i];
637   }
638         return d;
639 };
640
641 $.grep = function(a,f,s) {
642   var r = [];
643         if ( a != null )
644                 for ( var i = 0; i < a.length; i++ )
645                         if ( (!s && f(a[i],i)) || (s && !f(a[i],i)) )
646                                 r[r.length] = a[i];
647   return r;
648 };
649
650 $.map = function(a,f) {
651   var r = [];
652   for ( var i = 0; i < a.length; i++ ) {
653     var t = f(a[i],i);
654     if ( t != null ) {
655       if ( t.constructor != Array ) t = [t];
656                         r = $.merge( t, r );
657                 }
658   }
659   return r;
660 };
661
662 // Bind an event to an element
663 // Original by Dean Edwards
664 function addEvent(element, type, handler) {
665         if ( element.location ) element = window; // Ughhhhh....
666         if (!handler.$$guid) handler.$$guid = addEvent.guid++;
667         if (!element.events) element.events = {};
668         var handlers = element.events[type];
669         if (!handlers) {
670                 handlers = element.events[type] = {};
671                 if (element["on" + type])
672                         handlers[0] = element["on" + type];
673         }
674         handlers[handler.$$guid] = handler;
675         element["on" + type] = handleEvent;
676 };
677 addEvent.guid = 1;
678
679 // Detach an event or set of events from an element
680 function removeEvent(element, type, handler) {
681         if (element.events) {
682                 if (type && element.events[type]) {
683                         if ( handler ) {
684                                 delete element.events[type][handler.$$guid];
685                         } else {
686                                 for ( var i in element.events[type] )
687                                         delete element.events[type][i];
688                         }
689                 } else {
690                         for ( var i in element.events )
691                                 removeEvent( element, i );
692                 }
693         }
694 };
695
696 function triggerEvent(element,type) {
697   if ( element["on" + type] )
698     element["on" + type]({ type: type });
699 }
700
701 function handleEvent(event) {
702         var returnValue = true;
703         event = event || fixEvent(window.event);
704         var handlers = [];
705         for ( var i in this.events[event.type] )
706                 handlers[handlers.length] = this.events[event.type][i];
707   for ( var i = 0; i < handlers.length; i++ ) {
708                 try {
709                         if ( handlers[i].constructor == Function ) {
710                                 this.$$handleEvent = handlers[i];
711                                 if (this.$$handleEvent(event) === false) {
712                                         event.preventDefault();
713                                         event.stopPropagation();
714                                         returnValue = false;
715                                 }
716                         }
717                 } catch(e){}
718         }
719         return returnValue;
720 };
721
722 function fixEvent(event) {
723         event.preventDefault = fixEvent.preventDefault;
724         event.stopPropagation = fixEvent.stopPropagation;
725         return event;
726 };
727 fixEvent.preventDefault = function() {
728         this.returnValue = false;
729 };
730 fixEvent.stopPropagation = function() {
731         this.cancelBubble = true;
732 };
733
734 // Move to module
735
736 $.fn.text = function(e) {
737         e = e || this.cur;
738         var t = "";
739         for ( var j = 0; j < e.length; j++ ) {
740                 for ( var i = 0; i < e[j].childNodes.length; i++ )
741                         t += e[j].childNodes[i].nodeType != 1 ?
742                                 e[j].childNodes[i].nodeValue :
743                                 $.fn.text(e[j].childNodes[i].childNodes);
744         }
745         return t;
746 };
747
748 setTimeout(function(){
749   if ( typeof Prototype != "undefined" && $.g == null && $.clean == null )
750     throw "Error: You are overwriting jQuery, please include jQuery last.";
751 }, 1000);