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

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

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                          100x 100x 100x                         96x   96x 96x 96x              
import mouseDoubleClickListener from './mouseDoubleClickListener';
import mouseDownListener from './mouseDownListener';
import mouseMoveListener from './mouseMoveListener';
 
/**
 * Removes mouse event listeners for native mouse 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 {
  element.removeEventListener('dblclick', mouseDoubleClickListener);
  element.removeEventListener('mousedown', mouseDownListener);
  element.removeEventListener('mousemove', mouseMoveListener);
}
 
/**
 * Registers mouse event listeners for native mouse 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);
 
  element.addEventListener('dblclick', mouseDoubleClickListener);
  element.addEventListener('mousedown', mouseDownListener);
  element.addEventListener('mousemove', mouseMoveListener);
}
 
export default {
  enable,
  disable,
};