a zip code crypto-currency system good for red ONLY

slide-gesture.js 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. (function (factory) {
  12. if (typeof module === "object" && typeof module.exports === "object") {
  13. var v = factory(require, exports);
  14. if (v !== undefined) module.exports = v;
  15. }
  16. else if (typeof define === "function" && define.amd) {
  17. define(["require", "exports", "./pan-gesture", "../util/util", "../util/dom"], factory);
  18. }
  19. })(function (require, exports) {
  20. "use strict";
  21. Object.defineProperty(exports, "__esModule", { value: true });
  22. var pan_gesture_1 = require("./pan-gesture");
  23. var util_1 = require("../util/util");
  24. var dom_1 = require("../util/dom");
  25. /**
  26. * @hidden
  27. */
  28. var SlideGesture = (function (_super) {
  29. __extends(SlideGesture, _super);
  30. function SlideGesture(plt, element, opts) {
  31. if (opts === void 0) { opts = {}; }
  32. var _this = _super.call(this, plt, element, opts) || this;
  33. _this.slide = null;
  34. return _this;
  35. }
  36. /*
  37. * Get the min and max for the slide. pageX/pageY.
  38. * Only called on dragstart.
  39. */
  40. SlideGesture.prototype.getSlideBoundaries = function (_slide, _ev) {
  41. return {
  42. min: 0,
  43. max: this.getNativeElement().offsetWidth
  44. };
  45. };
  46. /*
  47. * Get the element's pos when the drag starts.
  48. * For example, an open side menu starts at 100% and a closed
  49. * sidemenu starts at 0%.
  50. */
  51. SlideGesture.prototype.getElementStartPos = function (_slide, _ev) {
  52. return 0;
  53. };
  54. SlideGesture.prototype.onDragStart = function (ev) {
  55. this.onSlideBeforeStart(ev);
  56. var coord = dom_1.pointerCoord(ev);
  57. var pos = coord[this.direction];
  58. this.slide = {
  59. min: 0,
  60. max: 0,
  61. pointerStartPos: pos,
  62. pos: pos,
  63. timestamp: Date.now(),
  64. elementStartPos: 0,
  65. started: true,
  66. delta: 0,
  67. distance: 0,
  68. velocity: 0,
  69. };
  70. // TODO: we should run this in the next frame
  71. var _a = this.getSlideBoundaries(this.slide, ev), min = _a.min, max = _a.max;
  72. this.slide.min = min;
  73. this.slide.max = max;
  74. this.slide.elementStartPos = this.getElementStartPos(this.slide, ev);
  75. this.onSlideStart(this.slide, ev);
  76. };
  77. SlideGesture.prototype.onDragMove = function (ev) {
  78. var slide = this.slide;
  79. (void 0) /* assert */;
  80. var coord = dom_1.pointerCoord(ev);
  81. var newPos = coord[this.direction];
  82. var newTimestamp = Date.now();
  83. var velocity = (this.plt.isRTL ? (slide.pos - newPos) : (newPos - slide.pos)) / (newTimestamp - slide.timestamp);
  84. slide.pos = newPos;
  85. slide.timestamp = newTimestamp;
  86. slide.distance = util_1.clamp(slide.min, (this.plt.isRTL ? slide.pointerStartPos - newPos : newPos - slide.pointerStartPos) + slide.elementStartPos, slide.max);
  87. slide.velocity = velocity;
  88. slide.delta = (this.plt.isRTL ? slide.pointerStartPos - newPos : newPos - slide.pointerStartPos);
  89. this.onSlide(slide, ev);
  90. };
  91. SlideGesture.prototype.onDragEnd = function (ev) {
  92. this.onSlideEnd(this.slide, ev);
  93. this.slide = null;
  94. };
  95. SlideGesture.prototype.onSlideBeforeStart = function (_ev) { };
  96. SlideGesture.prototype.onSlideStart = function (_slide, _ev) { };
  97. SlideGesture.prototype.onSlide = function (_slide, _ev) { };
  98. SlideGesture.prototype.onSlideEnd = function (_slide, _ev) { };
  99. return SlideGesture;
  100. }(pan_gesture_1.PanGesture));
  101. exports.SlideGesture = SlideGesture;
  102. });
  103. //# sourceMappingURL=slide-gesture.js.map