X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fselector%2Fselector.js;h=f2c224a027362c3355659bf3290001a206df3648;hb=b6d920cf05fae3dcfe515166013ce39411ac5e16;hp=13fd09428b20704797fbb8e1b5db59c9426ff4ab;hpb=fd249ca808408166882847c217d55ae4c5a799e8;p=jquery.git diff --git a/src/selector/selector.js b/src/selector/selector.js index 13fd094..f2c224a 100644 --- a/src/selector/selector.js +++ b/src/selector/selector.js @@ -1,3 +1,11 @@ + +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: { "": "m[2]=='*'||jQuery.nodeName(a,m[2])", @@ -16,7 +24,7 @@ jQuery.extend({ // Child Checks "first-child": "a.parentNode.getElementsByTagName('*')[0]==a", "last-child": "jQuery.nth(a.parentNode.lastChild,1,'previousSibling')==a", - "only-child": "a.parentNode.getElementsByTagName('*').length==1", + "only-child": "!jQuery.nth(a.parentNode.lastChild,2,'previousSibling')", // Parent Checks parent: "a.firstChild", @@ -53,7 +61,7 @@ jQuery.extend({ // The regular expressions that power the parsing engine parse: [ // Match: [@value='test'], [@foo] - /^\[ *(@)([\w-]+) *([!*$^=]*) *('?"?)(.*?)\4 *\]/, + /^\[ *(@)([\w-]+) *([!*$^~=]*) *('?"?)(.*?)\4 *\]/, // Match: [div], [div p] /^(\[)\s*(.*?(\[.*?\])?[^[]*?)\s*\]/, @@ -62,8 +70,7 @@ jQuery.extend({ /^(:)([\w-]+)\("?'?(.*?(\(.*?\))?[^(]*?)"?'?\)/, // Match: :even, :last-chlid, #id, .class - new RegExp("^([:.#]*)(" + - ( jQuery.chars = "(?:[\\w\u0128-\uFFFF*_-]|\\\\.)" ) + "+)") + new RegExp("^([:.#]*)(" + chars + "+)") ], multiFilter: function( expr, elems, not ) { @@ -99,7 +106,7 @@ jQuery.extend({ // Handle the common XPath // expression if ( !t.indexOf("//") ) { - context = context.documentElement; + //context = context.documentElement; t = t.substr(2,t.length); // And the / root expression @@ -125,7 +132,7 @@ jQuery.extend({ // An attempt at speeding up child selectors that // point to a specific element tag - var re = new RegExp("^[/>]\\s*(" + jQuery.chars + "+)"); + var re = quickChild; var m = re.exec(t); if ( m ) { @@ -134,7 +141,7 @@ jQuery.extend({ // 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 == nodeName.toUpperCase()) ) + if ( c.nodeType == 1 && (nodeName == "*" || c.nodeName.toUpperCase() == nodeName.toUpperCase()) ) r.push( c ); ret = r; @@ -142,7 +149,7 @@ jQuery.extend({ if ( t.indexOf(" ") == 0 ) continue; foundToken = true; } else { - re = /^((\/?\.\.)|([>\/+~]))\s*([a-z]*)/i; + re = /^((\/?\.\.)|([>\/+~]))\s*(\w*)/i; if ( (m = re.exec(t)) != null ) { r = []; @@ -157,7 +164,7 @@ jQuery.extend({ if ( n.nodeType == 1 ) { if ( m == "~" && n.mergeNum == mergeNum ) break; - if (!nodeName || n.nodeName == nodeName.toUpperCase() ) { + if (!nodeName || n.nodeName.toUpperCase() == nodeName.toUpperCase() ) { if ( m == "~" ) n.mergeNum = mergeNum; r.push( n ); } @@ -193,8 +200,8 @@ jQuery.extend({ t = " " + t.substr(1,t.length); } else { - // Optomize for the case nodeName#idName - var re2 = new RegExp("^(" + jQuery.chars + "+)(#)(" + jQuery.chars + "+)"); + // Optimize for the case nodeName#idName + var re2 = quickID; var m = re2.exec(t); // Re-organize the results, so that they're consistent @@ -204,7 +211,7 @@ jQuery.extend({ } else { // Otherwise, do a traditional filter check for // ID, class, and element selectors - re2 = new RegExp("^([#.]?)(" + jQuery.chars + "*)"); + re2 = quickClass; m = re2.exec(t); } @@ -213,7 +220,7 @@ jQuery.extend({ var elem = ret[ret.length-1]; // Try to do a global search by ID, where we can - if ( m[1] == "#" && elem && elem.getElementById ) { + if ( m[1] == "#" && elem && elem.getElementById && !jQuery.isXMLDoc(elem) ) { // Optimization for HTML document case var oid = elem.getElementById(m[2]); @@ -339,15 +346,15 @@ jQuery.extend({ for ( var i = 0, rl = r.length; i < rl; i++ ) { var a = r[i], z = a[ jQuery.props[m[2]] || m[2] ]; - if ( z == null || /href|src/.test(m[2]) ) - z = jQuery.attr(a,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 == "*=" && z.indexOf(m[5]) >= 0) ^ not ) + (type == "*=" || type == "~=") && z.indexOf(m[5]) >= 0) ^ not ) tmp.push( a ); } @@ -377,7 +384,7 @@ jQuery.extend({ var add = false; if ( first == 1 ) { - if ( node.nodeIndex == last ) + if ( last == 0 || node.nodeIndex == last ) add = true; } else if ( (node.nodeIndex + last) % first == 0 ) add = true;