Fixed a bug with certain + selectors failing (Fixes jQuery bug #4023). Also tweaked the + and > functions a little bit.

This commit is contained in:
John Resig 2009-02-16 15:36:42 +00:00
parent f0189d6181
commit 5586fedf29
2 changed files with 22 additions and 10 deletions

View File

@ -261,23 +261,32 @@ var Expr = Sizzle.selectors = {
}, },
relative: { relative: {
"+": function(checkSet, part, isXML){ "+": function(checkSet, part, isXML){
var isPartStr = typeof part === "string", var isPartStr = typeof part === "string",
isTag = isPartStr && !/\W/.test(part), isTag = isPartStr && !/\W/.test(part),
isPartStrNotTag = isPartStr && !isTag; isPartStrNotTag = isPartStr && !isTag;
if ( isTag && !isXML ) part = part.toUpperCase();
if ( isTag && !isXML ) {
part = part.toUpperCase();
}
for ( var i = 0, l = checkSet.length, elem; i < l; i++ ) { for ( var i = 0, l = checkSet.length, elem; i < l; i++ ) {
if ( elem = checkSet[i] ) { if ( (elem = checkSet[i]) ) {
while ( (elem = elem.previousSibling) && elem.nodeType !== 1 ) {}; while ( (elem = elem.previousSibling) && elem.nodeType !== 1 ) {}
checkSet[i] = isPartStrNotTag || elem && elem.nodeName === part ? checkSet[i] = isPartStrNotTag || elem && elem.nodeName === part ?
elem : elem === part; elem || false :
elem === part;
} }
} }
if (isPartStrNotTag) {
if ( isPartStrNotTag ) {
Sizzle.filter( part, checkSet, true ); Sizzle.filter( part, checkSet, true );
} }
}, },
">": function(checkSet, part, isXML){ ">": function(checkSet, part, isXML){
if ( typeof part === "string" && !/\W/.test(part) ) { var isPartStr = typeof part === "string";
if ( isPartStr && !/\W/.test(part) ) {
part = isXML ? part : part.toUpperCase(); part = isXML ? part : part.toUpperCase();
for ( var i = 0, l = checkSet.length; i < l; i++ ) { for ( var i = 0, l = checkSet.length; i < l; i++ ) {
@ -291,13 +300,13 @@ var Expr = Sizzle.selectors = {
for ( var i = 0, l = checkSet.length; i < l; i++ ) { for ( var i = 0, l = checkSet.length; i < l; i++ ) {
var elem = checkSet[i]; var elem = checkSet[i];
if ( elem ) { if ( elem ) {
checkSet[i] = typeof part === "string" ? checkSet[i] = isPartStr ?
elem.parentNode : elem.parentNode :
elem.parentNode === part; elem.parentNode === part;
} }
} }
if ( typeof part === "string" ) { if ( isPartStr ) {
Sizzle.filter( part, checkSet, true ); Sizzle.filter( part, checkSet, true );
} }
} }

View File

@ -180,7 +180,7 @@ test("multiple", function() {
}); });
test("child and adjacent", function() { test("child and adjacent", function() {
expect(45); expect(48);
t( "Child", "p > a", ["simon1","google","groups","mark","yahoo","simon"] ); t( "Child", "p > a", ["simon1","google","groups","mark","yahoo","simon"] );
t( "Child", "p> a", ["simon1","google","groups","mark","yahoo","simon"] ); t( "Child", "p> a", ["simon1","google","groups","mark","yahoo","simon"] );
t( "Child", "p >a", ["simon1","google","groups","mark","yahoo","simon"] ); t( "Child", "p >a", ["simon1","google","groups","mark","yahoo","simon"] );
@ -193,6 +193,9 @@ test("child and adjacent", function() {
t( "Adjacent", "a+ a", ["groups"] ); t( "Adjacent", "a+ a", ["groups"] );
t( "Adjacent", "a+a", ["groups"] ); t( "Adjacent", "a+a", ["groups"] );
t( "Adjacent", "p + p", ["ap","en","sap"] ); t( "Adjacent", "p + p", ["ap","en","sap"] );
t( "Adjacent", "p#firstp + p", ["ap"] );
t( "Adjacent", "p[lang=en] + p", ["sap"] );
t( "Adjacent", "a.GROUPS + code + a", ["mark"] );
t( "Comma, Child, and Adjacent", "a + a, code > a", ["groups","anchor1","anchor2"] ); t( "Comma, Child, and Adjacent", "a + a, code > a", ["groups","anchor1","anchor2"] );
t( "Verify deep class selector", "div.blah > p > a", [] ); t( "Verify deep class selector", "div.blah > p > a", [] );