Created
September 16, 2014 09:01
-
-
Save toothfairy/bd278a698d5cd36f515b to your computer and use it in GitHub Desktop.
Crossbrowser howler mute on tab live
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
hidden = undefined | |
visibilityChange = undefined | |
if typeof document.hidden isnt "undefined" # Opera 12.10 and Firefox 18 and later support | |
hidden = "hidden" | |
visibilityChange = "visibilitychange" | |
else if typeof document.mozHidden isnt "undefined" | |
hidden = "mozHidden" | |
visibilityChange = "mozvisibilitychange" | |
else if typeof document.msHidden isnt "undefined" | |
hidden = "msHidden" | |
visibilityChange = "msvisibilitychange" | |
else if typeof document.webkitHidden isnt "undefined" | |
hidden = "webkitHidden" | |
visibilityChange = "webkitvisibilitychange" | |
handleVisibilityChange = -> | |
if document[hidden] | |
Howler.mute() | |
else | |
Howler.unmute() | |
return | |
document.addEventListener visibilityChange, handleVisibilityChange, false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment