mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-27 20:13:32 +01:00
Extract duplicate settings logic to own file
This commit is contained in:
@@ -3,45 +3,45 @@
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
(function () {
|
||||
const settings = JSON.parse(document.getElementById('vscode-markdown-preview-data').getAttribute('data-settings'));
|
||||
const strings = JSON.parse(document.getElementById('vscode-markdown-preview-data').getAttribute('data-strings'));
|
||||
import { getSettings } from './settings';
|
||||
|
||||
let didShow = false;
|
||||
const strings = JSON.parse(document.getElementById('vscode-markdown-preview-data').getAttribute('data-strings'));
|
||||
const settings = getSettings();
|
||||
|
||||
const showCspWarning = () => {
|
||||
if (didShow || settings.disableSecurityWarnings) {
|
||||
return;
|
||||
}
|
||||
didShow = true;
|
||||
let didShow = false;
|
||||
|
||||
const notification = document.createElement('a');
|
||||
notification.innerText = strings.cspAlertMessageText;
|
||||
notification.setAttribute('id', 'code-csp-warning');
|
||||
notification.setAttribute('title', strings.cspAlertMessageTitle);
|
||||
const showCspWarning = () => {
|
||||
if (didShow || settings.disableSecurityWarnings) {
|
||||
return;
|
||||
}
|
||||
didShow = true;
|
||||
|
||||
notification.setAttribute('role', 'button');
|
||||
notification.setAttribute('aria-label', strings.cspAlertMessageLabel);
|
||||
notification.onclick = () => {
|
||||
window.parent.postMessage({
|
||||
type: 'command',
|
||||
source: settings.source,
|
||||
body: {
|
||||
command: 'markdown.showPreviewSecuritySelector',
|
||||
args: [settings.source]
|
||||
}
|
||||
}, '*');
|
||||
};
|
||||
document.body.appendChild(notification);
|
||||
const notification = document.createElement('a');
|
||||
notification.innerText = strings.cspAlertMessageText;
|
||||
notification.setAttribute('id', 'code-csp-warning');
|
||||
notification.setAttribute('title', strings.cspAlertMessageTitle);
|
||||
|
||||
notification.setAttribute('role', 'button');
|
||||
notification.setAttribute('aria-label', strings.cspAlertMessageLabel);
|
||||
notification.onclick = () => {
|
||||
window.parent.postMessage({
|
||||
type: 'command',
|
||||
source: settings.source,
|
||||
body: {
|
||||
command: 'markdown.showPreviewSecuritySelector',
|
||||
args: [settings.source]
|
||||
}
|
||||
}, '*');
|
||||
};
|
||||
document.body.appendChild(notification);
|
||||
};
|
||||
|
||||
document.addEventListener('securitypolicyviolation', () => {
|
||||
document.addEventListener('securitypolicyviolation', () => {
|
||||
showCspWarning();
|
||||
});
|
||||
|
||||
window.addEventListener('message', (event) => {
|
||||
if (event && event.data && event.data.name === 'vscode-did-block-svg') {
|
||||
showCspWarning();
|
||||
});
|
||||
|
||||
window.addEventListener('message', (event) => {
|
||||
if (event && event.data && event.data.name === 'vscode-did-block-svg') {
|
||||
showCspWarning();
|
||||
}
|
||||
});
|
||||
}());
|
||||
}
|
||||
});
|
||||
@@ -3,6 +3,9 @@
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { getSettings } from './settings';
|
||||
|
||||
|
||||
// From https://remysharp.com/2010/07/21/throttling-function-calls
|
||||
function throttle(fn: (x: any) => any, threshhold: any, scope?: any) {
|
||||
threshhold = threshhold || (threshhold = 250);
|
||||
@@ -195,7 +198,7 @@ class ActiveLineMarker {
|
||||
|
||||
var scrollDisabled = true;
|
||||
const marker = new ActiveLineMarker();
|
||||
const settings = JSON.parse(document.getElementById('vscode-markdown-preview-data').getAttribute('data-settings'));
|
||||
const settings = getSettings();
|
||||
|
||||
function onLoad() {
|
||||
if (settings.scrollPreviewWithEditor) {
|
||||
|
||||
@@ -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]
|
||||
}
|
||||
}, '*');
|
||||
});
|
||||
})();
|
||||
}, '*');
|
||||
});
|
||||
9
extensions/markdown/preview-src/settings.ts
Normal file
9
extensions/markdown/preview-src/settings.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
export function getSettings(): any {
|
||||
return JSON.parse(document.getElementById('vscode-markdown-preview-data').getAttribute('data-settings'));
|
||||
}
|
||||
Reference in New Issue
Block a user