a zip code crypto-currency system good for red ONLY

pan-gesture.js 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. (function (factory) {
  2. if (typeof module === "object" && typeof module.exports === "object") {
  3. var v = factory(require, exports);
  4. if (v !== undefined) module.exports = v;
  5. }
  6. else if (typeof define === "function" && define.amd) {
  7. define(["require", "exports", "../util/util", "./recognizers", "../util/dom", "./ui-event-manager"], factory);
  8. }
  9. })(function (require, exports) {
  10. "use strict";
  11. Object.defineProperty(exports, "__esModule", { value: true });
  12. var util_1 = require("../util/util");
  13. var recognizers_1 = require("./recognizers");
  14. var dom_1 = require("../util/dom");
  15. var ui_event_manager_1 = require("./ui-event-manager");
  16. /**
  17. * @hidden
  18. */
  19. var PanGesture = (function () {
  20. function PanGesture(plt, element, opts) {
  21. if (opts === void 0) { opts = {}; }
  22. this.plt = plt;
  23. this.element = element;
  24. util_1.defaults(opts, {
  25. threshold: 20,
  26. maxAngle: 40,
  27. direction: 'x',
  28. zone: true,
  29. capture: false,
  30. passive: false,
  31. });
  32. this.events = new ui_event_manager_1.UIEventManager(plt);
  33. if (opts.domController) {
  34. this.debouncer = opts.domController.debouncer();
  35. }
  36. this.gestute = opts.gesture;
  37. this.direction = opts.direction;
  38. this.eventsConfig = {
  39. element: this.element,
  40. pointerDown: this.pointerDown.bind(this),
  41. pointerMove: this.pointerMove.bind(this),
  42. pointerUp: this.pointerUp.bind(this),
  43. zone: opts.zone,
  44. capture: opts.capture,
  45. passive: opts.passive
  46. };
  47. if (opts.threshold > 0) {
  48. this.detector = new recognizers_1.PanRecognizer(opts.direction, opts.threshold, opts.maxAngle);
  49. }
  50. }
  51. PanGesture.prototype.listen = function () {
  52. if (!this.isListening) {
  53. this.pointerEvents = this.events.pointerEvents(this.eventsConfig);
  54. this.isListening = true;
  55. }
  56. };
  57. PanGesture.prototype.unlisten = function () {
  58. if (this.isListening) {
  59. this.gestute && this.gestute.release();
  60. this.events.unlistenAll();
  61. this.isListening = false;
  62. }
  63. };
  64. PanGesture.prototype.destroy = function () {
  65. this.gestute && this.gestute.destroy();
  66. this.gestute = null;
  67. this.unlisten();
  68. this.events.destroy();
  69. this.events = this.element = this.gestute = null;
  70. };
  71. PanGesture.prototype.pointerDown = function (ev) {
  72. if (this.started) {
  73. return;
  74. }
  75. if (!this.canStart(ev)) {
  76. return false;
  77. }
  78. if (this.gestute) {
  79. // Release fallback
  80. this.gestute.release();
  81. // Start gesture
  82. if (!this.gestute.start()) {
  83. return false;
  84. }
  85. }
  86. this.started = true;
  87. this.captured = false;
  88. var coord = dom_1.pointerCoord(ev);
  89. if (this.detector) {
  90. this.detector.start(coord);
  91. }
  92. else {
  93. if (!this.tryToCapture(ev)) {
  94. this.started = false;
  95. this.captured = false;
  96. this.gestute.release();
  97. return false;
  98. }
  99. }
  100. return true;
  101. };
  102. PanGesture.prototype.pointerMove = function (ev) {
  103. var _this = this;
  104. (void 0) /* assert */;
  105. if (this.captured) {
  106. this.debouncer.write(function () {
  107. _this.onDragMove(ev);
  108. });
  109. return;
  110. }
  111. (void 0) /* assert */;
  112. var coord = dom_1.pointerCoord(ev);
  113. if (this.detector.detect(coord)) {
  114. if (this.detector.pan() !== 0) {
  115. if (!this.tryToCapture(ev)) {
  116. this.abort(ev);
  117. }
  118. }
  119. }
  120. };
  121. PanGesture.prototype.pointerUp = function (ev) {
  122. (void 0) /* assert */;
  123. this.debouncer.cancel();
  124. this.gestute && this.gestute.release();
  125. if (this.captured) {
  126. this.onDragEnd(ev);
  127. }
  128. else {
  129. this.notCaptured(ev);
  130. }
  131. this.captured = false;
  132. this.started = false;
  133. };
  134. PanGesture.prototype.tryToCapture = function (ev) {
  135. (void 0) /* assert */;
  136. (void 0) /* assert */;
  137. if (this.gestute && !this.gestute.capture()) {
  138. return false;
  139. }
  140. this.onDragStart(ev);
  141. this.captured = true;
  142. return true;
  143. };
  144. PanGesture.prototype.abort = function (ev) {
  145. this.started = false;
  146. this.captured = false;
  147. this.gestute.release();
  148. this.pointerEvents.stop();
  149. this.notCaptured(ev);
  150. };
  151. PanGesture.prototype.getNativeElement = function () {
  152. return this.element;
  153. };
  154. // Implemented in a subclass
  155. PanGesture.prototype.canStart = function (_ev) { return true; };
  156. PanGesture.prototype.onDragStart = function (_ev) { };
  157. PanGesture.prototype.onDragMove = function (_ev) { };
  158. PanGesture.prototype.onDragEnd = function (_ev) { };
  159. PanGesture.prototype.notCaptured = function (_ev) { };
  160. return PanGesture;
  161. }());
  162. exports.PanGesture = PanGesture;
  163. });
  164. //# sourceMappingURL=pan-gesture.js.map