Skip to content

Commit 24edc45

Browse files
authored
feat: add js initializers (#87)
1 parent 0ebaa7d commit 24edc45

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

src/layout/example/AntDesign.ProLayout.Wasm/wwwroot/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
77
<title>AntDesign.ProLayout.Wasm</title>
88
<base href="/" />
9-
<link href="_content/AntDesign/css/ant-design-blazor.css" rel="stylesheet" />
10-
<link href="_content/AntDesign.ProLayout/css/ant-design-pro-layout-blazor.css" rel="stylesheet" />
9+
<!--<link href="_content/AntDesign/css/ant-design-blazor.css" rel="stylesheet" />
10+
<link href="_content/AntDesign.ProLayout/css/ant-design-pro-layout-blazor.css" rel="stylesheet" />-->
1111
<link href="css/app.css" rel="stylesheet" />
1212
</head>
1313

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
var beforeStartCalled = false;
2+
var afterStartedCalled = false;
3+
4+
export function beforeWebStart() {
5+
loadScriptAndStyle();
6+
}
7+
8+
export function beforeStart(options, extensions) {
9+
loadScriptAndStyle();
10+
}
11+
12+
function loadScriptAndStyle() {
13+
if (beforeStartCalled) {
14+
return;
15+
}
16+
17+
beforeStartCalled = true;
18+
19+
const antblazorCss = '_content/AntDesign/css/ant-design-blazor.css';
20+
const prolayoutCss = '_content/AntDesign.ProLayout/css/ant-design-pro-layout-blazor.css';
21+
22+
if (!document.querySelector(`[href="${prolayoutCss}"]`)){
23+
var customStyle = document.createElement('link');
24+
customStyle.setAttribute('href', `${prolayoutCss}`);
25+
customStyle.setAttribute('rel', 'stylesheet');
26+
27+
const antblazorStyle = document.querySelector(`[href="${antblazorCss}"]`);
28+
if (antblazorStyle) {
29+
antblazorStyle.after(customStyle);
30+
}
31+
else {
32+
console.log('no antblazorStyle')
33+
document.head.insertBefore(customStyle, document.querySelector('[prolayout-css]') || document.querySelector('link'));
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)