Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

touch.js 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. var _helpers = require('../util/helpers');
  6. var handleGesture = function handleGesture(wrapper) {
  7. var touchstartX = wrapper.touchstartX,
  8. touchendX = wrapper.touchendX,
  9. touchstartY = wrapper.touchstartY,
  10. touchendY = wrapper.touchendY;
  11. var dirRatio = 0.5;
  12. var minDistance = 16;
  13. wrapper.offsetX = touchendX - touchstartX;
  14. wrapper.offsetY = touchendY - touchstartY;
  15. if (Math.abs(wrapper.offsetY) < dirRatio * Math.abs(wrapper.offsetX)) {
  16. wrapper.left && touchendX < touchstartX - minDistance && wrapper.left(wrapper);
  17. wrapper.right && touchendX > touchstartX + minDistance && wrapper.right(wrapper);
  18. }
  19. if (Math.abs(wrapper.offsetX) < dirRatio * Math.abs(wrapper.offsetY)) {
  20. wrapper.up && touchendY < touchstartY - minDistance && wrapper.up(wrapper);
  21. wrapper.down && touchendY > touchstartY + minDistance && wrapper.down(wrapper);
  22. }
  23. };
  24. function _touchstart(event, wrapper) {
  25. var touch = event.changedTouches[0];
  26. wrapper.touchstartX = touch.clientX;
  27. wrapper.touchstartY = touch.clientY;
  28. wrapper.start && wrapper.start(Object.assign(event, wrapper));
  29. }
  30. function _touchend(event, wrapper) {
  31. var touch = event.changedTouches[0];
  32. wrapper.touchendX = touch.clientX;
  33. wrapper.touchendY = touch.clientY;
  34. wrapper.end && wrapper.end(Object.assign(event, wrapper));
  35. handleGesture(wrapper);
  36. }
  37. function _touchmove(event, wrapper) {
  38. var touch = event.changedTouches[0];
  39. wrapper.touchmoveX = touch.clientX;
  40. wrapper.touchmoveY = touch.clientY;
  41. wrapper.move && wrapper.move(Object.assign(event, wrapper));
  42. }
  43. function createHandlers(value) {
  44. var wrapper = {
  45. touchstartX: 0,
  46. touchstartY: 0,
  47. touchendX: 0,
  48. touchendY: 0,
  49. touchmoveX: 0,
  50. touchmoveY: 0,
  51. offsetX: 0,
  52. offsetY: 0,
  53. left: value.left,
  54. right: value.right,
  55. up: value.up,
  56. down: value.down,
  57. start: value.start,
  58. move: value.move,
  59. end: value.end
  60. };
  61. return {
  62. touchstart: function touchstart(e) {
  63. return _touchstart(e, wrapper);
  64. },
  65. touchend: function touchend(e) {
  66. return _touchend(e, wrapper);
  67. },
  68. touchmove: function touchmove(e) {
  69. return _touchmove(e, wrapper);
  70. }
  71. };
  72. }
  73. function inserted(el, binding, vnode) {
  74. var value = binding.value;
  75. var target = value.parent ? el.parentElement : el;
  76. var options = value.options || { passive: true };
  77. // Needed to pass unit tests
  78. if (!target) return;
  79. var handlers = createHandlers(binding.value);
  80. target._touchHandlers = Object(target._touchHandlers);
  81. target._touchHandlers[vnode.context._uid] = handlers;
  82. (0, _helpers.keys)(handlers).forEach(function (eventName) {
  83. target.addEventListener(eventName, handlers[eventName], options);
  84. });
  85. }
  86. function unbind(el, binding, vnode) {
  87. var target = binding.value.parent ? el.parentElement : el;
  88. if (!target || !target._touchHandlers) return;
  89. var handlers = target._touchHandlers[vnode.context._uid];
  90. (0, _helpers.keys)(handlers).forEach(function (eventName) {
  91. target.removeEventListener(eventName, handlers[eventName]);
  92. });
  93. delete target._touchHandlers[vnode.context._uid];
  94. }
  95. exports.default = {
  96. inserted: inserted,
  97. unbind: unbind
  98. };
  99. //# sourceMappingURL=touch.js.map