3 "": "m[2]=='*'||jQuery.nodeName(a,m[2])",
4 "#": "a.getAttribute('id')==m[2]",
12 last: "i==r.length-1",
17 "nth-child": "jQuery.nth(a.parentNode.firstChild,m[3],'nextSibling',a)==a",
18 "first-child": "jQuery.nth(a.parentNode.firstChild,1,'nextSibling')==a",
19 "last-child": "jQuery.nth(a.parentNode.lastChild,1,'previousSibling')==a",
20 "only-child": "jQuery.sibling(a.parentNode.firstChild).length==1",
23 parent: "a.firstChild",
24 empty: "!a.firstChild",
27 contains: "jQuery.fn.text.apply([a]).indexOf(m[3])>=0",
30 visible: 'a.type!="hidden"&&jQuery.css(a,"display")!="none"&&jQuery.css(a,"visibility")!="hidden"',
31 hidden: 'a.type=="hidden"||jQuery.css(a,"display")=="none"||jQuery.css(a,"visibility")=="hidden"',
34 enabled: "!a.disabled",
35 disabled: "a.disabled",
37 selected: "a.selected||jQuery.attr(a,'selected')",
40 text: "a.type=='text'",
41 radio: "a.type=='radio'",
42 checkbox: "a.type=='checkbox'",
43 file: "a.type=='file'",
44 password: "a.type=='password'",
45 submit: "a.type=='submit'",
46 image: "a.type=='image'",
47 reset: "a.type=='reset'",
48 button: 'a.type=="button"||jQuery.nodeName(a,"button")',
49 input: "/input|select|textarea|button/i.test(a.nodeName)"
51 ".": "jQuery.className.has(a,m[2])",
55 "^=": "z&&!z.indexOf(m[4])",
56 "$=": "z&&z.substr(z.length - m[4].length,m[4].length)==m[4]",
57 "*=": "z&&z.indexOf(m[4])>=0",
60 return ["", m[1], m[3], m[2], m[5]];
62 _prefix: "z=a[m[3]]||jQuery.attr(a,m[3]);"
64 "[": "jQuery.find(m[2],a).length"
67 // The regular expressions that power the parsing engine
69 // Match: [@value='test'], [@foo]
70 /^\[ *(@)([a-z0-9_-]*) *([!*$^=]*) *('?"?)(.*?)\4 *\]/i,
72 // Match: [div], [div p]
73 /^(\[)\s*(.*?(\[.*?\])?[^[]*?)\s*\]/,
75 // Match: :contains('foo')
76 /^(:)([a-z0-9_-]*)\("?'?(.*?(\(.*?\))?[^(]*?)"?'?\)/i,
78 // Match: :even, :last-chlid
79 /^([:.#]*)([a-z0-9_*-]*)/i
83 /^(\/?\.\.)/, "a.parentNode",
84 /^(>|\/)/, "jQuery.sibling(a.firstChild)",
85 /^(\+)/, "jQuery.nth(a,2,'nextSibling')",
87 var s = jQuery.sibling(a.parentNode.firstChild);
88 return s.slice(jQuery.inArray(a,s) + 1);
92 multiFilter: function( expr, elems, not ) {
95 while ( expr && expr != old ) {
97 var f = jQuery.filter( expr, elems, not );
98 expr = f.t.replace(/^\s*,\s*/, "" );
99 cur = not ? elems = f.r : jQuery.merge( cur, f.r );
107 * @type Array<Element>
111 find: function( t, context ) {
112 // Quickly handle non-string expressions
113 if ( typeof t != "string" )
116 // Make sure that the context is a DOM Element
117 if ( context && !context.nodeType )
120 // Set the correct context (if none is provided)
121 context = context || document;
123 // Handle the common XPath // expression
124 if ( !t.indexOf("//") ) {
125 context = context.documentElement;
126 t = t.substr(2,t.length);
128 // And the / root expression
129 } else if ( !t.indexOf("/") ) {
130 context = context.documentElement;
131 t = t.substr(1,t.length);
132 if ( t.indexOf("/") >= 1 )
133 t = t.substr(t.indexOf("/"),t.length);
136 // Initialize the search
137 var ret = [context], done = [], last = null;
139 // Continue while a selector expression exists, and while
140 // we're no longer looping upon ourselves
141 while ( t && last != t ) {
145 t = jQuery.trim(t).replace( /^\/\//i, "" );
147 var foundToken = false;
149 // An attempt at speeding up child selectors that
150 // point to a specific element tag
151 var re = /^[\/>]\s*([a-z0-9*-]+)/i;
155 // Perform our own iteration and filter
156 jQuery.each( ret, function(){
157 for ( var c = this.firstChild; c; c = c.nextSibling )
158 if ( c.nodeType == 1 && ( jQuery.nodeName(c, m[1]) || m[1] == "*" ) )
163 t = t.replace( re, "" );
164 if ( t.indexOf(" ") == 0 ) continue;
167 // Look for pre-defined expression tokens
168 for ( var i = 0; i < jQuery.token.length; i += 2 ) {
169 // Attempt to match each, individual, token in
170 // the specified order
171 var re = jQuery.token[i];
174 // If the token match was found
176 // Map it against the token's handler
177 r = ret = jQuery.map( ret, jQuery.isFunction( jQuery.token[i+1] ) ?
179 function(a){ return eval(jQuery.token[i+1]); });
181 // And remove the token
182 t = jQuery.trim( t.replace( re, "" ) );
189 // See if there's still an expression, and that we haven't already
191 if ( t && !foundToken ) {
192 // Handle multiple expressions
193 if ( !t.indexOf(",") ) {
194 // Clean the result set
195 if ( ret[0] == context ) ret.shift();
197 // Merge the result sets
198 jQuery.merge( done, ret );
203 // Touch up the selector string
204 t = " " + t.substr(1,t.length);
207 // Optomize for the case nodeName#idName
208 var re2 = /^([a-z0-9_-]+)(#)([a-z0-9\\*_-]*)/i;
211 // Re-organize the results, so that they're consistent
213 m = [ 0, m[2], m[3], m[1] ];
216 // Otherwise, do a traditional filter check for
217 // ID, class, and element selectors
218 re2 = /^([#.]?)([a-z0-9\\*_-]*)/i;
222 // Try to do a global search by ID, where we can
223 if ( m[1] == "#" && ret[ret.length-1].getElementById ) {
224 // Optimization for HTML document case
225 var oid = ret[ret.length-1].getElementById(m[2]);
227 // Do a quick check for node name (where applicable) so
228 // that div#foo searches will be really fast
230 (!m[3] || jQuery.nodeName(oid, m[3])) ? [oid] : [];
233 // Pre-compile a regular expression to handle class searches
235 var rec = new RegExp("(^|\\s)" + m[2] + "(\\s|$)");
237 // We need to find all descendant elements, it is more
238 // efficient to use getAll() when we are already further down
239 // the tree - we try to recognize that here
240 jQuery.each( ret, function(){
241 // Grab the tag name being searched for
242 var tag = m[1] != "" || m[0] == "" ? "*" : m[2];
244 // Handle IE7 being really dumb about <object>s
245 if ( jQuery.nodeName(this, "object") && tag == "*" )
249 m[1] != "" && ret.length != 1 ?
250 jQuery.getAll( this, [], m[1], m[2], rec ) :
251 this.getElementsByTagName( tag )
255 // It's faster to filter by class and be done with it
256 if ( m[1] == "." && ret.length == 1 )
257 r = jQuery.grep( r, function(e) {
258 return rec.test(e.className);
261 // Same with ID filtering
262 if ( m[1] == "#" && ret.length == 1 ) {
263 // Remember, then wipe out, the result set
267 // Then try to find the element with the ID
268 jQuery.each( tmp, function(){
269 if ( this.getAttribute("id") == m[2] ) {
279 t = t.replace( re2, "" );
284 // If a selector string still exists
286 // Attempt to filter it
287 var val = jQuery.filter(t,r);
289 t = jQuery.trim(val.t);
293 // Remove the root context
294 if ( ret && ret[0] == context ) ret.shift();
296 // And combine the results
297 jQuery.merge( done, ret );
302 filter: function(t,r,not) {
303 // Look for common filter expressions
304 while ( t && /^[a-z[({<*:.#]/i.test(t) ) {
306 var p = jQuery.parse, m;
308 jQuery.each( p, function(i,re){
310 // Look for, and replace, string-like sequences
311 // and finally build a regexp out of it
315 // Remove what we just matched
316 t = t.substring( m[0].length );
318 // Re-organize the first match
319 if ( jQuery.expr[ m[1] ]._resort )
320 m = jQuery.expr[ m[1] ]._resort( m );
326 // :not() is a special case that can be optimized by
327 // keeping it out of the expression list
328 if ( m[1] == ":" && m[2] == "not" )
329 r = jQuery.filter(m[3], r, true).r;
331 // Handle classes as a special case (this will help to
332 // improve the speed, as the regexp will only be compiled once)
333 else if ( m[1] == "." ) {
335 var re = new RegExp("(^|\\s)" + m[2] + "(\\s|$)");
336 r = jQuery.grep( r, function(e){
337 return re.test(e.className || "");
340 // Otherwise, find the expression to execute
342 var f = jQuery.expr[m[1]];
343 if ( typeof f != "string" )
344 f = jQuery.expr[m[1]][m[2]];
346 // Build a custom macro to enclose it
347 eval("f = function(a,i){" +
348 ( jQuery.expr[ m[1] ]._prefix || "" ) +
349 "return " + f + "}");
351 // Execute it against the current filter
352 r = jQuery.grep( r, f, not );
356 // Return an array of filtered elements (r)
357 // and the modified expression string (t)
358 return { r: r, t: t };
361 getAll: function( o, r, token, name, re ) {
362 for ( var s = o.firstChild; s; s = s.nextSibling )
363 if ( s.nodeType == 1 ) {
367 add = s.className && re.test(s.className);
368 else if ( token == "#" )
369 add = s.getAttribute("id") == name;
374 if ( token == "#" && r.length ) break;
377 jQuery.getAll( s, r, token, name, re );
384 * All ancestors of a given element.
388 * @type Array<Element>
389 * @param Element elem The element to find the ancestors of.
390 * @cat DOM/Traversing
392 parents: function( elem ){
394 var cur = elem.parentNode;
395 while ( cur && cur != document ) {
397 cur = cur.parentNode;
403 * A handy, and fast, way to traverse in a particular direction and find
404 * a specific element.
409 * @param DOMElement cur The element to search from.
410 * @param String|Number num The Nth result to match. Can be a number or a string (like 'even' or 'odd').
411 * @param String dir The direction to move in (pass in something like 'previousSibling' or 'nextSibling').
412 * @cat DOM/Traversing
414 nth: function(cur,result,dir,elem){
415 result = result || 1;
417 for ( ; cur; cur = cur[dir] ) {
418 if ( cur.nodeType == 1 ) num++;
419 if ( num == result || result == "even" && num % 2 == 0 && num > 1 && cur == elem ||
420 result == "odd" && num % 2 == 1 && cur == elem ) return cur;
425 * All elements on a specified axis.
430 * @param Element elem The element to find all the siblings of (including itself).
431 * @cat DOM/Traversing
433 sibling: function( n, elem ) {
436 for ( ; n; n = n.nextSibling ) {
437 if ( n.nodeType == 1 && (!elem || n != elem) )