Last active
December 16, 2015 07:39
-
-
Save sweatpantsninja/5400379 to your computer and use it in GitHub Desktop.
How to remove :hover styles from your stylesheets without messing up complex, useful rules like: .ok, .not-ok:hover, .also-ok { ... } FYI relies on UnderscoreJS to user _.reject(), but that's clearly a writable function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if 'createTouch' of document | |
ignore = /:hover\b/ | |
try | |
for stylesheet in document.styleSheets | |
idxsToDelete = [] | |
# detect hover rules | |
for rule, idx in stylesheet.cssRules | |
if rule.type is CSSRule.STYLE_RULE and ignore.test(rule.selectorText) | |
newSelector = _.reject rule.selectorText.split(","), (s) -> ignore.test s | |
if newSelector.length > 0 | |
newRule = newSelector.join(",").concat rule.cssText.substr(rule.cssText.indexOf("{")) | |
stylesheet.deleteRule idx | |
stylesheet.insertRule newRule, idx | |
else | |
idxsToDelete.unshift idx | |
# delete hover rules | |
stylesheet.deleteRule idx for idx in idxsToDelete |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment