Fixed line endings.
authorScott González <scott.gonzalez@gmail.com>
Tue, 29 Apr 2008 22:52:36 +0000 (22:52 +0000)
committerScott González <scott.gonzalez@gmail.com>
Tue, 29 Apr 2008 22:52:36 +0000 (22:52 +0000)
src/selector.js

index eeb8b50..72fe07e 100644 (file)
-\r
-var chars = jQuery.browser.safari && parseInt(jQuery.browser.version) < 417 ?\r
-               "(?:[\\w*_-]|\\\\.)" :\r
-               "(?:[\\w\u0128-\uFFFF*_-]|\\\\.)",\r
-       quickChild = new RegExp("^>\\s*(" + chars + "+)"),\r
-       quickID = new RegExp("^(" + chars + "+)(#)(" + chars + "+)"),\r
-       quickClass = new RegExp("^([#.]?)(" + chars + "*)");\r
-\r
-jQuery.extend({\r
-       expr: {\r
-               "": function(a,i,m){return m[2]=="*"||jQuery.nodeName(a,m[2]);},\r
-               "#": function(a,i,m){return a.getAttribute("id")==m[2];},\r
-               ":": {\r
-                       // Position Checks\r
-                       lt: function(a,i,m){return i<m[3]-0;},\r
-                       gt: function(a,i,m){return i>m[3]-0;},\r
-                       nth: function(a,i,m){return m[3]-0==i;},\r
-                       eq: function(a,i,m){return m[3]-0==i;},\r
-                       first: function(a,i){return i==0;},\r
-                       last: function(a,i,m,r){return i==r.length-1;},\r
-                       even: function(a,i){return i%2==0;},\r
-                       odd: function(a,i){return i%2;},\r
-\r
-                       // Child Checks\r
-                       "first-child": function(a){return a.parentNode.getElementsByTagName("*")[0]==a;},\r
-                       "last-child": function(a){return jQuery.nth(a.parentNode.lastChild,1,"previousSibling")==a;},\r
-                       "only-child": function(a){return !jQuery.nth(a.parentNode.lastChild,2,"previousSibling");},\r
-\r
-                       // Parent Checks\r
-                       parent: function(a){return a.firstChild;},\r
-                       empty: function(a){return !a.firstChild;},\r
-\r
-                       // Text Check\r
-                       contains: function(a,i,m){return (a.textContent||a.innerText||jQuery(a).text()||"").indexOf(m[3])>=0;},\r
-\r
-                       // Visibility\r
-                       visible: function(a){return "hidden"!=a.type&&jQuery.css(a,"display")!="none"&&jQuery.css(a,"visibility")!="hidden";},\r
-                       hidden: function(a){return "hidden"==a.type||jQuery.css(a,"display")=="none"||jQuery.css(a,"visibility")=="hidden";},\r
-\r
-                       // Form attributes\r
-                       enabled: function(a){return !a.disabled;},\r
-                       disabled: function(a){return a.disabled;},\r
-                       checked: function(a){return a.checked;},\r
-                       selected: function(a){return a.selected||jQuery.attr(a,"selected");},\r
-\r
-                       // Form elements\r
-                       text: function(a){return "text"==a.type;},\r
-                       radio: function(a){return "radio"==a.type;},\r
-                       checkbox: function(a){return "checkbox"==a.type;},\r
-                       file: function(a){return "file"==a.type;},\r
-                       password: function(a){return "password"==a.type;},\r
-                       submit: function(a){return "submit"==a.type;},\r
-                       image: function(a){return "image"==a.type;},\r
-                       reset: function(a){return "reset"==a.type;},\r
-                       button: function(a){return "button"==a.type||jQuery.nodeName(a,"button");},\r
-                       input: function(a){return /input|select|textarea|button/i.test(a.nodeName);},\r
-\r
-                       // :has()\r
-                       has: function(a,i,m){return jQuery.find(m[3],a).length;},\r
-\r
-                       // :header\r
-                       header: function(a){return /h\d/i.test(a.nodeName);},\r
-\r
-                       // :animated\r
-                       animated: function(a){return jQuery.grep(jQuery.timers,function(fn){return a==fn.elem;}).length;}\r
-               }\r
-       },\r
-       \r
-       // The regular expressions that power the parsing engine\r
-       parse: [\r
-               // Match: [@value='test'], [@foo]\r
-               /^(\[) *@?([\w-]+) *([!*$^~=]*) *('?"?)(.*?)\4 *\]/,\r
-\r
-               // Match: :contains('foo')\r
-               /^(:)([\w-]+)\("?'?(.*?(\(.*?\))?[^(]*?)"?'?\)/,\r
-\r
-               // Match: :even, :last-chlid, #id, .class\r
-               new RegExp("^([:.#]*)(" + chars + "+)")\r
-       ],\r
-\r
-       multiFilter: function( expr, elems, not ) {\r
-               var old, cur = [];\r
-\r
-               while ( expr && expr != old ) {\r
-                       old = expr;\r
-                       var f = jQuery.filter( expr, elems, not );\r
-                       expr = f.t.replace(/^\s*,\s*/, "" );\r
-                       cur = not ? elems = f.r : jQuery.merge( cur, f.r );\r
-               }\r
-\r
-               return cur;\r
-       },\r
-\r
-       find: function( t, context ) {\r
-               // Quickly handle non-string expressions\r
-               if ( typeof t != "string" )\r
-                       return [ t ];\r
-\r
-               // check to make sure context is a DOM element or a document\r
-               if ( context && context.nodeType != 1 && context.nodeType != 9)\r
-                       return [ ];\r
-\r
-               // Set the correct context (if none is provided)\r
-               context = context || document;\r
-\r
-               // Initialize the search\r
-               var ret = [context], done = [], last, nodeName;\r
-\r
-               // Continue while a selector expression exists, and while\r
-               // we're no longer looping upon ourselves\r
-               while ( t && last != t ) {\r
-                       var r = [];\r
-                       last = t;\r
-\r
-                       t = jQuery.trim(t);\r
-\r
-                       var foundToken = false;\r
-\r
-                       // An attempt at speeding up child selectors that\r
-                       // point to a specific element tag\r
-                       var re = quickChild;\r
-                       var m = re.exec(t);\r
-\r
-                       if ( m ) {\r
-                               nodeName = m[1].toUpperCase();\r
-\r
-                               // Perform our own iteration and filter\r
-                               for ( var i = 0; ret[i]; i++ )\r
-                                       for ( var c = ret[i].firstChild; c; c = c.nextSibling )\r
-                                               if ( c.nodeType == 1 && (nodeName == "*" || c.nodeName.toUpperCase() == nodeName) )\r
-                                                       r.push( c );\r
-\r
-                               ret = r;\r
-                               t = t.replace( re, "" );\r
-                               if ( t.indexOf(" ") == 0 ) continue;\r
-                               foundToken = true;\r
-                       } else {\r
-                               re = /^([>+~])\s*(\w*)/i;\r
-\r
-                               if ( (m = re.exec(t)) != null ) {\r
-                                       r = [];\r
-\r
-                                       var merge = {};\r
-                                       nodeName = m[2].toUpperCase();\r
-                                       m = m[1];\r
-\r
-                                       for ( var j = 0, rl = ret.length; j < rl; j++ ) {\r
-                                               var n = m == "~" || m == "+" ? ret[j].nextSibling : ret[j].firstChild;\r
-                                               for ( ; n; n = n.nextSibling )\r
-                                                       if ( n.nodeType == 1 ) {\r
-                                                               var id = jQuery.data(n);\r
-\r
-                                                               if ( m == "~" && merge[id] ) break;\r
-                                                               \r
-                                                               if (!nodeName || n.nodeName.toUpperCase() == nodeName ) {\r
-                                                                       if ( m == "~" ) merge[id] = true;\r
-                                                                       r.push( n );\r
-                                                               }\r
-                                                               \r
-                                                               if ( m == "+" ) break;\r
-                                                       }\r
-                                       }\r
-\r
-                                       ret = r;\r
-\r
-                                       // And remove the token\r
-                                       t = jQuery.trim( t.replace( re, "" ) );\r
-                                       foundToken = true;\r
-                               }\r
-                       }\r
-\r
-                       // See if there's still an expression, and that we haven't already\r
-                       // matched a token\r
-                       if ( t && !foundToken ) {\r
-                               // Handle multiple expressions\r
-                               if ( !t.indexOf(",") ) {\r
-                                       // Clean the result set\r
-                                       if ( context == ret[0] ) ret.shift();\r
-\r
-                                       // Merge the result sets\r
-                                       done = jQuery.merge( done, ret );\r
-\r
-                                       // Reset the context\r
-                                       r = ret = [context];\r
-\r
-                                       // Touch up the selector string\r
-                                       t = " " + t.substr(1,t.length);\r
-\r
-                               } else {\r
-                                       // Optimize for the case nodeName#idName\r
-                                       var re2 = quickID;\r
-                                       var m = re2.exec(t);\r
-                                       \r
-                                       // Re-organize the results, so that they're consistent\r
-                                       if ( m ) {\r
-                                               m = [ 0, m[2], m[3], m[1] ];\r
-\r
-                                       } else {\r
-                                               // Otherwise, do a traditional filter check for\r
-                                               // ID, class, and element selectors\r
-                                               re2 = quickClass;\r
-                                               m = re2.exec(t);\r
-                                       }\r
-\r
-                                       m[2] = m[2].replace(/\\/g, "");\r
-\r
-                                       var elem = ret[ret.length-1];\r
-\r
-                                       // Try to do a global search by ID, where we can\r
-                                       if ( m[1] == "#" && elem && elem.getElementById && !jQuery.isXMLDoc(elem) ) {\r
-                                               // Optimization for HTML document case\r
-                                               var oid = elem.getElementById(m[2]);\r
-                                               \r
-                                               // Do a quick check for the existence of the actual ID attribute\r
-                                               // to avoid selecting by the name attribute in IE\r
-                                               // also check to insure id is a string to avoid selecting an element with the name of 'id' inside a form\r
-                                               if ( (jQuery.browser.msie||jQuery.browser.opera) && oid && typeof oid.id == "string" && oid.id != m[2] )\r
-                                                       oid = jQuery('[@id="'+m[2]+'"]', elem)[0];\r
-\r
-                                               // Do a quick check for node name (where applicable) so\r
-                                               // that div#foo searches will be really fast\r
-                                               ret = r = oid && (!m[3] || jQuery.nodeName(oid, m[3])) ? [oid] : [];\r
-                                       } else {\r
-                                               // We need to find all descendant elements\r
-                                               for ( var i = 0; ret[i]; i++ ) {\r
-                                                       // Grab the tag name being searched for\r
-                                                       var tag = m[1] == "#" && m[3] ? m[3] : m[1] != "" || m[0] == "" ? "*" : m[2];\r
-\r
-                                                       // Handle IE7 being really dumb about <object>s\r
-                                                       if ( tag == "*" && ret[i].nodeName.toLowerCase() == "object" )\r
-                                                               tag = "param";\r
-\r
-                                                       r = jQuery.merge( r, ret[i].getElementsByTagName( tag ));\r
-                                               }\r
-\r
-                                               // It's faster to filter by class and be done with it\r
-                                               if ( m[1] == "." )\r
-                                                       r = jQuery.classFilter( r, m[2] );\r
-\r
-                                               // Same with ID filtering\r
-                                               if ( m[1] == "#" ) {\r
-                                                       var tmp = [];\r
-\r
-                                                       // Try to find the element with the ID\r
-                                                       for ( var i = 0; r[i]; i++ )\r
-                                                               if ( r[i].getAttribute("id") == m[2] ) {\r
-                                                                       tmp = [ r[i] ];\r
-                                                                       break;\r
-                                                               }\r
-\r
-                                                       r = tmp;\r
-                                               }\r
-\r
-                                               ret = r;\r
-                                       }\r
-\r
-                                       t = t.replace( re2, "" );\r
-                               }\r
-\r
-                       }\r
-\r
-                       // If a selector string still exists\r
-                       if ( t ) {\r
-                               // Attempt to filter it\r
-                               var val = jQuery.filter(t,r);\r
-                               ret = r = val.r;\r
-                               t = jQuery.trim(val.t);\r
-                       }\r
-               }\r
-\r
-               // An error occurred with the selector;\r
-               // just return an empty set instead\r
-               if ( t )\r
-                       ret = [];\r
-\r
-               // Remove the root context\r
-               if ( ret && context == ret[0] )\r
-                       ret.shift();\r
-\r
-               // And combine the results\r
-               done = jQuery.merge( done, ret );\r
-\r
-               return done;\r
-       },\r
-\r
-       classFilter: function(r,m,not){\r
-               m = " " + m + " ";\r
-               var tmp = [];\r
-               for ( var i = 0; r[i]; i++ ) {\r
-                       var pass = (" " + r[i].className + " ").indexOf( m ) >= 0;\r
-                       if ( !not && pass || not && !pass )\r
-                               tmp.push( r[i] );\r
-               }\r
-               return tmp;\r
-       },\r
-\r
-       filter: function(t,r,not) {\r
-               var last;\r
-\r
-               // Look for common filter expressions\r
-               while ( t && t != last ) {\r
-                       last = t;\r
-\r
-                       var p = jQuery.parse, m;\r
-\r
-                       for ( var i = 0; p[i]; i++ ) {\r
-                               m = p[i].exec( t );\r
-\r
-                               if ( m ) {\r
-                                       // Remove what we just matched\r
-                                       t = t.substring( m[0].length );\r
-\r
-                                       m[2] = m[2].replace(/\\/g, "");\r
-                                       break;\r
-                               }\r
-                       }\r
-\r
-                       if ( !m )\r
-                               break;\r
-\r
-                       // :not() is a special case that can be optimized by\r
-                       // keeping it out of the expression list\r
-                       if ( m[1] == ":" && m[2] == "not" )\r
-                               // optimize if only one selector found (most common case)\r
-                               r = isSimple.test( m[3] ) ?\r
-                                       jQuery.filter(m[3], r, true).r :\r
-                                       jQuery( r ).not( m[3] );\r
-\r
-                       // We can get a big speed boost by filtering by class here\r
-                       else if ( m[1] == "." )\r
-                               r = jQuery.classFilter(r, m[2], not);\r
-\r
-                       else if ( m[1] == "[" ) {\r
-                               var type = m[3];\r
-                               \r
-                               // special case, filter by exact name\r
-                               if ( !not && m[2] == 'name' && type == '=' )\r
-                                       r = jQuery.grep( document.getElementsByName(m[5]), function(elem){\r
-                                               return jQuery.inArray( elem, r ) != -1; \r
-                                       });\r
-                               else {\r
-                                       for ( var i = 0, rl = r.length, tmp = []; i < rl; i++ ) {\r
-                                               var a = r[i], z = a[ jQuery.props[m[2]] || m[2] ];\r
-                                               \r
-                                               if ( z == null || /href|src|selected/.test(m[2]) )\r
-                                                       z = jQuery.attr(a,m[2]) || '';\r
-       \r
-                                               if ( (type == "" && !!z ||\r
-                                                        type == "=" && z == m[5] ||\r
-                                                        type == "!=" && z != m[5] ||\r
-                                                        type == "^=" && z && !z.indexOf(m[5]) ||\r
-                                                        type == "$=" && z.substr(z.length - m[5].length) == m[5] ||\r
-                                                        (type == "*=" || type == "~=") && z.indexOf(m[5]) >= 0) ^ not )\r
-                                                               tmp.push( a );\r
-                                       }                                       \r
-                                       r = tmp;\r
-                               }\r
-\r
-                       // We can get a speed boost by handling nth-child here\r
-                       } else if ( m[1] == ":" && m[2] == "nth-child" ) {\r
-                               var merge = {}, tmp = [],\r
-                                       // parse equations like 'even', 'odd', '5', '2n', '3n+2', '4n-1', '-n+6'\r
-                                       test = /(-?)(\d*)n((?:\+|-)?\d*)/.exec(\r
-                                               m[3] == "even" && "2n" || m[3] == "odd" && "2n+1" ||\r
-                                               !/\D/.test(m[3]) && "0n+" + m[3] || m[3]),\r
-                                       // calculate the numbers (first)n+(last) including if they are negative\r
-                                       first = (test[1] + (test[2] || 1)) - 0, last = test[3] - 0;\r
\r
-                               // loop through all the elements left in the jQuery object\r
-                               for ( var i = 0, rl = r.length; i < rl; i++ ) {\r
-                                       var node = r[i], parentNode = node.parentNode, id = jQuery.data(parentNode);\r
-\r
-                                       if ( !merge[id] ) {\r
-                                               var c = 1;\r
-\r
-                                               for ( var n = parentNode.firstChild; n; n = n.nextSibling )\r
-                                                       if ( n.nodeType == 1 )\r
-                                                               n.nodeIndex = c++;\r
-\r
-                                               merge[id] = true;\r
-                                       }\r
-\r
-                                       var add = false;\r
-\r
-                                       if ( first == 0 ) {\r
-                                               if ( node.nodeIndex == last )\r
-                                                       add = true;\r
-                                       } else if ( (node.nodeIndex - last) % first == 0 && (node.nodeIndex - last) / first >= 0 )\r
-                                               add = true;\r
-\r
-                                       if ( add ^ not )\r
-                                               tmp.push( node );\r
-                               }\r
-\r
-                               r = tmp;\r
-\r
-                       // Otherwise, find the expression to execute\r
-                       } else {\r
-                               var fn = jQuery.expr[ m[1] ];\r
-                               if ( typeof fn == "object" )\r
-                                       fn = fn[ m[2] ];\r
-\r
-                               if ( typeof fn == "string" )\r
-                                       fn = eval("false||function(a,i){return " + fn + ";}");\r
-\r
-                               // Execute it against the current filter\r
-                               r = jQuery.grep( r, function(elem, i){\r
-                                       return fn(elem, i, m, r);\r
-                               }, not );\r
-                       }\r
-               }\r
-\r
-               // Return an array of filtered elements (r)\r
-               // and the modified expression string (t)\r
-               return { r: r, t: t };\r
-       },\r
-\r
-       dir: function( elem, dir ){\r
-               var matched = [];\r
-               var cur = elem[dir];\r
-               while ( cur && cur != document ) {\r
-                       if ( cur.nodeType == 1 )\r
-                               matched.push( cur );\r
-                       cur = cur[dir];\r
-               }\r
-               return matched;\r
-       },\r
-       \r
-       nth: function(cur,result,dir,elem){\r
-               result = result || 1;\r
-               var num = 0;\r
-\r
-               for ( ; cur; cur = cur[dir] )\r
-                       if ( cur.nodeType == 1 && ++num == result )\r
-                               break;\r
-\r
-               return cur;\r
-       },\r
-       \r
-       sibling: function( n, elem ) {\r
-               var r = [];\r
-\r
-               for ( ; n; n = n.nextSibling ) {\r
-                       if ( n.nodeType == 1 && (!elem || n != elem) )\r
-                               r.push( n );\r
-               }\r
-\r
-               return r;\r
-       }\r
-});\r
-\r
+
+var chars = jQuery.browser.safari && parseInt(jQuery.browser.version) < 417 ?
+               "(?:[\\w*_-]|\\\\.)" :
+               "(?:[\\w\u0128-\uFFFF*_-]|\\\\.)",
+       quickChild = new RegExp("^>\\s*(" + chars + "+)"),
+       quickID = new RegExp("^(" + chars + "+)(#)(" + chars + "+)"),
+       quickClass = new RegExp("^([#.]?)(" + chars + "*)");
+
+jQuery.extend({
+       expr: {
+               "": function(a,i,m){return m[2]=="*"||jQuery.nodeName(a,m[2]);},
+               "#": function(a,i,m){return a.getAttribute("id")==m[2];},
+               ":": {
+                       // Position Checks
+                       lt: function(a,i,m){return i<m[3]-0;},
+                       gt: function(a,i,m){return i>m[3]-0;},
+                       nth: function(a,i,m){return m[3]-0==i;},
+                       eq: function(a,i,m){return m[3]-0==i;},
+                       first: function(a,i){return i==0;},
+                       last: function(a,i,m,r){return i==r.length-1;},
+                       even: function(a,i){return i%2==0;},
+                       odd: function(a,i){return i%2;},
+
+                       // Child Checks
+                       "first-child": function(a){return a.parentNode.getElementsByTagName("*")[0]==a;},
+                       "last-child": function(a){return jQuery.nth(a.parentNode.lastChild,1,"previousSibling")==a;},
+                       "only-child": function(a){return !jQuery.nth(a.parentNode.lastChild,2,"previousSibling");},
+
+                       // Parent Checks
+                       parent: function(a){return a.firstChild;},
+                       empty: function(a){return !a.firstChild;},
+
+                       // Text Check
+                       contains: function(a,i,m){return (a.textContent||a.innerText||jQuery(a).text()||"").indexOf(m[3])>=0;},
+
+                       // Visibility
+                       visible: function(a){return "hidden"!=a.type&&jQuery.css(a,"display")!="none"&&jQuery.css(a,"visibility")!="hidden";},
+                       hidden: function(a){return "hidden"==a.type||jQuery.css(a,"display")=="none"||jQuery.css(a,"visibility")=="hidden";},
+
+                       // Form attributes
+                       enabled: function(a){return !a.disabled;},
+                       disabled: function(a){return a.disabled;},
+                       checked: function(a){return a.checked;},
+                       selected: function(a){return a.selected||jQuery.attr(a,"selected");},
+
+                       // Form elements
+                       text: function(a){return "text"==a.type;},
+                       radio: function(a){return "radio"==a.type;},
+                       checkbox: function(a){return "checkbox"==a.type;},
+                       file: function(a){return "file"==a.type;},
+                       password: function(a){return "password"==a.type;},
+                       submit: function(a){return "submit"==a.type;},
+                       image: function(a){return "image"==a.type;},
+                       reset: function(a){return "reset"==a.type;},
+                       button: function(a){return "button"==a.type||jQuery.nodeName(a,"button");},
+                       input: function(a){return /input|select|textarea|button/i.test(a.nodeName);},
+
+                       // :has()
+                       has: function(a,i,m){return jQuery.find(m[3],a).length;},
+
+                       // :header
+                       header: function(a){return /h\d/i.test(a.nodeName);},
+
+                       // :animated
+                       animated: function(a){return jQuery.grep(jQuery.timers,function(fn){return a==fn.elem;}).length;}
+               }
+       },
+       
+       // The regular expressions that power the parsing engine
+       parse: [
+               // Match: [@value='test'], [@foo]
+               /^(\[) *@?([\w-]+) *([!*$^~=]*) *('?"?)(.*?)\4 *\]/,
+
+               // Match: :contains('foo')
+               /^(:)([\w-]+)\("?'?(.*?(\(.*?\))?[^(]*?)"?'?\)/,
+
+               // Match: :even, :last-chlid, #id, .class
+               new RegExp("^([:.#]*)(" + chars + "+)")
+       ],
+
+       multiFilter: function( expr, elems, not ) {
+               var old, cur = [];
+
+               while ( expr && expr != old ) {
+                       old = expr;
+                       var f = jQuery.filter( expr, elems, not );
+                       expr = f.t.replace(/^\s*,\s*/, "" );
+                       cur = not ? elems = f.r : jQuery.merge( cur, f.r );
+               }
+
+               return cur;
+       },
+
+       find: function( t, context ) {
+               // Quickly handle non-string expressions
+               if ( typeof t != "string" )
+                       return [ t ];
+
+               // check to make sure context is a DOM element or a document
+               if ( context && context.nodeType != 1 && context.nodeType != 9)
+                       return [ ];
+
+               // Set the correct context (if none is provided)
+               context = context || document;
+
+               // Initialize the search
+               var ret = [context], done = [], last, nodeName;
+
+               // Continue while a selector expression exists, and while
+               // we're no longer looping upon ourselves
+               while ( t && last != t ) {
+                       var r = [];
+                       last = t;
+
+                       t = jQuery.trim(t);
+
+                       var foundToken = false;
+
+                       // An attempt at speeding up child selectors that
+                       // point to a specific element tag
+                       var re = quickChild;
+                       var m = re.exec(t);
+
+                       if ( m ) {
+                               nodeName = m[1].toUpperCase();
+
+                               // Perform our own iteration and filter
+                               for ( var i = 0; ret[i]; i++ )
+                                       for ( var c = ret[i].firstChild; c; c = c.nextSibling )
+                                               if ( c.nodeType == 1 && (nodeName == "*" || c.nodeName.toUpperCase() == nodeName) )
+                                                       r.push( c );
+
+                               ret = r;
+                               t = t.replace( re, "" );
+                               if ( t.indexOf(" ") == 0 ) continue;
+                               foundToken = true;
+                       } else {
+                               re = /^([>+~])\s*(\w*)/i;
+
+                               if ( (m = re.exec(t)) != null ) {
+                                       r = [];
+
+                                       var merge = {};
+                                       nodeName = m[2].toUpperCase();
+                                       m = m[1];
+
+                                       for ( var j = 0, rl = ret.length; j < rl; j++ ) {
+                                               var n = m == "~" || m == "+" ? ret[j].nextSibling : ret[j].firstChild;
+                                               for ( ; n; n = n.nextSibling )
+                                                       if ( n.nodeType == 1 ) {
+                                                               var id = jQuery.data(n);
+
+                                                               if ( m == "~" && merge[id] ) break;
+                                                               
+                                                               if (!nodeName || n.nodeName.toUpperCase() == nodeName ) {
+                                                                       if ( m == "~" ) merge[id] = true;
+                                                                       r.push( n );
+                                                               }
+                                                               
+                                                               if ( m == "+" ) break;
+                                                       }
+                                       }
+
+                                       ret = r;
+
+                                       // And remove the token
+                                       t = jQuery.trim( t.replace( re, "" ) );
+                                       foundToken = true;
+                               }
+                       }
+
+                       // See if there's still an expression, and that we haven't already
+                       // matched a token
+                       if ( t && !foundToken ) {
+                               // Handle multiple expressions
+                               if ( !t.indexOf(",") ) {
+                                       // Clean the result set
+                                       if ( context == ret[0] ) ret.shift();
+
+                                       // Merge the result sets
+                                       done = jQuery.merge( done, ret );
+
+                                       // Reset the context
+                                       r = ret = [context];
+
+                                       // Touch up the selector string
+                                       t = " " + t.substr(1,t.length);
+
+                               } else {
+                                       // Optimize for the case nodeName#idName
+                                       var re2 = quickID;
+                                       var m = re2.exec(t);
+                                       
+                                       // Re-organize the results, so that they're consistent
+                                       if ( m ) {
+                                               m = [ 0, m[2], m[3], m[1] ];
+
+                                       } else {
+                                               // Otherwise, do a traditional filter check for
+                                               // ID, class, and element selectors
+                                               re2 = quickClass;
+                                               m = re2.exec(t);
+                                       }
+
+                                       m[2] = m[2].replace(/\\/g, "");
+
+                                       var elem = ret[ret.length-1];
+
+                                       // Try to do a global search by ID, where we can
+                                       if ( m[1] == "#" && elem && elem.getElementById && !jQuery.isXMLDoc(elem) ) {
+                                               // Optimization for HTML document case
+                                               var oid = elem.getElementById(m[2]);
+                                               
+                                               // Do a quick check for the existence of the actual ID attribute
+                                               // to avoid selecting by the name attribute in IE
+                                               // also check to insure id is a string to avoid selecting an element with the name of 'id' inside a form
+                                               if ( (jQuery.browser.msie||jQuery.browser.opera) && oid && typeof oid.id == "string" && oid.id != m[2] )
+                                                       oid = jQuery('[@id="'+m[2]+'"]', elem)[0];
+
+                                               // Do a quick check for node name (where applicable) so
+                                               // that div#foo searches will be really fast
+                                               ret = r = oid && (!m[3] || jQuery.nodeName(oid, m[3])) ? [oid] : [];
+                                       } else {
+                                               // We need to find all descendant elements
+                                               for ( var i = 0; ret[i]; i++ ) {
+                                                       // Grab the tag name being searched for
+                                                       var tag = m[1] == "#" && m[3] ? m[3] : m[1] != "" || m[0] == "" ? "*" : m[2];
+
+                                                       // Handle IE7 being really dumb about <object>s
+                                                       if ( tag == "*" && ret[i].nodeName.toLowerCase() == "object" )
+                                                               tag = "param";
+
+                                                       r = jQuery.merge( r, ret[i].getElementsByTagName( tag ));
+                                               }
+
+                                               // It's faster to filter by class and be done with it
+                                               if ( m[1] == "." )
+                                                       r = jQuery.classFilter( r, m[2] );
+
+                                               // Same with ID filtering
+                                               if ( m[1] == "#" ) {
+                                                       var tmp = [];
+
+                                                       // Try to find the element with the ID
+                                                       for ( var i = 0; r[i]; i++ )
+                                                               if ( r[i].getAttribute("id") == m[2] ) {
+                                                                       tmp = [ r[i] ];
+                                                                       break;
+                                                               }
+
+                                                       r = tmp;
+                                               }
+
+                                               ret = r;
+                                       }
+
+                                       t = t.replace( re2, "" );
+                               }
+
+                       }
+
+                       // If a selector string still exists
+                       if ( t ) {
+                               // Attempt to filter it
+                               var val = jQuery.filter(t,r);
+                               ret = r = val.r;
+                               t = jQuery.trim(val.t);
+                       }
+               }
+
+               // An error occurred with the selector;
+               // just return an empty set instead
+               if ( t )
+                       ret = [];
+
+               // Remove the root context
+               if ( ret && context == ret[0] )
+                       ret.shift();
+
+               // And combine the results
+               done = jQuery.merge( done, ret );
+
+               return done;
+       },
+
+       classFilter: function(r,m,not){
+               m = " " + m + " ";
+               var tmp = [];
+               for ( var i = 0; r[i]; i++ ) {
+                       var pass = (" " + r[i].className + " ").indexOf( m ) >= 0;
+                       if ( !not && pass || not && !pass )
+                               tmp.push( r[i] );
+               }
+               return tmp;
+       },
+
+       filter: function(t,r,not) {
+               var last;
+
+               // Look for common filter expressions
+               while ( t && t != last ) {
+                       last = t;
+
+                       var p = jQuery.parse, m;
+
+                       for ( var i = 0; p[i]; i++ ) {
+                               m = p[i].exec( t );
+
+                               if ( m ) {
+                                       // Remove what we just matched
+                                       t = t.substring( m[0].length );
+
+                                       m[2] = m[2].replace(/\\/g, "");
+                                       break;
+                               }
+                       }
+
+                       if ( !m )
+                               break;
+
+                       // :not() is a special case that can be optimized by
+                       // keeping it out of the expression list
+                       if ( m[1] == ":" && m[2] == "not" )
+                               // optimize if only one selector found (most common case)
+                               r = isSimple.test( m[3] ) ?
+                                       jQuery.filter(m[3], r, true).r :
+                                       jQuery( r ).not( m[3] );
+
+                       // We can get a big speed boost by filtering by class here
+                       else if ( m[1] == "." )
+                               r = jQuery.classFilter(r, m[2], not);
+
+                       else if ( m[1] == "[" ) {
+                               var type = m[3];
+                               
+                               // special case, filter by exact name
+                               if ( !not && m[2] == 'name' && type == '=' )
+                                       r = jQuery.grep( document.getElementsByName(m[5]), function(elem){
+                                               return jQuery.inArray( elem, r ) != -1; 
+                                       });
+                               else {
+                                       for ( var i = 0, rl = r.length, tmp = []; i < rl; i++ ) {
+                                               var a = r[i], z = a[ jQuery.props[m[2]] || m[2] ];
+                                               
+                                               if ( z == null || /href|src|selected/.test(m[2]) )
+                                                       z = jQuery.attr(a,m[2]) || '';
+       
+                                               if ( (type == "" && !!z ||
+                                                        type == "=" && z == m[5] ||
+                                                        type == "!=" && z != m[5] ||
+                                                        type == "^=" && z && !z.indexOf(m[5]) ||
+                                                        type == "$=" && z.substr(z.length - m[5].length) == m[5] ||
+                                                        (type == "*=" || type == "~=") && z.indexOf(m[5]) >= 0) ^ not )
+                                                               tmp.push( a );
+                                       }                                       
+                                       r = tmp;
+                               }
+
+                       // We can get a speed boost by handling nth-child here
+                       } else if ( m[1] == ":" && m[2] == "nth-child" ) {
+                               var merge = {}, tmp = [],
+                                       // parse equations like 'even', 'odd', '5', '2n', '3n+2', '4n-1', '-n+6'
+                                       test = /(-?)(\d*)n((?:\+|-)?\d*)/.exec(
+                                               m[3] == "even" && "2n" || m[3] == "odd" && "2n+1" ||
+                                               !/\D/.test(m[3]) && "0n+" + m[3] || m[3]),
+                                       // calculate the numbers (first)n+(last) including if they are negative
+                                       first = (test[1] + (test[2] || 1)) - 0, last = test[3] - 0;
+                               // loop through all the elements left in the jQuery object
+                               for ( var i = 0, rl = r.length; i < rl; i++ ) {
+                                       var node = r[i], parentNode = node.parentNode, id = jQuery.data(parentNode);
+
+                                       if ( !merge[id] ) {
+                                               var c = 1;
+
+                                               for ( var n = parentNode.firstChild; n; n = n.nextSibling )
+                                                       if ( n.nodeType == 1 )
+                                                               n.nodeIndex = c++;
+
+                                               merge[id] = true;
+                                       }
+
+                                       var add = false;
+
+                                       if ( first == 0 ) {
+                                               if ( node.nodeIndex == last )
+                                                       add = true;
+                                       } else if ( (node.nodeIndex - last) % first == 0 && (node.nodeIndex - last) / first >= 0 )
+                                               add = true;
+
+                                       if ( add ^ not )
+                                               tmp.push( node );
+                               }
+
+                               r = tmp;
+
+                       // Otherwise, find the expression to execute
+                       } else {
+                               var fn = jQuery.expr[ m[1] ];
+                               if ( typeof fn == "object" )
+                                       fn = fn[ m[2] ];
+
+                               if ( typeof fn == "string" )
+                                       fn = eval("false||function(a,i){return " + fn + ";}");
+
+                               // Execute it against the current filter
+                               r = jQuery.grep( r, function(elem, i){
+                                       return fn(elem, i, m, r);
+                               }, not );
+                       }
+               }
+
+               // Return an array of filtered elements (r)
+               // and the modified expression string (t)
+               return { r: r, t: t };
+       },
+
+       dir: function( elem, dir ){
+               var matched = [];
+               var cur = elem[dir];
+               while ( cur && cur != document ) {
+                       if ( cur.nodeType == 1 )
+                               matched.push( cur );
+                       cur = cur[dir];
+               }
+               return matched;
+       },
+       
+       nth: function(cur,result,dir,elem){
+               result = result || 1;
+               var num = 0;
+
+               for ( ; cur; cur = cur[dir] )
+                       if ( cur.nodeType == 1 && ++num == result )
+                               break;
+
+               return cur;
+       },
+       
+       sibling: function( n, elem ) {
+               var r = [];
+
+               for ( ; n; n = n.nextSibling ) {
+                       if ( n.nodeType == 1 && (!elem || n != elem) )
+                               r.push( n );
+               }
+
+               return r;
+       }
+});
+