Skip to content

Instantly share code, notes, and snippets.

@jasonblanchard
Last active August 29, 2015 14:21
Show Gist options
  • Select an option

  • Save jasonblanchard/070491c3489a26736564 to your computer and use it in GitHub Desktop.

Select an option

Save jasonblanchard/070491c3489a26736564 to your computer and use it in GitHub Desktop.
custom batterystatus event
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