a zip code crypto-currency system good for red ONLY

tab.js 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. var __extends = (this && this.__extends) || (function () {
  2. var extendStatics = Object.setPrototypeOf ||
  3. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  4. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  5. return function (d, b) {
  6. extendStatics(d, b);
  7. function __() { this.constructor = d; }
  8. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  9. };
  10. })();
  11. import { ChangeDetectorRef, Component, ComponentFactoryResolver, ElementRef, ErrorHandler, EventEmitter, Input, NgZone, Optional, Output, Renderer, ViewChild, ViewContainerRef, ViewEncapsulation } from '@angular/core';
  12. import { App } from '../app/app';
  13. import { Config } from '../../config/config';
  14. import { DeepLinker } from '../../navigation/deep-linker';
  15. import { DomController } from '../../platform/dom-controller';
  16. import { GestureController } from '../../gestures/gesture-controller';
  17. import { isTrueProperty } from '../../util/util';
  18. import { NavControllerBase } from '../../navigation/nav-controller-base';
  19. import { Platform } from '../../platform/platform';
  20. import { Tabs } from './tabs';
  21. import { TransitionController } from '../../transitions/transition-controller';
  22. /**
  23. * @name Tab
  24. * @description
  25. * The Tab component, written `<ion-tab>`, is styled based on the mode and should
  26. * be used in conjunction with the [Tabs](../Tabs/) component.
  27. *
  28. * Each `ion-tab` is a declarative component for a [NavController](../../../navigation/NavController/).
  29. * Basically, each tab is a `NavController`. For more information on using
  30. * navigation controllers take a look at the [NavController API Docs](../../../navigation/NavController/).
  31. *
  32. * See the [Tabs API Docs](../Tabs/) for more details on configuring Tabs.
  33. *
  34. * @usage
  35. *
  36. * To add a basic tab, you can use the following markup where the `root` property
  37. * is the page you want to load for that tab, `tabTitle` is the optional text to
  38. * display on the tab, and `tabIcon` is the optional [icon](../../icon/Icon/).
  39. *
  40. * ```html
  41. * <ion-tabs>
  42. * <ion-tab [root]="chatRoot" tabTitle="Chat" tabIcon="chat"></ion-tab>
  43. * </ion-tabs>
  44. * ```
  45. *
  46. * Then, in your class you can set `chatRoot` to an imported class:
  47. *
  48. * ```ts
  49. * import { ChatPage } from '../chat/chat';
  50. *
  51. * export class Tabs {
  52. * // here we'll set the property of chatRoot to
  53. * // the imported class of ChatPage
  54. * chatRoot = ChatPage;
  55. *
  56. * constructor() {
  57. *
  58. * }
  59. * }
  60. * ```
  61. *
  62. * You can also pass some parameters to the root page of the tab through
  63. * `rootParams`. Below we pass `chatParams` to the Chat tab:
  64. *
  65. * ```html
  66. * <ion-tabs>
  67. * <ion-tab [root]="chatRoot" [rootParams]="chatParams" tabTitle="Chat" tabIcon="chat"></ion-tab>
  68. * </ion-tabs>
  69. * ```
  70. *
  71. * ```ts
  72. * export class Tabs {
  73. * chatRoot = ChatPage;
  74. *
  75. * // set some user information on chatParams
  76. * chatParams = {
  77. * user1: 'admin',
  78. * user2: 'ionic'
  79. * };
  80. *
  81. * constructor() {
  82. *
  83. * }
  84. * }
  85. * ```
  86. *
  87. * And in `ChatPage` you can get the data from `NavParams`:
  88. *
  89. * ```ts
  90. * export class ChatPage {
  91. * constructor(navParams: NavParams) {
  92. * console.log('Passed params', navParams.data);
  93. * }
  94. * }
  95. * ```
  96. *
  97. * Sometimes you may want to call a method instead of navigating to a new
  98. * page. You can use the `(ionSelect)` event to call a method on your class when
  99. * the tab is selected. Below is an example of presenting a modal from one of
  100. * the tabs.
  101. *
  102. * ```html
  103. * <ion-tabs>
  104. * <ion-tab (ionSelect)="chat()" tabTitle="Show Modal"></ion-tab>
  105. * </ion-tabs>pop
  106. * ```
  107. *
  108. * ```ts
  109. * export class Tabs {
  110. * constructor(public modalCtrl: ModalController) {
  111. *
  112. * }
  113. *
  114. * chat() {
  115. * let modal = this.modalCtrl.create(ChatPage);
  116. * modal.present();
  117. * }
  118. * }
  119. * ```
  120. *
  121. *
  122. * @demo /docs/demos/src/tabs/
  123. * @see {@link /docs/components#tabs Tabs Component Docs}
  124. * @see {@link ../../tabs/Tabs Tabs API Docs}
  125. * @see {@link ../../nav/Nav Nav API Docs}
  126. * @see {@link ../../nav/NavController NavController API Docs}
  127. */
  128. var Tab = (function (_super) {
  129. __extends(Tab, _super);
  130. function Tab(parent, app, config, plt, elementRef, zone, renderer, cfr, _cd, gestureCtrl, transCtrl, linker, _dom, errHandler) {
  131. var _this =
  132. // A Tab is a NavController for its child pages
  133. _super.call(this, parent, app, config, plt, elementRef, zone, renderer, cfr, gestureCtrl, transCtrl, linker, _dom, errHandler) || this;
  134. _this._cd = _cd;
  135. _this.linker = linker;
  136. _this._dom = _dom;
  137. /**
  138. * @hidden
  139. */
  140. _this._isEnabled = true;
  141. /**
  142. * @hidden
  143. */
  144. _this._isShown = true;
  145. /**
  146. * @output {Tab} Emitted when the current tab is selected.
  147. */
  148. _this.ionSelect = new EventEmitter();
  149. _this.id = parent.add(_this);
  150. _this._tabsHideOnSubPages = config.getBoolean('tabsHideOnSubPages');
  151. _this._tabId = 'tabpanel-' + _this.id;
  152. _this._btnId = 'tab-' + _this.id;
  153. return _this;
  154. }
  155. Object.defineProperty(Tab.prototype, "enabled", {
  156. /**
  157. * @input {boolean} If true, enable the tab. If false,
  158. * the user cannot interact with this element.
  159. * Default: `true`.
  160. */
  161. get: function () {
  162. return this._isEnabled;
  163. },
  164. set: function (val) {
  165. this._isEnabled = isTrueProperty(val);
  166. },
  167. enumerable: true,
  168. configurable: true
  169. });
  170. Object.defineProperty(Tab.prototype, "show", {
  171. /**
  172. * @input {boolean} If true, the tab button is visible within the
  173. * tabbar. Default: `true`.
  174. */
  175. get: function () {
  176. return this._isShown;
  177. },
  178. set: function (val) {
  179. this._isShown = isTrueProperty(val);
  180. },
  181. enumerable: true,
  182. configurable: true
  183. });
  184. Object.defineProperty(Tab.prototype, "tabsHideOnSubPages", {
  185. /**
  186. * @input {boolean} If true, hide the tabs on child pages.
  187. */
  188. get: function () {
  189. return this._tabsHideOnSubPages;
  190. },
  191. set: function (val) {
  192. this._tabsHideOnSubPages = isTrueProperty(val);
  193. },
  194. enumerable: true,
  195. configurable: true
  196. });
  197. Object.defineProperty(Tab.prototype, "_vp", {
  198. /**
  199. * @hidden
  200. */
  201. set: function (val) {
  202. this.setViewport(val);
  203. },
  204. enumerable: true,
  205. configurable: true
  206. });
  207. /**
  208. * @hidden
  209. */
  210. Tab.prototype.ngOnInit = function () {
  211. this.tabBadgeStyle = this.tabBadgeStyle ? this.tabBadgeStyle : 'default';
  212. };
  213. /**
  214. * @hidden
  215. */
  216. Tab.prototype.load = function (opts) {
  217. var _this = this;
  218. var segment = this._segment;
  219. if (segment || (!this._loaded && this.root)) {
  220. this.setElementClass('show-tab', true);
  221. // okay, first thing we need to do if check if the view already exists
  222. var nameToUse = segment && segment.name ? segment.name : this.root;
  223. var dataToUse = segment ? segment.data : this.rootParams;
  224. var numViews = this.length() - 1;
  225. for (var i = numViews; i >= 0; i--) {
  226. var viewController = this.getByIndex(i);
  227. if (viewController && (viewController.id === nameToUse || viewController.component === nameToUse)) {
  228. if (i === numViews) {
  229. // this is the last view in the stack and it's the same
  230. // as the segment so there's no change needed
  231. return Promise.resolve();
  232. }
  233. else {
  234. // it's not the exact view as the end
  235. // let's have this nav go back to this exact view
  236. return this.popTo(viewController, {
  237. animate: false,
  238. updateUrl: false,
  239. });
  240. }
  241. }
  242. }
  243. var promise = null;
  244. if (segment && segment.defaultHistory && segment.defaultHistory.length && this._views.length === 0) {
  245. promise = this.linker.initViews(segment).then(function (views) {
  246. return _this.setPages(views, opts);
  247. });
  248. }
  249. else {
  250. promise = this.push(nameToUse, dataToUse, opts);
  251. }
  252. return promise.then(function () {
  253. _this._segment = null;
  254. _this._loaded = true;
  255. });
  256. }
  257. else {
  258. // if this is not the Tab's initial load then we need
  259. // to refresh the tabbar and content dimensions to be sure
  260. // they're lined up correctly
  261. this._dom.read(function () {
  262. _this.resize();
  263. });
  264. return Promise.resolve();
  265. }
  266. };
  267. /**
  268. * @hidden
  269. */
  270. Tab.prototype.resize = function () {
  271. var active = this.getActive();
  272. if (!active) {
  273. return;
  274. }
  275. var content = active.getIONContent();
  276. content && content.resize();
  277. };
  278. /**
  279. * @hidden
  280. */
  281. Tab.prototype._viewAttachToDOM = function (viewCtrl, componentRef, viewport) {
  282. var isTabSubPage = (this._tabsHideOnSubPages && viewCtrl.index > 0);
  283. if (isTabSubPage) {
  284. viewport = this.parent.portal;
  285. }
  286. _super.prototype._viewAttachToDOM.call(this, viewCtrl, componentRef, viewport);
  287. if (isTabSubPage) {
  288. // add the .tab-subpage css class to tabs pages that should act like subpages
  289. var pageEleRef = viewCtrl.pageRef();
  290. if (pageEleRef) {
  291. this._renderer.setElementClass(pageEleRef.nativeElement, 'tab-subpage', true);
  292. }
  293. }
  294. };
  295. /**
  296. * @hidden
  297. */
  298. Tab.prototype.setSelected = function (isSelected) {
  299. this.isSelected = isSelected;
  300. this.setElementClass('show-tab', isSelected);
  301. this.setElementAttribute('aria-hidden', (!isSelected).toString());
  302. if (isSelected) {
  303. // this is the selected tab, detect changes
  304. this._cd.reattach();
  305. }
  306. else {
  307. // this tab is not selected, do not detect changes
  308. this._cd.detach();
  309. }
  310. };
  311. Object.defineProperty(Tab.prototype, "index", {
  312. /**
  313. * @hidden
  314. */
  315. get: function () {
  316. return this.parent.getIndex(this);
  317. },
  318. enumerable: true,
  319. configurable: true
  320. });
  321. /**
  322. * @hidden
  323. */
  324. Tab.prototype.updateHref = function (component, data) {
  325. if (this.btn && this.linker) {
  326. var href = this.linker.createUrl(this.parent, component, data) || '#';
  327. this.btn.updateHref(href);
  328. }
  329. };
  330. /**
  331. * @hidden
  332. */
  333. Tab.prototype.ngOnDestroy = function () {
  334. this.destroy();
  335. };
  336. /**
  337. * @hidden
  338. */
  339. Tab.prototype.getType = function () {
  340. return 'tab';
  341. };
  342. Tab.prototype.goToRoot = function (opts) {
  343. return this.setRoot(this.root, this.rootParams, opts, null);
  344. };
  345. Tab.decorators = [
  346. { type: Component, args: [{
  347. selector: 'ion-tab',
  348. template: '<div #viewport></div><div class="nav-decor"></div>',
  349. host: {
  350. '[attr.id]': '_tabId',
  351. '[attr.aria-labelledby]': '_btnId',
  352. 'role': 'tabpanel'
  353. },
  354. encapsulation: ViewEncapsulation.None,
  355. },] },
  356. ];
  357. /** @nocollapse */
  358. Tab.ctorParameters = function () { return [
  359. { type: Tabs, },
  360. { type: App, },
  361. { type: Config, },
  362. { type: Platform, },
  363. { type: ElementRef, },
  364. { type: NgZone, },
  365. { type: Renderer, },
  366. { type: ComponentFactoryResolver, },
  367. { type: ChangeDetectorRef, },
  368. { type: GestureController, },
  369. { type: TransitionController, },
  370. { type: DeepLinker, decorators: [{ type: Optional },] },
  371. { type: DomController, },
  372. { type: ErrorHandler, },
  373. ]; };
  374. Tab.propDecorators = {
  375. 'root': [{ type: Input },],
  376. 'rootParams': [{ type: Input },],
  377. 'tabUrlPath': [{ type: Input },],
  378. 'tabTitle': [{ type: Input },],
  379. 'tabIcon': [{ type: Input },],
  380. 'tabBadge': [{ type: Input },],
  381. 'tabBadgeStyle': [{ type: Input },],
  382. 'enabled': [{ type: Input },],
  383. 'show': [{ type: Input },],
  384. 'tabsHideOnSubPages': [{ type: Input },],
  385. 'ionSelect': [{ type: Output },],
  386. '_vp': [{ type: ViewChild, args: ['viewport', { read: ViewContainerRef },] },],
  387. };
  388. return Tab;
  389. }(NavControllerBase));
  390. export { Tab };
  391. //# sourceMappingURL=tab.js.map