X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fselector%2Fselector.js;h=be279a7fc117277c0716aae7bb0d6c9850d115fb;hb=ddb3004a476d6eec3d449bc39d93fb5b5f98f01b;hp=001f80a21e3f704ae4503341952b86b64e399367;hpb=2b82ffbbfac419e017acea3e0f83c063549e545e;p=jquery.git diff --git a/src/selector/selector.js b/src/selector/selector.js index 001f80a..be279a7 100644 --- a/src/selector/selector.js +++ b/src/selector/selector.js @@ -14,7 +14,7 @@ jQuery.extend({ odd: "i%2", // Child Checks - "nth-child": "jQuery.nth(a.parentNode.firstChild,m[3],'nextSibling')==a", + "nth-child": "jQuery.nth(a.parentNode.firstChild,m[3],'nextSibling',a)==a", "first-child": "jQuery.nth(a.parentNode.firstChild,1,'nextSibling')==a", "last-child": "jQuery.nth(a.parentNode.lastChild,1,'previousSibling')==a", "only-child": "jQuery.sibling(a.parentNode.firstChild).length==1", @@ -76,7 +76,7 @@ jQuery.extend({ /^(:)([a-z0-9_-]*)\("?'?(.*?(\(.*?\))?[^(]*?)"?'?\)/i, // Match: :even, :last-chlid - /^([:.#]*)([a-z0-9_-]*)/i + /^([:.#]*)([a-z0-9_*-]*)/i ], token: [ @@ -153,10 +153,11 @@ jQuery.extend({ if ( m ) { // Perform our own iteration and filter - for ( var i = 0, rl = ret.length; i < rl; i++ ) - for ( var c = ret[i].firstChild; c; c = c.nextSibling ) - if ( c.nodeType == 1 && ( c.nodeName == m[1].toUpperCase() || m[1] == "*" ) ) + jQuery.each( ret, function(){ + for ( var c = this.firstChild; c; c = c.nextSibling ) + if ( c.nodeType == 1 && ( c.nodeName.toUpperCase() == m[1].toUpperCase() || m[1] == "*" ) ) r.push( c ); + }); ret = r; t = jQuery.trim( t.replace( re, "" ) ); @@ -235,20 +236,20 @@ jQuery.extend({ // We need to find all descendant elements, it is more // efficient to use getAll() when we are already further down // the tree - we try to recognize that here - for ( var i = 0, rl = ret.length; i < rl; i++ ) { + jQuery.each( ret, function(){ // Grab the tag name being searched for var tag = m[1] != "" || m[0] == "" ? "*" : m[2]; // Handle IE7 being really dumb about s - if ( ret[i].nodeName.toUpperCase() == "OBJECT" && tag == "*" ) + if ( this.nodeName.toUpperCase() == "OBJECT" && tag == "*" ) tag = "param"; jQuery.merge( r, m[1] != "" && ret.length != 1 ? - jQuery.getAll( ret[i], [], m[1], m[2], rec ) : - ret[i].getElementsByTagName( tag ) + jQuery.getAll( this, [], m[1], m[2], rec ) : + this.getElementsByTagName( tag ) ); - } + }); // It's faster to filter by class and be done with it if ( m[1] == "." && ret.length == 1 ) @@ -263,11 +264,12 @@ jQuery.extend({ r = []; // Then try to find the element with the ID - for ( var i = 0, tl = tmp.length; i < tl; i++ ) - if ( tmp[i].getAttribute("id") == m[2] ) { - r = [ tmp[i] ]; - break; + jQuery.each( tmp, function(){ + if ( this.getAttribute("id") == m[2] ) { + r = [ this ]; + return false; } + }); } ret = r; @@ -300,14 +302,13 @@ jQuery.extend({ // Look for common filter expressions while ( t && /^[a-z[({<*:.#]/i.test(t) ) { - var p = jQuery.parse; + var p = jQuery.parse, m; - for ( var i = 0, pl = p.length; i < pl; i++ ) { + jQuery.each( p, function(i,re){ // Look for, and replace, string-like sequences // and finally build a regexp out of it - var re = p[i]; - var m = re.exec( t ); + m = re.exec( t ); if ( m ) { // Remove what we just matched @@ -317,9 +318,9 @@ jQuery.extend({ if ( jQuery.expr[ m[1] ]._resort ) m = jQuery.expr[ m[1] ]._resort( m ); - break; + return false; } - } + }); // :not() is a special case that can be optimized by // keeping it out of the expression list @@ -409,13 +410,13 @@ jQuery.extend({ * @param String dir The direction to move in (pass in something like 'previousSibling' or 'nextSibling'). * @cat DOM/Traversing */ - nth: function(cur,result,dir){ + nth: function(cur,result,dir,elem){ result = result || 1; var num = 0; for ( ; cur; cur = cur[dir] ) { if ( cur.nodeType == 1 ) num++; - if ( num == result || result == "even" && num % 2 == 0 && num > 1 || - result == "odd" && num % 2 == 1 ) return cur; + if ( num == result || result == "even" && num % 2 == 0 && num > 1 && cur == elem || + result == "odd" && num % 2 == 1 && cur == elem ) return cur; } },