You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
625 B
JavaScript
31 lines
625 B
JavaScript
"use strict";
|
|
|
|
module.exports = function createClickTimer({ timeout }) {
|
|
let timer;
|
|
|
|
// NOTE: We have separate handling for mouseDown and click events, so that even if the user double-clicks, the response to initial click feels instant.
|
|
return {
|
|
mouseDown: function () {
|
|
// returns: is first click
|
|
return (timer == null);
|
|
},
|
|
click: function () {
|
|
// returns: is double click
|
|
if (timer == null) {
|
|
timer = setTimeout(() => {
|
|
timer = null;
|
|
}, timeout);
|
|
|
|
return false;
|
|
} else {
|
|
timer = null;
|
|
|
|
return true;
|
|
}
|
|
},
|
|
isRunning: function () {
|
|
return (timer != null);
|
|
}
|
|
};
|
|
};
|