Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
Anton M. jitter authored

Showing 2 changed files with 11 additions and 3 deletions. Show diff stats Hide diff stats

  1. +7 2 sizzle.js
  2. +4 1 test/unit/selector.js
9 sizzle.js
@@ -1108,14 +1108,19 @@ if ( document.querySelectorAll ) {
1108 1108 // IE 8 doesn't work on object elements
1109 1109 } else if ( context.nodeType === 1 && context.nodeName.toLowerCase() !== "object" ) {
1110 1110 var old = context.getAttribute( "id" ),
1111   - nid = old || id;
  1111 + nid = old || id,
  1112 + hasParent = context.parentNode,
  1113 + relativeHierarchySelector = /^\s*[+~]/.test( query );
1112 1114
1113 1115 if ( !old ) {
1114 1116 context.setAttribute( "id", nid );
1115 1117 }
  1118 + if ( relativeHierarchySelector && hasParent ) {
  1119 + context = context.parentNode;
  1120 + }
1116 1121
1117 1122 try {
1118   - if ( !/^\s*[+~]/.test( query ) ) {
  1123 + if ( !relativeHierarchySelector || hasParent ) {
1119 1124 return makeArray( context.querySelectorAll( "#" + nid + " " + query ), extra );
1120 1125 }
1121 1126
5 test/unit/selector.js
@@ -213,7 +213,7 @@ test("multiple", function() {
213 213 });
214 214
215 215 test("child and adjacent", function() {
216   - expect(29);
  216 + expect(31);
217 217 t( "Child", "p > a", ["simon1","google","groups","mark","yahoo","simon"] );
218 218 t( "Child", "p> a", ["simon1","google","groups","mark","yahoo","simon"] );
219 219 t( "Child", "p >a", ["simon1","google","groups","mark","yahoo","simon"] );
@@ -237,6 +237,9 @@ test("child and adjacent", function() {
237 237 t( "Element Preceded By", "#siblingfirst ~ em", ["siblingnext"] );
238 238 same( jQuery("#siblingfirst").find("~ em").get(), q("siblingnext"), "Element Preceded By with a context." );
239 239 same( jQuery("#siblingfirst").find("+ em").get(), q("siblingnext"), "Element Directly Preceded By with a context." );
  240 + var a = jQuery("<div id='foo'></div><p id='bar'></p><p id='bar2'></p>");
  241 + same( jQuery("~ p", a[0]).get(), [a[1], a[2]], "Detached Element Directly Preceded By with a context." );
  242 + same( jQuery("+ p", a[0]).get(), [a[1]], "Detached Element Preceded By with a context." );
240 243
241 244 t( "Verify deep class selector", "div.blah > p > a", [] );
242 245

0 comments on commit 8b34687

Please sign in to comment.
Something went wrong with that request. Please try again.