MCPcopy Create free account
hub / github.com/SuperMap/iClient-JavaScript / setRootStyle

Function setRootStyle

examples/js/theme/theme.js:8–48  ·  view source on GitHub ↗
(theme)

Source from the content-addressed store, hash-verified

6var isNativeSupport = isBrowser && window.CSS && window.CSS.supports && window.CSS.supports('(--a: 0)');
7
8function setRootStyle (theme) {
9 var targetTheme = null;
10 window.themeConfig.forEach(function (item) {
11 if (item.label === theme) {
12 targetTheme = item;
13 };
14 })
15 var acceptedThemeStyle = targetTheme || window.themeConfig[1];
16 var variables = {};
17 var themeKeys = Object.keys(acceptedThemeStyle);
18 themeKeys.forEach(function(key) {
19 var varKey = toStyleVariable(key);
20 variables[varKey] = acceptedThemeStyle[key];
21 })
22 var rootStyleSelector = ':root';
23 var antdStyleId = 'sm-theme-style';
24 var rootStyle = rootStyleSelector + ' ' + JSON.stringify(variables, null, 2)
25 .replace(/(:.+),/g, '$1;')
26 .replace(/"/g, '');
27 var rootStyleTag = document.getElementById(antdStyleId);
28 if (!rootStyleTag) {
29 rootStyleTag = document.createElement('style');
30 rootStyleTag.setAttribute('id', antdStyleId);
31 rootStyleTag.setAttribute('type', 'text/css');
32 document.head.insertBefore(rootStyleTag, document.head.firstChild);
33 }
34 var options = {
35 include: 'style#sm-theme-style, link[href*=css]',
36 silent: true,
37 onlyLegacy: true,
38 variables: {},
39 watch: false
40 };
41 if (!isNativeSupport) {
42 options.onlyLegacy = false;
43 options.watch = true;
44 options.variables = variables;
45 }
46 cssVars(options);
47 rootStyleTag.innerHTML = rootStyle;
48}
49
50
51initSkin();

Callers 1

initSkinFunction · 0.85

Calls 3

toStyleVariableFunction · 0.85
forEachMethod · 0.80
createElementMethod · 0.80

Tested by

no test coverage detected