1 var chars = jQuery.browser.safari && parseInt(jQuery.browser.version) < 417 ?
3 "(?:[\\w\u0128-\uFFFF*_-]|\\\\.)",
4 quickChild = new RegExp("^>\\s*(" + chars + "+)"),
5 quickID = new RegExp("^(" + chars + "+)(#)(" + chars + "+)"),
6 quickClass = new RegExp("^([#.]?)(" + chars + "*)");
10 "": function(a,i,m){return m[2]=="*"||jQuery.nodeName(a,m[2]);},
11 "#": function(a,i,m){return a.getAttribute("id")==m[2];},
14 lt: function(a,i,m){return i<m[3]-0;},
15 gt: function(a,i,m){return i>m[3]-0;},
16 nth: function(a,i,m){return m[3]-0==i;},
17 eq: function(a,i,m){return m[3]-0==i;},
18 first: function(a,i){return i==0;},
19 last: function(a,i,m,r){return i==r.length-1;},
20 even: function(a,i){return i%2==0;},
21 odd: function(a,i){return i%2;},
24 "first-child": function(a){return a.parentNode.getElementsByTagName("*")[0]==a;},
25 "last-child": function(a){return jQuery.nth(a.parentNode.lastChild,1,"previousSibling")==a;},
26 "only-child": function(a){return !jQuery.nth(a.parentNode.lastChild,2,"previousSibling");},
29 parent: function(a){return a.firstChild;},
30 empty: function(a){return !a.firstChild;},
33 contains: function(a,i,m){return (a.textContent||a.innerText||jQuery(a).text()||"").indexOf(m[3])>=0;},
36 visible: function(a){return "hidden"!=a.type&&jQuery.css(a,"display")!="none"&&jQuery.css(a,"visibility")!="hidden";},
37 hidden: function(a){return "hidden"==a.type||jQuery.css(a,"display")=="none"||jQuery.css(a,"visibility")=="hidden";},
40 enabled: function(a){return !a.disabled;},
41 disabled: function(a){return a.disabled;},
42 checked: function(a){return a.checked;},
43 selected: function(a){return a.selected||jQuery.attr(a,"selected");},
46 text: function(a){return "text"==a.type;},
47 radio: function(a){return "radio"==a.type;},
48 checkbox: function(a){return "checkbox"==a.type;},
49 file: function(a){return "file"==a.type;},
50 password: function(a){return "password"==a.type;},
51 submit: function(a){return "submit"==a.type;},
52 image: function(a){return "image"==a.type;},
53 reset: function(a){return "reset"==a.type;},
54 button: function(a){return "button"==a.type||jQuery.nodeName(a,"button");},
55 input: function(a){return /input|select|textarea|button/i.test(a.nodeName);},
58 has: function(a,i,m){return jQuery.find(m[3],a).length;},
61 header: function(a){return /h\d/i.test(a.nodeName);},
64 animated: function(a){return jQuery.grep(jQuery.timers,function(fn){return a==fn.elem;}).length;}
68 // The regular expressions that power the parsing engine
70 // Match: [@value='test'], [@foo]
71 /^(\[) *@?([\w-]+) *([!*$^~=]*) *('?"?)(.*?)\4 *\]/,
73 // Match: :contains('foo')
74 /^(:)([\w-]+)\("?'?(.*?(\(.*?\))?[^(]*?)"?'?\)/,
76 // Match: :even, :last-child, #id, .class
77 new RegExp("^([:.#]*)(" + chars + "+)")
80 multiFilter: function( expr, elems, not ) {
83 while ( expr && expr != old ) {
85 var f = jQuery.filter( expr, elems, not );
86 expr = f.t.replace(/^\s*,\s*/, "" );
87 cur = not ? elems = f.r : jQuery.merge( cur, f.r );
93 find: function( t, context ) {
94 // Quickly handle non-string expressions
95 if ( typeof t != "string" )
98 // check to make sure context is a DOM element or a document
99 if ( context && context.nodeType != 1 && context.nodeType != 9)
102 // Set the correct context (if none is provided)
103 context = context || document;
105 // Initialize the search
106 var ret = [context], done = [], last, nodeName;
108 // Continue while a selector expression exists, and while
109 // we're no longer looping upon ourselves
110 while ( t && last != t ) {
116 var foundToken = false,
118 // An attempt at speeding up child selectors that
119 // 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 ) {
144 nodeName = m[2].toUpperCase();
147 for ( var j = 0, rl = ret.length; j < rl; j++ ) {
148 var n = m == "~" || m == "+" ? ret[j].nextSibling : ret[j].firstChild;
149 for ( ; n; n = n.nextSibling )
150 if ( n.nodeType == 1 ) {
151 var id = jQuery.data(n);
153 if ( m == "~" && merge[id] ) break;
155 if (!nodeName || n.nodeName.toUpperCase() == nodeName ) {
156 if ( m == "~" ) merge[id] = true;
160 if ( m == "+" ) break;
166 // And remove the token
167 t = jQuery.trim( t.replace( re, "" ) );
172 // See if there's still an expression, and that we haven't already
174 if ( t && !foundToken ) {
175 // Handle multiple expressions
176 if ( !t.indexOf(",") ) {
177 // Clean the result set
178 if ( context == ret[0] ) ret.shift();
180 // Merge the result sets
181 done = jQuery.merge( done, ret );
186 // Touch up the selector string
187 t = " " + t.substr(1,t.length);
190 // Optimize for the case nodeName#idName
194 // Re-organize the results, so that they're consistent
196 m = [ 0, m[2], m[3], m[1] ];
199 // Otherwise, do a traditional filter check for
200 // ID, class, and element selectors
205 m[2] = m[2].replace(/\\/g, "");
207 var elem = ret[ret.length-1];
209 // Try to do a global search by ID, where we can
210 if ( m[1] == "#" && elem && elem.getElementById && !jQuery.isXMLDoc(elem) ) {
211 // Optimization for HTML document case
212 var oid = elem.getElementById(m[2]);
214 // Do a quick check for the existence of the actual ID attribute
215 // to avoid selecting by the name attribute in IE
216 // also check to insure id is a string to avoid selecting an element with the name of 'id' inside a form
217 if ( (jQuery.browser.msie||jQuery.browser.opera) && oid && typeof oid.id == "string" && oid.id != m[2] )
218 oid = jQuery('[@id="'+m[2]+'"]', elem)[0];
220 // Do a quick check for node name (where applicable) so
221 // that div#foo searches will be really fast
222 ret = r = oid && (!m[3] || jQuery.nodeName(oid, m[3])) ? [oid] : [];
224 // We need to find all descendant elements
225 for ( var i = 0; ret[i]; i++ ) {
226 // Grab the tag name being searched for
227 var tag = m[1] == "#" && m[3] ? m[3] : m[1] != "" || m[0] == "" ? "*" : m[2];
229 // Handle IE7 being really dumb about <object>s
230 if ( tag == "*" && ret[i].nodeName.toLowerCase() == "object" )
233 r = jQuery.merge( r, ret[i].getElementsByTagName( tag ));
236 // It's faster to filter by class and be done with it
238 r = jQuery.classFilter( r, m[2] );
240 // Same with ID filtering
244 // Try to find the element with the ID
245 for ( var i = 0; r[i]; i++ )
246 if ( r[i].getAttribute("id") == m[2] ) {
257 t = t.replace( re2, "" );
262 // If a selector string still exists
264 // Attempt to filter it
265 var val = jQuery.filter(t,r);
267 t = jQuery.trim(val.t);
271 // An error occurred with the selector;
272 // just return an empty set instead
276 // Remove the root context
277 if ( ret && context == ret[0] )
280 // And combine the results
281 done = jQuery.merge( done, ret );
286 classFilter: function(r,m,not){
289 for ( var i = 0; r[i]; i++ ) {
290 var pass = (" " + r[i].className + " ").indexOf( m ) >= 0;
291 if ( !not && pass || not && !pass )
297 filter: function(t,r,not) {
300 // Look for common filter expressions
301 while ( t && t != last ) {
304 var p = jQuery.parse, m;
306 for ( var i = 0; p[i]; i++ ) {
310 // Remove what we just matched
311 t = t.substring( m[0].length );
313 m[2] = m[2].replace(/\\/g, "");
321 // :not() is a special case that can be optimized by
322 // keeping it out of the expression list
323 if ( m[1] == ":" && m[2] == "not" )
324 // optimize if only one selector found (most common case)
325 r = isSimple.test( m[3] ) ?
326 jQuery.filter(m[3], r, true).r :
327 jQuery( r ).not( m[3] );
329 // We can get a big speed boost by filtering by class here
330 else if ( m[1] == "." )
331 r = jQuery.classFilter(r, m[2], not);
333 else if ( m[1] == "[" ) {
334 var tmp = [], type = m[3];
336 for ( var i = 0, rl = r.length; i < rl; i++ ) {
337 var a = r[i], z = a[ jQuery.props[m[2]] || m[2] ];
339 if ( z == null || /href|src|selected/.test(m[2]) )
340 z = jQuery.attr(a,m[2]) || '';
342 if ( (type == "" && !!z ||
343 type == "=" && z == m[5] ||
344 type == "!=" && z != m[5] ||
345 type == "^=" && z && !z.indexOf(m[5]) ||
346 type == "$=" && z.substr(z.length - m[5].length) == m[5] ||
347 (type == "*=" || type == "~=") && z.indexOf(m[5]) >= 0) ^ not )
353 // We can get a speed boost by handling nth-child here
354 } else if ( m[1] == ":" && m[2] == "nth-child" ) {
355 var merge = {}, tmp = [],
356 // parse equations like 'even', 'odd', '5', '2n', '3n+2', '4n-1', '-n+6'
357 test = /(-?)(\d*)n((?:\+|-)?\d*)/.exec(
358 m[3] == "even" && "2n" || m[3] == "odd" && "2n+1" ||
359 !/\D/.test(m[3]) && "0n+" + m[3] || m[3]),
360 // calculate the numbers (first)n+(last) including if they are negative
361 first = (test[1] + (test[2] || 1)) - 0, last = test[3] - 0;
363 // loop through all the elements left in the jQuery object
364 for ( var i = 0, rl = r.length; i < rl; i++ ) {
365 var node = r[i], parentNode = node.parentNode, id = jQuery.data(parentNode);
370 for ( var n = parentNode.firstChild; n; n = n.nextSibling )
371 if ( n.nodeType == 1 )
380 if ( node.nodeIndex == last )
382 } else if ( (node.nodeIndex - last) % first == 0 && (node.nodeIndex - last) / first >= 0 )
391 // Otherwise, find the expression to execute
393 var fn = jQuery.expr[ m[1] ];
394 if ( typeof fn == "object" )
397 if ( typeof fn == "string" )
398 fn = eval("false||function(a,i){return " + fn + ";}");
400 // Execute it against the current filter
401 r = jQuery.grep( r, function(elem, i){
402 return fn(elem, i, m, r);
407 // Return an array of filtered elements (r)
408 // and the modified expression string (t)
409 return { r: r, t: t };
412 dir: function( elem, dir ){
415 while ( cur && cur != document ) {
416 if ( cur.nodeType == 1 )
423 nth: function(cur,result,dir,elem){
424 result = result || 1;
427 for ( ; cur; cur = cur[dir] )
428 if ( cur.nodeType == 1 && ++num == result )
434 sibling: function( n, elem ) {
437 for ( ; n; n = n.nextSibling ) {
438 if ( n.nodeType == 1 && n != elem )