app-root.js 8.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. (function (factory) {
  12. if (typeof module === "object" && typeof module.exports === "object") {
  13. var v = factory(require, exports);
  14. if (v !== undefined) module.exports = v;
  15. }
  16. else if (typeof define === "function" && define.amd) {
  17. define(["require", "exports", "@angular/core", "./app", "../../config/config", "../ion", "./overlay-portal", "../../platform/platform", "./app-constants"], factory);
  18. }
  19. })(function (require, exports) {
  20. "use strict";
  21. Object.defineProperty(exports, "__esModule", { value: true });
  22. var core_1 = require("@angular/core");
  23. var app_1 = require("./app");
  24. var config_1 = require("../../config/config");
  25. var ion_1 = require("../ion");
  26. var overlay_portal_1 = require("./overlay-portal");
  27. var platform_1 = require("../../platform/platform");
  28. var Constants = require("./app-constants");
  29. exports.AppRootToken = new core_1.InjectionToken('USERROOT');
  30. /**
  31. * @hidden
  32. */
  33. var IonicApp = (function (_super) {
  34. __extends(IonicApp, _super);
  35. function IonicApp(_userCmp, _cfr, elementRef, renderer, config, _plt, app) {
  36. var _this = _super.call(this, config, elementRef, renderer, 'app-root') || this;
  37. _this._userCmp = _userCmp;
  38. _this._cfr = _cfr;
  39. _this._plt = _plt;
  40. // register with App that this is Ionic's appRoot component. tada!
  41. app._appRoot = _this;
  42. _this._stopScrollPlugin = window['IonicStopScroll'];
  43. return _this;
  44. }
  45. IonicApp.prototype.ngOnInit = function () {
  46. var _this = this;
  47. // load the user root component
  48. // into Ionic's root component
  49. var factory = this._cfr.resolveComponentFactory(this._userCmp);
  50. var componentRef = this._viewport.createComponent(factory);
  51. this._renderer.setElementClass(componentRef.location.nativeElement, 'app-root', true);
  52. componentRef.changeDetectorRef.detectChanges();
  53. // set the mode class name
  54. // ios/md/wp
  55. this.setElementClass(this._config.get('mode'), true);
  56. var versions = this._plt.versions();
  57. this._plt.platforms().forEach(function (platformName) {
  58. // platform-ios
  59. var platformClass = 'platform-' + platformName;
  60. _this.setElementClass(platformClass, true);
  61. var platformVersion = versions[platformName];
  62. if (platformVersion) {
  63. // platform-ios9
  64. platformClass += platformVersion.major;
  65. _this.setElementClass(platformClass, true);
  66. // platform-ios9_3
  67. _this.setElementClass(platformClass + '_' + platformVersion.minor, true);
  68. }
  69. });
  70. // touch devices should not use :hover CSS pseudo
  71. // enable :hover CSS when the "hoverCSS" setting is not false
  72. if (this._config.getBoolean('hoverCSS', true)) {
  73. this.setElementClass('enable-hover', true);
  74. }
  75. // sweet, the app root has loaded!
  76. // which means angular and ionic has fully loaded!
  77. // fire off the platform prepare ready, which could
  78. // have been switched out by any of the platform engines
  79. this._plt.prepareReady();
  80. };
  81. /**
  82. * @hidden
  83. */
  84. IonicApp.prototype._getPortal = function (portal) {
  85. if (portal === Constants.PORTAL_LOADING) {
  86. return this._loadingPortal;
  87. }
  88. if (portal === Constants.PORTAL_TOAST) {
  89. return this._toastPortal;
  90. }
  91. // Modals need their own overlay becuase we don't want an ActionSheet
  92. // or Alert to trigger lifecycle events inside a modal
  93. if (portal === Constants.PORTAL_MODAL) {
  94. return this._modalPortal;
  95. }
  96. return this._overlayPortal;
  97. };
  98. IonicApp.prototype._getActivePortal = function () {
  99. var defaultPortal = this._overlayPortal;
  100. var modalPortal = this._modalPortal;
  101. var hasModal = modalPortal.length() > 0;
  102. var hasDefault = defaultPortal.length() > 0;
  103. if (!hasModal && !hasDefault) {
  104. return null;
  105. }
  106. else if (hasModal && hasDefault) {
  107. var defaultIndex = defaultPortal.getActive().getZIndex();
  108. var modalIndex = modalPortal.getActive().getZIndex();
  109. if (defaultIndex > modalIndex) {
  110. return defaultPortal;
  111. }
  112. else {
  113. (void 0) /* assert */;
  114. return modalPortal;
  115. }
  116. }
  117. if (hasModal) {
  118. return modalPortal;
  119. }
  120. else if (hasDefault) {
  121. return defaultPortal;
  122. }
  123. };
  124. IonicApp.prototype._disableScroll = function (shouldDisableScroll) {
  125. var _this = this;
  126. if (shouldDisableScroll) {
  127. this.stopScroll().then(function () {
  128. _this._tmr = _this._plt.timeout(function () {
  129. (void 0) /* console.debug */;
  130. _this.setElementClass('disable-scroll', true);
  131. }, 32);
  132. });
  133. }
  134. else {
  135. var plugin = this._stopScrollPlugin;
  136. if (plugin && plugin.cancel) {
  137. plugin.cancel();
  138. }
  139. clearTimeout(this._tmr);
  140. (void 0) /* console.debug */;
  141. this.setElementClass('disable-scroll', false);
  142. }
  143. };
  144. IonicApp.prototype.stopScroll = function () {
  145. var _this = this;
  146. if (this._stopScrollPlugin) {
  147. return new Promise(function (resolve) {
  148. _this._stopScrollPlugin.stop(function () { return resolve(true); });
  149. });
  150. }
  151. else {
  152. return Promise.resolve(false);
  153. }
  154. };
  155. IonicApp.decorators = [
  156. { type: core_1.Component, args: [{
  157. selector: 'ion-app',
  158. template: '<div #viewport app-viewport></div>' +
  159. '<div #modalPortal overlay-portal></div>' +
  160. '<div #overlayPortal overlay-portal></div>' +
  161. '<div #loadingPortal class="loading-portal" overlay-portal></div>' +
  162. '<div #toastPortal class="toast-portal" [overlay-portal]="10000"></div>' +
  163. '<div class="click-block"></div>'
  164. },] },
  165. ];
  166. /** @nocollapse */
  167. IonicApp.ctorParameters = function () { return [
  168. { type: undefined, decorators: [{ type: core_1.Inject, args: [exports.AppRootToken,] },] },
  169. { type: core_1.ComponentFactoryResolver, },
  170. { type: core_1.ElementRef, },
  171. { type: core_1.Renderer, },
  172. { type: config_1.Config, },
  173. { type: platform_1.Platform, },
  174. { type: app_1.App, },
  175. ]; };
  176. IonicApp.propDecorators = {
  177. '_viewport': [{ type: core_1.ViewChild, args: ['viewport', { read: core_1.ViewContainerRef },] },],
  178. '_modalPortal': [{ type: core_1.ViewChild, args: ['modalPortal', { read: overlay_portal_1.OverlayPortal },] },],
  179. '_overlayPortal': [{ type: core_1.ViewChild, args: ['overlayPortal', { read: overlay_portal_1.OverlayPortal },] },],
  180. '_loadingPortal': [{ type: core_1.ViewChild, args: ['loadingPortal', { read: overlay_portal_1.OverlayPortal },] },],
  181. '_toastPortal': [{ type: core_1.ViewChild, args: ['toastPortal', { read: overlay_portal_1.OverlayPortal },] },],
  182. };
  183. return IonicApp;
  184. }(ion_1.Ion));
  185. exports.IonicApp = IonicApp;
  186. });
  187. //# sourceMappingURL=app-root.js.map