Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/markdown-language-features/preview-src/loading.ts
3292 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
import { MessagePoster } from './messaging';
6
7
export class StyleLoadingMonitor {
8
private readonly _unloadedStyles: string[] = [];
9
private _finishedLoading: boolean = false;
10
11
private _poster?: MessagePoster;
12
13
constructor() {
14
const onStyleLoadError = (event: any) => {
15
const source = event.target.dataset.source;
16
this._unloadedStyles.push(source);
17
};
18
19
window.addEventListener('DOMContentLoaded', () => {
20
for (const link of document.getElementsByClassName('code-user-style') as HTMLCollectionOf<HTMLElement>) {
21
if (link.dataset.source) {
22
link.onerror = onStyleLoadError;
23
}
24
}
25
});
26
27
window.addEventListener('load', () => {
28
if (!this._unloadedStyles.length) {
29
return;
30
}
31
this._finishedLoading = true;
32
this._poster?.postMessage('previewStyleLoadError', { unloadedStyles: this._unloadedStyles });
33
});
34
}
35
36
public setPoster(poster: MessagePoster): void {
37
this._poster = poster;
38
if (this._finishedLoading) {
39
poster.postMessage('previewStyleLoadError', { unloadedStyles: this._unloadedStyles });
40
}
41
}
42
}
43
44