Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
allow scoping to use an array of selectors.
Browse files Browse the repository at this point in the history
  • Loading branch information
sorvell committed Apr 15, 2014
1 parent 3ee3a6f commit 75903cc
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/ShadowCSS.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,20 +417,36 @@ var ShadowCSS = {
if (this.selectorNeedsScoping(p, scopeSelector)) {
p = (strict && !p.match(polyfillHostNoCombinator)) ?
this.applyStrictSelectorScope(p, scopeSelector) :
this.applySimpleSelectorScope(p, scopeSelector);
this.applySelectorScope(p, scopeSelector);
}
r.push(p);
}, this);
return r.join(', ');
},
selectorNeedsScoping: function(selector, scopeSelector) {
if (Array.isArray(scopeSelector)) {
return true;
}
var re = this.makeScopeMatcher(scopeSelector);
return !selector.match(re);
},
makeScopeMatcher: function(scopeSelector) {
scopeSelector = scopeSelector.replace(/\[/g, '\\[').replace(/\[/g, '\\]');
return new RegExp('^(' + scopeSelector + ')' + selectorReSuffix, 'm');
},
applySelectorScope: function(selector, selectorScope) {
return Array.isArray(selectorScope) ?
this.applySelectorScopeList(selector, selectorScope) :
this.applySimpleSelectorScope(selector, selectorScope);
},
// apply an array of selectors
applySelectorScopeList: function(selector, scopeSelectorList) {
var r = [];
for (var i=0, s; (s=scopeSelectorList[i]); i++) {
r.push(this.applySimpleSelectorScope(selector, s));
}
return r.join(', ');
},
// scope via name and [is=name]
applySimpleSelectorScope: function(selector, scopeSelector) {
if (selector.match(polyfillHostRe)) {
Expand Down

0 comments on commit 75903cc

Please sign in to comment.