Skip to content

Instantly share code, notes, and snippets.

@iddan
Last active July 5, 2016 11:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iddan/037402f10b1b7451ba088557d0d5a744 to your computer and use it in GitHub Desktop.
Save iddan/037402f10b1b7451ba088557d0d5a744 to your computer and use it in GitHub Desktop.
MouseEvent.prototype.buttons Polyfill
if (!MouseEvent.prototype.hasOwnProperty('buttons')) {
let mousedown = 0;
addEventListener('mousedown', e => mousedown = e.button || 1);
addEventListener('mouseup', () => mousedown = 0);
Object.defineProperty(MouseEvent.prototype, 'buttons', {
get () {
return mousedown;
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment