Extract duplicate settings logic to own file

This commit is contained in:
Matt Bierner
2018-03-05 10:52:50 -08:00
parent 36c3f4b008
commit e49c6b3f8e
4 changed files with 74 additions and 62 deletions

View File

@@ -2,35 +2,35 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
(function () {
const unloadedStyles: string[] = [];
import { getSettings } from './settings';
const settings: any = JSON.parse(document.getElementById('vscode-markdown-preview-data').getAttribute('data-settings'));
const unloadedStyles: string[] = [];
const onStyleLoadError = (event: any) => {
const source = event.target.dataset.source;
unloadedStyles.push(source);
};
const settings = getSettings();
window.addEventListener('DOMContentLoaded', () => {
for (const link of document.getElementsByClassName('code-user-style') as HTMLCollectionOf<HTMLElement>) {
if (link.dataset.source) {
link.onerror = onStyleLoadError;
}
const onStyleLoadError = (event: any) => {
const source = event.target.dataset.source;
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('load', () => {
if (!unloadedStyles.length) {
return;
window.addEventListener('load', () => {
if (!unloadedStyles.length) {
return;
}
window.parent.postMessage({
type: 'command',
source: settings.source,
body: {
command: '_markdown.onPreviewStyleLoadError',
args: [unloadedStyles]
}
window.parent.postMessage({
type: 'command',
source: settings.source,
body: {
command: '_markdown.onPreviewStyleLoadError',
args: [unloadedStyles]
}
}, '*');
});
})();
}, '*');
});