提交 5ef492b8 编写于 作者: M Matt Bierner

Move style loading monitor to class

上级 dc0d6bad
......@@ -4,24 +4,28 @@
*--------------------------------------------------------------------------------------------*/
import { postCommand } from './messaging';
const unloadedStyles: string[] = [];
export class StyleLoadingMonitor {
private unloadedStyles: string[] = [];
const onStyleLoadError = (event: any) => {
const source = event.target.dataset.source;
unloadedStyles.push(source);
};
constructor() {
const onStyleLoadError = (event: any) => {
const source = event.target.dataset.source;
this.unloadedStyles.push(source);
};
window.addEventListener('DOMContentLoaded', () => {
for (const link of document.getElementsByClassName('code-user-style') as HTMLCollectionOf<HTMLElement>) {
if (link.dataset.source) {
link.onerror = onStyleLoadError;
}
}
});
window.addEventListener('DOMContentLoaded', () => {
for (const link of document.getElementsByClassName('code-user-style') as HTMLCollectionOf<HTMLElement>) {
if (link.dataset.source) {
link.onerror = onStyleLoadError;
}
}
});
window.addEventListener('load', () => {
if (!unloadedStyles.length) {
return;
window.addEventListener('load', () => {
if (!this.unloadedStyles.length) {
return;
}
postCommand('_markdown.onPreviewStyleLoadError', [this.unloadedStyles]);
});
}
postCommand('_markdown.onPreviewStyleLoadError', [unloadedStyles]);
});
\ No newline at end of file
}
\ No newline at end of file
......@@ -3,8 +3,11 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import './loading';
import { CspAlerter } from './csp';
import { StyleLoadingMonitor } from './loading';
// tslint:disable-next-line:no-unused-expression
new CspAlerter();
\ No newline at end of file
new CspAlerter();
// tslint:disable-next-line:no-unused-expression
new StyleLoadingMonitor();
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册