diff --git a/extensions/markdown/preview-src/loading.ts b/extensions/markdown/preview-src/loading.ts index f60cdf226d8d80fb71be44094883c91aa70ac604..3469255877480082dfa3224967bc2c53562960af 100644 --- a/extensions/markdown/preview-src/loading.ts +++ b/extensions/markdown/preview-src/loading.ts @@ -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) { - if (link.dataset.source) { - link.onerror = onStyleLoadError; - } - } -}); + window.addEventListener('DOMContentLoaded', () => { + for (const link of document.getElementsByClassName('code-user-style') as HTMLCollectionOf) { + 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 diff --git a/extensions/markdown/preview-src/pre.ts b/extensions/markdown/preview-src/pre.ts index bf5ba852591ddb3aea803cf14e4d7b61ac5243a5..c9fd0ec5b35123cb934f3ac521e0e3bef3e855d5 100644 --- a/extensions/markdown/preview-src/pre.ts +++ b/extensions/markdown/preview-src/pre.ts @@ -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