Skip to content
Browse files

added UNIQUE_ID mode to the 'configure()' method, this allow the engi…

…ne to fully match Query Selector API returning all elements matching the same '#id' (non unique)
  • Loading branch information...
1 parent ace7b0b commit d0ab968a17799007c614f1bd33258f32f748fa3c @dperini committed Dec 31, 2012
Showing with 10 additions and 5 deletions.
  1. +3 −2 src/nwmatcher-base.js
  2. +7 −3 src/nwmatcher.js
View
5 src/nwmatcher-base.js
@@ -177,6 +177,7 @@
Config = {
CACHING: false,
SIMPLENOT: true,
+ UNIQUE_ID: true,
USE_HTML5: true,
VERBOSITY: true
},
@@ -533,7 +534,7 @@
lastPosition = selector.length - token.length;
}
- if ((parts = lastSlice.match(Optimize.ID)) && (token = parts[1])) {
+ if (Config.UNIQUE_ID && (parts = lastSlice.match(Optimize.ID)) && (token = parts[1])) {
if ((element = _byId(token, from))) {
if (match(element, selector)) {
callback && callback(element);
@@ -542,7 +543,7 @@
}
}
- else if ((parts = selector.match(Optimize.ID)) && (token = parts[1])) {
+ else if (Config.UNIQUE_ID && (parts = selector.match(Optimize.ID)) && (token = parts[1])) {
if ((element = _byId(token, doc))) {
if ('#' + token == selector) {
callback && callback(element);
View
10 src/nwmatcher.js
@@ -847,6 +847,10 @@
// ':not()' pseudo-classes, as for specifications
SIMPLENOT: true,
+ // strict QSA match all non-unique IDs (false)
+ // speed & libs compat match unique ID (true)
+ UNIQUE_ID: true,
+
// HTML5 handling for the ":checked" pseudo-class
USE_HTML5: true,
@@ -1354,7 +1358,7 @@
if (!OPERA_QSAPI && RE_SIMPLE_SELECTOR.test(selector)) {
switch (selector.charAt(0)) {
case '#':
- if ((element = _byId(selector.slice(1), from))) {
+ if (Config.UNIQUE_ID && (element = _byId(selector.slice(1), from))) {
elements = [ element ];
} else elements = [ ];
break;
@@ -1419,7 +1423,7 @@
}
// ID optimization RTL, to reduce number of elements to visit
- if ((parts = lastSlice.match(Optimize.ID)) && (token = parts[1])) {
+ if (Config.UNIQUE_ID && (parts = lastSlice.match(Optimize.ID)) && (token = parts[1])) {
if ((element = _byId(token, from))) {
if (match(element, selector)) {
callback && callback(element);
@@ -1429,7 +1433,7 @@
}
// ID optimization LTR, to reduce selection context searches
- else if ((parts = selector.match(Optimize.ID)) && (token = parts[1])) {
+ else if (Config.UNIQUE_ID && (parts = selector.match(Optimize.ID)) && (token = parts[1])) {
if ((element = _byId(token, doc))) {
if ('#' + token == selector) {
callback && callback(element);

0 comments on commit d0ab968

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