-
Notifications
You must be signed in to change notification settings - Fork 13.5k
/
ionic-global.ts
64 lines (50 loc) · 1.74 KB
/
ionic-global.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { getMode, setMode } from '@stencil/core';
import { Mode } from '../interface';
import { isPlatform, setupPlatforms } from '../utils/platform';
import { config, configFromSession, configFromURL, saveConfig } from './config';
declare const Context: any;
let defaultMode: Mode;
export const getIonMode = (ref?: any): Mode => {
return (ref && getMode(ref)) || defaultMode;
};
export default () => {
const doc = document;
const win = window;
Context.config = config;
const Ionic = (win as any).Ionic = (win as any).Ionic || {};
// Setup platforms
setupPlatforms(win);
// create the Ionic.config from raw config object (if it exists)
// and convert Ionic.config into a ConfigApi that has a get() fn
const configObj = {
...configFromSession(win),
persistConfig: false,
...Ionic.config,
...configFromURL(win)
};
config.reset(configObj);
if (config.getBoolean('persistConfig')) {
saveConfig(win, configObj);
}
// first see if the mode was set as an attribute on <html>
// which could have been set by the user, or by pre-rendering
// otherwise get the mode via config settings, and fallback to md
Ionic.config = config;
Ionic.mode = defaultMode = config.get('mode', (doc.documentElement.getAttribute('mode')) || (isPlatform(win, 'ios') ? 'ios' : 'md'));
config.set('mode', defaultMode);
doc.documentElement.setAttribute('mode', defaultMode);
doc.documentElement.classList.add(defaultMode);
if (config.getBoolean('_testing')) {
config.set('animated', false);
}
setMode((elm: any) => {
while (elm) {
const elmMode = (elm as any).mode || elm.getAttribute('mode');
if (elmMode) {
return elmMode;
}
elm = elm.parentElement;
}
return defaultMode;
});
};