123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  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"], 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. /**
  15. * @name Config
  16. * @demo /docs/demos/src/config/
  17. * @description
  18. * The Config lets you configure your entire app or specific platforms.
  19. * You can set the tab placement, icon mode, animations, and more here.
  20. *
  21. * ```ts
  22. * import { IonicApp, IonicModule } from 'ionic-angular';
  23. *
  24. * @NgModule({
  25. * declarations: [ MyApp ],
  26. * imports: [
  27. * BrowserModule,
  28. * IonicModule.forRoot(MyApp, {
  29. * backButtonText: 'Go Back',
  30. * iconMode: 'ios',
  31. * modalEnter: 'modal-slide-in',
  32. * modalLeave: 'modal-slide-out',
  33. * tabsPlacement: 'bottom',
  34. * pageTransition: 'ios-transition'
  35. * }, {}
  36. * )],
  37. * bootstrap: [IonicApp],
  38. * entryComponents: [ MyApp ],
  39. * providers: []
  40. * })
  41. * ```
  42. *
  43. *
  44. * Config can be overwritten at multiple levels allowing for more granular configuration.
  45. * Below is an example where an app can override any setting we want based on a platform.
  46. *
  47. * ```ts
  48. * import { IonicModule } from 'ionic-angular';
  49. *
  50. * @NgModule({
  51. * ...
  52. * imports: [
  53. * BrowserModule,
  54. * IonicModule.forRoot(MyApp, {
  55. * tabsPlacement: 'bottom',
  56. * platforms: {
  57. * ios: {
  58. * tabsPlacement: 'top',
  59. * }
  60. * }
  61. * }, {}
  62. * )],
  63. * ...
  64. * })
  65. * ```
  66. *
  67. * We could also configure these values at a component level. Take `tabsPlacement`,
  68. * we can configure this as a property on our `ion-tabs`.
  69. *
  70. * ```html
  71. * <ion-tabs tabsPlacement="top">
  72. * <ion-tab tabTitle="Dash" tabIcon="pulse" [root]="tabRoot"></ion-tab>
  73. * </ion-tabs>
  74. * ```
  75. *
  76. * The last way we could configure is through URL query strings. This is useful for testing
  77. * while in the browser. Simply add `?ionic<PROPERTYNAME>=<value>` to the url.
  78. *
  79. * ```bash
  80. * http://localhost:8100/?ionicTabsPlacement=bottom
  81. * ```
  82. *
  83. * Any value can be added to config, and looked up at a later in any component.
  84. *
  85. * ```js
  86. * config.set('ios', 'favoriteColor', 'green');
  87. *
  88. * // from any page in your app:
  89. * config.get('favoriteColor'); // 'green' when iOS
  90. * ```
  91. *
  92. *
  93. * A config value can come from anywhere and be anything, but there are default
  94. * values for each mode. The [theming](../../../theming/platform-specific-styles/)
  95. * documentation has a chart of the default mode configuration. The following
  96. * chart displays each property with a description of what it controls.
  97. *
  98. *
  99. * | Config Property | Type | Details |
  100. * |--------------------------|---------------------|--------------------------------------------------------------------------------------------------------------------------------------------------|
  101. * | `activator` | `string` | Used for buttons, changes the effect of pressing on a button. Available options: `"ripple"`, `"highlight"`. |
  102. * | `actionSheetEnter` | `string` | The name of the transition to use while an action sheet is presented. |
  103. * | `actionSheetLeave` | `string` | The name of the transition to use while an action sheet is dismissed. |
  104. * | `alertEnter` | `string` | The name of the transition to use while an alert is presented. |
  105. * | `alertLeave` | `string` | The name of the transition to use while an alert is dismissed. |
  106. * | `backButtonText` | `string` | The text to display by the back button icon in the navbar. |
  107. * | `backButtonIcon` | `string` | The icon to use as the back button icon. |
  108. * | `iconMode` | `string` | The mode to use for all icons throughout the application. Available options: `"ios"`, `"md"` |
  109. * | `locationStrategy` | `string` | Set to 'path' to remove hashbangs when using Deeplinking. |
  110. * | `loadingEnter` | `string` | The name of the transition to use while a loading indicator is presented. |
  111. * | `loadingLeave` | `string` | The name of the transition to use while a loading indicator is dismissed. |
  112. * | `menuType` | `string` | Type of menu to display. Available options: `"overlay"`, `"reveal"`, `"push"`. |
  113. * | `modalEnter` | `string` | The name of the transition to use while a modal is presented. |
  114. * | `modalLeave` | `string` | The name of the transition to use while a modal is dismiss. |
  115. * | `mode` | `string` | The mode to use throughout the application. |
  116. * | `pageTransition` | `string` | The name of the transition to use while changing pages. Available options: `"ios-transition"`, `"md-transition"`, `"wp-transition"`. |
  117. * | `pickerEnter` | `string` | The name of the transition to use while a picker is presented. |
  118. * | `pickerLeave` | `string` | The name of the transition to use while a picker is dismissed. |
  119. * | `popoverEnter` | `string` | The name of the transition to use while a popover is presented. |
  120. * | `popoverLeave` | `string` | The name of the transition to use while a popover is dismissed.
  121. * | `scrollAssist` | `boolean` | Used to avoid the input to be hidden by the keyboard if it's near the bottom of the page.
  122. * | `scrollPadding` | `boolean` | Used to remove the extra padding on ion-content when keyboard is displayed.
  123. * | `spinner` | `string` | The default spinner to use when a name is not defined. |
  124. * | `statusbarPadding` | `boolean` | Whether to hide extra padding for statusbar. |
  125. * | `swipeBackEnabled` | `boolean` | Whether native iOS swipe to go back functionality is enabled. |
  126. * | `tabsHighlight` | `boolean` | Whether to show a highlight line under the tab when it is selected. |
  127. * | `tabsLayout` | `string` | The layout to use for all tabs. Available options: `"icon-top"`, `"icon-start"`, `"icon-end"`, `"icon-bottom"`, `"icon-hide"`, `"title-hide"`. |
  128. * | `tabsPlacement` | `string` | The position of the tabs relative to the content. Available options: `"top"`, `"bottom"` |
  129. * | `tabsHideOnSubPages` | `boolean` | Whether to hide the tabs on child pages or not. If `true` it will not show the tabs on child pages. |
  130. * | `toastEnter` | `string` | The name of the transition to use while a toast is presented. |
  131. * | `toastLeave` | `string` | The name of the transition to use while a toast is dismissed. |
  132. *
  133. **/
  134. var Config = (function () {
  135. function Config() {
  136. this._c = {};
  137. this._s = {};
  138. this._modes = {};
  139. this._trns = {};
  140. }
  141. /**
  142. * @hidden
  143. */
  144. Config.prototype.init = function (config, plt) {
  145. this._s = config && util_1.isObject(config) && !util_1.isArray(config) ? config : {};
  146. this.plt = plt;
  147. };
  148. /**
  149. * @name get
  150. * @description
  151. * Returns a single config value, given a key.
  152. *
  153. * @param {string} [key] - the key for the config value
  154. * @param {any} [fallbackValue] - a fallback value to use when the config
  155. * value was not found, or is config value is `null`. Fallback value
  156. * defaults to `null`.
  157. */
  158. Config.prototype.get = function (key, fallbackValue) {
  159. if (fallbackValue === void 0) { fallbackValue = null; }
  160. var platform = this.plt;
  161. if (!util_1.isDefined(this._c[key])) {
  162. if (!util_1.isDefined(key)) {
  163. throw 'config key is not defined';
  164. }
  165. // if the value was already set this will all be skipped
  166. // if there was no user config then it'll check each of
  167. // the user config's platforms, which already contains
  168. // settings from default platform configs
  169. var userPlatformValue = undefined;
  170. var userDefaultValue = this._s[key];
  171. var userPlatformModeValue = undefined;
  172. var userDefaultModeValue = undefined;
  173. var platformValue = undefined;
  174. var platformModeValue = undefined;
  175. var configObj = null;
  176. if (platform) {
  177. var queryStringValue = platform.getQueryParam('ionic' + key);
  178. if (util_1.isDefined(queryStringValue)) {
  179. return this._c[key] = (queryStringValue === 'true' ? true : queryStringValue === 'false' ? false : queryStringValue);
  180. }
  181. // check the platform settings object for this value
  182. // loop though each of the active platforms
  183. // array of active platforms, which also knows the hierarchy,
  184. // with the last one the most important
  185. var activePlatformKeys = platform.platforms();
  186. // loop through all of the active platforms we're on
  187. for (var i = 0, ilen = activePlatformKeys.length; i < ilen; i++) {
  188. // get user defined platform values
  189. if (this._s.platforms) {
  190. configObj = this._s.platforms[activePlatformKeys[i]];
  191. if (configObj) {
  192. if (util_1.isDefined(configObj[key])) {
  193. userPlatformValue = configObj[key];
  194. }
  195. configObj = this.getModeConfig(configObj.mode);
  196. if (configObj && util_1.isDefined(configObj[key])) {
  197. userPlatformModeValue = configObj[key];
  198. }
  199. }
  200. }
  201. // get default platform's setting
  202. configObj = platform.getPlatformConfig(activePlatformKeys[i]);
  203. if (configObj && configObj.settings) {
  204. if (util_1.isDefined(configObj.settings[key])) {
  205. // found a setting for this platform
  206. platformValue = configObj.settings[key];
  207. }
  208. configObj = this.getModeConfig(configObj.settings.mode);
  209. if (configObj && util_1.isDefined(configObj[key])) {
  210. // found setting for this platform's mode
  211. platformModeValue = configObj[key];
  212. }
  213. }
  214. }
  215. }
  216. configObj = this.getModeConfig(this._s.mode);
  217. if (configObj && util_1.isDefined(configObj[key])) {
  218. userDefaultModeValue = configObj[key];
  219. }
  220. // cache the value
  221. this._c[key] = util_1.isDefined(userPlatformValue) ? userPlatformValue :
  222. util_1.isDefined(userDefaultValue) ? userDefaultValue :
  223. util_1.isDefined(userPlatformModeValue) ? userPlatformModeValue :
  224. util_1.isDefined(userDefaultModeValue) ? userDefaultModeValue :
  225. util_1.isDefined(platformValue) ? platformValue :
  226. util_1.isDefined(platformModeValue) ? platformModeValue :
  227. null;
  228. }
  229. // return key's value
  230. // either it came directly from the user config
  231. // or it was from the users platform configs
  232. // or it was from the default platform configs
  233. // in that order
  234. var rtnVal = this._c[key];
  235. if (util_1.isFunction(rtnVal)) {
  236. rtnVal = rtnVal(platform);
  237. }
  238. return (rtnVal !== null ? rtnVal : fallbackValue);
  239. };
  240. /**
  241. * @name getBoolean
  242. * @description
  243. * Same as `get()`, however always returns a boolean value. If the
  244. * value from `get()` is `null`, then it'll return the `fallbackValue`
  245. * which defaults to `false`. Otherwise, `getBoolean()` will return
  246. * if the config value is truthy or not. It also returns `true` if
  247. * the config value was the string value `"true"`.
  248. * @param {string} [key] - the key for the config value
  249. * @param {boolean} [fallbackValue] - a fallback value to use when the config
  250. * value was `null`. Fallback value defaults to `false`.
  251. */
  252. Config.prototype.getBoolean = function (key, fallbackValue) {
  253. if (fallbackValue === void 0) { fallbackValue = false; }
  254. var val = this.get(key);
  255. if (val === null) {
  256. return fallbackValue;
  257. }
  258. if (typeof val === 'string') {
  259. return val === 'true';
  260. }
  261. return !!val;
  262. };
  263. /**
  264. * @name getNumber
  265. * @description
  266. * Same as `get()`, however always returns a number value. Uses `parseFloat()`
  267. * on the value received from `get()`. If the result from the parse is `NaN`,
  268. * then it will return the value passed to `fallbackValue`. If no fallback
  269. * value was provided then it'll default to returning `NaN` when the result
  270. * is not a valid number.
  271. * @param {string} [key] - the key for the config value
  272. * @param {number} [fallbackValue] - a fallback value to use when the config
  273. * value turned out to be `NaN`. Fallback value defaults to `NaN`.
  274. */
  275. Config.prototype.getNumber = function (key, fallbackValue) {
  276. if (fallbackValue === void 0) { fallbackValue = NaN; }
  277. var val = parseFloat(this.get(key));
  278. return isNaN(val) ? fallbackValue : val;
  279. };
  280. /**
  281. * @name set
  282. * @description
  283. * Sets a single config value.
  284. *
  285. * @param {string} [platform] - The platform (either 'ios' or 'android') that the config value should apply to. Leaving this blank will apply the config value to all platforms.
  286. * @param {string} [key] - The key used to look up the value at a later point in time.
  287. * @param {string} [value] - The config value being stored.
  288. */
  289. Config.prototype.set = function () {
  290. var args = [];
  291. for (var _i = 0; _i < arguments.length; _i++) {
  292. args[_i] = arguments[_i];
  293. }
  294. var arg0 = args[0];
  295. var arg1 = args[1];
  296. switch (args.length) {
  297. case 2:
  298. // set('key', 'value') = set key/value pair
  299. // arg1 = value
  300. this._s[arg0] = arg1;
  301. delete this._c[arg0]; // clear cache
  302. break;
  303. case 3:
  304. // setting('ios', 'key', 'value') = set key/value pair for platform
  305. // arg0 = platform
  306. // arg1 = key
  307. // arg2 = value
  308. this._s.platforms = this._s.platforms || {};
  309. this._s.platforms[arg0] = this._s.platforms[arg0] || {};
  310. this._s.platforms[arg0][arg1] = args[2];
  311. delete this._c[arg1]; // clear cache
  312. break;
  313. }
  314. return this;
  315. };
  316. /**
  317. * @hidden
  318. * @name settings()
  319. * @description
  320. */
  321. Config.prototype.settings = function (arg0, arg1) {
  322. switch (arguments.length) {
  323. case 0:
  324. return this._s;
  325. case 1:
  326. // settings({...})
  327. this._s = arg0;
  328. this._c = {}; // clear cache
  329. break;
  330. case 2:
  331. // settings('ios', {...})
  332. this._s.platforms = this._s.platforms || {};
  333. this._s.platforms[arg0] = arg1;
  334. this._c = {}; // clear cache
  335. break;
  336. }
  337. return this;
  338. };
  339. /**
  340. * @hidden
  341. */
  342. Config.prototype.setModeConfig = function (modeName, modeConfig) {
  343. this._modes[modeName] = modeConfig;
  344. };
  345. /**
  346. * @hidden
  347. */
  348. Config.prototype.getModeConfig = function (modeName) {
  349. return this._modes[modeName] || null;
  350. };
  351. /**
  352. * @hidden
  353. */
  354. Config.prototype.setTransition = function (trnsName, trnsClass) {
  355. this._trns[trnsName] = trnsClass;
  356. };
  357. /**
  358. * @hidden
  359. */
  360. Config.prototype.getTransition = function (trnsName) {
  361. return this._trns[trnsName] || null;
  362. };
  363. return Config;
  364. }());
  365. exports.Config = Config;
  366. /**
  367. * @hidden
  368. */
  369. function setupConfig(userConfig, plt) {
  370. var config = new Config();
  371. config.init(userConfig, plt);
  372. // add the config obj to the window
  373. var win = plt.win();
  374. win['Ionic'] = win['Ionic'] || {};
  375. win['Ionic']['config'] = config;
  376. return config;
  377. }
  378. exports.setupConfig = setupConfig;
  379. /**
  380. * @hidden
  381. */
  382. exports.ConfigToken = new core_1.InjectionToken('USERCONFIG');
  383. });
  384. //# sourceMappingURL=config.js.map