Browse files

made all pseudo-class names to match case-insensitive, allowed spaces…

… in pseudo-class parameters, fixed 'reSplitGroup'
  • Loading branch information...
1 parent 91db52f commit 129a98907b655b97fe7046f2f561779c15f7104d @dperini committed Nov 29, 2012
Showing with 29 additions and 29 deletions.
  1. +13 −13 src/modules/nwmatcher-pseudos.js
  2. +2 −2 src/nwmatcher-base.js
  3. +14 −14 src/nwmatcher.js
View
26 src/modules/nwmatcher-pseudos.js
@@ -89,7 +89,7 @@
NW.Dom.registerSelector(
'nwmatcher:spseudos',
- /^\:(root|empty|(?:first|last|only)(?:-child|-of-type)|nth(?:-last)?(?:-child|-of-type)\((even|odd|(?:[+-]{0,1}\d*n)?[+-]{0,1}\d*)\))?(.*)/,
+ /^\:(root|empty|(?:first|last|only)(?:-child|-of-type)|nth(?:-last)?(?:-child|-of-type)\(\s*(even|odd|(?:[-+]{0,1}\d*n\s*)?[-+]{0,1}\s*\d*)\s*\))?(.*)/i,
function(match, source) {
var a, n, b, status = true, test, type;
@@ -121,31 +121,31 @@ NW.Dom.registerSelector(
b = 1;
} else {
b = ((n = match[2].match(/(-?\d+)$/)) ? parseInt(n[1], 10) : 0);
- a = ((n = match[2].match(/(-?\d*)n/)) ? parseInt(n[1], 10) : 0);
+ a = ((n = match[2].match(/(-?\d*)n/i)) ? parseInt(n[1], 10) : 0);
if (n && n[1] == '-') a = -1;
}
test = a > 1 ?
- (/last/.test(match[1])) ? '(n-(' + b + '))%' + a + '==0' :
+ (/last/i.test(match[1])) ? '(n-(' + b + '))%' + a + '==0' :
'n>=' + b + '&&(n-(' + b + '))%' + a + '==0' : a < -1 ?
- (/last/.test(match[1])) ? '(n-(' + b + '))%' + a + '==0' :
+ (/last/i.test(match[1])) ? '(n-(' + b + '))%' + a + '==0' :
'n<=' + b + '&&(n-(' + b + '))%' + a + '==0' : a=== 0 ?
'n==' + b :
- (/last/.test(match[1])) ?
+ (/last/i.test(match[1])) ?
a == -1 ? 'n>=' + b : 'n<=' + b :
a == -1 ? 'n<=' + b : 'n>=' + b;
source =
'if(e!==h){' +
- 'n=s[' + (/-of-type/.test(match[1]) ? '"nthOfType"' : '"nthElement"') + ']' +
- '(e,' + (/last/.test(match[1]) ? 'true' : 'false') + ');' +
+ 'n=s[' + (/-of-type/i.test(match[1]) ? '"nthOfType"' : '"nthElement"') + ']' +
+ '(e,' + (/last/i.test(match[1]) ? 'true' : 'false') + ');' +
'if(' + test + '){' + source + '}' +
'}';
} else if (match[1]) {
- a = /first/.test(match[1]) ? 'previous' : 'next';
- n = /only/.test(match[1]) ? 'previous' : 'next';
- b = /first|last/.test(match[1]);
- type = /-of-type/.test(match[1]) ? '&&n.nodeName!==e.nodeName' : '&&n.nodeName<"@"';
+ a = /first/i.test(match[1]) ? 'previous' : 'next';
+ n = /only/i.test(match[1]) ? 'previous' : 'next';
+ b = /first|last/i.test(match[1]);
+ type = /-of-type/i.test(match[1]) ? '&&n.nodeName!==e.nodeName' : '&&n.nodeName<"@"';
source = 'if(e!==h){' +
( 'n=e;while((n=n.' + a + 'Sibling)' + type + ');if(!n){' + (b ? source :
'n=e;while((n=n.' + n + 'Sibling)' + type + ');if(!n){' + source + '}') + '}' ) + '}';
@@ -167,7 +167,7 @@ NW.Dom.registerSelector(
NW.Dom.registerSelector(
'nwmatcher:dpseudos',
- /^\:(link|visited|target|active|focus|hover|checked|disabled|enabled|selected|lang\(([-\w]{2,})\)|not\(([^()]*|.*)\))?(.*)/,
+ /^\:(link|visited|target|active|focus|hover|checked|disabled|enabled|selected|lang\(([-\w]{2,})\)|not\(([^()]*|.*)\))?(.*)/i,
(function() {
var doc = document,
@@ -194,7 +194,7 @@ NW.Dom.registerSelector(
NW.Dom.emit('Negation pseudo-class only accepts simple selectors "' + match.join('') + '"');
} else {
if ('compatMode' in doc) {
- source = 'if(!' + NW.Dom.compile([ expr ], '', false) + '(e,s,r,d,h,g)){' + source + '}';
+ source = 'if(!' + NW.Dom.compile(expr, '', false) + '(e,s,r,d,h,g)){' + source + '}';
} else {
source = 'if(!s.match(e, "' + expr.replace(/\x22/g, '\\"') + '",g)){' + source +'}';
}
View
4 src/nwmatcher-base.js
@@ -93,7 +93,7 @@
'|\\[' + attributes + '\\]' +
'|\\(' + pseudoclass + '\\)' +
'|\\{' + extensions + '\\}' +
- '|,' +
+ '|(?:,|' + whitespace + ')' +
')+',
extendedValidator = standardValidator.replace(pseudoclass, '.*'),
@@ -104,7 +104,7 @@
whitespace + '|' + whitespace + '$', 'g'),
reSplitGroup = RegExp('(' +
- '[^,\\\\\\[\\]]+' +
+ '[^,\\\\()[\\]]+' +
'|\\[[^[\\]]*\\]|\\[.*\\]' +
'|\\([^()]+\\)|\\(.*\\)' +
'|\\{[^{}]+\\}|\\{.*\\}' +
View
28 src/nwmatcher.js
@@ -147,7 +147,7 @@
// dom properties selector (extension)
'|\\{' + extensions + '\\}' +
// selector group separator (comma)
- '|,' +
+ '|(?:,|' + whitespace + ')' +
// close match group
')+',
@@ -174,7 +174,7 @@
// split comma groups, exclude commas from
// quotes '' "" and from brackets () [] {}
reSplitGroup = new RegExp('(' +
- '[^,\\\\\\[\\]]+' +
+ '[^,\\\\()[\\]]+' +
'|' + skipsquare +
'|' + skipround +
'|' + skipcurly +
@@ -473,9 +473,9 @@
// precompiled Regular Expressions
Patterns = {
// structural pseudo-classes and child selectors
- spseudos: /^\:(root|empty|(?:first|last|only)(?:-child|-of-type)|nth(?:-last)?(?:-child|-of-type)\((even|odd|(?:[+-]{0,1}\d*n)?[+-]{0,1}\d*)\))?(.*)/,
+ spseudos: /^\:(root|empty|(?:first|last|only)(?:-child|-of-type)|nth(?:-last)?(?:-child|-of-type)\(\s*(even|odd|(?:[-+]{0,1}\d*n\s*)?[-+]{0,1}\s*\d*)\s*\))?(.*)/i,
// uistates + dynamic + negation pseudo-classes
- dpseudos: /^\:(link|visited|target|active|focus|hover|checked|disabled|enabled|selected|lang\(([-\w]{2,})\)|not\(([^()]*|.*)\))?(.*)/,
+ dpseudos: /^\:(link|visited|target|active|focus|hover|checked|disabled|enabled|selected|lang\(([-\w]{2,})\)|not\(([^()]*|.*)\))?(.*)/i,
// element attribute matcher
attribute: new RegExp('^\\[' + attrmatcher + '\\](.*)'),
// E > F
@@ -1077,37 +1077,37 @@
} else {
// assumes correct "an+b" format, "b" before "a" to keep "n" values
b = ((n = match[2].match(/(-?\d+)$/)) ? parseInt(n[1], 10) : 0);
- a = ((n = match[2].match(/(-?\d*)n/)) ? parseInt(n[1], 10) : 0);
+ a = ((n = match[2].match(/(-?\d*)n/i)) ? parseInt(n[1], 10) : 0);
if (n && n[1] == '-') a = -1;
}
// build test expression out of structural pseudo (an+b) parameters
// see here: http://www.w3.org/TR/css3-selectors/#nth-child-pseudo
test = a > 1 ?
- (/last/.test(match[1])) ? '(n-(' + b + '))%' + a + '==0' :
+ (/last/i.test(match[1])) ? '(n-(' + b + '))%' + a + '==0' :
'n>=' + b + '&&(n-(' + b + '))%' + a + '==0' : a < -1 ?
- (/last/.test(match[1])) ? '(n-(' + b + '))%' + a + '==0' :
+ (/last/i.test(match[1])) ? '(n-(' + b + '))%' + a + '==0' :
'n<=' + b + '&&(n-(' + b + '))%' + a + '==0' : a=== 0 ?
'n==' + b :
- (/last/.test(match[1])) ?
+ (/last/i.test(match[1])) ?
a == -1 ? 'n>=' + b : 'n<=' + b :
a == -1 ? 'n<=' + b : 'n>=' + b;
// 4 cases: 1 (nth) x 4 (child, of-type, last-child, last-of-type)
source =
'if(e!==h){' +
- 'n=s[' + (/-of-type/.test(match[1]) ? '"nthOfType"' : '"nthElement"') + ']' +
- '(e,' + (/last/.test(match[1]) ? 'true' : 'false') + ');' +
+ 'n=s[' + (/-of-type/i.test(match[1]) ? '"nthOfType"' : '"nthElement"') + ']' +
+ '(e,' + (/last/i.test(match[1]) ? 'true' : 'false') + ');' +
'if(' + test + '){' + source + '}' +
'}';
} else {
// 6 cases: 3 (first, last, only) x 1 (child) x 2 (-of-type)
- a = /first/.test(match[1]) ? 'previous' : 'next';
- n = /only/.test(match[1]) ? 'previous' : 'next';
- b = /first|last/.test(match[1]);
+ a = /first/i.test(match[1]) ? 'previous' : 'next';
+ n = /only/i.test(match[1]) ? 'previous' : 'next';
+ b = /first|last/i.test(match[1]);
- type = /of-type/.test(match[1]) ? '&&n.nodeName!=e.nodeName' : '&&n.nodeName<"@"';
+ type = /of-type/i.test(match[1]) ? '&&n.nodeName!=e.nodeName' : '&&n.nodeName<"@"';
source = 'if(e!==h){' +
( 'n=e;while((n=n.' + a + 'Sibling)' + type + ');if(!n){' + (b ? source :

0 comments on commit 129a989

Please sign in to comment.