import { InjectionToken } from '@angular/core' ; ngdoc name module description import { Platform } from '../platform/platform' ; import { isArray , isDefined , isFunction , isObject } from '../util/util' ; name demo description NgModule NgModule export class Config { private _c : any = { } ; private _s : any = { } ; private _modes : any = { } ; private _trns : any = { } ; hidden plt : Platform ; hidden init ( config , plt ) { this . _s = config && isObject ( config ) && ! isArray ( config ) ? config : { } ; this . plt = plt ; } name description param { string } key param { any } fallbackValue get ( key , fallbackValue = null ) { const platform = this . plt ; if ( ! isDefined ( this . _c [ key ] ) ) { if ( ! isDefined ( key ) ) { throw 'config key is not defined' ; } var userPlatformValue = undefined ; var userDefaultValue = this . _s [ key ] ; var userPlatformModeValue = undefined ; var userDefaultModeValue = undefined ; var platformValue = undefined ; var platformModeValue = undefined ; var configObj = null ; if ( platform ) { var queryStringValue = platform . getQueryParam ( 'ionic' + key ) ; if ( isDefined ( queryStringValue ) ) { return this . _c [ key ] = ( queryStringValue === 'true' ? true : queryStringValue === 'false' ? false : queryStringValue ) ; } var activePlatformKeys = platform . platforms ( ) ; for ( var i = 0 , ilen = activePlatformKeys . length ; i < ilen ; i ++ ) { if ( this . _s . platforms ) { configObj = this . _s . platforms [ activePlatformKeys [ i ] ] ; if ( configObj ) { if ( isDefined ( configObj [ key ] ) ) { userPlatformValue = configObj [ key ] ; } configObj = this . getModeConfig ( configObj . mode ) ; if ( configObj && isDefined ( configObj [ key ] ) ) { userPlatformModeValue = configObj [ key ] ; } } } configObj = platform . getPlatformConfig ( activePlatformKeys [ i ] ) ; if ( configObj && configObj . settings ) { if ( isDefined ( configObj . settings [ key ] ) ) { platformValue = configObj . settings [ key ] ; } configObj = this . getModeConfig ( configObj . settings . mode ) ; if ( configObj && isDefined ( configObj [ key ] ) ) { platformModeValue = configObj [ key ] ; } } } } configObj = this . getModeConfig ( this . _s . mode ) ; if ( configObj && isDefined ( configObj [ key ] ) ) { userDefaultModeValue = configObj [ key ] ; } this . _c [ key ] = isDefined ( userPlatformValue ) ? userPlatformValue : isDefined ( userDefaultValue ) ? userDefaultValue : isDefined ( userPlatformModeValue ) ? userPlatformModeValue : isDefined ( userDefaultModeValue ) ? userDefaultModeValue : isDefined ( platformValue ) ? platformValue : isDefined ( platformModeValue ) ? platformModeValue : null ; } var rtnVal = this . _c [ key ] ; if ( isFunction ( rtnVal ) ) { rtnVal = rtnVal ( platform ) ; } return ( rtnVal !== null ? rtnVal : fallbackValue ) ; } name description param { string } key param { boolean } fallbackValue getBoolean ( key , fallbackValue = false ) { const val = this . get ( key ) ; if ( val === null ) { return fallbackValue ; } if ( typeof val === 'string' ) { return val === 'true' ; } return ! ! val ; } name description param { string } key param { number } fallbackValue getNumber ( key , fallbackValue = NaN ) { return this . parseNumber ( this . get ( key ) , fallbackValue ) ; } parseNumber ( value , fallbackValue = NaN ) { const val = parseFloat ( value ) ; return isNaN ( val ) ? fallbackValue : val ; } name description param { string } platform param { string } key param { string } value set ( ... args ) { const arg0 = args [ 0 ] ; const arg1 = args [ 1 ] ; switch ( args . length ) { case 2 : this . _s [ arg0 ] = arg1 ; delete this . _c [ arg0 ] ; break ; case 3 : this . _s . platforms = this . _s . platforms || { } ; this . _s . platforms [ arg0 ] = this . _s . platforms [ arg0 ] || { } ; this . _s . platforms [ arg0 ] [ arg1 ] = args [ 2 ] ; delete this . _c [ arg1 ] ; break ; } return this ; } hidden name description settings ( arg0 ? , arg1 ? ) { switch ( arguments . length ) { case 0 : return this . _s ; case 1 : this . _s = arg0 ; this . _c = { } ; break ; case 2 : this . _s . platforms = this . _s . platforms || { } ; this . _s . platforms [ arg0 ] = arg1 ; this . _c = { } ; break ; } return this ; } hidden setModeConfig ( modeName , modeConfig ) { this . _modes [ modeName ] = modeConfig ; } hidden getModeConfig ( modeName ) { return this . _modes [ modeName ] || null ; } hidden setTransition ( trnsName , trnsClass ) { this . _trns [ trnsName ] = trnsClass ; } hidden getTransition ( trnsName ) { return this . _trns [ trnsName ] || null ; } } hidden export function setupConfig ( userConfig , plt ) { const config = new Config ( ) ; config . init ( userConfig , plt ) ; const win = plt . win ( ) ; win [ 'Ionic' ] = win [ 'Ionic' ] || { } ; win [ 'Ionic' ] [ 'config' ] = config ; return config ; } hidden export const ConfigToken = new InjectionToken < any > ( 'USERCONFIG' ) ;