mirror of https://github.com/sveltejs/svelte
parent
39bbac4393
commit
2285ee222a
@ -1,17 +1,25 @@
|
||||
export function longpress(node) {
|
||||
export function longpress(node, duration) {
|
||||
let timer;
|
||||
|
||||
const handleMousedown = () => {
|
||||
setTimeout(() => {
|
||||
timer = setTimeout(() => {
|
||||
node.dispatchEvent(
|
||||
new CustomEvent('longpress')
|
||||
);
|
||||
}, 500);
|
||||
};
|
||||
|
||||
const handleMouseup = () => {
|
||||
clearTimeout(timer)
|
||||
};
|
||||
|
||||
node.addEventListener('mousedown', handleMousedown);
|
||||
node.addEventListener('mouseup', handleMouseup);
|
||||
|
||||
return {
|
||||
destroy() {
|
||||
node.removeEventListener('mousedown', handleMousedown);
|
||||
node.removeEventListener('mouseup', handleMouseup);
|
||||
}
|
||||
};
|
||||
}
|
Loading…
Reference in new issue