Last active
July 5, 2016 11:43
-
-
Save iddan/037402f10b1b7451ba088557d0d5a744 to your computer and use it in GitHub Desktop.
MouseEvent.prototype.buttons Polyfill
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
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