Added stopMouseDownPropagation option

This commit is contained in:
Francisco Hodge 2019-03-11 18:25:51 -04:00
parent 1d0e985922
commit 8582350774

View File

@ -226,6 +226,12 @@ class SimpleKeyboard {
*/ */
/* istanbul ignore next */ /* istanbul ignore next */
handleButtonMouseDown(button, e) { handleButtonMouseDown(button, e) {
/**
* Handle event options
*/
if (this.options.preventMouseDownDefault) e.preventDefault();
if (this.options.stopMouseDownPropagation) e.stopPropagation();
/** /**
* @type {boolean} Whether the mouse is being held onKeyPress * @type {boolean} Whether the mouse is being held onKeyPress
*/ */
@ -1039,15 +1045,13 @@ class SimpleKeyboard {
!useMouseEvents !useMouseEvents
) { ) {
/** /**
* PointerEvents support * Handle PointerEvents
*/ */
buttonDOM.onpointerdown = e => { buttonDOM.onpointerdown = e => {
if (this.options.preventMouseDownDefault) e.preventDefault();
this.handleButtonClicked(button); this.handleButtonClicked(button);
this.handleButtonMouseDown(button, e); this.handleButtonMouseDown(button, e);
}; };
buttonDOM.onpointerup = e => { buttonDOM.onpointerup = e => {
if (this.options.preventMouseDownDefault) e.preventDefault();
this.handleButtonMouseUp(); this.handleButtonMouseUp();
}; };
buttonDOM.onpointercancel = e => this.handleButtonMouseUp(); buttonDOM.onpointercancel = e => this.handleButtonMouseUp();
@ -1056,6 +1060,9 @@ class SimpleKeyboard {
* Fallback for browsers not supporting PointerEvents * Fallback for browsers not supporting PointerEvents
*/ */
if (useTouchEvents) { if (useTouchEvents) {
/**
* Handle touch events
*/
buttonDOM.ontouchstart = e => { buttonDOM.ontouchstart = e => {
this.handleButtonClicked(button); this.handleButtonClicked(button);
this.handleButtonMouseDown(button, e); this.handleButtonMouseDown(button, e);
@ -1063,12 +1070,14 @@ class SimpleKeyboard {
buttonDOM.ontouchend = e => this.handleButtonMouseUp(); buttonDOM.ontouchend = e => this.handleButtonMouseUp();
buttonDOM.ontouchcancel = e => this.handleButtonMouseUp(); buttonDOM.ontouchcancel = e => this.handleButtonMouseUp();
} else { } else {
/**
* Handle mouse events
*/
buttonDOM.onclick = () => { buttonDOM.onclick = () => {
this.isMouseHold = false; this.isMouseHold = false;
this.handleButtonClicked(button); this.handleButtonClicked(button);
}; };
buttonDOM.onmousedown = e => { buttonDOM.onmousedown = e => {
if (this.options.preventMouseDownDefault) e.preventDefault();
this.handleButtonMouseDown(button, e); this.handleButtonMouseDown(button, e);
}; };
} }