All files / packages/tools/src/eventDispatchers touchToolEventDispatcher.ts

100% Statements 14/14
100% Branches 0/0
100% Functions 2/2
100% Lines 14/14

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 52                                  1x 96x 96x       96x 96x 96x 96x               1x 4x 4x       4x 4x 4x     1x            
import Events from '../enums/Events';
 
import {
  touchStart,
  touchStartActivate,
  touchDrag,
  touchEnd,
  touchTap,
  touchPress,
} from './touchEventHandlers';
 
/**
 * Enable these listeners are emitted in order, and can be cancelled/prevented from bubbling
 * by any previous event.
 *
 * @param element - The element to add the event listeners to.
 */
const enable = function (element: HTMLDivElement): void {
  element.addEventListener(Events.TOUCH_START, touchStart as EventListener);
  element.addEventListener(
    Events.TOUCH_START_ACTIVATE,
    touchStartActivate as EventListener
  );
  element.addEventListener(Events.TOUCH_DRAG, touchDrag as EventListener);
  element.addEventListener(Events.TOUCH_END, touchEnd as EventListener);
  element.addEventListener(Events.TOUCH_TAP, touchTap as EventListener);
  element.addEventListener(Events.TOUCH_PRESS, touchPress as EventListener);
};
 
/**
 * Disable and Remove the MouseToolEventDispatcher handlers from the element.
 *
 * @param element - HTMLDivElement
 */
const disable = function (element: HTMLDivElement) {
  element.removeEventListener(Events.TOUCH_START, touchStart as EventListener);
  element.removeEventListener(
    Events.TOUCH_START_ACTIVATE,
    touchStartActivate as EventListener
  );
  element.removeEventListener(Events.TOUCH_DRAG, touchDrag as EventListener);
  element.removeEventListener(Events.TOUCH_END, touchEnd as EventListener);
  element.removeEventListener(Events.TOUCH_PRESS, touchPress as EventListener);
};
 
const touchToolEventDispatcher = {
  enable,
  disable,
};
 
export default touchToolEventDispatcher;