3 "": "m[2]== '*'||a.nodeName.toUpperCase()==m[2].toUpperCase()",
4 "#": "a.getAttribute('id')==m[2]",
12 last: "i==r.length-1",
17 "nth-child": "jQuery.nth(a.parentNode.firstChild,m[3],'nextSibling')==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'||a.nodeName=='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 "\\[ *(@)S *([!*$^=]*) *('?\"?)(.*?)\\4 *\\]",
72 // Match: [div], [div p]
73 "(\\[)\\s*(.*?(\\[.*?\\])?[^[]*?)\\s*\\]",
75 // Match: :contains('foo')
76 "(:)S\\(\"?'?(.*?(\\(.*?\\))?[^(]*?)\"?'?\\)",
78 // Match: :even, :last-chlid
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(0, jQuery.inArray(a,s));
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 for ( var i = 0, rl = ret.length; i < rl; i++ )
157 for ( var c = ret[i].firstChild; c; c = c.nextSibling )
158 if ( c.nodeType == 1 && ( c.nodeName == m[1].toUpperCase() || m[1] == "*" ) )
162 t = jQuery.trim( t.replace( re, "" ) );
165 // Look for pre-defined expression tokens
166 for ( var i = 0; i < jQuery.token.length; i += 2 ) {
167 // Attempt to match each, individual, token in
168 // the specified order
169 var re = new RegExp("^(" + jQuery.token[i] + ")");
172 // If the token match was found
174 // Map it against the token's handler
175 r = ret = jQuery.map( ret, jQuery.token[i+1].constructor == Function ?
177 function(a){ return eval(jQuery.token[i+1]); });
179 // And remove the token
180 t = jQuery.trim( t.replace( re, "" ) );
187 // See if there's still an expression, and that we haven't already
189 if ( t && !foundToken ) {
190 // Handle multiple expressions
191 if ( !t.indexOf(",") || !t.indexOf("|") ) {
192 // Clean teh result set
193 if ( ret[0] == context ) ret.shift();
195 // Merge the result sets
196 jQuery.merge( done, ret );
201 // Touch up the selector string
202 t = " " + t.substr(1,t.length);
205 // Optomize for the case nodeName#idName
206 var re2 = /^([a-z0-9_-]+)(#)([a-z0-9\\*_-]*)/i;
209 // Re-organize the results, so that they're consistent
211 m = [ 0, m[2], m[3], m[1] ];
214 // Otherwise, do a traditional filter check for
215 // ID, class, and element selectors
216 re2 = /^([#.]?)([a-z0-9\\*_-]*)/i;
220 // Try to do a global search by ID, where we can
221 if ( m[1] == "#" && ret[ret.length-1].getElementById ) {
222 // Optimization for HTML document case
223 var oid = ret[ret.length-1].getElementById(m[2]);
225 // Do a quick check for node name (where applicable) so
226 // that div#foo searches will be really fast
228 (!m[3] || oid.nodeName == m[3].toUpperCase()) ? [oid] : [];
231 // Pre-compile a regular expression to handle class searches
233 var rec = new RegExp("(^|\\s)" + m[2] + "(\\s|$)");
235 // We need to find all descendant elements, it is more
236 // efficient to use getAll() when we are already further down
237 // the tree - we try to recognize that here
238 for ( var i = 0, rl = ret.length; i < rl; i++ )
240 m[1] != "" && ret.length != 1 ?
241 jQuery.getAll( ret[i], [], m[1], m[2], rec ) :
242 ret[i].getElementsByTagName( m[1] != "" || m[0] == "" ? "*" : m[2] )
245 // It's faster to filter by class and be done with it
246 if ( m[1] == "." && ret.length == 1 )
247 r = jQuery.grep( r, function(e) {
248 return rec.test(e.className);
251 // Same with ID filtering
252 if ( m[1] == "#" && ret.length == 1 ) {
253 // Remember, then wipe out, the result set
257 // Then try to find the element with the ID
258 for ( var i = 0, tl = tmp.length; i < tl; i++ )
259 if ( tmp[i].getAttribute("id") == m[2] ) {
268 t = t.replace( re2, "" );
273 // If a selector string still exists
275 // Attempt to filter it
276 var val = jQuery.filter(t,r);
278 t = jQuery.trim(val.t);
282 // Remove the root context
283 if ( ret && ret[0] == context ) ret.shift();
285 // And combine the results
286 jQuery.merge( done, ret );
291 filter: function(t,r,not) {
292 // Look for common filter expressions
293 while ( t && /^[a-z[({<*:.#]/i.test(t) ) {
295 var p = jQuery.parse;
297 for ( var i = 0, pl = p.length; i < pl; i++ ) {
299 // Look for, and replace, string-like sequences
300 // and finally build a regexp out of it
302 "^" + p[i].replace("S", "([a-z*_-][a-z0-9_-]*)"), "i" );
304 var m = re.exec( t );
307 // Re-organize the first match
308 if ( jQuery.expr[ m[1] ]._resort )
309 m = jQuery.expr[ m[1] ]._resort( m );
311 // Remove what we just matched
312 t = t.replace( re, "" );
318 // :not() is a special case that can be optimized by
319 // keeping it out of the expression list
320 if ( m[1] == ":" && m[2] == "not" )
321 r = jQuery.filter(m[3], r, true).r;
323 // Handle classes as a special case (this will help to
324 // improve the speed, as the regexp will only be compiled once)
325 else if ( m[1] == "." ) {
327 var re = new RegExp("(^|\\s)" + m[2] + "(\\s|$)");
328 r = jQuery.grep( r, function(e){
329 return re.test(e.className || '');
332 // Otherwise, find the expression to execute
334 var f = jQuery.expr[m[1]];
335 if ( typeof f != "string" )
336 f = jQuery.expr[m[1]][m[2]];
338 // Build a custom macro to enclose it
339 eval("f = function(a,i){" +
340 ( jQuery.expr[ m[1] ]._prefix || "" ) +
341 "return " + f + "}");
343 // Execute it against the current filter
344 r = jQuery.grep( r, f, not );
348 // Return an array of filtered elements (r)
349 // and the modified expression string (t)
350 return { r: r, t: t };
353 getAll: function( o, r, token, name, re ) {
354 for ( var s = o.firstChild; s; s = s.nextSibling )
355 if ( s.nodeType == 1 ) {
359 add = s.className && re.test(s.className);
360 else if ( token == "#" )
361 add = s.getAttribute('id') == name;
366 if ( token == "#" && r.length ) break;
369 jQuery.getAll( s, r, token, name, re );
376 * All ancestors of a given element.
380 * @type Array<Element>
381 * @param Element elem The element to find the ancestors of.
382 * @cat DOM/Traversing
384 parents: function( elem ){
386 var cur = elem.parentNode;
387 while ( cur && cur != document ) {
389 cur = cur.parentNode;
395 * A handy, and fast, way to traverse in a particular direction and find
396 * a specific element.
401 * @param DOMElement cur The element to search from.
402 * @param Number|String num The Nth result to match. Can be a number or a string (like 'even' or 'odd').
403 * @param String dir The direction to move in (pass in something like 'previousSibling' or 'nextSibling').
404 * @cat DOM/Traversing
406 nth: function(cur,result,dir){
407 result = result || 1;
409 for ( ; cur; cur = cur[dir] ) {
410 if ( cur.nodeType == 1 ) num++;
411 if ( num == result || result == "even" && num % 2 == 0 && num > 1 ||
412 result == "odd" && num % 2 == 1 ) return cur;
417 * All elements on a specified axis.
422 * @param Element elem The element to find all the siblings of (including itself).
423 * @cat DOM/Traversing
425 sibling: function( n, elem ) {
428 for ( ; n; n = n.nextSibling ) {
429 if ( n.nodeType == 1 && (!elem || n != elem) )