|
| 1 | +const pointerEvents = require('./index.js'); |
| 2 | +const Interaction = require('../Interaction'); |
| 3 | + |
| 4 | +pointerEvents.signals.on('new', function ({ pointerEvent }) { |
| 5 | + pointerEvent.count = (pointerEvent.count || 0) + 1; |
| 6 | +}); |
| 7 | + |
| 8 | +pointerEvents.signals.on('fired', function ({ interaction, pointerEvent, eventTarget, targets }) { |
| 9 | + if (pointerEvent.type !== 'hold') { return; } |
| 10 | + |
| 11 | + // get the repeat interval from the first eventable |
| 12 | + const interval = targets[0].eventable.options.holdRepeatInterval; |
| 13 | + |
| 14 | + // don't repeat if the interval is 0 or less |
| 15 | + if (interval <= 0) { return; } |
| 16 | + |
| 17 | + // set a timeout to fire the holdrepeat event |
| 18 | + interaction.holdIntervalHandle = setTimeout(function () { |
| 19 | + pointerEvents.collectEventTargets(interaction, pointerEvent, pointerEvent, eventTarget, 'hold'); |
| 20 | + }, interval); |
| 21 | +}); |
| 22 | + |
| 23 | +function endHoldRepeat ({ interaction }) { |
| 24 | + // set the interaction's holdStopTime property |
| 25 | + // to stop further holdRepeat events |
| 26 | + if (interaction.holdIntervalHandle) { |
| 27 | + clearInterval(interaction.holdIntervalHandle); |
| 28 | + interaction.holdIntervalHandle = null; |
| 29 | + } |
| 30 | +} |
| 31 | + |
| 32 | +for (const signal of ['move', 'up', 'cancel', 'endall']) { |
| 33 | + Interaction.signals.on(signal, endHoldRepeat); |
| 34 | +} |
| 35 | + |
| 36 | +// don't repeat by default |
| 37 | +pointerEvents.defaults.holdRepeatInterval = 0; |
| 38 | +pointerEvents.types.push('holdrepeat'); |
0 commit comments