a zip code crypto-currency system good for red ONLY

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. import { Inject, Injectable, forwardRef } from '@angular/core';
  2. import { App } from '../components/app/app';
  3. /** @hidden */
  4. export var GESTURE_GO_BACK_SWIPE = 'goback-swipe';
  5. /** @hidden */
  6. export var GESTURE_MENU_SWIPE = 'menu-swipe';
  7. /** @hidden */
  8. export var GESTURE_ITEM_SWIPE = 'item-swipe';
  9. /** @hidden */
  10. export var GESTURE_REFRESHER = 'refresher';
  11. /** @hidden */
  12. export var GESTURE_TOGGLE = 'toggle';
  13. /** @hidden */
  14. export var GESTURE_PRIORITY_SLIDING_ITEM = -10;
  15. /** @hidden */
  16. export var GESTURE_PRIORITY_REFRESHER = 0;
  17. /** @hidden */
  18. export var GESTURE_PRIORITY_MENU_SWIPE = 10;
  19. /** @hidden */
  20. export var GESTURE_PRIORITY_GO_BACK_SWIPE = 20;
  21. /** @hidden */
  22. export var GESTURE_PRIORITY_TOGGLE = 30;
  23. /**
  24. * @hidden
  25. */
  26. export var BLOCK_ALL = {
  27. disable: [GESTURE_MENU_SWIPE, GESTURE_GO_BACK_SWIPE],
  28. disableScroll: true
  29. };
  30. /**
  31. * @hidden
  32. */
  33. var GestureController = (function () {
  34. function GestureController(_app) {
  35. this._app = _app;
  36. this.id = 1;
  37. this.requestedStart = {};
  38. this.disabledGestures = {};
  39. this.disabledScroll = new Set();
  40. this.capturedID = null;
  41. }
  42. GestureController.prototype.createGesture = function (opts) {
  43. if (!opts.name) {
  44. throw new Error('name is undefined');
  45. }
  46. return new GestureDelegate(opts.name, this.newID(), this, opts.priority || 0, !!opts.disableScroll);
  47. };
  48. GestureController.prototype.createBlocker = function (opts) {
  49. if (opts === void 0) { opts = {}; }
  50. return new BlockerDelegate(this.newID(), this, opts.disable, !!opts.disableScroll);
  51. };
  52. GestureController.prototype.newID = function () {
  53. var id = this.id;
  54. this.id++;
  55. return id;
  56. };
  57. GestureController.prototype.start = function (gestureName, id, priority) {
  58. if (!this.canStart(gestureName)) {
  59. delete this.requestedStart[id];
  60. return false;
  61. }
  62. this.requestedStart[id] = priority;
  63. return true;
  64. };
  65. GestureController.prototype.capture = function (gestureName, id, priority) {
  66. if (!this.start(gestureName, id, priority)) {
  67. return false;
  68. }
  69. var requestedStart = this.requestedStart;
  70. var maxPriority = -10000;
  71. for (var gestureID in requestedStart) {
  72. maxPriority = Math.max(maxPriority, requestedStart[gestureID]);
  73. }
  74. if (maxPriority === priority) {
  75. this.capturedID = id;
  76. this.requestedStart = {};
  77. (void 0) /* console.debug */;
  78. return true;
  79. }
  80. delete requestedStart[id];
  81. (void 0) /* console.debug */;
  82. return false;
  83. };
  84. GestureController.prototype.release = function (id) {
  85. delete this.requestedStart[id];
  86. if (this.capturedID && id === this.capturedID) {
  87. this.capturedID = null;
  88. }
  89. };
  90. GestureController.prototype.disableGesture = function (gestureName, id) {
  91. var set = this.disabledGestures[gestureName];
  92. if (!set) {
  93. set = new Set();
  94. this.disabledGestures[gestureName] = set;
  95. }
  96. set.add(id);
  97. };
  98. GestureController.prototype.enableGesture = function (gestureName, id) {
  99. var set = this.disabledGestures[gestureName];
  100. if (set) {
  101. set.delete(id);
  102. }
  103. };
  104. GestureController.prototype.disableScroll = function (id) {
  105. var isEnabled = !this.isScrollDisabled();
  106. this.disabledScroll.add(id);
  107. if (this._app && isEnabled && this.isScrollDisabled()) {
  108. (void 0) /* console.debug */;
  109. this._app._setDisableScroll(true);
  110. }
  111. };
  112. GestureController.prototype.enableScroll = function (id) {
  113. var isDisabled = this.isScrollDisabled();
  114. this.disabledScroll.delete(id);
  115. if (this._app && isDisabled && !this.isScrollDisabled()) {
  116. (void 0) /* console.debug */;
  117. this._app._setDisableScroll(false);
  118. }
  119. };
  120. GestureController.prototype.canStart = function (gestureName) {
  121. if (this.capturedID) {
  122. (void 0) /* console.debug */;
  123. // a gesture already captured
  124. return false;
  125. }
  126. if (this.isDisabled(gestureName)) {
  127. (void 0) /* console.debug */;
  128. return false;
  129. }
  130. return true;
  131. };
  132. GestureController.prototype.isCaptured = function () {
  133. return !!this.capturedID;
  134. };
  135. GestureController.prototype.isScrollDisabled = function () {
  136. return this.disabledScroll.size > 0;
  137. };
  138. GestureController.prototype.isDisabled = function (gestureName) {
  139. var disabled = this.disabledGestures[gestureName];
  140. return !!(disabled && disabled.size > 0);
  141. };
  142. GestureController.decorators = [
  143. { type: Injectable },
  144. ];
  145. /** @nocollapse */
  146. GestureController.ctorParameters = function () { return [
  147. { type: App, decorators: [{ type: Inject, args: [forwardRef(function () { return App; }),] },] },
  148. ]; };
  149. return GestureController;
  150. }());
  151. export { GestureController };
  152. /**
  153. * @hidden
  154. */
  155. var GestureDelegate = (function () {
  156. function GestureDelegate(name, id, controller, priority, disableScroll) {
  157. this.name = name;
  158. this.id = id;
  159. this.controller = controller;
  160. this.priority = priority;
  161. this.disableScroll = disableScroll;
  162. }
  163. GestureDelegate.prototype.canStart = function () {
  164. if (!this.controller) {
  165. (void 0) /* assert */;
  166. return false;
  167. }
  168. return this.controller.canStart(this.name);
  169. };
  170. GestureDelegate.prototype.start = function () {
  171. if (!this.controller) {
  172. (void 0) /* assert */;
  173. return false;
  174. }
  175. return this.controller.start(this.name, this.id, this.priority);
  176. };
  177. GestureDelegate.prototype.capture = function () {
  178. if (!this.controller) {
  179. (void 0) /* assert */;
  180. return false;
  181. }
  182. var captured = this.controller.capture(this.name, this.id, this.priority);
  183. if (captured && this.disableScroll) {
  184. this.controller.disableScroll(this.id);
  185. }
  186. return captured;
  187. };
  188. GestureDelegate.prototype.release = function () {
  189. if (!this.controller) {
  190. (void 0) /* assert */;
  191. return;
  192. }
  193. this.controller.release(this.id);
  194. if (this.disableScroll) {
  195. this.controller.enableScroll(this.id);
  196. }
  197. };
  198. GestureDelegate.prototype.destroy = function () {
  199. this.release();
  200. this.controller = null;
  201. };
  202. return GestureDelegate;
  203. }());
  204. export { GestureDelegate };
  205. /**
  206. * @hidden
  207. */
  208. var BlockerDelegate = (function () {
  209. function BlockerDelegate(id, controller, disable, disableScroll) {
  210. this.id = id;
  211. this.controller = controller;
  212. this.disable = disable;
  213. this.disableScroll = disableScroll;
  214. this.blocked = false;
  215. }
  216. BlockerDelegate.prototype.block = function () {
  217. var _this = this;
  218. if (!this.controller) {
  219. (void 0) /* assert */;
  220. return;
  221. }
  222. if (this.disable) {
  223. this.disable.forEach(function (gesture) {
  224. _this.controller.disableGesture(gesture, _this.id);
  225. });
  226. }
  227. if (this.disableScroll) {
  228. this.controller.disableScroll(this.id);
  229. }
  230. this.blocked = true;
  231. };
  232. BlockerDelegate.prototype.unblock = function () {
  233. var _this = this;
  234. if (!this.controller) {
  235. (void 0) /* assert */;
  236. return;
  237. }
  238. if (this.disable) {
  239. this.disable.forEach(function (gesture) {
  240. _this.controller.enableGesture(gesture, _this.id);
  241. });
  242. }
  243. if (this.disableScroll) {
  244. this.controller.enableScroll(this.id);
  245. }
  246. this.blocked = false;
  247. };
  248. BlockerDelegate.prototype.destroy = function () {
  249. this.unblock();
  250. this.controller = null;
  251. };
  252. return BlockerDelegate;
  253. }());
  254. export { BlockerDelegate };
  255. //# sourceMappingURL=gesture-controller.js.map