From 355e55379b2d66019ada56f5d5bf105fda7c8b20 Mon Sep 17 00:00:00 2001 From: Eric Bock Date: Thu, 18 Aug 2011 02:09:05 -0400 Subject: [PATCH] Shortcut to use id selector as context should consider hierarchy --- sizzle.js | 2 +- test/unit/selector.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/sizzle.js b/sizzle.js index 07654d59..3035fb0f 100644 --- a/sizzle.js +++ b/sizzle.js @@ -96,7 +96,7 @@ var Sizzle = function( selector, context, results, seed ) { if ( context ) { ret = seed ? { expr: parts.pop(), set: makeArray(seed) } : - Sizzle.find( parts.pop(), parts.length === 1 && (parts[0] === "~" || parts[0] === "+") && context.parentNode ? context.parentNode : context, contextXML ); + Sizzle.find( parts.pop(), parts.length >= 1 && (parts[0] === "~" || parts[0] === "+") && context.parentNode ? context.parentNode : context, contextXML ); set = ret.expr ? Sizzle.filter( ret.expr, ret.set ) : diff --git a/test/unit/selector.js b/test/unit/selector.js index cead99e3..bcbcfdc3 100644 --- a/test/unit/selector.js +++ b/test/unit/selector.js @@ -230,7 +230,7 @@ test("multiple", function() { }); test("child and adjacent", function() { - expect(33); + expect(34); 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"] ); @@ -252,6 +252,7 @@ test("child and adjacent", function() { t( "Element Preceded By", "#groups ~ a", ["mark"] ); t( "Element Preceded By", "#length ~ input", ["idTest"] ); t( "Element Preceded By", "#siblingfirst ~ em", ["siblingnext"] ); + t( "Element Preceded By, Containing", "#liveHandlerOrder ~ div em:contains('1')", ["siblingfirst"] ); same( jQuery("#siblingfirst").find("~ em").get(), q("siblingnext"), "Element Preceded By with a context." ); same( jQuery("#siblingfirst").find("+ em").get(), q("siblingnext"), "Element Directly Preceded By with a context." );