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: '"hidden"!=a.type&&jQuery.css(a,"display")!="none"&&jQuery.css(a,"visibility")!="hidden"',
31 hidden: '"hidden"==a.type||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: "'text'==a.type",
41 radio: "'radio'==a.type",
42 checkbox: "'checkbox'==a.type",
43 file: "'file'==a.type",
44 password: "'password'==a.type",
45 submit: "'submit'==a.type",
46 image: "'image'==a.type",
47 reset: "'reset'==a.type",
48 button: '"button"==a.type||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: "var z=a[m[3]];if(!z||/href|src/.test(m[3]))z=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 /^\[ *(@)([\w-]+) *([!*$^=]*) *('?"?)(.*?)\4 *\]/,
72 // Match: [div], [div p]
73 /^(\[)\s*(.*?(\[.*?\])?[^[]*?)\s*\]/,
75 // Match: :contains('foo')
76 /^(:)([\w-]+)\("?'?(.*?(\(.*?\))?[^(]*?)"?'?\)/,
78 // Match: :even, :last-chlid, #id, .class
79 new RegExp("^([:.#]*)(" +
80 ( jQuery.chars = "(?:[\\w\u0128-\uFFFF*_-]|\\\\.)" ) + "+)")
84 /^(\/?\.\.)/, "a.parentNode",
85 /^(>|\/)/, "jQuery.sibling(a.firstChild)",
86 /^(\+)/, "jQuery.nth(a,2,'nextSibling')",
88 var s = jQuery.sibling(a.parentNode.firstChild);
89 return s.slice(jQuery.inArray(a,s) + 1);
93 multiFilter: function( expr, elems, not ) {
96 while ( expr && expr != old ) {
98 var f = jQuery.filter( expr, elems, not );
99 expr = f.t.replace(/^\s*,\s*/, "" );
100 cur = not ? elems = f.r : jQuery.merge( cur, f.r );
108 * @type Array<Element>
112 find: function( t, context ) {
113 // Quickly handle non-string expressions
114 if ( typeof t != "string" )
117 // Make sure that the context is a DOM Element
118 if ( context && !context.nodeType )
121 // Set the correct context (if none is provided)
122 context = context || document;
124 // Handle the common XPath // expression
125 if ( !t.indexOf("//") ) {
126 context = context.documentElement;
127 t = t.substr(2,t.length);
129 // And the / root expression
130 } else if ( !t.indexOf("/") && !context.ownerDocument ) {
131 context = context.documentElement;
132 t = t.substr(1,t.length);
133 if ( t.indexOf("/") >= 1 )
134 t = t.substr(t.indexOf("/"),t.length);
137 // Initialize the search
138 var ret = [context], done = [], last;
140 // Continue while a selector expression exists, and while
141 // we're no longer looping upon ourselves
142 while ( t && last != t ) {
146 t = jQuery.trim(t).replace( /^\/\//, "" );
148 var foundToken = false;
150 // An attempt at speeding up child selectors that
151 // point to a specific element tag
152 var re = new RegExp("^[/>]\\s*(" + jQuery.chars + "+)");
156 // Perform our own iteration and filter
157 for ( var i = 0; ret[i]; i++ )
158 for ( var c = ret[i].firstChild; c; c = c.nextSibling )
159 if ( c.nodeType == 1 && ( m[1] == "*" || jQuery.nodeName(c, 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, tl = jQuery.token.length; i < tl; i += 2 ) {
169 // Attempt to match each, individual, token in
170 // the specified order
171 var re = jQuery.token[i], fn = jQuery.token[i+1];
174 // If the token match was found
176 // Map it against the token's handler
177 r = ret = jQuery.map( ret, jQuery.isFunction( fn ) ?
178 fn : new Function( "a", "return " + fn ) );
180 // And remove the token
181 t = jQuery.trim( t.replace( re, "" ) );
188 // See if there's still an expression, and that we haven't already
190 if ( t && !foundToken ) {
191 // Handle multiple expressions
192 if ( !t.indexOf(",") ) {
193 // Clean the result set
194 if ( context == ret[0] ) ret.shift();
196 // Merge the result sets
197 done = jQuery.merge( done, ret );
202 // Touch up the selector string
203 t = " " + t.substr(1,t.length);
206 // Optomize for the case nodeName#idName
207 var re2 = new RegExp("^(" + jQuery.chars + "+)(#)(" + jQuery.chars + "+)");
210 // Re-organize the results, so that they're consistent
212 m = [ 0, m[2], m[3], m[1] ];
215 // Otherwise, do a traditional filter check for
216 // ID, class, and element selectors
217 re2 = new RegExp("^([#.]?)(" + jQuery.chars + "*)");
221 m[2] = m[2].replace(/\\/g, "");
223 var elem = ret[ret.length-1];
225 // Try to do a global search by ID, where we can
226 if ( m[1] == "#" && elem && elem.getElementById ) {
227 // Optimization for HTML document case
228 var oid = elem.getElementById(m[2]);
230 // Do a quick check for the existence of the actual ID attribute
231 // to avoid selecting by the name attribute in IE
232 // also check to insure id is a string to avoid selecting an element with the name of 'id' inside a form
233 if ( (jQuery.browser.msie||jQuery.browser.opera) && oid && typeof oid.id == "string" && oid.id != m[2] )
234 oid = jQuery('[@id="'+m[2]+'"]', elem)[0];
236 // Do a quick check for node name (where applicable) so
237 // that div#foo searches will be really fast
238 ret = r = oid && (!m[3] || jQuery.nodeName(oid, m[3])) ? [oid] : [];
240 // We need to find all descendant elements
241 for ( var i = 0; ret[i]; i++ ) {
242 // Grab the tag name being searched for
243 var tag = m[1] != "" || m[0] == "" ? "*" : m[2];
245 // Handle IE7 being really dumb about <object>s
246 if ( tag == "*" && ret[i].nodeName.toLowerCase() == "object" )
249 r = jQuery.merge( r, ret[i].getElementsByTagName( tag ));
252 // It's faster to filter by class and be done with it
254 r = jQuery.classFilter( r, m[2] );
256 // Same with ID filtering
260 // Try to find the element with the ID
261 for ( var i = 0; r[i]; i++ )
262 if ( r[i].getAttribute("id") == m[2] ) {
273 t = t.replace( re2, "" );
278 // If a selector string still exists
280 // Attempt to filter it
281 var val = jQuery.filter(t,r);
283 t = jQuery.trim(val.t);
287 // An error occurred with the selector;
288 // just return an empty set instead
292 // Remove the root context
293 if ( ret && context == ret[0] )
296 // And combine the results
297 done = jQuery.merge( done, ret );
302 classFilter: function(r,m,not){
305 for ( var i = 0; r[i]; i++ ) {
306 var pass = (" " + r[i].className + " ").indexOf( m ) >= 0;
307 if ( !not && pass || not && !pass )
313 filter: function(t,r,not) {
316 // Look for common filter expressions
317 while ( t && t != last ) {
320 var p = jQuery.parse, m;
322 for ( var i = 0; p[i]; i++ ) {
326 // Remove what we just matched
327 t = t.substring( m[0].length );
329 // Re-organize the first match
330 if ( jQuery.expr[ m[1] ]._resort )
331 m = jQuery.expr[ m[1] ]._resort( m );
333 m[2] = m[2].replace(/\\/g, "");
342 // :not() is a special case that can be optimized by
343 // keeping it out of the expression list
344 if ( m[1] == ":" && m[2] == "not" )
345 r = jQuery.filter(m[3], r, true).r;
347 // We can get a big speed boost by filtering by class here
348 else if ( m[1] == "." )
349 r = jQuery.classFilter(r, m[2], not);
351 // Otherwise, find the expression to execute
353 var f = jQuery.expr[m[1]];
354 if ( typeof f != "string" )
355 f = jQuery.expr[m[1]][m[2]];
357 // Build a custom macro to enclose it
358 eval("f = function(a,i){" +
359 ( jQuery.expr[ m[1] ]._prefix || "" ) +
360 "return " + f + "}");
362 // Execute it against the current filter
363 r = jQuery.grep( r, f, not );
367 // Return an array of filtered elements (r)
368 // and the modified expression string (t)
369 return { r: r, t: t };
373 * All ancestors of a given element.
377 * @type Array<Element>
378 * @param Element elem The element to find the ancestors of.
379 * @cat DOM/Traversing
381 parents: function( elem ){
383 var cur = elem.parentNode;
384 while ( cur && cur != document ) {
386 cur = cur.parentNode;
392 * A handy, and fast, way to traverse in a particular direction and find
393 * a specific element.
398 * @param DOMElement cur The element to search from.
399 * @param String|Number num The Nth result to match. Can be a number or a string (like 'even' or 'odd').
400 * @param String dir The direction to move in (pass in something like 'previousSibling' or 'nextSibling').
401 * @cat DOM/Traversing
403 nth: function(cur,result,dir,elem){
404 result = result || 1;
406 for ( ; cur; cur = cur[dir] ) {
407 if ( cur.nodeType == 1 ) num++;
408 if ( num == result || result == "even" && num % 2 == 0 && num > 1 && cur == elem ||
409 result == "odd" && num % 2 == 1 && cur == elem ) break;
415 * All elements on a specified axis.
420 * @param Element elem The element to find all the siblings of (including itself).
421 * @cat DOM/Traversing
423 sibling: function( n, elem ) {
426 for ( ; n; n = n.nextSibling ) {
427 if ( n.nodeType == 1 && (!elem || n != elem) )