a zip code crypto-currency system good for red ONLY

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  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", "@angular/platform-browser", "./app-constants", "../../config/config", "../../navigation/nav-util", "./menu-controller", "../../platform/platform", "../../transitions/transition-ios", "../../transitions/transition-md", "../../transitions/transition-wp"], 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 platform_browser_1 = require("@angular/platform-browser");
  14. var Constants = require("./app-constants");
  15. var config_1 = require("../../config/config");
  16. var nav_util_1 = require("../../navigation/nav-util");
  17. var menu_controller_1 = require("./menu-controller");
  18. var platform_1 = require("../../platform/platform");
  19. var transition_ios_1 = require("../../transitions/transition-ios");
  20. var transition_md_1 = require("../../transitions/transition-md");
  21. var transition_wp_1 = require("../../transitions/transition-wp");
  22. /**
  23. * @name App
  24. * @description
  25. * App is a utility class used in Ionic to get information about various aspects of an app
  26. */
  27. var App = (function () {
  28. function App(_config, _plt, _menuCtrl) {
  29. this._config = _config;
  30. this._plt = _plt;
  31. this._menuCtrl = _menuCtrl;
  32. this._disTime = 0;
  33. this._scrollTime = 0;
  34. this._title = '';
  35. this._titleSrv = new platform_browser_1.Title(platform_browser_1.DOCUMENT);
  36. this._rootNavs = new Map();
  37. this._didScroll = false;
  38. /**
  39. * Observable that emits whenever a view loads in the app.
  40. * @returns {Observable} Returns an observable
  41. */
  42. this.viewDidLoad = new core_1.EventEmitter();
  43. /**
  44. * Observable that emits before any view is entered in the app.
  45. * @returns {Observable} Returns an observable
  46. */
  47. this.viewWillEnter = new core_1.EventEmitter();
  48. /**
  49. * Observable that emits after any view is entered in the app.
  50. * @returns {Observable} Returns an observable
  51. */
  52. this.viewDidEnter = new core_1.EventEmitter();
  53. /**
  54. * Observable that emits before any view is exited in the app.
  55. * @returns {Observable} Returns an observable
  56. */
  57. this.viewWillLeave = new core_1.EventEmitter();
  58. /**
  59. * Observable that emits after any view is exited in the app.
  60. * @returns {Observable} Returns an observable
  61. */
  62. this.viewDidLeave = new core_1.EventEmitter();
  63. /**
  64. * Observable that emits before any view unloads in the app.
  65. * @returns {Observable} Returns an observable
  66. */
  67. this.viewWillUnload = new core_1.EventEmitter();
  68. // listen for hardware back button events
  69. // register this back button action with a default priority
  70. _plt.registerBackButtonAction(this.goBack.bind(this));
  71. this._disableScrollAssist = _config.getBoolean('disableScrollAssist', false);
  72. var blurring = _config.getBoolean('inputBlurring', false);
  73. if (blurring) {
  74. this._enableInputBlurring();
  75. }
  76. (void 0) /* runInDev */;
  77. _config.setTransition('ios-transition', transition_ios_1.IOSTransition);
  78. _config.setTransition('md-transition', transition_md_1.MDTransition);
  79. _config.setTransition('wp-transition', transition_wp_1.WPTransition);
  80. }
  81. /**
  82. * Sets the document title.
  83. * @param {string} val Value to set the document title to.
  84. */
  85. App.prototype.setTitle = function (val) {
  86. if (val !== this._title) {
  87. this._title = val;
  88. this._titleSrv.setTitle(val);
  89. }
  90. };
  91. /**
  92. * @hidden
  93. */
  94. App.prototype.setElementClass = function (className, isAdd) {
  95. this._appRoot.setElementClass(className, isAdd);
  96. };
  97. /**
  98. * @hidden
  99. * Sets if the app is currently enabled or not, meaning if it's
  100. * available to accept new user commands. For example, this is set to `false`
  101. * while views transition, a modal slides up, an action-sheet
  102. * slides up, etc. After the transition completes it is set back to `true`.
  103. * @param {boolean} isEnabled `true` for enabled, `false` for disabled
  104. * @param {number} duration When `isEnabled` is set to `false`, this argument
  105. * is used to set the maximum number of milliseconds that app will wait until
  106. * it will automatically enable the app again. It's basically a fallback incase
  107. * something goes wrong during a transition and the app wasn't re-enabled correctly.
  108. */
  109. App.prototype.setEnabled = function (isEnabled, duration, minDuration) {
  110. if (duration === void 0) { duration = 700; }
  111. if (minDuration === void 0) { minDuration = 0; }
  112. this._disTime = (isEnabled ? 0 : Date.now() + duration);
  113. if (this._clickBlock) {
  114. if (isEnabled) {
  115. // disable the click block if it's enabled, or the duration is tiny
  116. this._clickBlock.activate(false, CLICK_BLOCK_BUFFER_IN_MILLIS, minDuration);
  117. }
  118. else {
  119. // show the click block for duration + some number
  120. this._clickBlock.activate(true, duration + CLICK_BLOCK_BUFFER_IN_MILLIS, minDuration);
  121. }
  122. }
  123. };
  124. /**
  125. * @hidden
  126. * Toggles whether an application can be scrolled
  127. * @param {boolean} disableScroll when set to `false`, the application's
  128. * scrolling is enabled. When set to `true`, scrolling is disabled.
  129. */
  130. App.prototype._setDisableScroll = function (disableScroll) {
  131. if (this._disableScrollAssist) {
  132. this._appRoot._disableScroll(disableScroll);
  133. }
  134. };
  135. /**
  136. * @hidden
  137. * Boolean if the app is actively enabled or not.
  138. * @return {boolean}
  139. */
  140. App.prototype.isEnabled = function () {
  141. var disTime = this._disTime;
  142. if (disTime === 0) {
  143. return true;
  144. }
  145. return (disTime < Date.now());
  146. };
  147. /**
  148. * @hidden
  149. */
  150. App.prototype.setScrolling = function () {
  151. this._scrollTime = Date.now() + ACTIVE_SCROLLING_TIME;
  152. this._didScroll = true;
  153. };
  154. /**
  155. * Boolean if the app is actively scrolling or not.
  156. * @return {boolean} returns true or false
  157. */
  158. App.prototype.isScrolling = function () {
  159. var scrollTime = this._scrollTime;
  160. if (scrollTime === 0) {
  161. return false;
  162. }
  163. if (scrollTime < Date.now()) {
  164. this._scrollTime = 0;
  165. return false;
  166. }
  167. return true;
  168. };
  169. /**
  170. * @return {NavController} Returns the first Active Nav Controller from the list. This method is deprecated
  171. */
  172. App.prototype.getActiveNav = function () {
  173. console.warn('(getActiveNav) is deprecated and will be removed in the next major release. Use getActiveNavs instead.');
  174. var navs = this.getActiveNavs();
  175. if (navs && navs.length) {
  176. return navs[0];
  177. }
  178. return null;
  179. };
  180. /**
  181. * @return {NavController[]} Returns the active NavControllers. Using this method is preferred when we need access to the top-level navigation controller while on the outside views and handlers like `registerBackButtonAction()`
  182. */
  183. App.prototype.getActiveNavs = function (rootNavId) {
  184. var portal = this._appRoot._getPortal(Constants.PORTAL_MODAL);
  185. if (portal.length() > 0) {
  186. return findTopNavs(portal);
  187. }
  188. if (!this._rootNavs || !this._rootNavs.size) {
  189. return [];
  190. }
  191. if (this._rootNavs.size === 1) {
  192. return findTopNavs(this._rootNavs.values().next().value);
  193. }
  194. if (rootNavId) {
  195. return findTopNavs(this._rootNavs.get(rootNavId));
  196. }
  197. // fallback to just using all root names
  198. var activeNavs = [];
  199. this._rootNavs.forEach(function (nav) {
  200. var topNavs = findTopNavs(nav);
  201. activeNavs = activeNavs.concat(topNavs);
  202. });
  203. return activeNavs;
  204. };
  205. App.prototype.getRootNav = function () {
  206. console.warn('(getRootNav) is deprecated and will be removed in the next major release. Use getRootNavById instead.');
  207. var rootNavs = this.getRootNavs();
  208. if (rootNavs.length === 0) {
  209. return null;
  210. }
  211. else if (rootNavs.length > 1) {
  212. console.warn('(getRootNav) there are multiple root navs, use getRootNavs instead');
  213. }
  214. return rootNavs[0];
  215. };
  216. App.prototype.getRootNavs = function () {
  217. var navs = [];
  218. this._rootNavs.forEach(function (nav) { return navs.push(nav); });
  219. return navs;
  220. };
  221. /**
  222. * @return {NavController} Returns the root NavController
  223. */
  224. App.prototype.getRootNavById = function (navId) {
  225. return this._rootNavs.get(navId);
  226. };
  227. /**
  228. * @hidden
  229. */
  230. App.prototype.registerRootNav = function (nav) {
  231. this._rootNavs.set(nav.id, nav);
  232. };
  233. /**
  234. * @hidden
  235. */
  236. App.prototype.unregisterRootNav = function (nav) {
  237. this._rootNavs.delete(nav.id);
  238. };
  239. App.prototype.getActiveNavContainers = function () {
  240. // for each root nav container, get it's active nav
  241. var list = [];
  242. this._rootNavs.forEach(function (container) {
  243. list = list.concat(findTopNavs(container));
  244. });
  245. return list;
  246. };
  247. /**
  248. * @hidden
  249. */
  250. App.prototype.present = function (enteringView, opts, appPortal) {
  251. (void 0) /* assert */;
  252. var portal = this._appRoot._getPortal(appPortal);
  253. // Set Nav must be set here in order to dimiss() work synchnously.
  254. // TODO: move _setNav() to the earlier stages of NavController. _queueTrns()
  255. enteringView._setNav(portal);
  256. opts.direction = nav_util_1.DIRECTION_FORWARD;
  257. if (!opts.animation) {
  258. opts.animation = enteringView.getTransitionName(nav_util_1.DIRECTION_FORWARD);
  259. }
  260. enteringView.setLeavingOpts({
  261. keyboardClose: opts.keyboardClose,
  262. direction: nav_util_1.DIRECTION_BACK,
  263. animation: enteringView.getTransitionName(nav_util_1.DIRECTION_BACK),
  264. ev: opts.ev
  265. });
  266. return portal.insertPages(-1, [enteringView], opts);
  267. };
  268. /**
  269. * @hidden
  270. */
  271. App.prototype.goBack = function () {
  272. if (this._menuCtrl && this._menuCtrl.isOpen()) {
  273. return this._menuCtrl.close();
  274. }
  275. var navPromise = this.navPop();
  276. if (!navPromise) {
  277. // no views to go back to
  278. // let's exit the app
  279. if (this._config.getBoolean('navExitApp', true)) {
  280. (void 0) /* console.debug */;
  281. this._plt.exitApp();
  282. }
  283. }
  284. return navPromise;
  285. };
  286. /**
  287. * @hidden
  288. */
  289. App.prototype.navPop = function () {
  290. var _this = this;
  291. if (!this._rootNavs || this._rootNavs.size === 0 || !this.isEnabled()) {
  292. return Promise.resolve();
  293. }
  294. // If there are any alert/actionsheet open, let's do nothing
  295. var portal = this._appRoot._getPortal(Constants.PORTAL_DEFAULT);
  296. if (portal.length() > 0) {
  297. return Promise.resolve();
  298. }
  299. var navToPop = null;
  300. var mostRecentVC = null;
  301. this._rootNavs.forEach(function (navContainer) {
  302. var activeNavs = _this.getActiveNavs(navContainer.id);
  303. var poppableNavs = activeNavs.map(function (activeNav) { return getPoppableNav(activeNav); }).filter(function (nav) { return !!nav; });
  304. poppableNavs.forEach(function (poppable) {
  305. var topViewController = poppable.last();
  306. if (poppable._isPortal || (topViewController && poppable.length() > 1 && (!mostRecentVC || topViewController._ts >= mostRecentVC._ts))) {
  307. mostRecentVC = topViewController;
  308. navToPop = poppable;
  309. }
  310. });
  311. });
  312. if (navToPop) {
  313. return navToPop.pop();
  314. }
  315. };
  316. /**
  317. * @hidden
  318. */
  319. App.prototype._enableInputBlurring = function () {
  320. (void 0) /* console.debug */;
  321. var focused = true;
  322. var self = this;
  323. var platform = this._plt;
  324. platform.registerListener(platform.doc(), 'focusin', onFocusin, { capture: true, zone: false, passive: true });
  325. platform.registerListener(platform.doc(), 'touchend', onTouchend, { capture: false, zone: false, passive: true });
  326. function onFocusin() {
  327. focused = true;
  328. }
  329. function onTouchend(ev) {
  330. // if app did scroll return early
  331. if (self._didScroll) {
  332. self._didScroll = false;
  333. return;
  334. }
  335. var active = self._plt.getActiveElement();
  336. if (!active) {
  337. return;
  338. }
  339. // only blur if the active element is a text-input or a textarea
  340. if (SKIP_BLURRING.indexOf(active.tagName) === -1) {
  341. return;
  342. }
  343. // if the selected target is the active element, do not blur
  344. var tapped = ev.target;
  345. if (tapped === active) {
  346. return;
  347. }
  348. if (SKIP_BLURRING.indexOf(tapped.tagName) >= 0) {
  349. return;
  350. }
  351. // skip if div is a cover
  352. if (tapped.classList.contains('input-cover')) {
  353. return;
  354. }
  355. focused = false;
  356. // TODO: find a better way, why 50ms?
  357. platform.timeout(function () {
  358. if (!focused) {
  359. active.blur();
  360. }
  361. }, 50);
  362. }
  363. };
  364. App.prototype.getNavByIdOrName = function (id) {
  365. var navs = Array.from(this._rootNavs.values());
  366. for (var _i = 0, navs_1 = navs; _i < navs_1.length; _i++) {
  367. var navContainer = navs_1[_i];
  368. var match = getNavByIdOrName(navContainer, id);
  369. if (match) {
  370. return match;
  371. }
  372. }
  373. return null;
  374. };
  375. App.decorators = [
  376. { type: core_1.Injectable },
  377. ];
  378. /** @nocollapse */
  379. App.ctorParameters = function () { return [
  380. { type: config_1.Config, },
  381. { type: platform_1.Platform, },
  382. { type: menu_controller_1.MenuController, decorators: [{ type: core_1.Optional },] },
  383. ]; };
  384. return App;
  385. }());
  386. exports.App = App;
  387. function getNavByIdOrName(nav, id) {
  388. if (nav.id === id || nav.name === id) {
  389. return nav;
  390. }
  391. for (var _i = 0, _a = nav.getAllChildNavs(); _i < _a.length; _i++) {
  392. var child = _a[_i];
  393. var tmp = getNavByIdOrName(child, id);
  394. if (tmp) {
  395. return tmp;
  396. }
  397. }
  398. return null;
  399. }
  400. exports.getNavByIdOrName = getNavByIdOrName;
  401. function getPoppableNav(nav) {
  402. if (!nav) {
  403. return null;
  404. }
  405. if (nav_util_1.isTabs(nav)) {
  406. // tabs aren't a nav, so just call this function again immediately on the parent on tabs
  407. return getPoppableNav(nav.parent);
  408. }
  409. var len = nav.length();
  410. if (len > 1 || (nav._isPortal && len > 0)) {
  411. // this nav controller has more than one view
  412. // use this nav!
  413. return nav;
  414. }
  415. // try again using the parent nav (if there is one)
  416. return getPoppableNav(nav.parent);
  417. }
  418. function findTopNavs(nav) {
  419. var containers = [];
  420. var childNavs = nav.getActiveChildNavs();
  421. if (!childNavs || !childNavs.length) {
  422. containers.push(nav);
  423. }
  424. else {
  425. childNavs.forEach(function (childNav) {
  426. var topNavs = findTopNavs(childNav);
  427. containers = containers.concat(topNavs);
  428. });
  429. }
  430. return containers;
  431. }
  432. exports.findTopNavs = findTopNavs;
  433. var SKIP_BLURRING = ['INPUT', 'TEXTAREA', 'ION-INPUT', 'ION-TEXTAREA'];
  434. var ACTIVE_SCROLLING_TIME = 100;
  435. var CLICK_BLOCK_BUFFER_IN_MILLIS = 64;
  436. });
  437. //# sourceMappingURL=app.js.map