a zip code crypto-currency system good for red ONLY

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. import { ScrollView } from './scroll-view';
  2. /**
  3. * @name Events
  4. * @description
  5. * Events is a publish-subscribe style event system for sending and responding to application-level
  6. * events across your app.
  7. *
  8. * @usage
  9. * ```ts
  10. * import { Events } from 'ionic-angular';
  11. *
  12. * // first page (publish an event when a user is created)
  13. * constructor(public events: Events) { }
  14. *
  15. * createUser(user) {
  16. * console.log('User created!')
  17. * this.events.publish('user:created', user, Date.now());
  18. * }
  19. *
  20. *
  21. * // second page (listen for the user created event after function is called)
  22. * constructor(public events: Events) {
  23. * events.subscribe('user:created', (user, time) => {
  24. * // user and time are the same arguments passed in `events.publish(user, time)`
  25. * console.log('Welcome', user, 'at', time);
  26. * });
  27. * }
  28. *
  29. * ```
  30. * @demo /docs/demos/src/events/
  31. */
  32. var Events = (function () {
  33. function Events() {
  34. this._channels = [];
  35. }
  36. /**
  37. * Subscribe to an event topic. Events that get posted to that topic will trigger the provided handler.
  38. *
  39. * @param {string} topic the topic to subscribe to
  40. * @param {function} handler the event handler
  41. */
  42. Events.prototype.subscribe = function (topic) {
  43. var _this = this;
  44. var handlers = [];
  45. for (var _i = 1; _i < arguments.length; _i++) {
  46. handlers[_i - 1] = arguments[_i];
  47. }
  48. if (!this._channels[topic]) {
  49. this._channels[topic] = [];
  50. }
  51. handlers.forEach(function (handler) {
  52. _this._channels[topic].push(handler);
  53. });
  54. };
  55. /**
  56. * Unsubscribe from the given topic. Your handler will no longer receive events published to this topic.
  57. *
  58. * @param {string} topic the topic to unsubscribe from
  59. * @param {function} handler the event handler
  60. *
  61. * @return true if a handler was removed
  62. */
  63. Events.prototype.unsubscribe = function (topic, handler) {
  64. if (handler === void 0) { handler = null; }
  65. var t = this._channels[topic];
  66. if (!t) {
  67. // Wasn't found, wasn't removed
  68. return false;
  69. }
  70. if (!handler) {
  71. // Remove all handlers for this topic
  72. delete this._channels[topic];
  73. return true;
  74. }
  75. // We need to find and remove a specific handler
  76. var i = t.indexOf(handler);
  77. if (i < 0) {
  78. // Wasn't found, wasn't removed
  79. return false;
  80. }
  81. t.splice(i, 1);
  82. // If the channel is empty now, remove it from the channel map
  83. if (!t.length) {
  84. delete this._channels[topic];
  85. }
  86. return true;
  87. };
  88. /**
  89. * Publish an event to the given topic.
  90. *
  91. * @param {string} topic the topic to publish to
  92. * @param {any} eventData the data to send as the event
  93. */
  94. Events.prototype.publish = function (topic) {
  95. var args = [];
  96. for (var _i = 1; _i < arguments.length; _i++) {
  97. args[_i - 1] = arguments[_i];
  98. }
  99. var t = this._channels[topic];
  100. if (!t) {
  101. return null;
  102. }
  103. var responses = [];
  104. t.forEach(function (handler) {
  105. responses.push(handler.apply(void 0, args));
  106. });
  107. return responses;
  108. };
  109. return Events;
  110. }());
  111. export { Events };
  112. /**
  113. * @hidden
  114. */
  115. export function setupEvents(plt, dom) {
  116. var events = new Events();
  117. var win = plt.win();
  118. var doc = plt.doc();
  119. // start listening for resizes XXms after the app starts
  120. plt.timeout(function () {
  121. win.addEventListener('online', function (ev) {
  122. events.publish('app:online', ev);
  123. }, false);
  124. win.addEventListener('offline', function (ev) {
  125. events.publish('app:offline', ev);
  126. }, false);
  127. win.addEventListener('orientationchange', function (ev) {
  128. events.publish('app:rotated', ev);
  129. });
  130. // When that status taps, we respond
  131. win.addEventListener('statusTap', function () {
  132. // TODO: Make this more better
  133. var el = doc.elementFromPoint(plt.width() / 2, plt.height() / 2);
  134. if (!el) {
  135. return;
  136. }
  137. var contentEle = el.closest('.scroll-content');
  138. if (contentEle) {
  139. var style = contentEle.style;
  140. var scroll = new ScrollView(null, plt, dom);
  141. scroll._el = contentEle;
  142. // We need to stop scrolling if it's happening and scroll up
  143. style['WebkitBackfaceVisibility'] = 'hidden';
  144. style['WebkitTransform'] = 'translate3d(0,0,0)';
  145. dom.write(function () {
  146. style.overflow = 'hidden';
  147. function finish() {
  148. style.overflow = '';
  149. style['WebkitBackfaceVisibility'] = '';
  150. style['WebkitTransform'] = '';
  151. }
  152. var didScrollTimeout = plt.timeout(function () {
  153. finish();
  154. }, 400);
  155. scroll.scrollTo(0, 0, 300).then(function () {
  156. plt.cancelTimeout(didScrollTimeout);
  157. finish();
  158. });
  159. });
  160. }
  161. });
  162. }, 2000);
  163. return events;
  164. }
  165. /**
  166. * @hidden
  167. */
  168. export function setupProvideEvents(plt, dom) {
  169. return function () {
  170. return setupEvents(plt, dom);
  171. };
  172. }
  173. //# sourceMappingURL=events.js.map