Return button in onKeyReleased method. Tests updated. Fixes #145

This commit is contained in:
Francisco Hodge
2019-07-14 11:55:03 -04:00
parent 8ba6f879d0
commit d4e9f51182
12 changed files with 53 additions and 50 deletions
+12 -15
View File
@@ -295,15 +295,15 @@ class SimpleKeyboard {
/**
* Handles button mouseup
*/
handleButtonMouseUp() {
handleButtonMouseUp(button) {
this.isMouseHold = false;
if (this.holdInteractionTimeout) clearTimeout(this.holdInteractionTimeout);
/**
* Calling onKeyReleased
*/
if (typeof this.options.onKeyReleased === "function")
this.options.onKeyReleased();
if (button && typeof this.options.onKeyReleased === "function")
this.options.onKeyReleased(button);
}
/**
@@ -672,7 +672,7 @@ class SimpleKeyboard {
}
/**
* Called by {@link caretEventHandler} when an event that warrants a cursor position update is triggered
* Called by {@link setEventListeners} when an event that warrants a cursor position update is triggered
*/
caretEventHandler(event) {
let targetTagName;
@@ -1164,10 +1164,8 @@ class SimpleKeyboard {
this.handleButtonClicked(button);
this.handleButtonMouseDown(button, e);
};
buttonDOM.onpointerup = e => {
this.handleButtonMouseUp();
};
buttonDOM.onpointercancel = e => this.handleButtonMouseUp();
buttonDOM.onpointerup = () => this.handleButtonMouseUp(button);
buttonDOM.onpointercancel = () => this.handleButtonMouseUp(button);
} else {
/**
* Fallback for browsers not supporting PointerEvents
@@ -1180,8 +1178,8 @@ class SimpleKeyboard {
this.handleButtonClicked(button);
this.handleButtonMouseDown(button, e);
};
buttonDOM.ontouchend = e => this.handleButtonMouseUp();
buttonDOM.ontouchcancel = e => this.handleButtonMouseUp();
buttonDOM.ontouchend = () => this.handleButtonMouseUp(button);
buttonDOM.ontouchcancel = () => this.handleButtonMouseUp(button);
} else {
/**
* Handle mouse events
@@ -1190,9 +1188,8 @@ class SimpleKeyboard {
this.isMouseHold = false;
this.handleButtonClicked(button);
};
buttonDOM.onmousedown = e => {
this.handleButtonMouseDown(button, e);
};
buttonDOM.onmousedown = e => this.handleButtonMouseDown(button, e);
buttonDOM.onmouseup = () => this.handleButtonMouseUp(button);
}
}
@@ -1274,8 +1271,8 @@ class SimpleKeyboard {
/**
* Handling ontouchend, ontouchcancel
*/
document.ontouchend = e => this.handleButtonMouseUp();
document.ontouchcancel = e => this.handleButtonMouseUp();
document.ontouchend = () => this.handleButtonMouseUp();
document.ontouchcancel = () => this.handleButtonMouseUp();
} else if (!useTouchEvents) {
/**
* Handling mouseup