MCPcopy Index your code
hub / github.com/ionic-team/ionic-framework / initialize

Function initialize

core/src/global/ionic-global.ts:17–78  ·  view source on GitHub ↗
(userConfig: IonicConfig = {})

Source from the content-addressed store, hash-verified

15};
16
17export 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;

Callers 5

setupIonicReactFunction · 0.85
initializeIonicAngularFunction · 0.85
installFunction · 0.85
platform.spec.tsFile · 0.85

Calls 13

configFromSessionFunction · 0.90
configFromURLFunction · 0.90
saveConfigFunction · 0.90
setupPlatformsFunction · 0.90
isPlatformFunction · 0.90
printIonWarningFunction · 0.90
isAllowedIonicModeValueFunction · 0.85
isIonicElementFunction · 0.85
setMethod · 0.80
getMethod · 0.65
resetMethod · 0.45
getBooleanMethod · 0.45

Tested by

no test coverage detected