Created
November 10, 2011 10:49
-
-
Save ripper234/1354590 to your computer and use it in GitHub Desktop.
Remove background-image from within :hover tags
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
// Strip all background-image styles from :hover elements | |
// This causes weird issues in Chrome | |
// http://stackoverflow.com/questions/8035366/image-flickering-on-mouseover-even-when-sprites-are-used-for-hover-image/8057250#8057250 | |
// | |
// Note - this snippet has not been thoroughly tested, and uses simple regex - it's not aware of the actual CSS structure, and might make mistakes | |
// (E.g. a "}" inside of a comment might fool it | |
def cssFile = new File("$outputDir/css/combined-sprite.css") | |
String newCss = "" | |
boolean inHover = false | |
cssFile.eachLine(){ line -> | |
def writeThisLine = ({ | |
// in/out hover mode | |
if (line =~ /\:\s*hover.*\{/) { // entering hover | |
assert !inHover, "Can't enter hover while in hover mode" | |
inHover = true; | |
return true; | |
} | |
if (inHover && line =~ /\}/) { | |
inHover = false; | |
return true; | |
} | |
return !(inHover && line =~ /background-image\s*:/) | |
})() | |
if (writeThisLine) { | |
newCss += line + "\r\n"; | |
} | |
} | |
cssFile.text = newCss |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment