a zip code crypto-currency system good for red ONLY

tap-click.js 9.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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", "./activator", "../components/app/app", "../config/config", "../platform/dom-controller", "../gestures/gesture-controller", "../platform/platform", "../util/dom", "../gestures/pointer-events", "./ripple", "../gestures/ui-event-manager"], 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 activator_1 = require("./activator");
  14. var app_1 = require("../components/app/app");
  15. var config_1 = require("../config/config");
  16. var dom_controller_1 = require("../platform/dom-controller");
  17. var gesture_controller_1 = require("../gestures/gesture-controller");
  18. var platform_1 = require("../platform/platform");
  19. var dom_1 = require("../util/dom");
  20. var pointer_events_1 = require("../gestures/pointer-events");
  21. var ripple_1 = require("./ripple");
  22. var ui_event_manager_1 = require("../gestures/ui-event-manager");
  23. /**
  24. * @hidden
  25. */
  26. var TapClick = (function () {
  27. function TapClick(config, plt, dom, app, gestureCtrl) {
  28. this.plt = plt;
  29. this.app = app;
  30. this.gestureCtrl = gestureCtrl;
  31. this.disableClick = 0;
  32. this.events = new ui_event_manager_1.UIEventManager(plt);
  33. var activator = config.get('activator');
  34. if (activator === 'ripple') {
  35. this.activator = new ripple_1.RippleActivator(app, config, dom);
  36. }
  37. else if (activator === 'highlight') {
  38. this.activator = new activator_1.Activator(app, config, dom);
  39. }
  40. this.usePolyfill = config.getBoolean('tapPolyfill');
  41. (void 0) /* console.debug */;
  42. var doc = plt.doc();
  43. this.events.listen(doc, 'click', this.click.bind(this), { passive: false, capture: true });
  44. this.pointerEvents = this.events.pointerEvents({
  45. element: doc,
  46. pointerDown: this.pointerStart.bind(this),
  47. pointerMove: this.pointerMove.bind(this),
  48. pointerUp: this.pointerEnd.bind(this),
  49. passive: true
  50. });
  51. this.pointerEvents.mouseWait = DISABLE_NATIVE_CLICK_AMOUNT;
  52. }
  53. TapClick.prototype.pointerStart = function (ev) {
  54. if (this.startCoord) {
  55. return false;
  56. }
  57. if (!this.app.isEnabled()) {
  58. return false;
  59. }
  60. this.lastTouchEnd = 0;
  61. this.dispatchClick = true;
  62. if (this.plt.doc() === ev.target) {
  63. this.startCoord = dom_1.pointerCoord(ev);
  64. return true;
  65. }
  66. this.activatableEle = getActivatableTarget(ev.target);
  67. if (!this.activatableEle) {
  68. this.startCoord = null;
  69. return false;
  70. }
  71. this.startCoord = dom_1.pointerCoord(ev);
  72. this.activator && this.activator.downAction(ev, this.activatableEle, this.startCoord);
  73. return true;
  74. };
  75. TapClick.prototype.pointerMove = function (ev) {
  76. if (this.startCoord && this.shouldCancelEvent(ev)) {
  77. this.pointerCancel(ev);
  78. }
  79. };
  80. TapClick.prototype.pointerEnd = function (ev, pointerEventType) {
  81. if (!this.dispatchClick)
  82. return;
  83. (void 0) /* runInDev */;
  84. if (!this.startCoord) {
  85. return;
  86. }
  87. if (this.activator && ev.target !== this.plt.doc()) {
  88. var activatableEle = getActivatableTarget(ev.target) || this.activatableEle;
  89. if (activatableEle) {
  90. this.activator.upAction(ev, activatableEle, this.startCoord);
  91. }
  92. }
  93. if (this.usePolyfill && pointerEventType === pointer_events_1.POINTER_EVENT_TYPE_TOUCH && this.app.isEnabled()) {
  94. this.handleTapPolyfill(ev);
  95. }
  96. this.startCoord = null;
  97. this.activatableEle = null;
  98. };
  99. TapClick.prototype.pointerCancel = function (ev) {
  100. (void 0) /* console.debug */;
  101. this.startCoord = null;
  102. this.activatableEle = null;
  103. this.dispatchClick = false;
  104. this.activator && this.activator.clearState(false);
  105. this.pointerEvents.stop();
  106. };
  107. TapClick.prototype.shouldCancelEvent = function (ev) {
  108. return (this.app.isScrolling() ||
  109. this.gestureCtrl.isCaptured() ||
  110. dom_1.hasPointerMoved(POINTER_TOLERANCE, this.startCoord, dom_1.pointerCoord(ev)));
  111. };
  112. TapClick.prototype.click = function (ev) {
  113. if (this.shouldCancelClick(ev)) {
  114. ev.preventDefault();
  115. ev.stopPropagation();
  116. return;
  117. }
  118. if (this.activator && this.plt.doc() !== ev.target) {
  119. // cool, a click is gonna happen, let's tell the activator
  120. // so the element can get the given "active" style
  121. var activatableEle = getActivatableTarget(ev.target);
  122. if (activatableEle) {
  123. this.activator.clickAction(ev, activatableEle, this.startCoord);
  124. }
  125. }
  126. (void 0) /* runInDev */;
  127. };
  128. TapClick.prototype.shouldCancelClick = function (ev) {
  129. if (this.usePolyfill) {
  130. if (!ev.isIonicTap && this.isDisabledNativeClick()) {
  131. (void 0) /* console.debug */;
  132. return true;
  133. }
  134. }
  135. else if (!this.dispatchClick) {
  136. (void 0) /* console.debug */;
  137. return true;
  138. }
  139. if (!this.app.isEnabled()) {
  140. (void 0) /* console.debug */;
  141. return true;
  142. }
  143. if (this.gestureCtrl.isCaptured()) {
  144. (void 0) /* console.debug */;
  145. return true;
  146. }
  147. return false;
  148. };
  149. TapClick.prototype.profileClickDelay = function (ev) {
  150. if (this.lastTouchEnd) {
  151. var diff = Date.now() - this.lastTouchEnd;
  152. if (diff < 100) {
  153. (void 0) /* console.debug */;
  154. }
  155. else {
  156. console.warn("SLOW click dispatched. Delay(ms):", diff, ev);
  157. }
  158. this.lastTouchEnd = null;
  159. }
  160. else {
  161. (void 0) /* console.debug */;
  162. }
  163. };
  164. TapClick.prototype.handleTapPolyfill = function (ev) {
  165. (void 0) /* assert */;
  166. // only dispatch mouse click events from a touchend event
  167. // when tapPolyfill config is true, and the startCoordand endCoord
  168. // are not too far off from each other
  169. var endCoord = dom_1.pointerCoord(ev);
  170. if (dom_1.hasPointerMoved(POINTER_TOLERANCE, this.startCoord, endCoord)) {
  171. (void 0) /* console.debug */;
  172. return;
  173. }
  174. // prevent native mouse click events for XX amount of time
  175. this.disableClick = Date.now() + DISABLE_NATIVE_CLICK_AMOUNT;
  176. if (this.app.isScrolling()) {
  177. // do not fire off a click event while the app was scrolling
  178. (void 0) /* console.debug */;
  179. }
  180. else {
  181. // dispatch a mouse click event
  182. (void 0) /* console.debug */;
  183. var clickEvent = this.plt.doc().createEvent('MouseEvents');
  184. clickEvent.initMouseEvent('click', true, true, this.plt.win(), 1, 0, 0, endCoord.x, endCoord.y, false, false, false, false, 0, null);
  185. clickEvent.isIonicTap = true;
  186. ev.target.dispatchEvent(clickEvent);
  187. }
  188. };
  189. TapClick.prototype.isDisabledNativeClick = function () {
  190. return this.disableClick > Date.now();
  191. };
  192. TapClick.decorators = [
  193. { type: core_1.Injectable },
  194. ];
  195. /** @nocollapse */
  196. TapClick.ctorParameters = function () { return [
  197. { type: config_1.Config, },
  198. { type: platform_1.Platform, },
  199. { type: dom_controller_1.DomController, },
  200. { type: app_1.App, },
  201. { type: gesture_controller_1.GestureController, },
  202. ]; };
  203. return TapClick;
  204. }());
  205. exports.TapClick = TapClick;
  206. function getActivatableTarget(ele) {
  207. var targetEle = ele;
  208. for (var x = 0; x < 10; x++) {
  209. if (!targetEle)
  210. break;
  211. if (isActivatable(targetEle)) {
  212. return targetEle;
  213. }
  214. targetEle = targetEle.parentElement;
  215. }
  216. return null;
  217. }
  218. /**
  219. * @hidden
  220. */
  221. function isActivatable(ele) {
  222. if (ACTIVATABLE_ELEMENTS.indexOf(ele.tagName) > -1) {
  223. return true;
  224. }
  225. for (var i = 0, l = ACTIVATABLE_ATTRIBUTES.length; i < l; i++) {
  226. if (ele.hasAttribute && ele.hasAttribute(ACTIVATABLE_ATTRIBUTES[i])) {
  227. return true;
  228. }
  229. }
  230. return false;
  231. }
  232. exports.isActivatable = isActivatable;
  233. var ACTIVATABLE_ELEMENTS = ['A', 'BUTTON'];
  234. var ACTIVATABLE_ATTRIBUTES = ['tappable', 'ion-button'];
  235. var POINTER_TOLERANCE = 100;
  236. var DISABLE_NATIVE_CLICK_AMOUNT = 2500;
  237. /**
  238. * @hidden
  239. */
  240. function setupTapClick(config, plt, dom, app, gestureCtrl) {
  241. return function () {
  242. return new TapClick(config, plt, dom, app, gestureCtrl);
  243. };
  244. }
  245. exports.setupTapClick = setupTapClick;
  246. });
  247. //# sourceMappingURL=tap-click.js.map