Created
May 30, 2018 19:10
-
-
Save scottbarrow/32cdd64028e785166ae5d834faaea168 to your computer and use it in GitHub Desktop.
This file contains 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
# Converts :hover CSS to :active CSS on mobile devices. | |
# Otherwise, when tapping a button on a mobile device, the button stays in | |
# the :hover state until the button is pressed. | |
# | |
if 'ontouchstart' of document.documentElement | |
sheetI = document.styleSheets.length - 1 | |
while sheetI >= 0 | |
sheet = document.styleSheets[sheetI] | |
# Verify if cssRules exists in sheet and they are same origin | |
# (Chrome throws an exception for cross-origin requests on stylesheets) | |
try | |
cssRules = sheet.cssRules | |
catch e | |
if e.name != 'SecurityError' | |
throw e | |
if cssRules | |
# Loop through each rule in sheet | |
ruleI = cssRules.length - 1 | |
while ruleI >= 0 | |
rule = cssRules[ruleI] | |
# Verify rule has selector text | |
if rule.selectorText | |
# Replace hover psuedo-class with active psuedo-class | |
rule.selectorText = rule.selectorText.replace(':hover', ':active') | |
ruleI-- | |
sheetI-- | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment