(userConfig: IonicConfig = {})
| 15 | }; |
| 16 | |
| 17 | export const initialize = (userConfig: IonicConfig = {}) => { |
| 18 | if (typeof (window as any) === 'undefined') { |
| 19 | return; |
| 20 | } |
| 21 | |
| 22 | const doc = window.document; |
| 23 | const win = window; |
| 24 | const Ionic = ((win as any).Ionic = (win as any).Ionic || {}); |
| 25 | |
| 26 | // create the Ionic.config from raw config object (if it exists) |
| 27 | // and convert Ionic.config into a ConfigApi that has a get() fn |
| 28 | const configObj = { |
| 29 | ...configFromSession(win), |
| 30 | persistConfig: false, |
| 31 | ...Ionic.config, |
| 32 | ...configFromURL(win), |
| 33 | ...userConfig, |
| 34 | }; |
| 35 | |
| 36 | config.reset(configObj); |
| 37 | if (config.getBoolean('persistConfig')) { |
| 38 | saveConfig(win, configObj); |
| 39 | } |
| 40 | |
| 41 | // Setup platforms |
| 42 | setupPlatforms(win); |
| 43 | |
| 44 | // first see if the mode was set as an attribute on <html> |
| 45 | // which could have been set by the user, or by pre-rendering |
| 46 | // otherwise get the mode via config settings, and fallback to md |
| 47 | Ionic.config = config; |
| 48 | Ionic.mode = defaultMode = config.get( |
| 49 | 'mode', |
| 50 | doc.documentElement.getAttribute('mode') || (isPlatform(win, 'ios') ? 'ios' : 'md') |
| 51 | ); |
| 52 | config.set('mode', defaultMode); |
| 53 | doc.documentElement.setAttribute('mode', defaultMode); |
| 54 | doc.documentElement.classList.add(defaultMode); |
| 55 | |
| 56 | if (config.getBoolean('_testing')) { |
| 57 | config.set('animated', false); |
| 58 | } |
| 59 | |
| 60 | const isIonicElement = (elm: any) => elm.tagName?.startsWith('ION-'); |
| 61 | |
| 62 | const isAllowedIonicModeValue = (elmMode: string) => ['ios', 'md'].includes(elmMode); |
| 63 | |
| 64 | setMode((elm: any) => { |
| 65 | while (elm) { |
| 66 | const elmMode = (elm as any).mode || elm.getAttribute('mode'); |
| 67 | if (elmMode) { |
| 68 | if (isAllowedIonicModeValue(elmMode)) { |
| 69 | return elmMode; |
| 70 | } else if (isIonicElement(elm)) { |
| 71 | printIonWarning('Invalid ionic mode: "' + elmMode + '", expected: "ios" or "md"'); |
| 72 | } |
| 73 | } |
| 74 | elm = elm.parentElement; |
no test coverage detected