3 "": "m[2]=='*'||jQuery.nodeName(a,m[2])",
4 "#": "a.getAttribute('id')==m[2]",
12 last: "i==r.length-1",
17 "first-child": "a.parentNode.getElementsByTagName('*')[0]==a",
18 "last-child": "jQuery.nth(a.parentNode.lastChild,1,'previousSibling')==a",
19 "only-child": "!jQuery.nth(a.parentNode.lastChild,2,'previousSibling')",
22 parent: "a.firstChild",
23 empty: "!a.firstChild",
26 contains: "(a.textContent||a.innerText||'').indexOf(m[3])>=0",
29 visible: '"hidden"!=a.type&&jQuery.css(a,"display")!="none"&&jQuery.css(a,"visibility")!="hidden"',
30 hidden: '"hidden"==a.type||jQuery.css(a,"display")=="none"||jQuery.css(a,"visibility")=="hidden"',
33 enabled: "!a.disabled",
34 disabled: "a.disabled",
36 selected: "a.selected||jQuery.attr(a,'selected')",
39 text: "'text'==a.type",
40 radio: "'radio'==a.type",
41 checkbox: "'checkbox'==a.type",
42 file: "'file'==a.type",
43 password: "'password'==a.type",
44 submit: "'submit'==a.type",
45 image: "'image'==a.type",
46 reset: "'reset'==a.type",
47 button: '"button"==a.type||jQuery.nodeName(a,"button")',
48 input: "/input|select|textarea|button/i.test(a.nodeName)"
50 "[": "jQuery.find(m[2],a).length"
53 // The regular expressions that power the parsing engine
55 // Match: [@value='test'], [@foo]
56 /^\[ *(@)([\w-]+) *([!*$^~=]*) *('?"?)(.*?)\4 *\]/,
58 // Match: [div], [div p]
59 /^(\[)\s*(.*?(\[.*?\])?[^[]*?)\s*\]/,
61 // Match: :contains('foo')
62 /^(:)([\w-]+)\("?'?(.*?(\(.*?\))?[^(]*?)"?'?\)/,
64 // Match: :even, :last-chlid, #id, .class
65 new RegExp("^([:.#]*)(" +
66 ( jQuery.chars = jQuery.browser.safari && jQuery.browser.version < "3.0.0" ? "\\w" : "(?:[\\w\u0128-\uFFFF*_-]|\\\\.)" ) + "+)")
69 multiFilter: function( expr, elems, not ) {
72 while ( expr && expr != old ) {
74 var f = jQuery.filter( expr, elems, not );
75 expr = f.t.replace(/^\s*,\s*/, "" );
76 cur = not ? elems = f.r : jQuery.merge( cur, f.r );
84 * @type Array<Element>
88 find: function( t, context ) {
89 // Quickly handle non-string expressions
90 if ( typeof t != "string" )
93 // Make sure that the context is a DOM Element
94 if ( context && !context.nodeType )
97 // Set the correct context (if none is provided)
98 context = context || document;
100 // Handle the common XPath // expression
101 if ( !t.indexOf("//") ) {
102 context = context.documentElement;
103 t = t.substr(2,t.length);
105 // And the / root expression
106 } else if ( !t.indexOf("/") && !context.ownerDocument ) {
107 context = context.documentElement;
108 t = t.substr(1,t.length);
109 if ( t.indexOf("/") >= 1 )
110 t = t.substr(t.indexOf("/"),t.length);
113 // Initialize the search
114 var ret = [context], done = [], last;
116 // Continue while a selector expression exists, and while
117 // we're no longer looping upon ourselves
118 while ( t && last != t ) {
122 t = jQuery.trim(t).replace( /^\/\//, "" );
124 var foundToken = false;
126 // An attempt at speeding up child selectors that
127 // point to a specific element tag
128 var re = new RegExp("^[/>]\\s*(" + jQuery.chars + "+)");
132 var nodeName = m[1].toUpperCase();
134 // Perform our own iteration and filter
135 for ( var i = 0; ret[i]; i++ )
136 for ( var c = ret[i].firstChild; c; c = c.nextSibling )
137 if ( c.nodeType == 1 && (nodeName == "*" || c.nodeName.toUpperCase() == nodeName.toUpperCase()) )
141 t = t.replace( re, "" );
142 if ( t.indexOf(" ") == 0 ) continue;
145 re = /^((\/?\.\.)|([>\/+~]))\s*([a-z]*)/i;
147 if ( (m = re.exec(t)) != null ) {
150 var nodeName = m[4], mergeNum = jQuery.mergeNum++;
153 for ( var j = 0, rl = ret.length; j < rl; j++ )
154 if ( m.indexOf("..") < 0 ) {
155 var n = m == "~" || m == "+" ? ret[j].nextSibling : ret[j].firstChild;
156 for ( ; n; n = n.nextSibling )
157 if ( n.nodeType == 1 ) {
158 if ( m == "~" && n.mergeNum == mergeNum ) break;
160 if (!nodeName || n.nodeName.toUpperCase() == nodeName.toUpperCase() ) {
161 if ( m == "~" ) n.mergeNum = mergeNum;
165 if ( m == "+" ) break;
168 r.push( ret[j].parentNode );
172 // And remove the token
173 t = jQuery.trim( t.replace( re, "" ) );
178 // See if there's still an expression, and that we haven't already
180 if ( t && !foundToken ) {
181 // Handle multiple expressions
182 if ( !t.indexOf(",") ) {
183 // Clean the result set
184 if ( context == ret[0] ) ret.shift();
186 // Merge the result sets
187 done = jQuery.merge( done, ret );
192 // Touch up the selector string
193 t = " " + t.substr(1,t.length);
196 // Optomize for the case nodeName#idName
197 var re2 = new RegExp("^(" + jQuery.chars + "+)(#)(" + jQuery.chars + "+)");
200 // Re-organize the results, so that they're consistent
202 m = [ 0, m[2], m[3], m[1] ];
205 // Otherwise, do a traditional filter check for
206 // ID, class, and element selectors
207 re2 = new RegExp("^([#.]?)(" + jQuery.chars + "*)");
211 m[2] = m[2].replace(/\\/g, "");
213 var elem = ret[ret.length-1];
215 // Try to do a global search by ID, where we can
216 if ( m[1] == "#" && elem && elem.getElementById ) {
217 // Optimization for HTML document case
218 var oid = elem.getElementById(m[2]);
220 // Do a quick check for the existence of the actual ID attribute
221 // to avoid selecting by the name attribute in IE
222 // also check to insure id is a string to avoid selecting an element with the name of 'id' inside a form
223 if ( (jQuery.browser.msie||jQuery.browser.opera) && oid && typeof oid.id == "string" && oid.id != m[2] )
224 oid = jQuery('[@id="'+m[2]+'"]', elem)[0];
226 // Do a quick check for node name (where applicable) so
227 // that div#foo searches will be really fast
228 ret = r = oid && (!m[3] || jQuery.nodeName(oid, m[3])) ? [oid] : [];
230 // We need to find all descendant elements
231 for ( var i = 0; ret[i]; i++ ) {
232 // Grab the tag name being searched for
233 var tag = m[1] != "" || m[0] == "" ? "*" : m[2];
235 // Handle IE7 being really dumb about <object>s
236 if ( tag == "*" && ret[i].nodeName.toLowerCase() == "object" )
239 r = jQuery.merge( r, ret[i].getElementsByTagName( tag ));
242 // It's faster to filter by class and be done with it
244 r = jQuery.classFilter( r, m[2] );
246 // Same with ID filtering
250 // Try to find the element with the ID
251 for ( var i = 0; r[i]; i++ )
252 if ( r[i].getAttribute("id") == m[2] ) {
263 t = t.replace( re2, "" );
268 // If a selector string still exists
270 // Attempt to filter it
271 var val = jQuery.filter(t,r);
273 t = jQuery.trim(val.t);
277 // An error occurred with the selector;
278 // just return an empty set instead
282 // Remove the root context
283 if ( ret && context == ret[0] )
286 // And combine the results
287 done = jQuery.merge( done, ret );
292 classFilter: function(r,m,not){
295 for ( var i = 0; r[i]; i++ ) {
296 var pass = (" " + r[i].className + " ").indexOf( m ) >= 0;
297 if ( !not && pass || not && !pass )
303 filter: function(t,r,not) {
306 // Look for common filter expressions
307 while ( t && t != last ) {
310 var p = jQuery.parse, m;
312 for ( var i = 0; p[i]; i++ ) {
316 // Remove what we just matched
317 t = t.substring( m[0].length );
319 m[2] = m[2].replace(/\\/g, "");
327 // :not() is a special case that can be optimized by
328 // keeping it out of the expression list
329 if ( m[1] == ":" && m[2] == "not" )
330 r = jQuery.filter(m[3], r, true).r;
332 // We can get a big speed boost by filtering by class here
333 else if ( m[1] == "." )
334 r = jQuery.classFilter(r, m[2], not);
336 else if ( m[1] == "@" ) {
337 var tmp = [], type = m[3];
339 for ( var i = 0, rl = r.length; i < rl; i++ ) {
340 var a = r[i], z = a[ jQuery.props[m[2]] || m[2] ];
342 if ( z == null || /href|src/.test(m[2]) )
343 z = jQuery.attr(a,m[2]) || '';
345 if ( (type == "" && !!z ||
346 type == "=" && z == m[5] ||
347 type == "!=" && z != m[5] ||
348 type == "^=" && z && !z.indexOf(m[5]) ||
349 type == "$=" && z.substr(z.length - m[5].length) == m[5] ||
350 (type == "*=" || type == "~=") && z.indexOf(m[5]) >= 0) ^ not )
356 // We can get a speed boost by handling nth-child here
357 } else if ( m[1] == ":" && m[2] == "nth-child" ) {
358 var num = jQuery.mergeNum++, tmp = [],
359 test = /(\d*)n\+?(\d*)/.exec(
360 m[3] == "even" && "2n" || m[3] == "odd" && "2n+1" ||
361 !/\D/.test(m[3]) && "n+" + m[3] || m[3]),
362 first = (test[1] || 1) - 0, last = test[2] - 0;
364 for ( var i = 0, rl = r.length; i < rl; i++ ) {
365 var node = r[i], parentNode = node.parentNode;
367 if ( num != parentNode.mergeNum ) {
370 for ( var n = parentNode.firstChild; n; n = n.nextSibling )
371 if ( n.nodeType == 1 )
374 parentNode.mergeNum = num;
380 if ( last == 0 || node.nodeIndex == last )
382 } else if ( (node.nodeIndex + last) % first == 0 )
391 // Otherwise, find the expression to execute
393 var f = jQuery.expr[m[1]];
394 if ( typeof f != "string" )
395 f = jQuery.expr[m[1]][m[2]];
397 // Build a custom macro to enclose it
398 eval("f = function(a,i){return " + f + "}");
400 // Execute it against the current filter
401 r = jQuery.grep( r, f, not );
405 // Return an array of filtered elements (r)
406 // and the modified expression string (t)
407 return { r: r, t: t };
411 * All ancestors of a given element.
415 * @type Array<Element>
416 * @param Element elem The element to find the ancestors of.
417 * @cat DOM/Traversing
419 parents: function( elem ){
421 var cur = elem.parentNode;
422 while ( cur && cur != document ) {
424 cur = cur.parentNode;
430 * A handy, and fast, way to traverse in a particular direction and find
431 * a specific element.
436 * @param DOMElement cur The element to search from.
437 * @param String|Number num The Nth result to match. Can be a number or a string (like 'even' or 'odd').
438 * @param String dir The direction to move in (pass in something like 'previousSibling' or 'nextSibling').
439 * @cat DOM/Traversing
441 nth: function(cur,result,dir,elem){
442 result = result || 1;
445 for ( ; cur; cur = cur[dir] )
446 if ( cur.nodeType == 1 && ++num == result )
453 * All elements on a specified axis.
458 * @param Element elem The element to find all the siblings of (including itself).
459 * @cat DOM/Traversing
461 sibling: function( n, elem ) {
464 for ( ; n; n = n.nextSibling ) {
465 if ( n.nodeType == 1 && (!elem || n != elem) )