all files / lib/util/ ClickTrap.js

83.33% Statements 5/6
100% Branches 2/2
66.67% Functions 2/3
83.33% Lines 5/6
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21                                
var TRAP_PRIORITY = 5000;
 
/**
 * Installs a click trap that prevents a ghost click following a dragging operation.
 *
 * @return {Function} a function to immediately remove the installed trap.
 */
export function install(eventBus, eventName) {
 
  eventName = eventName || 'element.click';
 
  function trap() {
    return false;
  }
 
  eventBus.once(eventName, TRAP_PRIORITY, trap);
 
  return function() {
    eventBus.off(eventName, trap);
  };
}