a zip code crypto-currency system good for red ONLY

gesture-controller.js 9.5KB

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