a zip code crypto-currency system good for red ONLY

slide-gesture.js 3.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. var __extends = (this && this.__extends) || (function () {
  2. var extendStatics = Object.setPrototypeOf ||
  3. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  4. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  5. return function (d, b) {
  6. extendStatics(d, b);
  7. function __() { this.constructor = d; }
  8. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  9. };
  10. })();
  11. import { PanGesture } from './pan-gesture';
  12. import { clamp } from '../util/util';
  13. import { pointerCoord } from '../util/dom';
  14. /**
  15. * @hidden
  16. */
  17. var SlideGesture = (function (_super) {
  18. __extends(SlideGesture, _super);
  19. function SlideGesture(plt, element, opts) {
  20. if (opts === void 0) { opts = {}; }
  21. var _this = _super.call(this, plt, element, opts) || this;
  22. _this.slide = null;
  23. return _this;
  24. }
  25. /*
  26. * Get the min and max for the slide. pageX/pageY.
  27. * Only called on dragstart.
  28. */
  29. SlideGesture.prototype.getSlideBoundaries = function (_slide, _ev) {
  30. return {
  31. min: 0,
  32. max: this.getNativeElement().offsetWidth
  33. };
  34. };
  35. /*
  36. * Get the element's pos when the drag starts.
  37. * For example, an open side menu starts at 100% and a closed
  38. * sidemenu starts at 0%.
  39. */
  40. SlideGesture.prototype.getElementStartPos = function (_slide, _ev) {
  41. return 0;
  42. };
  43. SlideGesture.prototype.onDragStart = function (ev) {
  44. this.onSlideBeforeStart(ev);
  45. var coord = pointerCoord(ev);
  46. var pos = coord[this.direction];
  47. this.slide = {
  48. min: 0,
  49. max: 0,
  50. pointerStartPos: pos,
  51. pos: pos,
  52. timestamp: Date.now(),
  53. elementStartPos: 0,
  54. started: true,
  55. delta: 0,
  56. distance: 0,
  57. velocity: 0,
  58. };
  59. // TODO: we should run this in the next frame
  60. var _a = this.getSlideBoundaries(this.slide, ev), min = _a.min, max = _a.max;
  61. this.slide.min = min;
  62. this.slide.max = max;
  63. this.slide.elementStartPos = this.getElementStartPos(this.slide, ev);
  64. this.onSlideStart(this.slide, ev);
  65. };
  66. SlideGesture.prototype.onDragMove = function (ev) {
  67. var slide = this.slide;
  68. (void 0) /* assert */;
  69. var coord = pointerCoord(ev);
  70. var newPos = coord[this.direction];
  71. var newTimestamp = Date.now();
  72. var velocity = (this.plt.isRTL ? (slide.pos - newPos) : (newPos - slide.pos)) / (newTimestamp - slide.timestamp);
  73. slide.pos = newPos;
  74. slide.timestamp = newTimestamp;
  75. slide.distance = clamp(slide.min, (this.plt.isRTL ? slide.pointerStartPos - newPos : newPos - slide.pointerStartPos) + slide.elementStartPos, slide.max);
  76. slide.velocity = velocity;
  77. slide.delta = (this.plt.isRTL ? slide.pointerStartPos - newPos : newPos - slide.pointerStartPos);
  78. this.onSlide(slide, ev);
  79. };
  80. SlideGesture.prototype.onDragEnd = function (ev) {
  81. this.onSlideEnd(this.slide, ev);
  82. this.slide = null;
  83. };
  84. SlideGesture.prototype.onSlideBeforeStart = function (_ev) { };
  85. SlideGesture.prototype.onSlideStart = function (_slide, _ev) { };
  86. SlideGesture.prototype.onSlide = function (_slide, _ev) { };
  87. SlideGesture.prototype.onSlideEnd = function (_slide, _ev) { };
  88. return SlideGesture;
  89. }(PanGesture));
  90. export { SlideGesture };
  91. //# sourceMappingURL=slide-gesture.js.map