Skip to content

Commit

Permalink
Add key press awaitable
Browse files Browse the repository at this point in the history
  • Loading branch information
mesca committed Oct 9, 2022
1 parent 418a724 commit 8012ce0
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions timeflux_ui/www/common/assets/js/timeflux.js
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,24 @@ function sleep(duration) {
});
}

/**
* Resolve promise on keypress
*
* @param {number} code - key code
* @returns {Promise}
*/
function key(code) {
return new Promise((resolve) => {
const handler = (event) => {
if (code === undefined || event.keyCode === code) {
document.removeEventListener(event.type, handler);
resolve(true);
}
};
document.addEventListener('keydown', handler);
});
}

/**
* Load settings
*
Expand Down

0 comments on commit 8012ce0

Please sign in to comment.