2 var chars = jQuery.browser.safari && parseInt(jQuery.browser.version) < 417 ?
4 "(?:[\\w\u0128-\uFFFF*_-]|\\\\.)",
5 quickChild = new RegExp("^>\\s*(" + chars + "+)"),
6 quickID = new RegExp("^(" + chars + "+)(#)(" + chars + "+)"),
7 quickClass = new RegExp("^([#.]?)(" + chars + "*)");
11 "": "m[2]=='*'||jQuery.nodeName(a,m[2])",
12 "#": "a.getAttribute('id')==m[2]",
20 last: "i==r.length-1",
25 "first-child": "a.parentNode.getElementsByTagName('*')[0]==a",
26 "last-child": "jQuery.nth(a.parentNode.lastChild,1,'previousSibling')==a",
27 "only-child": "!jQuery.nth(a.parentNode.lastChild,2,'previousSibling')",
30 parent: "a.firstChild",
31 empty: "!a.firstChild",
34 contains: "(a.textContent||a.innerText||jQuery(a).text()||'').indexOf(m[3])>=0",
37 visible: '"hidden"!=a.type&&jQuery.css(a,"display")!="none"&&jQuery.css(a,"visibility")!="hidden"',
38 hidden: '"hidden"==a.type||jQuery.css(a,"display")=="none"||jQuery.css(a,"visibility")=="hidden"',
41 enabled: "!a.disabled",
42 disabled: "a.disabled",
44 selected: "a.selected||jQuery.attr(a,'selected')",
47 text: "'text'==a.type",
48 radio: "'radio'==a.type",
49 checkbox: "'checkbox'==a.type",
50 file: "'file'==a.type",
51 password: "'password'==a.type",
52 submit: "'submit'==a.type",
53 image: "'image'==a.type",
54 reset: "'reset'==a.type",
55 button: '"button"==a.type||jQuery.nodeName(a,"button")',
56 input: "/input|select|textarea|button/i.test(a.nodeName)",
59 has: "jQuery.find(m[3],a).length",
62 header: "/h\\d/i.test(a.nodeName)",
65 animated: "jQuery.grep(jQuery.timers,function(fn){return a==fn.elem;}).length"
69 // The regular expressions that power the parsing engine
71 // Match: [@value='test'], [@foo]
72 /^(\[) *@?([\w-]+) *([!*$^~=]*) *('?"?)(.*?)\4 *\]/,
74 // Match: :contains('foo')
75 /^(:)([\w-]+)\("?'?(.*?(\(.*?\))?[^(]*?)"?'?\)/,
77 // Match: :even, :last-chlid, #id, .class
78 new RegExp("^([:.#]*)(" + chars + "+)")
81 multiFilter: function( expr, elems, not ) {
84 while ( expr && expr != old ) {
86 var f = jQuery.filter( expr, elems, not );
87 expr = f.t.replace(/^\s*,\s*/, "" );
88 cur = not ? elems = f.r : jQuery.merge( cur, f.r );
94 find: function( t, context ) {
95 // Quickly handle non-string expressions
96 if ( typeof t != "string" )
99 // check to make sure context is a DOM element or a document
100 if ( context && context.nodeType != 1 && context.nodeType != 9)
103 // Set the correct context (if none is provided)
104 context = context || document;
106 // Initialize the search
107 var ret = [context], done = [], last, nodeName;
109 // Continue while a selector expression exists, and while
110 // we're no longer looping upon ourselves
111 while ( t && last != t ) {
117 var foundToken = false;
119 // An attempt at speeding up child selectors that
120 // point to a specific element tag
125 nodeName = m[1].toUpperCase();
127 // Perform our own iteration and filter
128 for ( var i = 0; ret[i]; i++ )
129 for ( var c = ret[i].firstChild; c; c = c.nextSibling )
130 if ( c.nodeType == 1 && (nodeName == "*" || c.nodeName.toUpperCase() == nodeName) )
134 t = t.replace( re, "" );
135 if ( t.indexOf(" ") == 0 ) continue;
138 re = /^([>+~])\s*(\w*)/i;
140 if ( (m = re.exec(t)) != null ) {
143 nodeName = m[2].toUpperCase(), merge = {};
146 for ( var j = 0, rl = ret.length; j < rl; j++ ) {
147 var n = m == "~" || m == "+" ? ret[j].nextSibling : ret[j].firstChild;
148 for ( ; n; n = n.nextSibling )
149 if ( n.nodeType == 1 ) {
150 var id = jQuery.data(n);
152 if ( m == "~" && merge[id] ) break;
154 if (!nodeName || n.nodeName.toUpperCase() == nodeName ) {
155 if ( m == "~" ) merge[id] = true;
159 if ( m == "+" ) break;
165 // And remove the token
166 t = jQuery.trim( t.replace( re, "" ) );
171 // See if there's still an expression, and that we haven't already
173 if ( t && !foundToken ) {
174 // Handle multiple expressions
175 if ( !t.indexOf(",") ) {
176 // Clean the result set
177 if ( context == ret[0] ) ret.shift();
179 // Merge the result sets
180 done = jQuery.merge( done, ret );
185 // Touch up the selector string
186 t = " " + t.substr(1,t.length);
189 // Optimize for the case nodeName#idName
193 // Re-organize the results, so that they're consistent
195 m = [ 0, m[2], m[3], m[1] ];
198 // Otherwise, do a traditional filter check for
199 // ID, class, and element selectors
204 m[2] = m[2].replace(/\\/g, "");
206 var elem = ret[ret.length-1];
208 // Try to do a global search by ID, where we can
209 if ( m[1] == "#" && elem && elem.getElementById && !jQuery.isXMLDoc(elem) ) {
210 // Optimization for HTML document case
211 var oid = elem.getElementById(m[2]);
213 // Do a quick check for the existence of the actual ID attribute
214 // to avoid selecting by the name attribute in IE
215 // also check to insure id is a string to avoid selecting an element with the name of 'id' inside a form
216 if ( (jQuery.browser.msie||jQuery.browser.opera) && oid && typeof oid.id == "string" && oid.id != m[2] )
217 oid = jQuery('[@id="'+m[2]+'"]', elem)[0];
219 // Do a quick check for node name (where applicable) so
220 // that div#foo searches will be really fast
221 ret = r = oid && (!m[3] || jQuery.nodeName(oid, m[3])) ? [oid] : [];
223 // We need to find all descendant elements
224 for ( var i = 0; ret[i]; i++ ) {
225 // Grab the tag name being searched for
226 var tag = m[1] == "#" && m[3] ? m[3] : m[1] != "" || m[0] == "" ? "*" : m[2];
228 // Handle IE7 being really dumb about <object>s
229 if ( tag == "*" && ret[i].nodeName.toLowerCase() == "object" )
232 r = jQuery.merge( r, ret[i].getElementsByTagName( tag ));
235 // It's faster to filter by class and be done with it
237 r = jQuery.classFilter( r, m[2] );
239 // Same with ID filtering
243 // Try to find the element with the ID
244 for ( var i = 0; r[i]; i++ )
245 if ( r[i].getAttribute("id") == m[2] ) {
256 t = t.replace( re2, "" );
261 // If a selector string still exists
263 // Attempt to filter it
264 var val = jQuery.filter(t,r);
266 t = jQuery.trim(val.t);
270 // An error occurred with the selector;
271 // just return an empty set instead
275 // Remove the root context
276 if ( ret && context == ret[0] )
279 // And combine the results
280 done = jQuery.merge( done, ret );
285 classFilter: function(r,m,not){
288 for ( var i = 0; r[i]; i++ ) {
289 var pass = (" " + r[i].className + " ").indexOf( m ) >= 0;
290 if ( !not && pass || not && !pass )
296 filter: function(t,r,not) {
299 // Look for common filter expressions
300 while ( t && t != last ) {
303 var p = jQuery.parse, m;
305 for ( var i = 0; p[i]; i++ ) {
309 // Remove what we just matched
310 t = t.substring( m[0].length );
312 m[2] = m[2].replace(/\\/g, "");
320 // :not() is a special case that can be optimized by
321 // keeping it out of the expression list
322 if ( m[1] == ":" && m[2] == "not" )
323 // optimize if only one selector found (most common case)
324 r = isSimple.test( m[3] ) ?
325 jQuery.filter(m[3], r, true).r :
326 jQuery( r ).not( m[3] );
328 // We can get a big speed boost by filtering by class here
329 else if ( m[1] == "." )
330 r = jQuery.classFilter(r, m[2], not);
332 else if ( m[1] == "[" ) {
333 var tmp = [], type = m[3];
335 for ( var i = 0, rl = r.length; i < rl; i++ ) {
336 var a = r[i], z = a[ jQuery.props[m[2]] || m[2] ];
338 if ( z == null || /href|src|selected/.test(m[2]) )
339 z = jQuery.attr(a,m[2]) || '';
341 if ( (type == "" && !!z ||
342 type == "=" && z == m[5] ||
343 type == "!=" && z != m[5] ||
344 type == "^=" && z && !z.indexOf(m[5]) ||
345 type == "$=" && z.substr(z.length - m[5].length) == m[5] ||
346 (type == "*=" || type == "~=") && z.indexOf(m[5]) >= 0) ^ not )
352 // We can get a speed boost by handling nth-child here
353 } else if ( m[1] == ":" && m[2] == "nth-child" ) {
354 var merge = {}, tmp = [],
355 // parse equations like 'even', 'odd', '5', '2n', '3n+2', '4n-1', '-n+6'
356 test = /(-?)(\d*)n((?:\+|-)?\d*)/.exec(
357 m[3] == "even" && "2n" || m[3] == "odd" && "2n+1" ||
358 !/\D/.test(m[3]) && "0n+" + m[3] || m[3]),
359 // calculate the numbers (first)n+(last) including if they are negative
360 first = (test[1] + (test[2] || 1)) - 0, last = test[3] - 0;
362 // loop through all the elements left in the jQuery object
363 for ( var i = 0, rl = r.length; i < rl; i++ ) {
364 var node = r[i], parentNode = node.parentNode, id = jQuery.data(parentNode);
369 for ( var n = parentNode.firstChild; n; n = n.nextSibling )
370 if ( n.nodeType == 1 )
379 if ( node.nodeIndex == last )
381 } else if ( (node.nodeIndex - last) % first == 0 && (node.nodeIndex - last) / first >= 0 )
390 // Otherwise, find the expression to execute
392 var f = jQuery.expr[m[1]];
393 if ( typeof f != "string" )
394 f = jQuery.expr[m[1]][m[2]];
396 // Build a custom macro to enclose it
397 f = eval("false||function(a,i){return " + f + "}");
399 // Execute it against the current filter
400 r = jQuery.grep( r, f, not );
404 // Return an array of filtered elements (r)
405 // and the modified expression string (t)
406 return { r: r, t: t };
409 dir: function( elem, dir ){
412 while ( cur && cur != document ) {
413 if ( cur.nodeType == 1 )
420 nth: function(cur,result,dir,elem){
421 result = result || 1;
424 for ( ; cur; cur = cur[dir] )
425 if ( cur.nodeType == 1 && ++num == result )
431 sibling: function( n, elem ) {
434 for ( ; n; n = n.nextSibling ) {
435 if ( n.nodeType == 1 && (!elem || n != elem) )