Skip to content

Instantly share code, notes, and snippets.

@tomhodgins
Created April 17, 2019 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomhodgins/2faf4683f866921839b53f2b0662b26b to your computer and use it in GitHub Desktop.
Save tomhodgins/2faf4683f866921839b53f2b0662b26b to your computer and use it in GitHub Desktop.
// includes anywhere (does this now)
function selector(string, list) {
list = list || all();
if (list.cssRules) {
list = [list];
}
return list.map(function(stylesheet) {
return filter(
stylesheet,
function(rule) {
return rule.selectorText && rule.selectorText.indexOf(string) !== -1;
}
);
}).filter(hasRules);
}
// strictly matches (doesnt do this now)
function selector(string, list) {
list = list || all();
if (list.cssRules) {
list = [list];
}
return list.map(function(stylesheet) {
return filter(
stylesheet,
function(rule) {
return rule.selectorText === string;
}
);
}).filter(hasRules);
}
// both (should it be like this?)
function selector(string, list, option) {
list = list || all();
option = option || false
if (list.cssRules) {
list = [list];
}
return list.map(function(stylesheet) {
return filter(
stylesheet,
function(rule) {
if (option) {
return rule.selectorText === string
} else {
return rule.selectorText && rule.selectorText.indexOf(string) !== -1
}
}
);
}).filter(hasRules);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment