Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Follow-up to fix for #7452. Enable use of qSA in most cases.

This "optimization" will allow the use of qSA even for Element-rooted
hierarchy-selectors. Only when the Element-root has no parent node
it falls back to oldSizzle.
  • Loading branch information...
commit 8b3468716e629fe2340fc8e407abe8a389b0d4f5 1 parent 2080eba
@jitter jitter authored
Showing with 11 additions and 3 deletions.
  1. +7 −2 sizzle.js
  2. +4 −1 test/unit/selector.js
View
9 sizzle.js
@@ -1108,14 +1108,19 @@ if ( document.querySelectorAll ) {
// IE 8 doesn't work on object elements
} else if ( context.nodeType === 1 && context.nodeName.toLowerCase() !== "object" ) {
var old = context.getAttribute( "id" ),
- nid = old || id;
+ nid = old || id,
+ hasParent = context.parentNode,
+ relativeHierarchySelector = /^\s*[+~]/.test( query );
if ( !old ) {
context.setAttribute( "id", nid );
}
+ if ( relativeHierarchySelector && hasParent ) {
+ context = context.parentNode;
+ }
try {
- if ( !/^\s*[+~]/.test( query ) ) {
+ if ( !relativeHierarchySelector || hasParent ) {
return makeArray( context.querySelectorAll( "#" + nid + " " + query ), extra );
}
View
5 test/unit/selector.js
@@ -213,7 +213,7 @@ test("multiple", function() {
});
test("child and adjacent", function() {
- expect(29);
+ expect(31);
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"] );
@@ -237,6 +237,9 @@ test("child and adjacent", function() {
t( "Element Preceded By", "#siblingfirst ~ em", ["siblingnext"] );
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." );
+ var a = jQuery("<div id='foo'></div><p id='bar'></p><p id='bar2'></p>");
+ same( jQuery("~ p", a[0]).get(), [a[1], a[2]], "Detached Element Directly Preceded By with a context." );
+ same( jQuery("+ p", a[0]).get(), [a[1]], "Detached Element Preceded By with a context." );
t( "Verify deep class selector", "div.blah > p > a", [] );
Please sign in to comment.
Something went wrong with that request. Please try again.