mouse_and_touch.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /**
  2. * DevExtreme (events/pointer/mouse_and_touch.js)
  3. * Version: 19.1.16
  4. * Build date: Tue Oct 18 2022
  5. *
  6. * Copyright (c) 2012 - 2022 Developer Express Inc. ALL RIGHTS RESERVED
  7. * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
  8. */
  9. "use strict";
  10. var extend = require("../../core/utils/extend").extend;
  11. var BaseStrategy = require("./base");
  12. var MouseStrategy = require("./mouse");
  13. var TouchStrategy = require("./touch");
  14. var eventUtils = require("../utils");
  15. var eventMap = {
  16. dxpointerdown: "touchstart mousedown",
  17. dxpointermove: "touchmove mousemove",
  18. dxpointerup: "touchend mouseup",
  19. dxpointercancel: "touchcancel",
  20. dxpointerover: "mouseover",
  21. dxpointerout: "mouseout",
  22. dxpointerenter: "mouseenter",
  23. dxpointerleave: "mouseleave"
  24. };
  25. var activated = false;
  26. var activateStrategy = function() {
  27. if (activated) {
  28. return
  29. }
  30. MouseStrategy.activate();
  31. activated = true
  32. };
  33. var MouseAndTouchStrategy = BaseStrategy.inherit({
  34. EVENT_LOCK_TIMEOUT: 100,
  35. ctor: function() {
  36. this.callBase.apply(this, arguments);
  37. activateStrategy()
  38. },
  39. _handler: function(e) {
  40. var isMouseEvent = eventUtils.isMouseEvent(e);
  41. if (!isMouseEvent) {
  42. this._skipNextEvents = true
  43. }
  44. if (isMouseEvent && this._mouseLocked) {
  45. return
  46. }
  47. if (isMouseEvent && this._skipNextEvents) {
  48. this._skipNextEvents = false;
  49. this._mouseLocked = true;
  50. clearTimeout(this._unlockMouseTimer);
  51. var that = this;
  52. this._unlockMouseTimer = setTimeout(function() {
  53. that._mouseLocked = false
  54. }, this.EVENT_LOCK_TIMEOUT);
  55. return
  56. }
  57. return this.callBase(e)
  58. },
  59. _fireEvent: function(args) {
  60. var isMouseEvent = eventUtils.isMouseEvent(args.originalEvent);
  61. var normalizer = isMouseEvent ? MouseStrategy.normalize : TouchStrategy.normalize;
  62. return this.callBase(extend(normalizer(args.originalEvent), args))
  63. },
  64. dispose: function() {
  65. this.callBase();
  66. this._skipNextEvents = false;
  67. this._mouseLocked = false;
  68. clearTimeout(this._unlockMouseTimer)
  69. }
  70. });
  71. MouseAndTouchStrategy.map = eventMap;
  72. MouseAndTouchStrategy.resetObserver = MouseStrategy.resetObserver;
  73. module.exports = MouseAndTouchStrategy;