2 * jQuery - New Wave Javascript
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 // Shortcut for document ready (because $(document).each() is silly)
22 if ( a && a.constructor == Function )
23 return $(document).ready(a);
25 // Make sure t hat a selection was provided
26 a = a || jQuery.context || document;
29 * Handle support for overriding other $() functions. Way too many libraries
30 * provide this function to simply ignore it and overwrite it.
33 // Check to see if this is a possible collision case
34 if ( jQuery._$ && !c && a.constructor == String &&
36 // Make sure that the expression is a colliding one
37 !/[^a-zA-Z0-9_-]/.test(a) &&
39 // and that there are no elements that match it
40 // (this is the one truly ambiguous case)
41 !document.getElementsByTagName(a).length )
43 // Use the default method, in case it works some voodoo
44 return jQuery._$( a );
46 // Watch for when a jQuery object is passed as the selector
50 // Watch for when a jQuery object is passed at the context
52 return $(c.get()).find(a);
54 // If the context is global, return a new object
56 return new jQuery(a,c);
58 // Watch for when an array is passed in
59 this.get( a.constructor == Array ?
60 // Assume that it's an array of DOM Elements
63 // Find the matching elements and save them for later
64 jQuery.find( a, c ) );
66 var fn = arguments[ arguments.length - 1 ];
67 if ( fn && fn.constructor == Function )
71 // Map over the $ in case of overwrite
75 // Map the jQuery namespace to the '$' one
78 jQuery.fn = jQuery.prototype = {
80 * The current SVN version of jQuery.
90 * The number of elements currently matched.
92 * @example $("img").length;
93 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
102 * The number of elements currently matched.
104 * @example $("img").size();
105 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
116 * Access all matched elements. This serves as a backwards-compatible
117 * way of accessing all matched elements (other than the jQuery object
118 * itself, which is, in fact, an array of elements).
120 * @example $("img").get();
121 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
122 * @result [ <img src="test1.jpg"/> <img src="test2.jpg"/> ]
125 * @type Array<Element>
129 * Access a single matched element. <tt>num</tt> is used to access the
130 * <tt>num</tt>th element matched.
132 * @example $("img").get(1);
133 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
134 * @result [ <img src="test1.jpg"/> ]
138 * @param Number num Access the element in the <tt>num</tt>th position.
142 * Set the jQuery object to an array of elements.
144 * @example $("img").get([ document.body ]);
145 * @result $("img").get() == [ document.body ]
150 * @param Elements elems An array of elements
152 get: function( num ) {
153 // Watch for when an array (of elements) is passed in
154 if ( num && num.constructor == Array ) {
156 // Use a tricky hack to make the jQuery object
157 // look and feel like an array
159 [].push.apply( this, num );
163 return num == undefined ?
165 // Return a 'clean' array
166 jQuery.map( this, function(a){ return a } ) :
168 // Return just the object
173 * Execute a function within the context of every matched element.
174 * This means that every time the passed-in function is executed
175 * (which is once for every element matched) the 'this' keyword
176 * points to the specific element.
178 * Additionally, the function, when executed, is passed a single
179 * argument representing the position of the element in the matched
182 * @example $("img").each(function(){ this.src = "test.jpg"; });
183 * @before <img/> <img/>
184 * @result <img src="test.jpg"/> <img src="test.jpg"/>
188 * @param Function fn A function to execute
190 each: function( fn ) {
191 // Iterate through all of the matched elements
192 for ( var i = 0; i < this.length; i++ )
194 // Execute the function within the context of each element
195 fn.apply( this[i], [i] );
201 * Access a property on the first matched element.
202 * This method makes it easy to retreive a property value
203 * from the first matched element.
205 * @example $("img").attr("src");
206 * @before <img src="test.jpg"/>
211 * @param String name The name of the property to access.
215 * Set a hash of key/value object properties to all matched elements.
216 * This serves as the best way to set a large number of properties
217 * on all matched elements.
219 * @example $("img").attr({ src: "test.jpg", alt: "Test Image" });
221 * @result <img src="test.jpg" alt="Test Image"/>
225 * @param Hash prop A set of key/value pairs to set as object properties.
229 * Set a single property to a value, on all matched elements.
231 * @example $("img").attr("src","test.jpg");
233 * @result <img src="test.jpg"/>
237 * @param String key The name of the property to set.
238 * @param Object value The value to set the property to.
240 attr: function( key, value, type ) {
241 // Check to see if we're setting style values
242 return key.constructor != String || value ?
243 this.each(function(){
244 // See if we're setting a hash of styles
245 if ( value == undefined )
246 // Set all the styles
247 for ( var prop in key )
249 type ? this.style : this,
253 // See if we're setting a single key/value style
256 type ? this.style : this,
261 // Look for the case where we're accessing a style value
262 jQuery[ type || "attr" ]( this[0], key );
266 * Access a style property on the first matched element.
267 * This method makes it easy to retreive a style property value
268 * from the first matched element.
270 * @example $("p").css("red");
271 * @before <p style="color:red;">Test Paragraph.</p>
276 * @param String name The name of the property to access.
280 * Set a hash of key/value style properties to all matched elements.
281 * This serves as the best way to set a large number of style properties
282 * on all matched elements.
284 * @example $("p").css({ color: "red", background: "blue" });
285 * @before <p>Test Paragraph.</p>
286 * @result <p style="color:red; background:blue;">Test Paragraph.</p>
290 * @param Hash prop A set of key/value pairs to set as style properties.
294 * Set a single style property to a value, on all matched elements.
296 * @example $("p").css("color","red");
297 * @before <p>Test Paragraph.</p>
298 * @result <p style="color:red;">Test Paragraph.</p>
302 * @param String key The name of the property to set.
303 * @param Object value The value to set the property to.
305 css: function( key, value ) {
306 return this.attr( key, value, "css" );
310 * Retreive the text contents of all matched elements. The result is
311 * a string that contains the combined text contents of all matched
312 * elements. This method works on both HTML and XML documents.
314 * @example $("p").text();
315 * @before <p>Test Paragraph.</p>
316 * @result Test Paragraph.
324 for ( var j = 0; j < e.length; j++ ) {
325 var r = e[j].childNodes;
326 for ( var i = 0; i < r.length; i++ )
327 t += r[i].nodeType != 1 ?
328 r[i].nodeValue : jQuery.fn.text([ r[i] ]);
334 * Wrap all matched elements with a structure of other elements.
335 * This wrapping process is most useful for injecting additional
336 * stucture into a document, without ruining the original semantic
337 * qualities of a document.
339 * The way that is works is that it goes through the first element argument
340 * provided and finds the deepest element within the structure - it is that
341 * element that will en-wrap everything else.
343 * @example $("p").wrap("<div class='wrap'></div>");
344 * @before <p>Test Paragraph.</p>
345 * @result <div class='wrap'><p>Test Paragraph.</p></div>
349 * @any String html A string of HTML, that will be created on the fly and wrapped around the target.
350 * @any Element elem A DOM element that will be wrapped.
351 * @any Array<Element> elems An array of elements, the first of which will be wrapped.
352 * @any Object obj Any object, converted to a string, then a text node.
355 // The elements to wrap the target around
356 var a = jQuery.clean(arguments);
358 // Wrap each of the matched elements individually
359 return this.each(function(){
360 // Clone the structure that we're using to wrap
361 var b = a[0].cloneNode(true);
363 // Insert it before the element to be wrapped
364 this.parentNode.insertBefore( b, this );
366 // Find he deepest point in the wrap structure
367 while ( b.firstChild )
370 // Move the matched element to within the wrap structure
371 b.appendChild( this );
376 * Append any number of elements to the inside of all matched elements.
377 * This operation is similar to doing an <tt>appendChild</tt> to all the
378 * specified elements, adding them into the document.
380 * @example $("p").append("<b>Hello</b>");
381 * @before <p>I would like to say: </p>
382 * @result <p>I would like to say: <b>Hello</b></p>
386 * @any String html A string of HTML, that will be created on the fly and appended to the target.
387 * @any Element elem A DOM element that will be appended.
388 * @any Array<Element> elems An array of elements, all of which will be appended.
389 * @any Object obj Any object, converted to a string, then a text node.
392 return this.domManip(arguments, true, 1, function(a){
393 this.appendChild( a );
398 * Prepend any number of elements to the inside of all matched elements.
399 * This operation is the best way to insert a set of elements inside, at the
400 * beginning, of all the matched element.
402 * @example $("p").prepend("<b>Hello</b>");
403 * @before <p>, how are you?</p>
404 * @result <p><b>Hello</b>, how are you?</p>
408 * @any String html A string of HTML, that will be created on the fly and prepended to the target.
409 * @any Element elem A DOM element that will be prepended.
410 * @any Array<Element> elems An array of elements, all of which will be prepended.
411 * @any Object obj Any object, converted to a string, then a text node.
413 prepend: function() {
414 return this.domManip(arguments, true, -1, function(a){
415 this.insertBefore( a, this.firstChild );
420 * Insert any number of elements before each of the matched elements.
422 * @example $("p").before("<b>Hello</b>");
423 * @before <p>how are you?</p>
424 * @result <b>Hello</b><p>how are you?</p>
428 * @any String html A string of HTML, that will be created on the fly and inserted.
429 * @any Element elem A DOM element that will beinserted.
430 * @any Array<Element> elems An array of elements, all of which will be inserted.
431 * @any Object obj Any object, converted to a string, then a text node.
434 return this.domManip(arguments, false, 1, function(a){
435 this.parentNode.insertBefore( a, this );
440 * Insert any number of elements after each of the matched elements.
442 * @example $("p").after("<p>I'm doing fine.</p>");
443 * @before <p>How are you?</p>
444 * @result <p>How are you?</p><p>I'm doing fine.</p>
448 * @any String html A string of HTML, that will be created on the fly and inserted.
449 * @any Element elem A DOM element that will beinserted.
450 * @any Array<Element> elems An array of elements, all of which will be inserted.
451 * @any Object obj Any object, converted to a string, then a text node.
454 return this.domManip(arguments, false, -1, function(a){
455 this.parentNode.insertBefore( a, this.nextSibling );
460 * End all 'destructive' operations, reverting the list of matched elements.
461 * After an end operation, the list of matched elements will revert to the last
462 * state of matched elements.
464 * @example $("p").find("span").end();
465 * @before <p><span>Hello</span>, how are you?</p>
466 * @result $("p").find("span").end() == [ <p>...</p> ]
472 return this.get( this.stack.pop() );
476 return this.pushStack( jQuery.map( this, function(a){
477 return jQuery.find(t,a);
481 filter: function(t) {
482 return t.constructor == Array ?
484 this.pushStack( jQuery.map(this,function(a){
485 for ( var i = 0; i < t.length; i++ )
486 if ( jQuery.filter(t[i],[a]).r.length )
490 this.pushStack( jQuery.filter(t,this).r, arguments );
494 return this.pushStack( t.constructor == String ?
495 jQuery.filter(t,this,false).r :
496 jQuery.grep(this,function(a){ return a != t; }), arguments );
500 return this.pushStack( jQuery.merge( this, t.constructor == String ?
501 jQuery.find(t) : t.constructor == Array ? t : [t] ), arguments );
505 * A wrapper function for each() to be used by append and prepend.
506 * Handles cases where you're trying to modify the inner contents of
507 * a table, when you actually need to work with the tbody.
510 * @param {String} expr The expression with which to filter
514 return jQuery.filter(expr,this).r.length > 0;
523 * @param Boolean table
525 * @param Function fn The function doing the DOM manipulation.
528 domManip: function(args, table, dir, fn){
529 var clone = this.size() > 1;
530 var a = jQuery.clean(args);
532 return this.each(function(){
535 if ( table && this.nodeName == "TABLE" ) {
536 var tbody = this.getElementsByTagName("tbody");
538 if ( !tbody.length ) {
539 obj = document.createElement("tbody");
540 this.appendChild( obj );
545 for ( var i = ( dir < 0 ? a.length - 1 : 0 );
546 i != ( dir < 0 ? dir : a.length ); i += dir )
547 fn.apply( obj, [ a[i] ] );
560 pushStack: function(a,args) {
561 var fn = args && args[args.length-1];
563 if ( !fn || fn.constructor != Function ) {
564 if ( !this.stack ) this.stack = [];
565 this.stack.push( this.get() );
568 var old = this.get();
570 if ( fn.constructor == Function )
571 return this.each( fn );
578 extend: function(obj,prop) {
\r if ( !prop ) {
\r prop = obj;
\r obj = this;
\r }
\r \r for ( var i in prop )
\r obj[i] = prop[i];
\r \r return obj;
\r }
581 jQuery.extend = jQuery.fn.extend;
584 var b = navigator.userAgent.toLowerCase();
586 // Figure out what browser is being used
588 safari: /webkit/.test(b),
589 opera: /opera/.test(b),
590 msie: /msie/.test(b) && !/opera/.test(b),
591 mozilla: /mozilla/.test(b) && !/compatible/.test(b)
594 // Check to see if the W3C box model is being used
595 jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
598 parent: "a.parentNode",
599 parents: jQuery.parents,
600 ancestors: jQuery.parents,
601 next: "a.nextSibling",
602 prev: "a.previousSibling",
603 siblings: jQuery.sibling
606 for ( var i in axis ) new function(){
608 jQuery.fn[ i ] = function(a) {
609 var ret = jQuery.map(this,t);
610 if ( a ) ret = jQuery.filter(a,ret).r;
611 return this.pushStack( ret, arguments );
615 /*var to = ["append","prepend","before","after"];
617 for ( var i = 0; i < to.length; i++ ) new function(){
619 jQuery.fn[ n + "To" ] = function(){
621 return this.each(function(){
622 for ( var i = 0; i < a.length; i++ )
630 this.style.display = this.oldblock ? this.oldblock : "";
631 if ( jQuery.css(this,"display") == "none" )
632 this.style.display = "block";
636 this.oldblock = jQuery.css(this,"display");
637 if ( this.oldblock == "none" )
638 this.oldblock = "block";
639 this.style.display = "none";
643 var d = jQuery.css(this,"display");
644 $(this)[ !d || d == "none" ? "show" : "hide" ]();
647 addClass: function(c){
648 jQuery.className.add(this,c);
651 removeClass: function(c){
652 jQuery.className.remove(this,c);
655 toggleClass: function( c ){
656 jQuery.className[ jQuery.className.has(this,a) ? "remove" : "add" ](this,c);
660 if ( !a || jQuery.filter( [this], a ).r )
661 this.parentNode.removeChild( this );
665 while ( this.firstChild )
666 this.removeChild( this.firstChild );
669 bind: function( type, fn ) {
670 jQuery.event.add( this, type, fn );
673 unbind: function( type, fn ) {
674 jQuery.event.remove( this, type, fn );
677 trigger: function( type ) {
678 jQuery.event.trigger( this, type );
682 for ( var i in each ) new function() {
684 jQuery.fn[ i ] = function() {
685 var args = arguments;
686 return this.each(function(){
687 n.apply( this, args );
704 for ( var i in attr ) new function() {
706 jQuery.fn[ i ] = function(h) {
707 return h == undefined ?
708 this.length ? this[0][n] : null :
713 var css = "width,height,top,left,position,float,overflow,color,background".split(",");
715 for ( var i in css ) new function() {
717 jQuery.fn[ i ] = function(h) {
718 return h == undefined ?
719 this.length ? jQuery.css( this[0], n ) : null :
729 if (jQuery.className.has(o,c)) return;
730 o.className += ( o.className ? " " : "" ) + c;
732 remove: function(o,c){
733 o.className = !c ? "" :
735 new RegExp("(^|\\s*\\b[^-])"+c+"($|\\b(?=[^-]))", "g"), "");
740 return new RegExp("(^|\\s)" + a + "(\\s|$)").test(e);
745 * Swap in/out style options.
748 swap: function(e,o,f) {
750 e.style["old"+i] = e.style[i];
755 e.style[i] = e.style["old"+i];
759 if ( p == "height" || p == "width" ) {
760 var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"];
763 old["padding" + d[i]] = 0;
764 old["border" + d[i] + "Width"] = 0;
767 jQuery.swap( e, old, function() {
768 if (jQuery.css(e,"display") != "none") {
769 oHeight = e.offsetHeight;
770 oWidth = e.offsetWidth;
772 jQuery.swap( e, { visibility: "hidden", position: "absolute", display: "" },
774 oHeight = e.clientHeight;
775 oWidth = e.clientWidth;
779 return p == "height" ? oHeight : oWidth;
786 else if (e.currentStyle)
787 r = e.currentStyle[p];
788 else if (document.defaultView && document.defaultView.getComputedStyle) {
789 p = p.replace(/([A-Z])/g,"-$1").toLowerCase();
790 var s = document.defaultView.getComputedStyle(e,"");
791 r = s ? s.getPropertyValue(p) : null;
799 for ( var i = 0; i < a.length; i++ ) {
800 if ( a[i].constructor == String ) {
802 if ( !a[i].indexOf("<tr") ) {
804 a[i] = "<table>" + a[i] + "</table>";
805 } else if ( !a[i].indexOf("<td") || !a[i].indexOf("<th") ) {
807 a[i] = "<table><tbody><tr>" + a[i] + "</tr></tbody></table>";
810 var div = document.createElement("div");
811 div.innerHTML = a[i];
814 div = div.firstChild.firstChild;
815 if ( td ) div = div.firstChild;
818 for ( var j = 0; j < div.childNodes.length; j++ )
819 r.push( div.childNodes[j] );
820 } else if ( a[i].jquery || a[i].length && !a[i].nodeType )
821 for ( var k = 0; k < a[i].length; k++ )
823 else if ( a[i] !== null )
824 r.push( a[i].nodeType ? a[i] : document.createTextNode(a[i].toString()) );
830 "": "m[2]== '*'||a.nodeName.toUpperCase()==m[2].toUpperCase()",
831 "#": "a.getAttribute('id')&&a.getAttribute('id')==m[2]",
839 last: "i==r.length-1",
844 "first-child": "jQuery.sibling(a,0).cur",
845 "last-child": "jQuery.sibling(a,0).last",
846 "only-child": "jQuery.sibling(a).length==1",
849 parent: "a.childNodes.length",
850 empty: "!a.childNodes.length",
853 contains: "(a.innerText||a.innerHTML).indexOf(m[3])>=0",
856 visible: "jQuery.css(a,'display')!='none'&&jQuery.css(a,'visibility')!='hidden'",
857 hidden: "jQuery.css(a,'display')=='none'||jQuery.css(a,'visibility')=='hidden'",
860 enabled: "!a.disabled",
861 disabled: "a.disabled",
864 ".": "jQuery.className.has(a,m[2])",
868 "^=": "!z.indexOf(m[4])",
869 "$=": "z.substr(z.length - m[4].length,m[4].length)==m[4]",
870 "*=": "z.indexOf(m[4])>=0",
873 "[": "jQuery.find(m[2],a).length"
877 "\\.\\.|/\\.\\.", "a.parentNode",
878 ">|/", "jQuery.sibling(a.firstChild)",
879 "\\+", "jQuery.sibling(a).next",
882 var s = jQuery.sibling(a);
884 for ( var i = s.n; i < s.length; i++ )
890 find: function( t, context ) {
891 // Make sure that the context is a DOM Element
892 if ( context && context.getElementsByTagName == undefined )
895 // Set the correct context (if none is provided)
896 context = context || jQuery.context || document;
898 if ( t.constructor != String ) return [t];
900 if ( !t.indexOf("//") ) {
901 context = context.documentElement;
902 t = t.substr(2,t.length);
903 } else if ( !t.indexOf("/") ) {
904 context = context.documentElement;
905 t = t.substr(1,t.length);
906 // FIX Assume the root element is right :(
907 if ( t.indexOf("/") >= 1 )
908 t = t.substr(t.indexOf("/"),t.length);
915 while ( t.length > 0 && last != t ) {
919 t = jQuery.trim(t).replace( /^\/\//i, "" );
921 var foundToken = false;
923 for ( var i = 0; i < jQuery.token.length; i += 2 ) {
924 var re = new RegExp("^(" + jQuery.token[i] + ")");
928 r = ret = jQuery.map( ret, jQuery.token[i+1] );
929 t = jQuery.trim(t).replace( re, "" );
935 if ( !t.indexOf(",") || !t.indexOf("|") ) {
936 if ( ret[0] == context ) ret.shift();
937 done = jQuery.merge( done, ret );
939 t = " " + t.substr(1,t.length);
941 var re2 = /^([#.]?)([a-z0-9\\*_-]*)/i;
945 // Ummm, should make this work in all XML docs
946 var oid = document.getElementById(m[2]);
947 r = ret = oid ? [oid] : [];
948 t = t.replace( re2, "" );
950 if ( !m[2] || m[1] == "." ) m[2] = "*";
952 for ( var i = 0; i < ret.length; i++ )
955 jQuery.getAll(ret[i]) :
956 ret[i].getElementsByTagName(m[2])
963 var val = jQuery.filter(t,r);
965 t = jQuery.trim(val.t);
969 if ( ret && ret[0] == context ) ret.shift();
970 done = jQuery.merge( done, ret );
975 getAll: function(o,r) {
977 var s = o.childNodes;
978 for ( var i = 0; i < s.length; i++ )
979 if ( s[i].nodeType == 1 ) {
981 jQuery.getAll( s[i], r );
986 attr: function(o,a,v){
987 if ( a && a.constructor == String ) {
990 "class": "className",
994 a = (fix[a] && fix[a].replace && fix[a] || a)
995 .replace(/-([a-z])/ig,function(z,b){
996 return b.toUpperCase();
999 if ( v != undefined ) {
1001 if ( o.setAttribute && a != "disabled" )
1002 o.setAttribute(a,v);
1005 return o[a] || o.getAttribute && o.getAttribute(a) || "";
1010 filter: function(t,r,not) {
1011 // Figure out if we're doing regular, or inverse, filtering
1012 var g = not !== false ? jQuery.grep :
1013 function(a,f) {return jQuery.grep(a,f,true);};
1015 // Look for a string-like sequence
1016 var str = "([a-zA-Z*_-][a-zA-Z0-9_-]*)";
1018 // Look for something (optionally) enclosed with quotes
1019 var qstr = " *'?\"?([^'\"]*)'?\"? *";
1021 while ( t && /^[a-zA-Z\[*:.#]/.test(t) ) {
1023 // [@foo], [@foo=bar], etc.
1024 var re = new RegExp("^\\[ *@" + str + " *([!*$^=]*) *" + qstr + "\\]");
1027 // Re-organize the match
1028 if ( m ) m = ["", "@", m[2], m[1], m[3]];
1033 re = new RegExp("^(\\[)" + qstr + "\\]");
1038 // :contains(test), :not(.foo)
1040 re = new RegExp("^(:)" + str + "\\(" + qstr + "\\)");
1045 // :foo, .foo, #foo, foo
1047 re = new RegExp("^([:.#]*)" + str);
1051 // Remove what we just matched
1052 t = t.replace( re, "" );
1054 // :not() is a special case that can be optomized by
1055 // keeping it out of the expression list
1056 if ( m[1] == ":" && m[2] == "not" )
1057 r = jQuery.filter(m[3],r,false).r;
1059 // Otherwise, find the expression to execute
1061 // Build a custom macro to enclose it
1062 eval("f = function(a,i){" +
1063 ( m[1] == "@" ? "z=jQuery.attr(a,m[3]);" : "" ) +
1064 "return " + jQuery.expr[m[1]] + "}");
1066 // Execute it against the current filter
1071 // Return an array of filtered elements (r)
1072 // and the modified expression string (t)
1073 return { r: r, t: t };
1077 * Remove the whitespace from the beginning and end of a string.
1082 * @param String str The string to trim.
1085 return t.replace(/^\s+|\s+$/g, "");
1089 * All ancestors of a given element.
1093 * @type Array<Element>
1094 * @param Element elem The element to find the ancestors of.
1096 parents: function(a){
1098 var c = a.parentNode;
1099 while ( c && c != document ) {
1107 * All elements on a specified axis.
1112 * @param Element elem The element to find all the siblings of (including itself).
1114 sibling: function(a,n) {
1116 var tmp = a.parentNode.childNodes;
1117 for ( var i = 0; i < tmp.length; i++ ) {
1118 if ( tmp[i].nodeType == 1 )
1119 type.push( tmp[i] );
1121 type.n = type.length - 1;
1123 type.last = type.n == type.length - 1;
1125 n == "even" && type.n % 2 == 0 ||
1126 n == "odd" && type.n % 2 ||
1128 type.next = type[type.n + 1];
1133 * Merge two arrays together, removing all duplicates.
1138 * @param Array a The first array to merge.
1139 * @param Array b The second array to merge.
1141 merge: function(a,b) {
1144 // Move b over to the new array (this helps to avoid
1145 // StaticNodeList instances)
1146 for ( var k = 0; k < b.length; k++ )
1149 // Now check for duplicates between a and b and only
1150 // add the unique items
1151 for ( var i = 0; i < a.length; i++ ) {
1154 // The collision-checking process
1155 for ( var j = 0; j < b.length; j++ )
1159 // If the item is unique, add it
1168 * Remove items that aren't matched in an array. The function passed
1169 * in to this method will be passed two arguments: 'a' (which is the
1170 * array item) and 'i' (which is the index of the item in the array).
1175 * @param Array array The Array to find items in.
1176 * @param Function fn The function to process each item against.
1177 * @param Boolean inv Invert the selection - select the opposite of the function.
1179 grep: function(a,f,s) {
1180 // If a string is passed in for the function, make a function
1181 // for it (a handy shortcut)
1182 if ( f.constructor == String )
1183 f = new Function("a","i","return " + f);
1187 // Go through the array, only saving the items
1188 // that pass the validator function
1189 for ( var i = 0; i < a.length; i++ )
1190 if ( !s && f(a[i],i) || s && !f(a[i],i) )
1197 * Translate all items in array to another array of items. The translation function
1198 * that is provided to this method is passed one argument: 'a' (the item to be
1199 * translated). If an array is returned, that array is mapped out and merged into
1200 * the full array. Additionally, returning 'null' or 'undefined' will delete the item
1201 * from the array. Both of these changes imply that the size of the array may not
1202 * be the same size upon completion, as it was when it started.
1207 * @param Array array The Array to translate.
1208 * @param Function fn The function to process each item against.
1210 map: function(a,f) {
1211 // If a string is passed in for the function, make a function
1212 // for it (a handy shortcut)
1213 if ( f.constructor == String )
1214 f = new Function("a","return " + f);
1218 // Go through the array, translating each of the items to their
1219 // new value (or values).
1220 for ( var i = 0; i < a.length; i++ ) {
1222 if ( t !== null && t != undefined ) {
1223 if ( t.constructor != Array ) t = [t];
1224 r = jQuery.merge( t, r );
1231 * A number of helper functions used for managing events.
1232 * Many of the ideas behind this code orignated from Dean Edwards' addEvent library.
1236 // Bind an event to an element
1237 // Original by Dean Edwards
1238 add: function(element, type, handler) {
1239 // For whatever reason, IE has trouble passing the window object
1240 // around, causing it to be cloned in the process
1241 if ( jQuery.browser.msie && element.setInterval != undefined )
1244 // Make sure that the function being executed has a unique ID
1245 if ( !handler.guid )
1246 handler.guid = this.guid++;
1248 // Init the element's event structure
1249 if (!element.events)
1250 element.events = {};
1252 // Get the current list of functions bound to this event
1253 var handlers = element.events[type];
1255 // If it hasn't been initialized yet
1257 // Init the event handler queue
1258 handlers = element.events[type] = {};
1260 // Remember an existing handler, if it's already there
1261 if (element["on" + type])
1262 handlers[0] = element["on" + type];
1265 // Add the function to the element's handler list
1266 handlers[handler.guid] = handler;
1268 // And bind the global event handler to the element
1269 element["on" + type] = this.handle;
1271 // Remember the function in a global list (for triggering)
1272 if (!this.global[type])
1273 this.global[type] = [];
1274 this.global[type].push( element );
1280 // Detach an event or set of events from an element
1281 remove: function(element, type, handler) {
1283 if (type && element.events[type])
1285 delete element.events[type][handler.guid];
1287 for ( var i in element.events[type] )
1288 delete element.events[type][i];
1290 for ( var j in element.events )
1291 this.remove( element, j );
1294 trigger: function(type,data,element) {
1295 // Touch up the incoming data
1298 // Handle a global trigger
1300 var g = this.global[type];
1302 for ( var i = 0; i < g.length; i++ )
1303 this.trigger( type, data, g[i] );
1305 // Handle triggering a single element
1306 } else if ( element["on" + type] ) {
1307 // Pass along a fake event
1308 data.unshift( this.fix({ type: type, target: element }) );
1310 // Trigger the event
1311 element["on" + type].apply( element, data );
1315 handle: function(event) {
1316 event = event || jQuery.event.fix( window.event );
1318 // If no correct event was found, fail
1319 if ( !event ) return;
1321 var returnValue = true;
1323 for ( var j in this.events[event.type] ) {
1324 if (this.events[event.type][j](event) === false) {
1325 event.preventDefault();
1326 event.stopPropagation();
1327 returnValue = false;
1334 fix: function(event) {
1336 event.preventDefault = function() {
1337 this.returnValue = false;
1340 event.stopPropagation = function() {
1341 this.cancelBubble = true;