a zip code crypto-currency system good for red ONLY

view-controller.js 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512
  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", "../util/util", "./nav-util", "./nav-params"], 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 util_1 = require("../util/util");
  14. var nav_util_1 = require("./nav-util");
  15. var nav_params_1 = require("./nav-params");
  16. /**
  17. * @name ViewController
  18. * @description
  19. * Access various features and information about the current view.
  20. * @usage
  21. * ```ts
  22. * import { Component } from '@angular/core';
  23. * import { ViewController } from 'ionic-angular';
  24. *
  25. * @Component({...})
  26. * export class MyPage{
  27. *
  28. * constructor(public viewCtrl: ViewController) {}
  29. *
  30. * }
  31. * ```
  32. */
  33. var ViewController = (function () {
  34. function ViewController(component, data, rootCssClass) {
  35. if (rootCssClass === void 0) { rootCssClass = DEFAULT_CSS_CLASS; }
  36. this.component = component;
  37. this._isHidden = false;
  38. this._state = nav_util_1.STATE_NEW;
  39. /**
  40. * Observable to be subscribed to when the current component will become active
  41. * @returns {Observable} Returns an observable
  42. */
  43. this.willEnter = new core_1.EventEmitter();
  44. /**
  45. * Observable to be subscribed to when the current component has become active
  46. * @returns {Observable} Returns an observable
  47. */
  48. this.didEnter = new core_1.EventEmitter();
  49. /**
  50. * Observable to be subscribed to when the current component will no longer be active
  51. * @returns {Observable} Returns an observable
  52. */
  53. this.willLeave = new core_1.EventEmitter();
  54. /**
  55. * Observable to be subscribed to when the current component is no long active
  56. * @returns {Observable} Returns an observable
  57. */
  58. this.didLeave = new core_1.EventEmitter();
  59. /**
  60. * Observable to be subscribed to when the current component has been destroyed
  61. * @returns {Observable} Returns an observable
  62. */
  63. this.willUnload = new core_1.EventEmitter();
  64. /**
  65. * @hidden
  66. */
  67. this.readReady = new core_1.EventEmitter();
  68. /**
  69. * @hidden
  70. */
  71. this.writeReady = new core_1.EventEmitter();
  72. /** @hidden */
  73. this.isOverlay = false;
  74. /** @hidden */
  75. this._emitter = new core_1.EventEmitter();
  76. // passed in data could be NavParams, but all we care about is its data object
  77. this.data = (data instanceof nav_params_1.NavParams ? data.data : (util_1.isPresent(data) ? data : {}));
  78. this._cssClass = rootCssClass;
  79. this._ts = Date.now();
  80. window.addEventListener('orientationchange', this.handleOrientationChange.bind(this));
  81. }
  82. ViewController.prototype.handleOrientationChange = function () {
  83. if (this.getContent()) {
  84. this.getContent().resize();
  85. }
  86. };
  87. /**
  88. * @hidden
  89. */
  90. ViewController.prototype.init = function (componentRef) {
  91. (void 0) /* assert */;
  92. this._ts = Date.now();
  93. this._cmp = componentRef;
  94. this.instance = this.instance || componentRef.instance;
  95. this._detached = false;
  96. };
  97. ViewController.prototype._setNav = function (navCtrl) {
  98. this._nav = navCtrl;
  99. };
  100. ViewController.prototype._setInstance = function (instance) {
  101. this.instance = instance;
  102. };
  103. /**
  104. * @hidden
  105. */
  106. ViewController.prototype.subscribe = function (generatorOrNext) {
  107. return this._emitter.subscribe(generatorOrNext);
  108. };
  109. /**
  110. * @hidden
  111. */
  112. ViewController.prototype.emit = function (data) {
  113. this._emitter.emit(data);
  114. };
  115. /**
  116. * Called when the current viewController has be successfully dismissed
  117. */
  118. ViewController.prototype.onDidDismiss = function (callback) {
  119. this._onDidDismiss = callback;
  120. };
  121. /**
  122. * Called when the current viewController will be dismissed
  123. */
  124. ViewController.prototype.onWillDismiss = function (callback) {
  125. this._onWillDismiss = callback;
  126. };
  127. /**
  128. * Dismiss the current viewController
  129. * @param {any} [data] Data that you want to return when the viewController is dismissed.
  130. * @param {any} [role ]
  131. * @param {NavOptions} navOptions Options for the dismiss navigation.
  132. * @returns {any} data Returns the data passed in, if any.
  133. */
  134. ViewController.prototype.dismiss = function (data, role, navOptions) {
  135. if (navOptions === void 0) { navOptions = {}; }
  136. if (!this._nav) {
  137. (void 0) /* assert */;
  138. return Promise.resolve(false);
  139. }
  140. if (this.isOverlay && !navOptions.minClickBlockDuration) {
  141. // This is a Modal being dismissed so we need
  142. // to add the minClickBlockDuration option
  143. // for UIWebView
  144. navOptions.minClickBlockDuration = 400;
  145. }
  146. this._dismissData = data;
  147. this._dismissRole = role;
  148. var options = Object.assign({}, this._leavingOpts, navOptions);
  149. return this._nav.removeView(this, options).then(function () { return data; });
  150. };
  151. /**
  152. * @hidden
  153. */
  154. ViewController.prototype.getNav = function () {
  155. return this._nav;
  156. };
  157. /**
  158. * @hidden
  159. */
  160. ViewController.prototype.getTransitionName = function (_direction) {
  161. return this._nav && this._nav.config.get('pageTransition');
  162. };
  163. /**
  164. * @hidden
  165. */
  166. ViewController.prototype.getNavParams = function () {
  167. return new nav_params_1.NavParams(this.data);
  168. };
  169. /**
  170. * @hidden
  171. */
  172. ViewController.prototype.setLeavingOpts = function (opts) {
  173. this._leavingOpts = opts;
  174. };
  175. /**
  176. * Check to see if you can go back in the navigation stack.
  177. * @returns {boolean} Returns if it's possible to go back from this Page.
  178. */
  179. ViewController.prototype.enableBack = function () {
  180. // update if it's possible to go back from this nav item
  181. if (!this._nav) {
  182. return false;
  183. }
  184. // the previous view may exist, but if it's about to be destroyed
  185. // it shouldn't be able to go back to
  186. var previousItem = this._nav.getPrevious(this);
  187. return !!(previousItem);
  188. };
  189. Object.defineProperty(ViewController.prototype, "name", {
  190. /**
  191. * @hidden
  192. */
  193. get: function () {
  194. return (this.component ? this.component.name : '');
  195. },
  196. enumerable: true,
  197. configurable: true
  198. });
  199. Object.defineProperty(ViewController.prototype, "index", {
  200. /**
  201. * Get the index of the current component in the current navigation stack.
  202. * @returns {number} Returns the index of this page within its `NavController`.
  203. */
  204. get: function () {
  205. return (this._nav ? this._nav.indexOf(this) : -1);
  206. },
  207. enumerable: true,
  208. configurable: true
  209. });
  210. /**
  211. * @returns {boolean} Returns if this Page is the first in the stack of pages within its NavController.
  212. */
  213. ViewController.prototype.isFirst = function () {
  214. return (this._nav ? this._nav.first() === this : false);
  215. };
  216. /**
  217. * @returns {boolean} Returns if this Page is the last in the stack of pages within its NavController.
  218. */
  219. ViewController.prototype.isLast = function () {
  220. return (this._nav ? this._nav.last() === this : false);
  221. };
  222. /**
  223. * @hidden
  224. * DOM WRITE
  225. */
  226. ViewController.prototype._domShow = function (shouldShow, renderer) {
  227. // using hidden element attribute to display:none and not render views
  228. // _hidden value of '' means the hidden attribute will be added
  229. // _hidden value of null means the hidden attribute will be removed
  230. // doing checks to make sure we only update the DOM when actually needed
  231. // if it should render, then the hidden attribute should not be on the element
  232. if (this._cmp && shouldShow === this._isHidden) {
  233. this._isHidden = !shouldShow;
  234. var value = (shouldShow ? null : '');
  235. // ******** DOM WRITE ****************
  236. renderer.setElementAttribute(this.pageRef().nativeElement, 'hidden', value);
  237. }
  238. };
  239. /**
  240. * @hidden
  241. */
  242. ViewController.prototype.getZIndex = function () {
  243. return this._zIndex;
  244. };
  245. /**
  246. * @hidden
  247. * DOM WRITE
  248. */
  249. ViewController.prototype._setZIndex = function (zIndex, renderer) {
  250. if (zIndex !== this._zIndex) {
  251. this._zIndex = zIndex;
  252. var pageRef = this.pageRef();
  253. if (pageRef) {
  254. // ******** DOM WRITE ****************
  255. renderer.setElementStyle(pageRef.nativeElement, 'z-index', zIndex);
  256. }
  257. }
  258. };
  259. /**
  260. * @returns {ElementRef} Returns the Page's ElementRef.
  261. */
  262. ViewController.prototype.pageRef = function () {
  263. return this._cmp && this._cmp.location;
  264. };
  265. ViewController.prototype._setContent = function (directive) {
  266. this._cntDir = directive;
  267. };
  268. /**
  269. * @returns {component} Returns the Page's Content component reference.
  270. */
  271. ViewController.prototype.getContent = function () {
  272. return this._cntDir;
  273. };
  274. ViewController.prototype._setContentRef = function (elementRef) {
  275. this._cntRef = elementRef;
  276. };
  277. /**
  278. * @returns {ElementRef} Returns the Content's ElementRef.
  279. */
  280. ViewController.prototype.contentRef = function () {
  281. return this._cntRef;
  282. };
  283. ViewController.prototype._setIONContent = function (content) {
  284. this._setContent(content);
  285. this._ionCntDir = content;
  286. };
  287. /**
  288. * @hidden
  289. */
  290. ViewController.prototype.getIONContent = function () {
  291. return this._ionCntDir;
  292. };
  293. ViewController.prototype._setIONContentRef = function (elementRef) {
  294. this._setContentRef(elementRef);
  295. this._ionCntRef = elementRef;
  296. };
  297. /**
  298. * @hidden
  299. */
  300. ViewController.prototype.getIONContentRef = function () {
  301. return this._ionCntRef;
  302. };
  303. ViewController.prototype._setHeader = function (directive) {
  304. this._hdrDir = directive;
  305. };
  306. /**
  307. * @hidden
  308. */
  309. ViewController.prototype.getHeader = function () {
  310. return this._hdrDir;
  311. };
  312. ViewController.prototype._setFooter = function (directive) {
  313. this._ftrDir = directive;
  314. };
  315. /**
  316. * @hidden
  317. */
  318. ViewController.prototype.getFooter = function () {
  319. return this._ftrDir;
  320. };
  321. ViewController.prototype._setNavbar = function (directive) {
  322. this._nb = directive;
  323. };
  324. /**
  325. * @hidden
  326. */
  327. ViewController.prototype.getNavbar = function () {
  328. return this._nb;
  329. };
  330. /**
  331. * Find out if the current component has a NavBar or not. Be sure
  332. * to wrap this in an `ionViewWillEnter` method in order to make sure
  333. * the view has rendered fully.
  334. * @returns {boolean} Returns a boolean if this Page has a navbar or not.
  335. */
  336. ViewController.prototype.hasNavbar = function () {
  337. return !!this._nb;
  338. };
  339. /**
  340. * Change the title of the back-button. Be sure to call this
  341. * after `ionViewWillEnter` to make sure the DOM has been rendered.
  342. * @param {string} val Set the back button text.
  343. */
  344. ViewController.prototype.setBackButtonText = function (val) {
  345. this._nb && this._nb.setBackButtonText(val);
  346. };
  347. /**
  348. * Set if the back button for the current view is visible or not. Be sure to call this
  349. * after `ionViewWillEnter` to make sure the DOM has been rendered.
  350. * @param {boolean} Set if this Page's back button should show or not.
  351. */
  352. ViewController.prototype.showBackButton = function (shouldShow) {
  353. if (this._nb) {
  354. this._nb.hideBackButton = !shouldShow;
  355. }
  356. };
  357. ViewController.prototype._preLoad = function () {
  358. (void 0) /* assert */;
  359. this._lifecycle('PreLoad');
  360. };
  361. /**
  362. * @hidden
  363. * The view has loaded. This event only happens once per view will be created.
  364. * This event is fired before the component and his children have been initialized.
  365. */
  366. ViewController.prototype._willLoad = function () {
  367. (void 0) /* assert */;
  368. this._lifecycle('WillLoad');
  369. };
  370. /**
  371. * @hidden
  372. * The view has loaded. This event only happens once per view being
  373. * created. If a view leaves but is cached, then this will not
  374. * fire again on a subsequent viewing. This method is a good place
  375. * to put your setup code for the view; however, it is not the
  376. * recommended method to use when a view becomes active.
  377. */
  378. ViewController.prototype._didLoad = function () {
  379. (void 0) /* assert */;
  380. this._lifecycle('DidLoad');
  381. };
  382. /**
  383. * @hidden
  384. * The view is about to enter and become the active view.
  385. */
  386. ViewController.prototype._willEnter = function () {
  387. this.handleOrientationChange();
  388. (void 0) /* assert */;
  389. if (this._detached && this._cmp) {
  390. // ensure this has been re-attached to the change detector
  391. this._cmp.changeDetectorRef.reattach();
  392. this._detached = false;
  393. }
  394. this.willEnter.emit(null);
  395. this._lifecycle('WillEnter');
  396. };
  397. /**
  398. * @hidden
  399. * The view has fully entered and is now the active view. This
  400. * will fire, whether it was the first load or loaded from the cache.
  401. */
  402. ViewController.prototype._didEnter = function () {
  403. (void 0) /* assert */;
  404. this._nb && this._nb.didEnter();
  405. this.didEnter.emit(null);
  406. this._lifecycle('DidEnter');
  407. };
  408. /**
  409. * @hidden
  410. * The view is about to leave and no longer be the active view.
  411. */
  412. ViewController.prototype._willLeave = function (willUnload) {
  413. this.willLeave.emit(null);
  414. this._lifecycle('WillLeave');
  415. if (willUnload && this._onWillDismiss) {
  416. this._onWillDismiss(this._dismissData, this._dismissRole);
  417. this._onWillDismiss = null;
  418. }
  419. };
  420. /**
  421. * @hidden
  422. * The view has finished leaving and is no longer the active view. This
  423. * will fire, whether it is cached or unloaded.
  424. */
  425. ViewController.prototype._didLeave = function () {
  426. this.didLeave.emit(null);
  427. this._lifecycle('DidLeave');
  428. // when this is not the active page
  429. // we no longer need to detect changes
  430. if (!this._detached && this._cmp) {
  431. this._cmp.changeDetectorRef.detach();
  432. this._detached = true;
  433. }
  434. };
  435. /**
  436. * @hidden
  437. */
  438. ViewController.prototype._willUnload = function () {
  439. this.willUnload.emit(null);
  440. this._lifecycle('WillUnload');
  441. this._onDidDismiss && this._onDidDismiss(this._dismissData, this._dismissRole);
  442. this._onDidDismiss = null;
  443. this._dismissData = null;
  444. this._dismissRole = null;
  445. };
  446. /**
  447. * @hidden
  448. * DOM WRITE
  449. */
  450. ViewController.prototype._destroy = function (renderer) {
  451. (void 0) /* assert */;
  452. if (this._cmp) {
  453. if (renderer) {
  454. // ensure the element is cleaned up for when the view pool reuses this element
  455. // ******** DOM WRITE ****************
  456. var cmpEle = this._cmp.location.nativeElement;
  457. renderer.setElementAttribute(cmpEle, 'class', null);
  458. renderer.setElementAttribute(cmpEle, 'style', null);
  459. }
  460. window.removeEventListener('orientationchange', this.handleOrientationChange.bind(this));
  461. // completely destroy this component. boom.
  462. this._cmp.destroy();
  463. }
  464. this._nav = this._cmp = this.instance = this._cntDir = this._cntRef = this._leavingOpts = this._hdrDir = this._ftrDir = this._nb = this._onDidDismiss = this._onWillDismiss = null;
  465. this._state = nav_util_1.STATE_DESTROYED;
  466. };
  467. /**
  468. * @hidden
  469. */
  470. ViewController.prototype._lifecycleTest = function (lifecycle) {
  471. var instance = this.instance;
  472. var methodName = 'ionViewCan' + lifecycle;
  473. if (instance && instance[methodName]) {
  474. try {
  475. var result = instance[methodName]();
  476. if (result instanceof Promise) {
  477. return result;
  478. }
  479. else {
  480. // Any value but explitic false, should be true
  481. return Promise.resolve(result !== false);
  482. }
  483. }
  484. catch (e) {
  485. return Promise.reject(this.name + " " + methodName + " error: " + e.message);
  486. }
  487. }
  488. return Promise.resolve(true);
  489. };
  490. /**
  491. * @hidden
  492. */
  493. ViewController.prototype._lifecycle = function (lifecycle) {
  494. var instance = this.instance;
  495. var methodName = 'ionView' + lifecycle;
  496. if (instance && instance[methodName]) {
  497. instance[methodName]();
  498. }
  499. };
  500. ViewController.propDecorators = {
  501. '_emitter': [{ type: core_1.Output },],
  502. };
  503. return ViewController;
  504. }());
  505. exports.ViewController = ViewController;
  506. function isViewController(viewCtrl) {
  507. return !!(viewCtrl && viewCtrl._didLoad && viewCtrl._willUnload);
  508. }
  509. exports.isViewController = isViewController;
  510. var DEFAULT_CSS_CLASS = 'ion-page';
  511. });
  512. //# sourceMappingURL=view-controller.js.map