Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix js initializer #132

Merged
merged 2 commits into from
Jan 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions README-zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@
$ dotnet add package AntDesign.Charts
```

- 在 `wwwroot/index.html`(WebAssembly) 或 `Pages/_Host.razor`(Server) 中引入静态文件:

```html
<script src="https://unpkg.com/@antv/g2plot@latest/dist/g2plot.min.js"></script>
<script src="_content/AntDesign.Charts/ant-design-charts-blazor.js"></script>
```

- 在 `_Imports.razor` 中加入命名空间

```csharp
Expand Down
11 changes: 2 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@ English | [简体中文](README-zh_CN.md)
$ dotnet add package AntDesign.Charts
```

- Link the static files in `wwwroot/index.html` (WebAssembly) or `Pages/_Host.razor` (Server)

```html
<script src="https://unpkg.com/@antv/g2plot@latest/dist/g2plot.min.js"></script>
<script src="_content/AntDesign.Charts/ant-design-charts-blazor.js"></script>
```

- Add namespace in `_Imports.razor`

```csharp
Expand Down Expand Up @@ -54,12 +47,12 @@ English | [简体中文](README-zh_CN.md)
title = new Title()
{
visible = true,
text = "曲线折线图",
text = "Line",
},
description = new Description()
{
visible = true,
text = "用平滑的曲线代替折线。",
text = "description",
},
padding = "auto",
forceFit = true,
Expand Down
27 changes: 12 additions & 15 deletions src/AntDesign.Charts/wwwroot/AntDesign.Charts.lib.module.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,31 @@
var beforeStartCalled = false;
var afterStartedCalled = false;

export function beforeWebStart() {
export function beforeWebStart() {
loadScriptAndStyle();
}

export function beforeStart(options, extensions) {
loadScriptAndStyle();
loadScriptAndStyle();
}

function loadScriptAndStyle() {
if (beforeStartCalled) {
return;
}

beforeStartCalled = true;

const interopJS = "_content/AntDesign.Charts/ant-design-charts-blazor.js";
const cdnJS = "https://unpkg.com/@antv/[email protected]/dist/g2plot.min.js";
const localJS = "_content/AntDesign.Charts/g2plot.min.js";
const cdnFlag = document.querySelector('[use-ant-design-charts-cdn]');

if (!document.querySelector(`[src="${interopJS}"]`)) {
var chartJS = cdnFlag ? cdnJS : localJS;
var chartScript = document.createElement('script');
const chartJS = cdnFlag ? cdnJS : localJS;
const chartScript = document.createElement('script');
chartScript.setAttribute('src', chartJS);

document.body.insertBefore(chartScript, document.body.querySelector("script"));
const jsMark = document.querySelector("script");
if (jsMark) {
jsMark.before(chartScript);
}
else {
document.body.appendChild(chartScript);
}

var interopScript = document.createElement('script');
const interopScript = document.createElement('script');
interopScript.setAttribute('src', interopJS);
chartScript.after(interopScript);
}
Expand Down
Loading