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

@@ -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();
}
});
}());
}
});