All files / packages/tools/src/eventListeners/touch index.ts

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

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                        139x 139x                         128x 128x 128x                  
import preventGhostClick from './preventGhostClick';
import touchStartListener from './touchStartListener';
 
/**
 * Removes touch event listeners for native touch event. Enables
 * vtk.js tools flavored events that build on top of existing events to
 * provide more helpful information.
 *
 * @private
 * @param element - The DOM element to remove event listeners from.
 */
function disable(element: HTMLDivElement): void {
  preventGhostClick.disable(element);
  element.removeEventListener('touchstart', touchStartListener);
}
 
/**
 * Registers touch event listeners for native touch event. Enables
 * vtk.js tools flavored events that build on top of existing events to
 * provide more helpful information.
 *
 * @private
 * @param element - The DOM element to register event listeners on.
 */
function enable(element: HTMLDivElement): void {
  // Prevent handlers from being attached multiple times
  disable(element);
  preventGhostClick.enable(element);
  element.addEventListener('touchstart', touchStartListener, {
    passive: false,
  });
}
 
export default {
  enable,
  disable,
};