mirror of https://github.com/sveltejs/svelte
Merge pull request #3947 from AlexxNB/master
fix 'action with param' example and tutorialpull/3950/head
commit
9dc5eecbcb
@ -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