X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fselector%2Fselector.js;h=6ad8e5cca8a85ffa46edf1e53969d3e82c459860;hb=7c6100f5ed840b49e8e0de1f9eb90ea2ef1c47ef;hp=d6d87c03cb6cd17dc50bd078f3b070313d92bc60;hpb=2fac5e7949ec342c450b2e032509eed0e35cf1ff;p=jquery.git diff --git a/src/selector/selector.js b/src/selector/selector.js index d6d87c0..6ad8e5c 100644 --- a/src/selector/selector.js +++ b/src/selector/selector.js @@ -27,8 +27,8 @@ jQuery.extend({ contains: "jQuery.fn.text.apply([a]).indexOf(m[3])>=0", // Visibility - visible: 'a.type!="hidden"&&jQuery.css(a,"display")!="none"&&jQuery.css(a,"visibility")!="hidden"', - hidden: 'a.type=="hidden"||jQuery.css(a,"display")=="none"||jQuery.css(a,"visibility")=="hidden"', + visible: '"hidden"!=a.type&&jQuery.css(a,"display")!="none"&&jQuery.css(a,"visibility")!="hidden"', + hidden: '"hidden"==a.type||jQuery.css(a,"display")=="none"||jQuery.css(a,"visibility")=="hidden"', // Form attributes enabled: "!a.disabled", @@ -37,15 +37,15 @@ jQuery.extend({ selected: "a.selected||jQuery.attr(a,'selected')", // Form elements - text: "a.type=='text'", - radio: "a.type=='radio'", - checkbox: "a.type=='checkbox'", - file: "a.type=='file'", - password: "a.type=='password'", - submit: "a.type=='submit'", - image: "a.type=='image'", - reset: "a.type=='reset'", - button: 'a.type=="button"||jQuery.nodeName(a,"button")', + text: "'text'==a.type", + radio: "'radio'==a.type", + checkbox: "'checkbox'==a.type", + file: "'file'==a.type", + password: "'password'==a.type", + submit: "'submit'==a.type", + 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)" }, ".": "jQuery.className.has(a,m[2])", @@ -56,21 +56,18 @@ jQuery.extend({ "$=": "z&&z.substr(z.length - m[4].length,m[4].length)==m[4]", "*=": "z&&z.indexOf(m[4])>=0", "": "z", - // these are for evaling in a regexp. - "=~": "eval(m[4]).test(z)", - "!~": "!eval(m[4]).test(z)", _resort: function(m){ return ["", m[1], m[3], m[2], m[5]]; }, - _prefix: "z=a[m[3]];if(!z||/href|src/.test(m[3]))z=jQuery.attr(a,m[3]);" + _prefix: "var z=a[m[3]];if(!z||/href|src/.test(m[3]))z=jQuery.attr(a,m[3]);" }, - "[": "parseInt(m[2])?jQuery.nth(a.parentNode.firstChild,parseInt(m[2]),'nextSibling',a)==a:jQuery.find(m[2],a).length" + "[": "jQuery.find(m[2],a).length" }, // The regular expressions that power the parsing engine parse: [ // Match: [@value='test'], [@foo] - /^\[ *(@)([\w-]+) *([!*$^=!~]*) *('?"?)(.*?)\4 *\]/, + /^\[ *(@)([\w-]+) *([!*$^=]*) *('?"?)(.*?)\4 *\]/, // Match: [div], [div p] /^(\[)\s*(.*?(\[.*?\])?[^[]*?)\s*\]/, @@ -80,7 +77,7 @@ jQuery.extend({ // Match: :even, :last-chlid, #id, .class new RegExp("^([:.#]*)(" + - ( jQuery.chars = "(?:[\\w\u0128-\uFFFF*-]|\\\\.)" ) + "+)") + ( jQuery.chars = "(?:[\\w\u0128-\uFFFF*_-]|\\\\.)" ) + "+)") ], token: [ @@ -152,7 +149,7 @@ jQuery.extend({ // An attempt at speeding up child selectors that // point to a specific element tag - var re = /^[\/>]\s*([\w*-]+)/; + var re = new RegExp("^[/>]\\s*(" + jQuery.chars + "+)"); var m = re.exec(t); if ( m ) { @@ -194,7 +191,7 @@ jQuery.extend({ // Handle multiple expressions if ( !t.indexOf(",") ) { // Clean the result set - if ( ret[0] == context ) ret.shift(); + if ( context == ret[0] ) ret.shift(); // Merge the result sets done = jQuery.merge( done, ret ); @@ -207,7 +204,7 @@ jQuery.extend({ } else { // Optomize for the case nodeName#idName - var re2 = new RegExp("^(\\w+)(#)(" + jQuery.chars + "+)"); + var re2 = new RegExp("^(" + jQuery.chars + "+)(#)(" + jQuery.chars + "+)"); var m = re2.exec(t); // Re-organize the results, so that they're consistent @@ -232,7 +229,8 @@ jQuery.extend({ // Do a quick check for the existence of the actual ID attribute // to avoid selecting by the name attribute in IE - if ( (jQuery.browser.msie||jQuery.browser.opera) && oid && oid.id != m[2] ) + // 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 @@ -292,7 +290,7 @@ jQuery.extend({ ret = []; // Remove the root context - if ( ret && ret[0] == context ) + if ( ret && context == ret[0] ) ret.shift(); // And combine the results @@ -408,8 +406,9 @@ jQuery.extend({ for ( ; cur; cur = cur[dir] ) { if ( cur.nodeType == 1 ) num++; if ( num == result || result == "even" && num % 2 == 0 && num > 1 && cur == elem || - result == "odd" && num % 2 == 1 && cur == elem ) return cur; + result == "odd" && num % 2 == 1 && cur == elem ) break; } + return cur; }, /**