-
Notifications
You must be signed in to change notification settings - Fork 273
/
Copy pathOpenUI5Support.js
90 lines (73 loc) · 1.88 KB
/
OpenUI5Support.js
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import { registerFeature } from "../FeaturesRegistry.js";
import { setTheme } from "../config/Theme.js";
const sap = window.sap;
const core = sap && sap.ui && typeof sap.ui.getCore === "function" && sap.ui.getCore();
const isLoaded = () => {
return !!core;
};
const init = () => {
if (!core) {
return Promise.resolve();
}
return new Promise(resolve => {
core.attachInit(() => {
sap.ui.require(["sap/ui/core/LocaleData"], resolve);
});
});
};
const getConfigurationSettingsObject = () => {
if (!core) {
return;
}
const config = core.getConfiguration();
const LocaleData = sap.ui.require("sap/ui/core/LocaleData");
return {
animationMode: config.getAnimationMode(),
language: config.getLanguage(),
theme: config.getTheme(),
rtl: config.getRTL(),
calendarType: config.getCalendarType(),
formatSettings: {
firstDayOfWeek: LocaleData ? LocaleData.getInstance(config.getLocale()).getFirstDayOfWeek() : undefined,
},
};
};
const getLocaleDataObject = () => {
if (!core) {
return;
}
const config = core.getConfiguration();
const LocaleData = sap.ui.require("sap/ui/core/LocaleData");
return LocaleData.getInstance(config.getLocale())._get();
};
const listenForThemeChange = () => {
const config = core.getConfiguration();
core.attachThemeChanged(async () => {
await setTheme(config.getTheme());
});
};
const attachListeners = () => {
if (!core) {
return;
}
listenForThemeChange();
};
const cssVariablesLoaded = () => {
if (!core) {
return;
}
const link = [...document.head.children].find(el => el.id === "sap-ui-theme-sap.ui.core"); // more reliable than querySelector early
if (!link) {
return;
}
return !!link.href.match(/\/css(-|_)variables\.css/);
};
const OpenUI5Support = {
isLoaded,
init,
getConfigurationSettingsObject,
getLocaleDataObject,
attachListeners,
cssVariablesLoaded,
};
registerFeature("OpenUI5Support", OpenUI5Support);