ui-event-manager.js 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { PointerEvents } from './pointer-events';
  2. /**
  3. * @hidden
  4. */
  5. export class UIEventManager {
  6. constructor(plt) {
  7. this.plt = plt;
  8. this.evts = [];
  9. }
  10. pointerEvents(config) {
  11. if (!config.element || !config.pointerDown) {
  12. console.error('PointerEvents config is invalid');
  13. return;
  14. }
  15. const eventListnerOpts = {
  16. capture: config.capture,
  17. passive: config.passive,
  18. zone: config.zone
  19. };
  20. const pointerEvents = new PointerEvents(this.plt, config.element, config.pointerDown, config.pointerMove, config.pointerUp, eventListnerOpts);
  21. const removeFunc = () => pointerEvents.destroy();
  22. this.evts.push(removeFunc);
  23. return pointerEvents;
  24. }
  25. listen(ele, eventName, callback, opts) {
  26. if (ele) {
  27. var removeFunc = this.plt.registerListener(ele, eventName, callback, opts);
  28. this.evts.push(removeFunc);
  29. return removeFunc;
  30. }
  31. }
  32. unlistenAll() {
  33. this.evts.forEach(unRegEvent => {
  34. unRegEvent();
  35. });
  36. this.evts.length = 0;
  37. }
  38. destroy() {
  39. this.unlistenAll();
  40. this.evts = null;
  41. }
  42. }
  43. //# sourceMappingURL=ui-event-manager.js.map