Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | 7x | import event from '../../utils/event';
export const repeatClick = {
bind(el, binding, vnode) {
const wait = +binding.arg || 400;
const interval = 100;
const handler = vnode.context[binding.expression];
let pressing = false;
let timer;
const fn = () => {
if (!pressing)
return;
handler();
timer = setTimeout(fn, interval);
};
el.__repeatClickOff = event.on(el, 'mousedown', (e) => {
// self 和 prevent 有个顺序问题,所以用 for 循环
const modifiers = Object.keys(binding.modifiers);
for (let i = 0; i < modifiers.length; i++) {
const modifier = modifiers[i];
if (modifier === 'self' && e.target !== el)
return;
else if (modifier === 'stop')
e.stopPropagation();
else if (modifier === 'prevent')
e.preventDefault();
}
// @TODO: 自定义指令其他相关
if (e.button !== 0)
return;
event.once(document, 'mouseup', () => pressing = false);
clearTimeout(timer);
pressing = true;
handler();
timer = setTimeout(fn, wait);
}, {
capture: binding.modifiers.capture,
once: binding.modifiers.once,
passive: binding.modifiers.passive,
});
},
unbind(el) {
el.__repeatClickOff();
},
};
|