a zip code crypto-currency system good for red ONLY

view-controller.js 17KB

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