Last active
August 29, 2015 14:21
-
-
Save jasonblanchard/070491c3489a26736564 to your computer and use it in GitHub Desktop.
custom batterystatus event
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
| var pluggedInEvent = new CustomEvent('batterystatus', {'detail': {level: 'low', isPlugged: false}}); | |
| var unpluggedEvent = new CustomEvent('batterystatus', {'detail': {level: 'high', isPlugged: true}}); | |
| window.addEventListener("batterysatatus", onBatteryStatus, false); | |
| function onBatteryStatus(info) { | |
| // The battery level and plugged/unplugged status | |
| // NOTE: the actual event has the level and isPlugged properties directly on the `info` attribute, so when using on device, remove the `detail` attribute so it's like: `info.level` and `info.isPlugged` | |
| console.log("Level: " + info.detail.level + " isPlugged: " + info.detail.isPlugged); | |
| } | |
| window.dispatchEvent(pluggedInEvent); | |
| window.dispatchEvent(unpluggedEvent); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment