Button hold adjustment

This commit is contained in:
Francisco Hodge
2018-11-03 01:39:41 -04:00
parent 342918a3be
commit 2eb88579ca
4 changed files with 21 additions and 11 deletions
+18 -8
View File
@@ -259,12 +259,19 @@ class SimpleKeyboard {
*/
/* istanbul ignore next */
handleButtonHold(button){
if(this.holdInteractionTimeout)
clearTimeout(this.holdInteractionTimeout);
/**
* @type {object} Timeout dictating the speed of key hold iterations
*/
this.holdInteractionTimeout = setTimeout(() => {
this.handleButtonClicked(button);
this.handleButtonHold(button);
if(this.isMouseHold){
this.handleButtonClicked(button);
this.handleButtonHold(button);
} else {
clearTimeout(this.holdInteractionTimeout);
}
}, 100);
}
@@ -684,7 +691,10 @@ class SimpleKeyboard {
*/
var buttonDOM = document.createElement('div');
buttonDOM.className += `hg-button ${fctBtnClass}${buttonThemeClass ? " "+buttonThemeClass : ""}`;
buttonDOM.onclick = () => this.handleButtonClicked(button);
buttonDOM.onclick = () => {
this.isMouseHold = false;
this.handleButtonClicked(button);
}
buttonDOM.onmousedown = (e) => this.handleButtonMouseDown(button, e);
/**
@@ -737,17 +747,17 @@ class SimpleKeyboard {
*/
this.onRender();
/**
* Handling mouseup
*/
document.onmouseup = () => this.handleButtonMouseUp();
if(!this.initialized){
/**
* Ensures that onInit is only called once per instantiation
*/
this.initialized = true;
/**
* Handling mouseup
*/
document.onmouseup = () => this.handleButtonMouseUp();
/**
* Calling onInit
*/