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 // Initalize the extra macro functions
22 if ( !jQuery.initDone ) jQuery.init();
24 // Shortcut for document ready (because $(document).each() is silly)
25 if ( a && a.constructor == Function && jQuery.fn.ready )
26 return jQuery(document).ready(a);
28 // Make sure t hat a selection was provided
29 a = a || jQuery.context || document;
32 * Handle support for overriding other $() functions. Way too many libraries
33 * provide this function to simply ignore it and overwrite it.
36 // Check to see if this is a possible collision case
37 if ( jQuery._$ && !c && a.constructor == String &&
39 // Make sure that the expression is a colliding one
40 !/[^a-zA-Z0-9_-]/.test(a) &&
42 // and that there are no elements that match it
43 // (this is the one truly ambiguous case)
44 !document.getElementsByTagName(a).length )
46 // Use the default method, in case it works some voodoo
47 return jQuery._$( a );
50 // Watch for when a jQuery object is passed as the selector
54 // Watch for when a jQuery object is passed at the context
56 return jQuery(c.get()).find(a);
58 // If the context is global, return a new object
60 return new jQuery(a,c);
62 // Handle HTML strings
63 var m = /^[^<]*(<.+>)[^>]*$/.exec(a);
64 if ( m ) a = jQuery.clean( [ m[1] ] );
66 // Watch for when an array is passed in
67 this.get( a.constructor == Array || a.length && !a.nodeType && a[0] != undefined && a[0].nodeType ?
68 // Assume that it is an array of DOM Elements
69 jQuery.merge( a, [] ) :
71 // Find the matching elements and save them for later
72 jQuery.find( a, c ) );
74 var fn = arguments[ arguments.length - 1 ];
75 if ( fn && fn.constructor == Function )
79 // Map over the $ in case of overwrite
83 // Map the jQuery namespace to the '$' one
86 jQuery.fn = jQuery.prototype = {
88 * The current SVN version of jQuery.
98 * The number of elements currently matched.
100 * @example $("img").length;
101 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
110 * The number of elements currently matched.
112 * @example $("img").size();
113 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
124 * Access all matched elements. This serves as a backwards-compatible
125 * way of accessing all matched elements (other than the jQuery object
126 * itself, which is, in fact, an array of elements).
128 * @example $("img").get();
129 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
130 * @result [ <img src="test1.jpg"/> <img src="test2.jpg"/> ]
133 * @type Array<Element>
137 * Access a single matched element. <tt>num</tt> is used to access the
138 * <tt>num</tt>th element matched.
140 * @example $("img").get(1);
141 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
142 * @result [ <img src="test1.jpg"/> ]
146 * @param Number num Access the element in the <tt>num</tt>th position.
150 * Set the jQuery object to an array of elements.
152 * @example $("img").get([ document.body ]);
153 * @result $("img").get() == [ document.body ]
158 * @param Elements elems An array of elements
160 get: function( num ) {
161 // Watch for when an array (of elements) is passed in
162 if ( num && num.constructor == Array ) {
164 // Use a tricky hack to make the jQuery object
165 // look and feel like an array
167 [].push.apply( this, num );
171 return num == undefined ?
173 // Return a 'clean' array
174 jQuery.map( this, function(a){ return a } ) :
176 // Return just the object
181 * Execute a function within the context of every matched element.
182 * This means that every time the passed-in function is executed
183 * (which is once for every element matched) the 'this' keyword
184 * points to the specific element.
186 * Additionally, the function, when executed, is passed a single
187 * argument representing the position of the element in the matched
190 * @example $("img").each(function(){ this.src = "test.jpg"; });
191 * @before <img/> <img/>
192 * @result <img src="test.jpg"/> <img src="test.jpg"/>
196 * @param Function fn A function to execute
198 each: function( fn, args ) {
199 return jQuery.each( this, fn, args );
203 * Access a property on the first matched element.
204 * This method makes it easy to retreive a property value
205 * from the first matched element.
207 * @example $("img").attr("src");
208 * @before <img src="test.jpg"/>
213 * @param String name The name of the property to access.
217 * Set a hash of key/value object properties to all matched elements.
218 * This serves as the best way to set a large number of properties
219 * on all matched elements.
221 * @example $("img").attr({ src: "test.jpg", alt: "Test Image" });
223 * @result <img src="test.jpg" alt="Test Image"/>
227 * @param Hash prop A set of key/value pairs to set as object properties.
231 * Set a single property to a value, on all matched elements.
233 * @example $("img").attr("src","test.jpg");
235 * @result <img src="test.jpg"/>
239 * @param String key The name of the property to set.
240 * @param Object value The value to set the property to.
242 attr: function( key, value, type ) {
243 // Check to see if we're setting style values
244 return key.constructor != String || value ?
245 this.each(function(){
246 // See if we're setting a hash of styles
247 if ( value == undefined )
248 // Set all the styles
249 for ( var prop in key )
251 type ? this.style : this,
255 // See if we're setting a single key/value style
258 type ? this.style : this,
263 // Look for the case where we're accessing a style value
264 jQuery[ type || "attr" ]( this[0], key );
268 * Access a style property on the first matched element.
269 * This method makes it easy to retreive a style property value
270 * from the first matched element.
272 * @example $("p").css("red");
273 * @before <p style="color:red;">Test Paragraph.</p>
278 * @param String name The name of the property to access.
282 * Set a hash of key/value style properties to all matched elements.
283 * This serves as the best way to set a large number of style properties
284 * on all matched elements.
286 * @example $("p").css({ color: "red", background: "blue" });
287 * @before <p>Test Paragraph.</p>
288 * @result <p style="color:red; background:blue;">Test Paragraph.</p>
292 * @param Hash prop A set of key/value pairs to set as style properties.
296 * Set a single style property to a value, on all matched elements.
298 * @example $("p").css("color","red");
299 * @before <p>Test Paragraph.</p>
300 * @result <p style="color:red;">Test Paragraph.</p>
304 * @param String key The name of the property to set.
305 * @param Object value The value to set the property to.
307 css: function( key, value ) {
308 return this.attr( key, value, "curCSS" );
312 * Retreive the text contents of all matched elements. The result is
313 * a string that contains the combined text contents of all matched
314 * elements. This method works on both HTML and XML documents.
316 * @example $("p").text();
317 * @before <p>Test Paragraph.</p>
318 * @result Test Paragraph.
326 for ( var j = 0; j < e.length; j++ ) {
327 var r = e[j].childNodes;
328 for ( var i = 0; i < r.length; i++ )
329 t += r[i].nodeType != 1 ?
330 r[i].nodeValue : jQuery.fn.text([ r[i] ]);
336 * Wrap all matched elements with a structure of other elements.
337 * This wrapping process is most useful for injecting additional
338 * stucture into a document, without ruining the original semantic
339 * qualities of a document.
341 * The way that is works is that it goes through the first element argument
342 * provided and finds the deepest element within the structure - it is that
343 * element that will en-wrap everything else.
345 * @example $("p").wrap("<div class='wrap'></div>");
346 * @before <p>Test Paragraph.</p>
347 * @result <div class='wrap'><p>Test Paragraph.</p></div>
351 * @any String html A string of HTML, that will be created on the fly and wrapped around the target.
352 * @any Element elem A DOM element that will be wrapped.
353 * @any Array<Element> elems An array of elements, the first of which will be wrapped.
354 * @any Object obj Any object, converted to a string, then a text node.
357 // The elements to wrap the target around
358 var a = jQuery.clean(arguments);
360 // Wrap each of the matched elements individually
361 return this.each(function(){
362 // Clone the structure that we're using to wrap
363 var b = a[0].cloneNode(true);
365 // Insert it before the element to be wrapped
366 this.parentNode.insertBefore( b, this );
368 // Find he deepest point in the wrap structure
369 while ( b.firstChild )
372 // Move the matched element to within the wrap structure
373 b.appendChild( this );
378 * Append any number of elements to the inside of all matched elements.
379 * This operation is similar to doing an <tt>appendChild</tt> to all the
380 * specified elements, adding them into the document.
382 * @example $("p").append("<b>Hello</b>");
383 * @before <p>I would like to say: </p>
384 * @result <p>I would like to say: <b>Hello</b></p>
388 * @any String html A string of HTML, that will be created on the fly and appended to the target.
389 * @any Element elem A DOM element that will be appended.
390 * @any Array<Element> elems An array of elements, all of which will be appended.
391 * @any Object obj Any object, converted to a string, then a text node.
394 return this.domManip(arguments, true, 1, function(a){
395 this.appendChild( a );
400 * Prepend any number of elements to the inside of all matched elements.
401 * This operation is the best way to insert a set of elements inside, at the
402 * beginning, of all the matched element.
404 * @example $("p").prepend("<b>Hello</b>");
405 * @before <p>, how are you?</p>
406 * @result <p><b>Hello</b>, how are you?</p>
410 * @any String html A string of HTML, that will be created on the fly and prepended to the target.
411 * @any Element elem A DOM element that will be prepended.
412 * @any Array<Element> elems An array of elements, all of which will be prepended.
413 * @any Object obj Any object, converted to a string, then a text node.
415 prepend: function() {
416 return this.domManip(arguments, true, -1, function(a){
417 this.insertBefore( a, this.firstChild );
422 * Insert any number of elements before each of the matched elements.
424 * @example $("p").before("<b>Hello</b>");
425 * @before <p>how are you?</p>
426 * @result <b>Hello</b><p>how are you?</p>
430 * @any String html A string of HTML, that will be created on the fly and inserted.
431 * @any Element elem A DOM element that will beinserted.
432 * @any Array<Element> elems An array of elements, all of which will be inserted.
433 * @any Object obj Any object, converted to a string, then a text node.
436 return this.domManip(arguments, false, 1, function(a){
437 this.parentNode.insertBefore( a, this );
442 * Insert any number of elements after each of the matched elements.
444 * @example $("p").after("<p>I'm doing fine.</p>");
445 * @before <p>How are you?</p>
446 * @result <p>How are you?</p><p>I'm doing fine.</p>
450 * @any String html A string of HTML, that will be created on the fly and inserted.
451 * @any Element elem A DOM element that will beinserted.
452 * @any Array<Element> elems An array of elements, all of which will be inserted.
453 * @any Object obj Any object, converted to a string, then a text node.
456 return this.domManip(arguments, false, -1, function(a){
457 this.parentNode.insertBefore( a, this.nextSibling );
462 * End the most recent 'destructive' operation, reverting the list of matched elements
463 * back to its previous state. After an end operation, the list of matched elements will
464 * revert to the last state of matched elements.
466 * @example $("p").find("span").end();
467 * @before <p><span>Hello</span>, how are you?</p>
468 * @result $("p").find("span").end() == [ <p>...</p> ]
474 return this.get( this.stack.pop() );
478 * Searches for all elements that match the specified expression.
479 * This method is the optimal way of finding additional descendant
480 * elements with which to process.
482 * All searching is done using a jQuery expression. The expression can be
483 * written using CSS 1-3 Selector syntax, or basic XPath.
485 * @example $("p").find("span");
486 * @before <p><span>Hello</span>, how are you?</p>
487 * @result $("p").find("span") == [ <span>Hello</span> ]
491 * @param String expr An expression to search with.
494 return this.pushStack( jQuery.map( this, function(a){
495 return jQuery.find(t,a);
500 * Removes all elements from the set of matched elements that do not
501 * match the specified expression. This method is used to narrow down
502 * the results of a search.
504 * All searching is done using a jQuery expression. The expression
505 * can be written using CSS 1-3 Selector syntax, or basic XPath.
507 * @example $("p").filter(".selected")
508 * @before <p class="selected">Hello</p><p>How are you?</p>
509 * @result $("p").filter(".selected") == [ <p class="selected">Hello</p> ]
513 * @param String expr An expression to search with.
517 * Removes all elements from the set of matched elements that do not
518 * match at least one of the expressions passed to the function. This
519 * method is used when you want to filter the set of matched elements
520 * through more than one expression.
522 * Elements will be retained in the jQuery object if they match at
523 * least one of the expressions passed.
525 * @example $("p").filter([".selected", ":first"])
526 * @before <p>Hello</p><p>Hello Again</p><p class="selected">And Again</p>
527 * @result $("p").filter([".selected", ":first"]) == [ <p>Hello</p>, <p class="selected">And Again</p> ]
531 * @param Array<String> exprs A set of expressions to evaluate against
533 filter: function(t) {
534 return this.pushStack(
535 t.constructor == Array &&
536 jQuery.map(this,function(a){
537 for ( var i = 0; i < t.length; i++ )
538 if ( jQuery.filter(t[i],[a]).r.length )
542 t.constructor == Boolean &&
543 ( t ? this.get() : [] ) ||
545 t.constructor == Function &&
546 jQuery.grep( this, t ) ||
548 jQuery.filter(t,this).r, arguments );
552 * Removes the specified Element from the set of matched elements. This
553 * method is used to remove a single Element from a jQuery object.
555 * @example $("p").not( document.getElementById("selected") )
556 * @before <p>Hello</p><p id="selected">Hello Again</p>
557 * @result [ <p>Hello</p> ]
561 * @param Element el An element to remove from the set
565 * Removes elements matching the specified expression from the set
566 * of matched elements. This method is used to remove one or more
567 * elements from a jQuery object.
569 * @example $("p").not("#selected")
570 * @before <p>Hello</p><p id="selected">Hello Again</p>
571 * @result [ <p>Hello</p> ]
575 * @param String expr An expression with which to remove matching elements
578 return this.pushStack( t.constructor == String ?
579 jQuery.filter(t,this,false).r :
580 jQuery.grep(this,function(a){ return a != t; }), arguments );
584 * Adds the elements matched by the expression to the jQuery object. This
585 * can be used to concatenate the result sets of two expressions.
587 * @example $("p").add("span")
588 * @before <p>Hello</p><p><span>Hello Again</span></p>
589 * @result [ <p>Hello</p>, <span>Hello Again</span> ]
593 * @param String expr An expression whose matched elements are added
597 * Adds each of the Elements in the array to the set of matched elements.
598 * This is used to add a set of Elements to a jQuery object.
600 * @example $("p").add([document.getElementById("a"), document.getElementById("b")])
601 * @before <p>Hello</p><p><span id="a">Hello Again</span><span id="b">And Again</span></p>
602 * @result [ <p>Hello</p>, <span id="a">Hello Again</span>, <span id="b">And Again</span> ]
606 * @param Array<Element> els An array of Elements to add
610 * Adds a single Element to the set of matched elements. This is used to
611 * add a single Element to a jQuery object.
613 * @example $("p").add( document.getElementById("a") )
614 * @before <p>Hello</p><p><span id="a">Hello Again</span></p>
615 * @result [ <p>Hello</p>, <span id="a">Hello Again</span> ]
619 * @param Element el An Element to add
622 return this.pushStack( jQuery.merge( this, t.constructor == String ?
623 jQuery.find(t) : t.constructor == Array ? t : [t] ), arguments );
627 * A wrapper function for each() to be used by append and prepend.
628 * Handles cases where you're trying to modify the inner contents of
629 * a table, when you actually need to work with the tbody.
632 * @param {String} expr The expression with which to filter
636 return expr ? jQuery.filter(expr,this).r.length > 0 : this.length > 0;
645 * @param Boolean table
647 * @param Function fn The function doing the DOM manipulation.
650 domManip: function(args, table, dir, fn){
651 var clone = this.size() > 1;
652 var a = jQuery.clean(args);
654 return this.each(function(){
657 if ( table && this.nodeName == "TABLE" ) {
658 var tbody = this.getElementsByTagName("tbody");
660 if ( !tbody.length ) {
661 obj = document.createElement("tbody");
662 this.appendChild( obj );
667 for ( var i = ( dir < 0 ? a.length - 1 : 0 );
668 i != ( dir < 0 ? dir : a.length ); i += dir ) {
669 fn.apply( obj, [ clone ? a[i].cloneNode(true) : a[i] ] );
683 pushStack: function(a,args) {
684 var fn = args && args[args.length-1];
686 if ( !fn || fn.constructor != Function ) {
687 if ( !this.stack ) this.stack = [];
688 this.stack.push( this.get() );
691 var old = this.get();
693 if ( fn.constructor == Function )
694 return this.each( fn );
702 jQuery.extend = jQuery.fn.extend = function(obj,prop) {
703 if ( !prop ) { prop = obj; obj = this; }
704 for ( var i in prop ) obj[i] = prop[i];
710 jQuery.initDone = true;
712 jQuery.each( jQuery.macros.axis, function(i,n){
713 jQuery.fn[ i ] = function(a) {
714 var ret = jQuery.map(this,n);
715 if ( a && a.constructor == String )
716 ret = jQuery.filter(a,ret).r;
717 return this.pushStack( ret, arguments );
721 // appendTo, prependTo, beforeTo, afterTo
723 jQuery.each( jQuery.macros.to, function(i,n){
724 jQuery.fn[ n + "To" ] = function(){
726 return this.each(function(){
727 for ( var i = 0; i < a.length; i++ )
733 jQuery.each( jQuery.macros.each, function(i,n){
734 jQuery.fn[ i ] = function() {
735 return this.each( n, arguments );
739 jQuery.each( jQuery.macros.attr, function(i,n){
741 jQuery.fn[ i ] = function(h) {
742 return h == undefined ?
743 this.length ? this[0][n] : null :
748 jQuery.each( jQuery.macros.css, function(i,n){
749 jQuery.fn[ i ] = function(h) {
750 return h == undefined ?
751 ( this.length ? jQuery.css( this[0], n ) : null ) :
758 each: function( obj, fn, args ) {
759 if ( obj.length == undefined )
761 fn.apply( obj[i], args || [i, obj[i]] );
763 for ( var i = 0; i < obj.length; i++ )
764 fn.apply( obj[i], args || [i, obj[i]] );
770 if (jQuery.className.has(o,c)) return;
771 o.className += ( o.className ? " " : "" ) + c;
773 remove: function(o,c){
774 o.className = !c ? "" :
776 new RegExp("(^|\\s*\\b[^-])"+c+"($|\\b(?=[^-]))", "g"), "");
781 return new RegExp("(^|\\s)" + a + "(\\s|$)").test(e);
786 * Swap in/out style options.
789 swap: function(e,o,f) {
791 e.style["old"+i] = e.style[i];
796 e.style[i] = e.style["old"+i];
800 if ( p == "height" || p == "width" ) {
801 var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"];
804 old["padding" + d[i]] = 0;
805 old["border" + d[i] + "Width"] = 0;
808 jQuery.swap( e, old, function() {
809 if (jQuery.css(e,"display") != "none") {
810 oHeight = e.offsetHeight;
811 oWidth = e.offsetWidth;
813 jQuery.swap( e, { visibility: "hidden", position: "absolute", display: "" },
815 oHeight = e.clientHeight;
816 oWidth = e.clientWidth;
820 return p == "height" ? oHeight : oWidth;
821 } else if ( p == "opacity" && jQuery.browser.msie )
822 return parseFloat( jQuery.curCSS(e,"filter").replace(/[^0-9.]/,"") ) || 1;
824 return jQuery.curCSS( e, p );
827 curCSS: function(e,p,force) {
830 if (!force && e.style[p])
832 else if (e.currentStyle) {
833 p = p.replace(/\-(\w)/g,function(m,c){return c.toUpperCase()});
834 r = e.currentStyle[p];
835 } else if (document.defaultView && document.defaultView.getComputedStyle) {
836 p = p.replace(/([A-Z])/g,"-$1").toLowerCase();
837 var s = document.defaultView.getComputedStyle(e,"");
838 r = s ? s.getPropertyValue(p) : null;
846 for ( var i = 0; i < a.length; i++ ) {
847 if ( a[i].constructor == String ) {
849 if ( !a[i].indexOf("<tr") ) {
851 a[i] = "<table>" + a[i] + "</table>";
852 } else if ( !a[i].indexOf("<td") || !a[i].indexOf("<th") ) {
854 a[i] = "<table><tbody><tr>" + a[i] + "</tr></tbody></table>";
857 var div = document.createElement("div");
858 div.innerHTML = a[i];
861 div = div.firstChild.firstChild;
862 if ( td ) div = div.firstChild;
865 for ( var j = 0; j < div.childNodes.length; j++ )
866 r.push( div.childNodes[j] );
867 } else if ( a[i].jquery || a[i].length && !a[i].nodeType )
868 for ( var k = 0; k < a[i].length; k++ )
870 else if ( a[i] !== null )
871 r.push( a[i].nodeType ? a[i] : document.createTextNode(a[i].toString()) );
877 "": "m[2]== '*'||a.nodeName.toUpperCase()==m[2].toUpperCase()",
878 "#": "a.getAttribute('id')&&a.getAttribute('id')==m[2]",
886 last: "i==r.length-1",
891 "first-child": "jQuery.sibling(a,0).cur",
892 "last-child": "jQuery.sibling(a,0).last",
893 "only-child": "jQuery.sibling(a).length==1",
896 parent: "a.childNodes.length",
897 empty: "!a.childNodes.length",
900 contains: "(a.innerText||a.innerHTML).indexOf(m[3])>=0",
903 visible: "a.type!='hidden'&&jQuery.css(a,'display')!='none'&&jQuery.css(a,'visibility')!='hidden'",
904 hidden: "a.type=='hidden'||jQuery.css(a,'display')=='none'||jQuery.css(a,'visibility')=='hidden'",
907 enabled: "!a.disabled",
908 disabled: "a.disabled",
911 ".": "jQuery.className.has(a,m[2])",
915 "^=": "!z.indexOf(m[4])",
916 "$=": "z.substr(z.length - m[4].length,m[4].length)==m[4]",
917 "*=": "z.indexOf(m[4])>=0",
920 "[": "jQuery.find(m[2],a).length"
924 "\\.\\.|/\\.\\.", "a.parentNode",
925 ">|/", "jQuery.sibling(a.firstChild)",
926 "\\+", "jQuery.sibling(a).next",
929 var s = jQuery.sibling(a);
931 for ( var i = s.n; i < s.length; i++ )
937 find: function( t, context ) {
938 // Make sure that the context is a DOM Element
939 if ( context && context.nodeType == undefined )
942 // Set the correct context (if none is provided)
943 context = context || jQuery.context || document;
945 if ( t.constructor != String ) return [t];
947 if ( !t.indexOf("//") ) {
948 context = context.documentElement;
949 t = t.substr(2,t.length);
950 } else if ( !t.indexOf("/") ) {
951 context = context.documentElement;
952 t = t.substr(1,t.length);
953 // FIX Assume the root element is right :(
954 if ( t.indexOf("/") >= 1 )
955 t = t.substr(t.indexOf("/"),t.length);
962 while ( t.length > 0 && last != t ) {
966 t = jQuery.trim(t).replace( /^\/\//i, "" );
968 var foundToken = false;
970 for ( var i = 0; i < jQuery.token.length; i += 2 ) {
971 var re = new RegExp("^(" + jQuery.token[i] + ")");
975 r = ret = jQuery.map( ret, jQuery.token[i+1] );
976 t = jQuery.trim( t.replace( re, "" ) );
982 if ( !t.indexOf(",") || !t.indexOf("|") ) {
983 if ( ret[0] == context ) ret.shift();
984 done = jQuery.merge( done, ret );
986 t = " " + t.substr(1,t.length);
988 var re2 = /^([#.]?)([a-z0-9\\*_-]*)/i;
992 // Ummm, should make this work in all XML docs
993 var oid = document.getElementById(m[2]);
994 r = ret = oid ? [oid] : [];
995 t = t.replace( re2, "" );
997 if ( !m[2] || m[1] == "." ) m[2] = "*";
999 for ( var i = 0; i < ret.length; i++ )
1000 r = jQuery.merge( r,
1002 jQuery.getAll(ret[i]) :
1003 ret[i].getElementsByTagName(m[2])
1010 var val = jQuery.filter(t,r);
1012 t = jQuery.trim(val.t);
1016 if ( ret && ret[0] == context ) ret.shift();
1017 done = jQuery.merge( done, ret );
1022 getAll: function(o,r) {
1024 var s = o.childNodes;
1025 for ( var i = 0; i < s.length; i++ )
1026 if ( s[i].nodeType == 1 ) {
1028 jQuery.getAll( s[i], r );
1033 attr: function(o,a,v){
1034 if ( a && a.constructor == String ) {
1037 "class": "className",
1041 a = (fix[a] && fix[a].replace && fix[a] || a)
1042 .replace(/-([a-z])/ig,function(z,b){
1043 return b.toUpperCase();
1046 if ( v != undefined ) {
1048 if ( o.setAttribute && a != "disabled" )
1049 o.setAttribute(a,v);
1052 return o[a] || o.getAttribute && o.getAttribute(a) || "";
1057 // The regular expressions that power the parsing engine
1059 // Match: [@value='test'], [@foo]
1060 [ "\\[ *(@)S *([!*$^=]*) *Q\\]", 1 ],
1062 // Match: [div], [div p]
1065 // Match: :contains('foo')
1066 [ "(:)S\\(Q\\)", 0 ],
1068 // Match: :even, :last-chlid
1072 filter: function(t,r,not) {
1073 // Figure out if we're doing regular, or inverse, filtering
1074 var g = not !== false ? jQuery.grep :
1075 function(a,f) {return jQuery.grep(a,f,true);};
1077 while ( t && /^[a-z[({<*:.#]/i.test(t) ) {
1079 var p = jQuery.parse;
1081 for ( var i = 0; i < p.length; i++ ) {
1082 var re = new RegExp( "^" + p[i][0]
1084 // Look for a string-like sequence
1085 .replace( 'S', "([a-z*_-][a-z0-9_-]*)" )
1087 // Look for something (optionally) enclosed with quotes
1088 .replace( 'Q', " *'?\"?([^'\"]*)'?\"? *" ), "i" );
1090 var m = re.exec( t );
1093 // Re-organize the match
1095 m = ["", m[1], m[3], m[2], m[4]];
1097 // Remove what we just matched
1098 t = t.replace( re, "" );
1104 // :not() is a special case that can be optomized by
1105 // keeping it out of the expression list
1106 if ( m[1] == ":" && m[2] == "not" )
1107 r = jQuery.filter(m[3],r,false).r;
1109 // Otherwise, find the expression to execute
1111 var f = jQuery.expr[m[1]];
1112 if ( f.constructor != String )
1113 f = jQuery.expr[m[1]][m[2]];
1115 // Build a custom macro to enclose it
1116 eval("f = function(a,i){" +
1117 ( m[1] == "@" ? "z=jQuery.attr(a,m[3]);" : "" ) +
1118 "return " + f + "}");
1120 // Execute it against the current filter
1125 // Return an array of filtered elements (r)
1126 // and the modified expression string (t)
1127 return { r: r, t: t };
1131 * Remove the whitespace from the beginning and end of a string.
1136 * @param String str The string to trim.
1139 return t.replace(/^\s+|\s+$/g, "");
1143 * All ancestors of a given element.
1147 * @type Array<Element>
1148 * @param Element elem The element to find the ancestors of.
1150 parents: function(a){
1152 var c = a.parentNode;
1153 while ( c && c != document ) {
1161 * All elements on a specified axis.
1166 * @param Element elem The element to find all the siblings of (including itself).
1168 sibling: function(a,n) {
1170 var tmp = a.parentNode.childNodes;
1171 for ( var i = 0; i < tmp.length; i++ ) {
1172 if ( tmp[i].nodeType == 1 )
1173 type.push( tmp[i] );
1175 type.n = type.length - 1;
1177 type.last = type.n == type.length - 1;
1179 n == "even" && type.n % 2 == 0 ||
1180 n == "odd" && type.n % 2 ||
1182 type.prev = type[type.n - 1];
1183 type.next = type[type.n + 1];
1188 * Merge two arrays together, removing all duplicates.
1193 * @param Array a The first array to merge.
1194 * @param Array b The second array to merge.
1196 merge: function(a,b) {
1199 // Move b over to the new array (this helps to avoid
1200 // StaticNodeList instances)
1201 for ( var k = 0; k < b.length; k++ )
1204 // Now check for duplicates between a and b and only
1205 // add the unique items
1206 for ( var i = 0; i < a.length; i++ ) {
1209 // The collision-checking process
1210 for ( var j = 0; j < b.length; j++ )
1214 // If the item is unique, add it
1223 * Remove items that aren't matched in an array. The function passed
1224 * in to this method will be passed two arguments: 'a' (which is the
1225 * array item) and 'i' (which is the index of the item in the array).
1230 * @param Array array The Array to find items in.
1231 * @param Function fn The function to process each item against.
1232 * @param Boolean inv Invert the selection - select the opposite of the function.
1234 grep: function(a,f,s) {
1235 // If a string is passed in for the function, make a function
1236 // for it (a handy shortcut)
1237 if ( f.constructor == String )
1238 f = new Function("a","i","return " + f);
1242 // Go through the array, only saving the items
1243 // that pass the validator function
1244 for ( var i = 0; i < a.length; i++ )
1245 if ( !s && f(a[i],i) || s && !f(a[i],i) )
1252 * Translate all items in array to another array of items. The translation function
1253 * that is provided to this method is passed one argument: 'a' (the item to be
1254 * translated). If an array is returned, that array is mapped out and merged into
1255 * the full array. Additionally, returning 'null' or 'undefined' will delete the item
1256 * from the array. Both of these changes imply that the size of the array may not
1257 * be the same size upon completion, as it was when it started.
1262 * @param Array array The Array to translate.
1263 * @param Function fn The function to process each item against.
1265 map: function(a,f) {
1266 // If a string is passed in for the function, make a function
1267 // for it (a handy shortcut)
1268 if ( f.constructor == String )
1269 f = new Function("a","return " + f);
1273 // Go through the array, translating each of the items to their
1274 // new value (or values).
1275 for ( var i = 0; i < a.length; i++ ) {
1277 if ( t !== null && t != undefined ) {
1278 if ( t.constructor != Array ) t = [t];
1279 r = jQuery.merge( t, r );
1286 * A number of helper functions used for managing events.
1287 * Many of the ideas behind this code orignated from Dean Edwards' addEvent library.
1291 // Bind an event to an element
1292 // Original by Dean Edwards
1293 add: function(element, type, handler) {
1294 // For whatever reason, IE has trouble passing the window object
1295 // around, causing it to be cloned in the process
1296 if ( jQuery.browser.msie && element.setInterval != undefined )
1299 // Make sure that the function being executed has a unique ID
1300 if ( !handler.guid )
1301 handler.guid = this.guid++;
1303 // Init the element's event structure
1304 if (!element.events)
1305 element.events = {};
1307 // Get the current list of functions bound to this event
1308 var handlers = element.events[type];
1310 // If it hasn't been initialized yet
1312 // Init the event handler queue
1313 handlers = element.events[type] = {};
1315 // Remember an existing handler, if it's already there
1316 if (element["on" + type])
1317 handlers[0] = element["on" + type];
1320 // Add the function to the element's handler list
1321 handlers[handler.guid] = handler;
1323 // And bind the global event handler to the element
1324 element["on" + type] = this.handle;
1326 // Remember the function in a global list (for triggering)
1327 if (!this.global[type])
1328 this.global[type] = [];
1329 this.global[type].push( element );
1335 // Detach an event or set of events from an element
1336 remove: function(element, type, handler) {
1338 if (type && element.events[type])
1340 delete element.events[type][handler.guid];
1342 for ( var i in element.events[type] )
1343 delete element.events[type][i];
1345 for ( var j in element.events )
1346 this.remove( element, j );
1349 trigger: function(type,data,element) {
1350 // Touch up the incoming data
1353 // Handle a global trigger
1355 var g = this.global[type];
1357 for ( var i = 0; i < g.length; i++ )
1358 this.trigger( type, data, g[i] );
1360 // Handle triggering a single element
1361 } else if ( element["on" + type] ) {
1362 // Pass along a fake event
1363 data.unshift( this.fix({ type: type, target: element }) );
1365 // Trigger the event
1366 element["on" + type].apply( element, data );
1370 handle: function(event) {
1371 if ( typeof jQuery == "undefined" ) return;
1373 event = event || jQuery.event.fix( window.event );
1375 // If no correct event was found, fail
1376 if ( !event ) return;
1378 var returnValue = true;
1380 var c = this.events[event.type];
1382 for ( var j in c ) {
1383 if ( c[j].apply( this, [event] ) === false ) {
1384 event.preventDefault();
1385 event.stopPropagation();
1386 returnValue = false;
1393 fix: function(event) {
1395 event.preventDefault = function() {
1396 this.returnValue = false;
1399 event.stopPropagation = function() {
1400 this.cancelBubble = true;
1411 var b = navigator.userAgent.toLowerCase();
1413 // Figure out what browser is being used
1415 safari: /webkit/.test(b),
1416 opera: /opera/.test(b),
1417 msie: /msie/.test(b) && !/opera/.test(b),
1418 mozilla: /mozilla/.test(b) && !/compatible/.test(b)
1421 // Check to see if the W3C box model is being used
1422 jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
1426 to: ["append","prepend","before","after"],
1427 css: "width,height,top,left,position,float,overflow,color,background".split(","),
1441 * Get a set of elements containing the unique parents of the matched
1444 * @example $("p").parent()
1445 * @before <div><p>Hello</p><p>Hello</p></div>
1446 * @result [ <div><p>Hello</p><p>Hello</p></div> ]
1453 * Get a set of elements containing the unique parents of the matched
1454 * set of elements, and filtered by an expression.
1456 * @example $("p").parent(".selected")
1457 * @before <div><p>Hello</p></div><div class="selected"><p>Hello Again</p></div>
1458 * @result [ <div class="selected"><p>Hello Again</p></div> ]
1462 * @param String expr An expression to filter the parents with
1464 parent: "a.parentNode",
1467 * Get a set of elements containing the unique ancestors of the matched
1470 * @example $("span").ancestors()
1471 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
1472 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
1479 * Get a set of elements containing the unique ancestors of the matched
1480 * set of elements, and filtered by an expression.
1482 * @example $("span").ancestors("p")
1483 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
1484 * @result [ <p><span>Hello</span></p> ]
1488 * @param String expr An expression to filter the ancestors with
1490 ancestors: jQuery.parents,
1493 * A synonym for ancestors
1495 parents: jQuery.parents,
1498 * Get a set of elements containing the unique next siblings of each of the
1499 * matched set of elements.
1501 * It only returns the very next sibling, not all next siblings.
1503 * @example $("p").next()
1504 * @before <p>Hello</p><p>Hello Again</p><div><span>And Again</span></div>
1505 * @result [ <p>Hello Again</p>, <div><span>And Again</span></div> ]
1512 * Get a set of elements containing the unique next siblings of each of the
1513 * matched set of elements, and filtered by an expression.
1515 * It only returns the very next sibling, not all next siblings.
1517 * @example $("p").next(".selected")
1518 * @before <p>Hello</p><p class="selected">Hello Again</p><div><span>And Again</span></div>
1519 * @result [ <p class="selected">Hello Again</p> ]
1523 * @param String expr An expression to filter the next Elements with
1525 next: "jQuery.sibling(a).next",
1528 * Get a set of elements containing the unique previous siblings of each of the
1529 * matched set of elements.
1531 * It only returns the immediately previous sibling, not all previous siblings.
1533 * @example $("p").previous()
1534 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
1535 * @result [ <div><span>Hello Again</span></div> ]
1542 * Get a set of elements containing the unique previous siblings of each of the
1543 * matched set of elements, and filtered by an expression.
1545 * It only returns the immediately previous sibling, not all previous siblings.
1547 * @example $("p").previous("selected")
1548 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
1549 * @result [ <div><span>Hello</span></div> ]
1553 * @param String expr An expression to filter the previous Elements with
1555 prev: "jQuery.sibling(a).prev",
1558 * Get a set of elements containing all of the unique siblings of each of the
1559 * matched set of elements.
1561 * @example $("div").siblings()
1562 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
1563 * @result [ <p>Hello</p>, <p>And Again</p> ]
1570 * Get a set of elements containing all of the unique siblings of each of the
1571 * matched set of elements, and filtered by an expression.
1573 * @example $("div").siblings("selected")
1574 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
1575 * @result [ <p class="selected">Hello Again</p> ]
1579 * @param String expr An expression to filter the sibling Elements with
1581 siblings: jQuery.sibling
1586 * Displays each of the set of matched elements if they are hidden.
1588 * @example $("p").show()
1589 * @before <p style="display: none">Hello</p>
1590 * @result [ <p style="display: block">Hello</p> ]
1596 this.style.display = this.oldblock ? this.oldblock : "";
1597 if ( jQuery.css(this,"display") == "none" )
1598 this.style.display = "block";
1602 * Hides each of the set of matched elements if they are shown.
1604 * @example $("p").hide()
1605 * @before <p>Hello</p>
1606 * @result [ <p style="display: none">Hello</p> ]
1612 this.oldblock = this.oldblock || jQuery.css(this,"display");
1613 if ( this.oldblock == "none" )
1614 this.oldblock = "block";
1615 this.style.display = "none";
1619 * Toggles each of the set of matched elements. If they are shown,
1620 * toggle makes them hidden. If they are hidden, toggle
1623 * @example $("p").toggle()
1624 * @before <p>Hello</p><p style="display: none">Hello Again</p>
1625 * @result [ <p style="display: none">Hello</p>, <p style="display: block">Hello Again</p> ]
1631 var d = jQuery.css(this,"display");
1632 $(this)[ !d || d == "none" ? "show" : "hide" ]();
1636 * Adds the specified class to each of the set of matched elements.
1638 * @example ("p").addClass("selected")
1639 * @before <p>Hello</p>
1640 * @result [ <p class="selected">Hello</p> ]
1644 * @param String class A CSS class to add to the elements
1646 addClass: function(c){
1647 jQuery.className.add(this,c);
1651 * The opposite of addClass. Removes the specified class from the
1652 * set of matched elements.
1654 * @example ("p").removeClass("selected")
1655 * @before <p class="selected">Hello</p>
1656 * @result [ <p>Hello</p> ]
1660 * @param String class A CSS class to remove from the elements
1662 removeClass: function(c){
1663 jQuery.className.remove(this,c);
1667 * Adds the specified class if it is present. Remove it if it is
1670 * @example ("p").toggleClass("selected")
1671 * @before <p>Hello</p><p class="selected">Hello Again</p>
1672 * @result [ <p class="selected">Hello</p>, <p>Hello Again</p> ]
1676 * @param String class A CSS class with which to toggle the elements
1678 toggleClass: function( c ){
1679 jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this,c);
1685 remove: function(a){
1686 if ( !a || jQuery.filter( [this], a ).r )
1687 this.parentNode.removeChild( this );
1691 * Removes all child nodes from the set of matched elements.
1693 * @example ("p").empty()
1694 * @before <p>Hello, <span>Person</span> <a href="#">and person</a></p>
1695 * @result [ <p></p> ]
1701 while ( this.firstChild )
1702 this.removeChild( this.firstChild );
1706 * Binds a particular event (like click) to a each of a set of match elements.
1708 * @example $("p").bind( "click", function() { alert("Hello"); } )
1709 * @before <p>Hello</p>
1710 * @result [ <p>Hello</p> ]
1712 * Cancel a default action and prevent it from bubbling by returning false
1713 * from your function.
1715 * @example $("form").bind( "submit", function() { return false; } )
1717 * Cancel a default action by using the preventDefault method.
1719 * @example $("form").bind( "submit", function() { e.preventDefault(); } )
1721 * Stop an event from bubbling by using the stopPropogation method.
1723 * @example $("form").bind( "submit", function() { e.stopPropogation(); } )
1727 * @param String type An event type
1728 * @param Function fn A function to bind to the event on each of the set of matched elements
1730 bind: function( type, fn ) {
1731 if ( fn.constructor == String )
1732 fn = new Function("e", ( !fn.indexOf(".") ? "$(this)" : "return " ) + fn);
1733 jQuery.event.add( this, type, fn );
1737 * The opposite of bind. Removes a bound event from each of a set of matched
1738 * elements. You must pass the identical function that was used in the original
1741 * @example $("p").unbind( "click", function() { alert("Hello"); } )
1742 * @before <p>Hello</p>
1743 * @result [ <p>Hello</p> ]
1747 * @param String type An event type
1748 * @param Function fn A function to unbind from the event on each of the set of matched elements
1750 unbind: function( type, fn ) {
1751 jQuery.event.remove( this, type, fn );
1755 * Trigger a particular event.
1757 * @example $("p").trigger("click")
1758 * @before <p>Hello</p>
1759 * @result [ <p>Hello</p> ]
1763 * @param String type An event type
1765 trigger: function( type, data ) {
1766 jQuery.event.trigger( type, data, this );