a zip code crypto-currency system good for red ONLY

config.js 18KB

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