TouchEventManager.js 957 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Mod with extended long tap
  2. export class TouchEventManager {
  3. ontouch = null;
  4. onlongtouch = null;
  5. ontouchdown = null;
  6. ontouchup = null;
  7. ontouchmove = null;
  8. constructor(widget) {
  9. this._init(widget);
  10. }
  11. _init(widget) {
  12. let handleClick = true;
  13. let timerLongTap = -1;
  14. widget.addEventListener(hmUI.event.CLICK_UP, (e) => {
  15. if(this.ontouchup) this.ontouchup(e);
  16. if(handleClick && this.ontouch) this.ontouch(e);
  17. handleClick = false;
  18. timer.stopTimer(timerLongTap);
  19. });
  20. widget.addEventListener(hmUI.event.CLICK_DOWN, (e) => {
  21. if(this.ontouchdown) this.ontouchdown(e);
  22. handleClick = true;
  23. timerLongTap = timer.createTimer(1500, 0, () => {
  24. if(handleClick && this.onlongtouch) {
  25. this.onlongtouch(e);
  26. handleClick = false;
  27. }
  28. })
  29. });
  30. widget.addEventListener(hmUI.event.MOVE, (e) => {
  31. if(this.ontouchmove) this.ontouchmove(e);
  32. handleClick = false;
  33. timer.stopTimer(timerLongTap);
  34. })
  35. }
  36. }