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 // Iterate through all of the matched elements
200 for ( var i = 0; i < this.length; i++ )
202 // Execute the function within the context of each element
203 fn.apply( this[i], args || [i] );
209 * Access a property on the first matched element.
210 * This method makes it easy to retreive a property value
211 * from the first matched element.
213 * @example $("img").attr("src");
214 * @before <img src="test.jpg"/>
219 * @param String name The name of the property to access.
223 * Set a hash of key/value object properties to all matched elements.
224 * This serves as the best way to set a large number of properties
225 * on all matched elements.
227 * @example $("img").attr({ src: "test.jpg", alt: "Test Image" });
229 * @result <img src="test.jpg" alt="Test Image"/>
233 * @param Hash prop A set of key/value pairs to set as object properties.
237 * Set a single property to a value, on all matched elements.
239 * @example $("img").attr("src","test.jpg");
241 * @result <img src="test.jpg"/>
245 * @param String key The name of the property to set.
246 * @param Object value The value to set the property to.
248 attr: function( key, value, type ) {
249 // Check to see if we're setting style values
250 return key.constructor != String || value ?
251 this.each(function(){
252 // See if we're setting a hash of styles
253 if ( value == undefined )
254 // Set all the styles
255 for ( var prop in key )
257 type ? this.style : this,
261 // See if we're setting a single key/value style
264 type ? this.style : this,
269 // Look for the case where we're accessing a style value
270 jQuery[ type || "attr" ]( this[0], key );
274 * Access a style property on the first matched element.
275 * This method makes it easy to retreive a style property value
276 * from the first matched element.
278 * @example $("p").css("red");
279 * @before <p style="color:red;">Test Paragraph.</p>
284 * @param String name The name of the property to access.
288 * Set a hash of key/value style properties to all matched elements.
289 * This serves as the best way to set a large number of style properties
290 * on all matched elements.
292 * @example $("p").css({ color: "red", background: "blue" });
293 * @before <p>Test Paragraph.</p>
294 * @result <p style="color:red; background:blue;">Test Paragraph.</p>
298 * @param Hash prop A set of key/value pairs to set as style properties.
302 * Set a single style property to a value, on all matched elements.
304 * @example $("p").css("color","red");
305 * @before <p>Test Paragraph.</p>
306 * @result <p style="color:red;">Test Paragraph.</p>
310 * @param String key The name of the property to set.
311 * @param Object value The value to set the property to.
313 css: function( key, value ) {
314 return this.attr( key, value, "curCSS" );
318 * Retreive the text contents of all matched elements. The result is
319 * a string that contains the combined text contents of all matched
320 * elements. This method works on both HTML and XML documents.
322 * @example $("p").text();
323 * @before <p>Test Paragraph.</p>
324 * @result Test Paragraph.
332 for ( var j = 0; j < e.length; j++ ) {
333 var r = e[j].childNodes;
334 for ( var i = 0; i < r.length; i++ )
335 t += r[i].nodeType != 1 ?
336 r[i].nodeValue : jQuery.fn.text([ r[i] ]);
342 * Wrap all matched elements with a structure of other elements.
343 * This wrapping process is most useful for injecting additional
344 * stucture into a document, without ruining the original semantic
345 * qualities of a document.
347 * The way that is works is that it goes through the first element argument
348 * provided and finds the deepest element within the structure - it is that
349 * element that will en-wrap everything else.
351 * @example $("p").wrap("<div class='wrap'></div>");
352 * @before <p>Test Paragraph.</p>
353 * @result <div class='wrap'><p>Test Paragraph.</p></div>
357 * @any String html A string of HTML, that will be created on the fly and wrapped around the target.
358 * @any Element elem A DOM element that will be wrapped.
359 * @any Array<Element> elems An array of elements, the first of which will be wrapped.
360 * @any Object obj Any object, converted to a string, then a text node.
363 // The elements to wrap the target around
364 var a = jQuery.clean(arguments);
366 // Wrap each of the matched elements individually
367 return this.each(function(){
368 // Clone the structure that we're using to wrap
369 var b = a[0].cloneNode(true);
371 // Insert it before the element to be wrapped
372 this.parentNode.insertBefore( b, this );
374 // Find he deepest point in the wrap structure
375 while ( b.firstChild )
378 // Move the matched element to within the wrap structure
379 b.appendChild( this );
384 * Append any number of elements to the inside of all matched elements.
385 * This operation is similar to doing an <tt>appendChild</tt> to all the
386 * specified elements, adding them into the document.
388 * @example $("p").append("<b>Hello</b>");
389 * @before <p>I would like to say: </p>
390 * @result <p>I would like to say: <b>Hello</b></p>
394 * @any String html A string of HTML, that will be created on the fly and appended to the target.
395 * @any Element elem A DOM element that will be appended.
396 * @any Array<Element> elems An array of elements, all of which will be appended.
397 * @any Object obj Any object, converted to a string, then a text node.
400 return this.domManip(arguments, true, 1, function(a){
401 this.appendChild( a );
406 * Prepend any number of elements to the inside of all matched elements.
407 * This operation is the best way to insert a set of elements inside, at the
408 * beginning, of all the matched element.
410 * @example $("p").prepend("<b>Hello</b>");
411 * @before <p>, how are you?</p>
412 * @result <p><b>Hello</b>, how are you?</p>
416 * @any String html A string of HTML, that will be created on the fly and prepended to the target.
417 * @any Element elem A DOM element that will be prepended.
418 * @any Array<Element> elems An array of elements, all of which will be prepended.
419 * @any Object obj Any object, converted to a string, then a text node.
421 prepend: function() {
422 return this.domManip(arguments, true, -1, function(a){
423 this.insertBefore( a, this.firstChild );
428 * Insert any number of elements before each of the matched elements.
430 * @example $("p").before("<b>Hello</b>");
431 * @before <p>how are you?</p>
432 * @result <b>Hello</b><p>how are you?</p>
436 * @any String html A string of HTML, that will be created on the fly and inserted.
437 * @any Element elem A DOM element that will beinserted.
438 * @any Array<Element> elems An array of elements, all of which will be inserted.
439 * @any Object obj Any object, converted to a string, then a text node.
442 return this.domManip(arguments, false, 1, function(a){
443 this.parentNode.insertBefore( a, this );
448 * Insert any number of elements after each of the matched elements.
450 * @example $("p").after("<p>I'm doing fine.</p>");
451 * @before <p>How are you?</p>
452 * @result <p>How are you?</p><p>I'm doing fine.</p>
456 * @any String html A string of HTML, that will be created on the fly and inserted.
457 * @any Element elem A DOM element that will beinserted.
458 * @any Array<Element> elems An array of elements, all of which will be inserted.
459 * @any Object obj Any object, converted to a string, then a text node.
462 return this.domManip(arguments, false, -1, function(a){
463 this.parentNode.insertBefore( a, this.nextSibling );
468 * End the most recent 'destructive' operation, reverting the list of matched elements
469 * back to its previous state. After an end operation, the list of matched elements will
470 * revert to the last state of matched elements.
472 * @example $("p").find("span").end();
473 * @before <p><span>Hello</span>, how are you?</p>
474 * @result $("p").find("span").end() == [ <p>...</p> ]
480 return this.get( this.stack.pop() );
484 * Searches for all elements that match the specified expression.
485 * This method is the optimal way of finding additional descendant
486 * elements with which to process.
488 * All searching is done using a jQuery expression. The expression can be
489 * written using CSS 1-3 Selector syntax, or basic XPath.
491 * @example $("p").find("span");
492 * @before <p><span>Hello</span>, how are you?</p>
493 * @result $("p").find("span") == [ <span>Hello</span> ]
497 * @param String expr An expression to search with.
500 return this.pushStack( jQuery.map( this, function(a){
501 return jQuery.find(t,a);
506 * Removes all elements from the set of matched elements that do not
507 * match the specified expression. This method is used to narrow down
508 * the results of a search.
510 * All searching is done using a jQuery expression. The expression
511 * can be written using CSS 1-3 Selector syntax, or basic XPath.
513 * @example $("p").filter(".selected")
514 * @before <p class="selected">Hello</p><p>How are you?</p>
515 * @result $("p").filter(".selected") == [ <p class="selected">Hello</p> ]
519 * @param String expr An expression to search with.
523 * Removes all elements from the set of matched elements that do not
524 * match at least one of the expressions passed to the function. This
525 * method is used when you want to filter the set of matched elements
526 * through more than one expression.
528 * Elements will be retained in the jQuery object if they match at
529 * least one of the expressions passed.
531 * @example $("p").filter([".selected", ":first"])
532 * @before <p>Hello</p><p>Hello Again</p><p class="selected">And Again</p>
533 * @result $("p").filter([".selected", ":first"]) == [ <p>Hello</p>, <p class="selected">And Again</p> ]
537 * @param Array<String> exprs A set of expressions to evaluate against
539 filter: function(t) {
540 return this.pushStack(
541 t.constructor == Array &&
542 jQuery.map(this,function(a){
543 for ( var i = 0; i < t.length; i++ )
544 if ( jQuery.filter(t[i],[a]).r.length )
548 t.constructor == Boolean &&
549 ( t ? this.get() : [] ) ||
551 t.constructor == Function &&
552 jQuery.grep( this, t ) ||
554 jQuery.filter(t,this).r, arguments );
558 * Removes the specified Element from the set of matched elements. This
559 * method is used to remove a single Element from a jQuery object.
561 * @example $("p").not( document.getElementById("selected") )
562 * @before <p>Hello</p><p id="selected">Hello Again</p>
563 * @result [ <p>Hello</p> ]
567 * @param Element el An element to remove from the set
571 * Removes elements matching the specified expression from the set
572 * of matched elements. This method is used to remove one or more
573 * elements from a jQuery object.
575 * @example $("p").not("#selected")
576 * @before <p>Hello</p><p id="selected">Hello Again</p>
577 * @result [ <p>Hello</p> ]
581 * @param String expr An expression with which to remove matching elements
584 return this.pushStack( t.constructor == String ?
585 jQuery.filter(t,this,false).r :
586 jQuery.grep(this,function(a){ return a != t; }), arguments );
590 * Adds the elements matched by the expression to the jQuery object. This
591 * can be used to concatenate the result sets of two expressions.
593 * @example $("p").add("span")
594 * @before <p>Hello</p><p><span>Hello Again</span></p>
595 * @result [ <p>Hello</p>, <span>Hello Again</span> ]
599 * @param String expr An expression whose matched elements are added
603 * Adds each of the Elements in the array to the set of matched elements.
604 * This is used to add a set of Elements to a jQuery object.
606 * @example $("p").add([document.getElementById("a"), document.getElementById("b")])
607 * @before <p>Hello</p><p><span id="a">Hello Again</span><span id="b">And Again</span></p>
608 * @result [ <p>Hello</p>, <span id="a">Hello Again</span>, <span id="b">And Again</span> ]
612 * @param Array<Element> els An array of Elements to add
616 * Adds a single Element to the set of matched elements. This is used to
617 * add a single Element to a jQuery object.
619 * @example $("p").add( document.getElementById("a") )
620 * @before <p>Hello</p><p><span id="a">Hello Again</span></p>
621 * @result [ <p>Hello</p>, <span id="a">Hello Again</span> ]
625 * @param Element el An Element to add
628 return this.pushStack( jQuery.merge( this, t.constructor == String ?
629 jQuery.find(t) : t.constructor == Array ? t : [t] ), arguments );
633 * A wrapper function for each() to be used by append and prepend.
634 * Handles cases where you're trying to modify the inner contents of
635 * a table, when you actually need to work with the tbody.
638 * @param {String} expr The expression with which to filter
642 return expr ? jQuery.filter(expr,this).r.length > 0 : this.length > 0;
651 * @param Boolean table
653 * @param Function fn The function doing the DOM manipulation.
656 domManip: function(args, table, dir, fn){
657 var clone = this.size() > 1;
658 var a = jQuery.clean(args);
660 return this.each(function(){
663 if ( table && this.nodeName == "TABLE" ) {
664 var tbody = this.getElementsByTagName("tbody");
666 if ( !tbody.length ) {
667 obj = document.createElement("tbody");
668 this.appendChild( obj );
673 for ( var i = ( dir < 0 ? a.length - 1 : 0 );
674 i != ( dir < 0 ? dir : a.length ); i += dir ) {
675 fn.apply( obj, [ clone ? a[i].cloneNode(true) : a[i] ] );
690 pushStack: function(a,args) {
691 var fn = args && args[args.length-1];
693 if ( !fn || fn.constructor != Function ) {
694 if ( !this.stack ) this.stack = [];
695 this.stack.push( this.get() );
698 var old = this.get();
700 if ( fn.constructor == Function )
701 return this.each( fn );
709 jQuery.extend = jQuery.fn.extend = function(obj,prop) {
710 if ( !prop ) { prop = obj; obj = this; }
711 for ( var i in prop ) obj[i] = prop[i];
717 jQuery.initDone = true;
719 for ( var i in jQuery.macros.axis ) new function(){
720 var t = jQuery.macros.axis[i];
722 jQuery.fn[ i ] = function(a) {
723 var ret = jQuery.map(this,t);
724 if ( a && a.constructor == String )
725 ret = jQuery.filter(a,ret).r;
726 return this.pushStack( ret, arguments );
730 // appendTo, prependTo, beforeTo, afterTo
732 for ( var i = 0; i < jQuery.macros.to.length; i++ ) new function(){
733 var n = jQuery.macros.to[i];
734 jQuery.fn[ n + "To" ] = function(){
736 return this.each(function(){
737 for ( var i = 0; i < a.length; i++ )
743 for ( var i in jQuery.macros.each ) new function() {
744 var n = jQuery.macros.each[i];
745 jQuery.fn[ i ] = function() {
746 return this.each( n, arguments );
750 for ( var i in jQuery.macros.attr ) new function() {
751 var n = jQuery.macros.attr[i] || i;
752 jQuery.fn[ i ] = function(h) {
753 return h == undefined ?
754 this.length ? this[0][n] : null :
759 for ( var i = 0; i < jQuery.macros.css.length; i++ ) new function() {
760 var n = jQuery.macros.css[i];
761 jQuery.fn[ i ] = function(h) {
762 return h == undefined ?
763 ( this.length ? jQuery.css( this[0], n ) : null ) :
772 if (jQuery.className.has(o,c)) return;
773 o.className += ( o.className ? " " : "" ) + c;
775 remove: function(o,c){
776 o.className = !c ? "" :
778 new RegExp("(^|\\s*\\b[^-])"+c+"($|\\b(?=[^-]))", "g"), "");
783 return new RegExp("(^|\\s)" + a + "(\\s|$)").test(e);
788 * Swap in/out style options.
791 swap: function(e,o,f) {
793 e.style["old"+i] = e.style[i];
798 e.style[i] = e.style["old"+i];
802 if ( p == "height" || p == "width" ) {
803 var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"];
806 old["padding" + d[i]] = 0;
807 old["border" + d[i] + "Width"] = 0;
810 jQuery.swap( e, old, function() {
811 if (jQuery.css(e,"display") != "none") {
812 oHeight = e.offsetHeight;
813 oWidth = e.offsetWidth;
815 jQuery.swap( e, { visibility: "hidden", position: "absolute", display: "" },
817 oHeight = e.clientHeight;
818 oWidth = e.clientWidth;
822 return p == "height" ? oHeight : oWidth;
823 } else if ( p == "opacity" && jQuery.browser.msie )
824 return parseFloat( jQuery.curCSS(e,"filter").replace(/[^0-9.]/,"") ) || 1;
826 return jQuery.curCSS( e, p );
829 curCSS: function(e,p,force) {
832 if (!force && e.style[p])
834 else if (e.currentStyle) {
835 p = p.replace(/\-(\w)/g,function(m,c){return c.toUpperCase()});
836 r = e.currentStyle[p];
837 } else if (document.defaultView && document.defaultView.getComputedStyle) {
838 p = p.replace(/([A-Z])/g,"-$1").toLowerCase();
839 var s = document.defaultView.getComputedStyle(e,"");
840 r = s ? s.getPropertyValue(p) : null;
848 for ( var i = 0; i < a.length; i++ ) {
849 if ( a[i].constructor == String ) {
851 if ( !a[i].indexOf("<tr") ) {
853 a[i] = "<table>" + a[i] + "</table>";
854 } else if ( !a[i].indexOf("<td") || !a[i].indexOf("<th") ) {
856 a[i] = "<table><tbody><tr>" + a[i] + "</tr></tbody></table>";
859 var div = document.createElement("div");
860 div.innerHTML = a[i];
863 div = div.firstChild.firstChild;
864 if ( td ) div = div.firstChild;
867 for ( var j = 0; j < div.childNodes.length; j++ )
868 r.push( div.childNodes[j] );
869 } else if ( a[i].jquery || a[i].length && !a[i].nodeType )
870 for ( var k = 0; k < a[i].length; k++ )
872 else if ( a[i] !== null )
873 r.push( a[i].nodeType ? a[i] : document.createTextNode(a[i].toString()) );
879 "": "m[2]== '*'||a.nodeName.toUpperCase()==m[2].toUpperCase()",
880 "#": "a.getAttribute('id')&&a.getAttribute('id')==m[2]",
888 last: "i==r.length-1",
893 "first-child": "jQuery.sibling(a,0).cur",
894 "last-child": "jQuery.sibling(a,0).last",
895 "only-child": "jQuery.sibling(a).length==1",
898 parent: "a.childNodes.length",
899 empty: "!a.childNodes.length",
902 contains: "(a.innerText||a.innerHTML).indexOf(m[3])>=0",
905 visible: "a.type!='hidden'&&jQuery.css(a,'display')!='none'&&jQuery.css(a,'visibility')!='hidden'",
906 hidden: "a.type=='hidden'||jQuery.css(a,'display')=='none'||jQuery.css(a,'visibility')=='hidden'",
909 enabled: "!a.disabled",
910 disabled: "a.disabled",
913 ".": "jQuery.className.has(a,m[2])",
917 "^=": "!z.indexOf(m[4])",
918 "$=": "z.substr(z.length - m[4].length,m[4].length)==m[4]",
919 "*=": "z.indexOf(m[4])>=0",
922 "[": "jQuery.find(m[2],a).length"
926 "\\.\\.|/\\.\\.", "a.parentNode",
927 ">|/", "jQuery.sibling(a.firstChild)",
928 "\\+", "jQuery.sibling(a).next",
931 var s = jQuery.sibling(a);
933 for ( var i = s.n; i < s.length; i++ )
939 find: function( t, context ) {
940 // Make sure that the context is a DOM Element
941 if ( context && context.nodeType == undefined )
944 // Set the correct context (if none is provided)
945 context = context || jQuery.context || document;
947 if ( t.constructor != String ) return [t];
949 if ( !t.indexOf("//") ) {
950 context = context.documentElement;
951 t = t.substr(2,t.length);
952 } else if ( !t.indexOf("/") ) {
953 context = context.documentElement;
954 t = t.substr(1,t.length);
955 // FIX Assume the root element is right :(
956 if ( t.indexOf("/") >= 1 )
957 t = t.substr(t.indexOf("/"),t.length);
964 while ( t.length > 0 && last != t ) {
968 t = jQuery.trim(t).replace( /^\/\//i, "" );
970 var foundToken = false;
972 for ( var i = 0; i < jQuery.token.length; i += 2 ) {
973 var re = new RegExp("^(" + jQuery.token[i] + ")");
977 r = ret = jQuery.map( ret, jQuery.token[i+1] );
978 t = jQuery.trim( t.replace( re, "" ) );
984 if ( !t.indexOf(",") || !t.indexOf("|") ) {
985 if ( ret[0] == context ) ret.shift();
986 done = jQuery.merge( done, ret );
988 t = " " + t.substr(1,t.length);
990 var re2 = /^([#.]?)([a-z0-9\\*_-]*)/i;
994 // Ummm, should make this work in all XML docs
995 var oid = document.getElementById(m[2]);
996 r = ret = oid ? [oid] : [];
997 t = t.replace( re2, "" );
999 if ( !m[2] || m[1] == "." ) m[2] = "*";
1001 for ( var i = 0; i < ret.length; i++ )
1002 r = jQuery.merge( r,
1004 jQuery.getAll(ret[i]) :
1005 ret[i].getElementsByTagName(m[2])
1012 var val = jQuery.filter(t,r);
1014 t = jQuery.trim(val.t);
1018 if ( ret && ret[0] == context ) ret.shift();
1019 done = jQuery.merge( done, ret );
1024 getAll: function(o,r) {
1026 var s = o.childNodes;
1027 for ( var i = 0; i < s.length; i++ )
1028 if ( s[i].nodeType == 1 ) {
1030 jQuery.getAll( s[i], r );
1035 attr: function(o,a,v){
1036 if ( a && a.constructor == String ) {
1039 "class": "className",
1043 a = (fix[a] && fix[a].replace && fix[a] || a)
1044 .replace(/-([a-z])/ig,function(z,b){
1045 return b.toUpperCase();
1048 if ( v != undefined ) {
1050 if ( o.setAttribute && a != "disabled" )
1051 o.setAttribute(a,v);
1054 return o[a] || o.getAttribute && o.getAttribute(a) || "";
1059 // The regular expressions that power the parsing engine
1061 // Match: [@value='test'], [@foo]
1062 [ "\\[ *(@)S *([!*$^=]*) *Q\\]", 1 ],
1064 // Match: [div], [div p]
1067 // Match: :contains('foo')
1068 [ "(:)S\\(Q\\)", 0 ],
1070 // Match: :even, :last-chlid
1074 filter: function(t,r,not) {
1075 // Figure out if we're doing regular, or inverse, filtering
1076 var g = not !== false ? jQuery.grep :
1077 function(a,f) {return jQuery.grep(a,f,true);};
1079 while ( t && /^[a-z[({<*:.#]/i.test(t) ) {
1081 var p = jQuery.parse;
1083 for ( var i = 0; i < p.length; i++ ) {
1084 var re = new RegExp( "^" + p[i][0]
1086 // Look for a string-like sequence
1087 .replace( 'S', "([a-z*_-][a-z0-9_-]*)" )
1089 // Look for something (optionally) enclosed with quotes
1090 .replace( 'Q', " *'?\"?([^'\"]*)'?\"? *" ), "i" );
1092 var m = re.exec( t );
1095 // Re-organize the match
1097 m = ["", m[1], m[3], m[2], m[4]];
1099 // Remove what we just matched
1100 t = t.replace( re, "" );
1106 // :not() is a special case that can be optomized by
1107 // keeping it out of the expression list
1108 if ( m[1] == ":" && m[2] == "not" )
1109 r = jQuery.filter(m[3],r,false).r;
1111 // Otherwise, find the expression to execute
1113 var f = jQuery.expr[m[1]];
1114 if ( f.constructor != String )
1115 f = jQuery.expr[m[1]][m[2]];
1117 // Build a custom macro to enclose it
1118 eval("f = function(a,i){" +
1119 ( m[1] == "@" ? "z=jQuery.attr(a,m[3]);" : "" ) +
1120 "return " + f + "}");
1122 // Execute it against the current filter
1127 // Return an array of filtered elements (r)
1128 // and the modified expression string (t)
1129 return { r: r, t: t };
1133 * Remove the whitespace from the beginning and end of a string.
1138 * @param String str The string to trim.
1141 return t.replace(/^\s+|\s+$/g, "");
1145 * All ancestors of a given element.
1149 * @type Array<Element>
1150 * @param Element elem The element to find the ancestors of.
1152 parents: function(a){
1154 var c = a.parentNode;
1155 while ( c && c != document ) {
1163 * All elements on a specified axis.
1168 * @param Element elem The element to find all the siblings of (including itself).
1170 sibling: function(a,n) {
1172 var tmp = a.parentNode.childNodes;
1173 for ( var i = 0; i < tmp.length; i++ ) {
1174 if ( tmp[i].nodeType == 1 )
1175 type.push( tmp[i] );
1177 type.n = type.length - 1;
1179 type.last = type.n == type.length - 1;
1181 n == "even" && type.n % 2 == 0 ||
1182 n == "odd" && type.n % 2 ||
1184 type.prev = type[type.n - 1];
1185 type.next = type[type.n + 1];
1190 * Merge two arrays together, removing all duplicates.
1195 * @param Array a The first array to merge.
1196 * @param Array b The second array to merge.
1198 merge: function(a,b) {
1201 // Move b over to the new array (this helps to avoid
1202 // StaticNodeList instances)
1203 for ( var k = 0; k < b.length; k++ )
1206 // Now check for duplicates between a and b and only
1207 // add the unique items
1208 for ( var i = 0; i < a.length; i++ ) {
1211 // The collision-checking process
1212 for ( var j = 0; j < b.length; j++ )
1216 // If the item is unique, add it
1225 * Remove items that aren't matched in an array. The function passed
1226 * in to this method will be passed two arguments: 'a' (which is the
1227 * array item) and 'i' (which is the index of the item in the array).
1232 * @param Array array The Array to find items in.
1233 * @param Function fn The function to process each item against.
1234 * @param Boolean inv Invert the selection - select the opposite of the function.
1236 grep: function(a,f,s) {
1237 // If a string is passed in for the function, make a function
1238 // for it (a handy shortcut)
1239 if ( f.constructor == String )
1240 f = new Function("a","i","return " + f);
1244 // Go through the array, only saving the items
1245 // that pass the validator function
1246 for ( var i = 0; i < a.length; i++ )
1247 if ( !s && f(a[i],i) || s && !f(a[i],i) )
1254 * Translate all items in array to another array of items. The translation function
1255 * that is provided to this method is passed one argument: 'a' (the item to be
1256 * translated). If an array is returned, that array is mapped out and merged into
1257 * the full array. Additionally, returning 'null' or 'undefined' will delete the item
1258 * from the array. Both of these changes imply that the size of the array may not
1259 * be the same size upon completion, as it was when it started.
1264 * @param Array array The Array to translate.
1265 * @param Function fn The function to process each item against.
1267 map: function(a,f) {
1268 // If a string is passed in for the function, make a function
1269 // for it (a handy shortcut)
1270 if ( f.constructor == String )
1271 f = new Function("a","return " + f);
1275 // Go through the array, translating each of the items to their
1276 // new value (or values).
1277 for ( var i = 0; i < a.length; i++ ) {
1279 if ( t !== null && t != undefined ) {
1280 if ( t.constructor != Array ) t = [t];
1281 r = jQuery.merge( t, r );
1288 * A number of helper functions used for managing events.
1289 * Many of the ideas behind this code orignated from Dean Edwards' addEvent library.
1293 // Bind an event to an element
1294 // Original by Dean Edwards
1295 add: function(element, type, handler) {
1296 // For whatever reason, IE has trouble passing the window object
1297 // around, causing it to be cloned in the process
1298 if ( jQuery.browser.msie && element.setInterval != undefined )
1301 // Make sure that the function being executed has a unique ID
1302 if ( !handler.guid )
1303 handler.guid = this.guid++;
1305 // Init the element's event structure
1306 if (!element.events)
1307 element.events = {};
1309 // Get the current list of functions bound to this event
1310 var handlers = element.events[type];
1312 // If it hasn't been initialized yet
1314 // Init the event handler queue
1315 handlers = element.events[type] = {};
1317 // Remember an existing handler, if it's already there
1318 if (element["on" + type])
1319 handlers[0] = element["on" + type];
1322 // Add the function to the element's handler list
1323 handlers[handler.guid] = handler;
1325 // And bind the global event handler to the element
1326 element["on" + type] = this.handle;
1328 // Remember the function in a global list (for triggering)
1329 if (!this.global[type])
1330 this.global[type] = [];
1331 this.global[type].push( element );
1337 // Detach an event or set of events from an element
1338 remove: function(element, type, handler) {
1340 if (type && element.events[type])
1342 delete element.events[type][handler.guid];
1344 for ( var i in element.events[type] )
1345 delete element.events[type][i];
1347 for ( var j in element.events )
1348 this.remove( element, j );
1351 trigger: function(type,data,element) {
1352 // Touch up the incoming data
1355 // Handle a global trigger
1357 var g = this.global[type];
1359 for ( var i = 0; i < g.length; i++ )
1360 this.trigger( type, data, g[i] );
1362 // Handle triggering a single element
1363 } else if ( element["on" + type] ) {
1364 // Pass along a fake event
1365 data.unshift( this.fix({ type: type, target: element }) );
1367 // Trigger the event
1368 element["on" + type].apply( element, data );
1372 handle: function(event) {
1373 if ( typeof jQuery == "undefined" ) return;
1375 event = event || jQuery.event.fix( window.event );
1377 // If no correct event was found, fail
1378 if ( !event ) return;
1380 var returnValue = true;
1382 var c = this.events[event.type];
1384 for ( var j in c ) {
1385 if ( c[j].apply( this, [event] ) === false ) {
1386 event.preventDefault();
1387 event.stopPropagation();
1388 returnValue = false;
1395 fix: function(event) {
1397 event.preventDefault = function() {
1398 this.returnValue = false;
1401 event.stopPropagation = function() {
1402 this.cancelBubble = true;
1413 var b = navigator.userAgent.toLowerCase();
1415 // Figure out what browser is being used
1417 safari: /webkit/.test(b),
1418 opera: /opera/.test(b),
1419 msie: /msie/.test(b) && !/opera/.test(b),
1420 mozilla: /mozilla/.test(b) && !/compatible/.test(b)
1423 // Check to see if the W3C box model is being used
1424 jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
1428 to: ["append","prepend","before","after"],
1429 css: "width,height,top,left,position,float,overflow,color,background".split(","),
1443 * Get a set of elements containing the unique parents of the matched
1446 * @example $("p").parent()
1447 * @before <div><p>Hello</p><p>Hello</p></div>
1448 * @result [ <div><p>Hello</p><p>Hello</p></div> ]
1455 * Get a set of elements containing the unique parents of the matched
1456 * set of elements, and filtered by an expression.
1458 * @example $("p").parent(".selected")
1459 * @before <div><p>Hello</p></div><div class="selected"><p>Hello Again</p></div>
1460 * @result [ <div class="selected"><p>Hello Again</p></div> ]
1464 * @param String expr An expression to filter the parents with
1466 parent: "a.parentNode",
1469 * Get a set of elements containing the unique ancestors of the matched
1472 * @example $("span").ancestors()
1473 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
1474 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
1481 * Get a set of elements containing the unique ancestors of the matched
1482 * set of elements, and filtered by an expression.
1484 * @example $("span").ancestors("p")
1485 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
1486 * @result [ <p><span>Hello</span></p> ]
1490 * @param String expr An expression to filter the ancestors with
1492 ancestors: jQuery.parents,
1495 * A synonym for ancestors
1497 parents: jQuery.parents,
1500 * Get a set of elements containing the unique next siblings of each of the
1501 * matched set of elements.
1503 * It only returns the very next sibling, not all next siblings.
1505 * @example $("p").next()
1506 * @before <p>Hello</p><p>Hello Again</p><div><span>And Again</span></div>
1507 * @result [ <p>Hello Again</p>, <div><span>And Again</span></div> ]
1514 * Get a set of elements containing the unique next siblings of each of the
1515 * matched set of elements, and filtered by an expression.
1517 * It only returns the very next sibling, not all next siblings.
1519 * @example $("p").next(".selected")
1520 * @before <p>Hello</p><p class="selected">Hello Again</p><div><span>And Again</span></div>
1521 * @result [ <p class="selected">Hello Again</p> ]
1525 * @param String expr An expression to filter the next Elements with
1527 next: "jQuery.sibling(a).next",
1530 * Get a set of elements containing the unique previous siblings of each of the
1531 * matched set of elements.
1533 * It only returns the immediately previous sibling, not all previous siblings.
1535 * @example $("p").previous()
1536 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
1537 * @result [ <div><span>Hello Again</span></div> ]
1544 * Get a set of elements containing the unique previous siblings of each of the
1545 * matched set of elements, and filtered by an expression.
1547 * It only returns the immediately previous sibling, not all previous siblings.
1549 * @example $("p").previous("selected")
1550 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
1551 * @result [ <div><span>Hello</span></div> ]
1555 * @param String expr An expression to filter the previous Elements with
1557 prev: "jQuery.sibling(a).prev",
1560 * Get a set of elements containing all of the unique siblings of each of the
1561 * matched set of elements.
1563 * @example $("div").siblings()
1564 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
1565 * @result [ <p>Hello</p>, <p>And Again</p> ]
1572 * Get a set of elements containing all of the unique siblings of each of the
1573 * matched set of elements, and filtered by an expression.
1575 * @example $("div").siblings("selected")
1576 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
1577 * @result [ <p class="selected">Hello Again</p> ]
1581 * @param String expr An expression to filter the sibling Elements with
1583 siblings: jQuery.sibling
1588 * Displays each of the set of matched elements if they are hidden.
1590 * @example $("p").show()
1591 * @before <p style="display: none">Hello</p>
1592 * @result [ <p style="display: block">Hello</p> ]
1598 this.style.display = this.oldblock ? this.oldblock : "";
1599 if ( jQuery.css(this,"display") == "none" )
1600 this.style.display = "block";
1604 * Hides each of the set of matched elements if they are shown.
1606 * @example $("p").hide()
1607 * @before <p>Hello</p>
1608 * @result [ <p style="display: none">Hello</p> ]
1614 this.oldblock = jQuery.css(this,"display");
1615 if ( this.oldblock == "none" )
1616 this.oldblock = "block";
1617 this.style.display = "none";
1621 * Toggles each of the set of matched elements. If they are shown,
1622 * toggle makes them hidden. If they are hidden, toggle
1625 * @example $("p").toggle()
1626 * @before <p>Hello</p><p style="display: none">Hello Again</p>
1627 * @result [ <p style="display: none">Hello</p>, <p style="display: block">Hello Again</p> ]
1633 var d = jQuery.css(this,"display");
1634 $(this)[ !d || d == "none" ? "show" : "hide" ]();
1638 * Adds the specified class to each of the set of matched elements.
1640 * @example ("p").addClass("selected")
1641 * @before <p>Hello</p>
1642 * @result [ <p class="selected">Hello</p> ]
1646 * @param String class A CSS class to add to the elements
1648 addClass: function(c){
1649 jQuery.className.add(this,c);
1653 * The opposite of addClass. Removes the specified class from the
1654 * set of matched elements.
1656 * @example ("p").removeClass("selected")
1657 * @before <p class="selected">Hello</p>
1658 * @result [ <p>Hello</p> ]
1662 * @param String class A CSS class to remove from the elements
1664 removeClass: function(c){
1665 jQuery.className.remove(this,c);
1669 * Adds the specified class if it is present. Remove it if it is
1672 * @example ("p").toggleClass("selected")
1673 * @before <p>Hello</p><p class="selected">Hello Again</p>
1674 * @result [ <p class="selected">Hello</p>, <p>Hello Again</p> ]
1678 * @param String class A CSS class with which to toggle the elements
1680 toggleClass: function( c ){
1681 jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this,c);
1687 remove: function(a){
1688 if ( !a || jQuery.filter( [this], a ).r )
1689 this.parentNode.removeChild( this );
1693 * Removes all child nodes from the set of matched elements.
1695 * @example ("p").empty()
1696 * @before <p>Hello, <span>Person</span> <a href="#">and person</a></p>
1697 * @result [ <p></p> ]
1703 while ( this.firstChild )
1704 this.removeChild( this.firstChild );
1708 * Binds a particular event (like click) to a each of a set of match elements.
1710 * @example $("p").bind( "click", function() { alert("Hello"); } )
1711 * @before <p>Hello</p>
1712 * @result [ <p>Hello</p> ]
1714 * Cancel a default action and prevent it from bubbling by returning false
1715 * from your function.
1717 * @example $("form").bind( "submit", function() { return false; } )
1719 * Cancel a default action by using the preventDefault method.
1721 * @example $("form").bind( "submit", function() { e.preventDefault(); } )
1723 * Stop an event from bubbling by using the stopPropogation method.
1725 * @example $("form").bind( "submit", function() { e.stopPropogation(); } )
1729 * @param String type An event type
1730 * @param Function fn A function to bind to the event on each of the set of matched elements
1732 bind: function( type, fn ) {
1733 if ( fn.constructor == String )
1734 fn = new Function("e", ( !fn.indexOf(".") ? "$(this)" : "return " ) + fn);
1735 jQuery.event.add( this, type, fn );
1739 * The opposite of bind. Removes a bound event from each of a set of matched
1740 * elements. You must pass the identical function that was used in the original
1743 * @example $("p").unbind( "click", function() { alert("Hello"); } )
1744 * @before <p>Hello</p>
1745 * @result [ <p>Hello</p> ]
1749 * @param String type An event type
1750 * @param Function fn A function to unbind from the event on each of the set of matched elements
1752 unbind: function( type, fn ) {
1753 jQuery.event.remove( this, type, fn );
1757 * Trigger a particular event.
1759 * @example $("p").trigger("click")
1760 * @before <p>Hello</p>
1761 * @result [ <p>Hello</p> ]
1765 * @param String type An event type
1767 trigger: function( type, data ) {
1768 jQuery.event.trigger( type, data, this );