X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;ds=sidebyside;f=src%2Fselector%2Fselector.js;h=b15ee7cde13121ca8b8e6e54784f037e80d21404;hb=257eaf7ee32df66ddd0a3333a5b6a829b9d388ef;hp=5f6f87b0460965522b19dca45256c1aeddb19968;hpb=fa7bfcfd783421b561bccb5c9402e0993b4af769;p=jquery.git diff --git a/src/selector/selector.js b/src/selector/selector.js index 5f6f87b..b15ee7c 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])", @@ -45,8 +53,12 @@ jQuery.extend({ image: "'image'==a.type", reset: "'reset'==a.type", button: '"button"==a.type||jQuery.nodeName(a,"button")', - input: "/input|select|textarea|button/i.test(a.nodeName)" + input: "/input|select|textarea|button/i.test(a.nodeName)", + + // :has() + has: "jQuery.find(m[3],a).length" }, + // DEPRECATED "[": "jQuery.find(m[2],a).length" }, @@ -55,6 +67,7 @@ jQuery.extend({ // Match: [@value='test'], [@foo] /^\[ *(@)([\w-]+) *([!*$^~=]*) *('?"?)(.*?)\4 *\]/, + // DEPRECATED // Match: [div], [div p] /^(\[)\s*(.*?(\[.*?\])?[^[]*?)\s*\]/, @@ -62,8 +75,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 ) { @@ -97,11 +109,13 @@ jQuery.extend({ // Set the correct context (if none is provided) context = context || document; + // DEPRECATED // Handle the common XPath // expression if ( !t.indexOf("//") ) { - context = context.documentElement; + //context = context.documentElement; t = t.substr(2,t.length); + // DEPRECATED // And the / root expression } else if ( !t.indexOf("/") && !context.ownerDocument ) { context = context.documentElement; @@ -119,13 +133,14 @@ jQuery.extend({ var r = []; last = t; + // DEPRECATED t = jQuery.trim(t).replace( /^\/\//, "" ); var foundToken = false; // 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 +149,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 +157,8 @@ jQuery.extend({ if ( t.indexOf(" ") == 0 ) continue; foundToken = true; } else { - re = /^((\/?\.\.)|([>\/+~]))\s*([a-z]*)/i; + // (.. and /) DEPRECATED + re = /^((\/?\.\.)|([>\/+~]))\s*(\w*)/i; if ( (m = re.exec(t)) != null ) { r = []; @@ -157,13 +173,14 @@ 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 ); } if ( m == "+" ) break; } + // DEPRECATED } else r.push( ret[j].parentNode ); @@ -193,8 +210,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 +221,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 +230,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,7 +356,7 @@ 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]) ) + if ( z == null || /href|src|selected/.test(m[2]) ) z = jQuery.attr(a,m[2]) || ''; if ( (type == "" && !!z || @@ -395,7 +412,7 @@ jQuery.extend({ f = jQuery.expr[m[1]][m[2]]; // Build a custom macro to enclose it - eval("f = function(a,i){return " + f + "}"); + f = eval("false||function(a,i){return " + f + "}"); // Execute it against the current filter r = jQuery.grep( r, f, not );