提交 0a68f769 编写于 作者: M Matt Bierner

Move common command logic to own file

上级 3c4002f8
......@@ -4,6 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import { getSettings } from './settings';
import { postCommand } from './messaging';
const strings = JSON.parse(document.getElementById('vscode-markdown-preview-data').getAttribute('data-strings'));
const settings = getSettings();
......@@ -24,14 +25,7 @@ const showCspWarning = () => {
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]
}
}, '*');
postCommand('markdown.showPreviewSecuritySelector', [settings.source]);
};
document.body.appendChild(notification);
};
......
......@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import { getSettings } from './settings';
import { postCommand, postMessage } from './messaging';
// From https://remysharp.com/2010/07/21/throttling-function-calls
function throttle(fn: (x: any) => any, threshhold: any, scope?: any) {
......@@ -37,24 +37,6 @@ function clampLine(line: number) {
return clamp(0, settings.lineCount - 1, line);
}
/**
* Post a message to the markdown extension
*/
function postMessage(type: string, body: object) {
window.parent.postMessage({
type,
source: settings.source,
body
}, '*');
}
/**
* Post a command to be executed to the markdown extension
*/
function postCommand(command: string, args: any[]) {
postMessage('command', { command, args });
}
interface CodeLineElement {
element: HTMLElement;
......
......@@ -3,6 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { getSettings } from './settings';
import { postCommand } from './messaging';
const unloadedStyles: string[] = [];
......@@ -25,12 +26,5 @@ window.addEventListener('load', () => {
if (!unloadedStyles.length) {
return;
}
window.parent.postMessage({
type: 'command',
source: settings.source,
body: {
command: '_markdown.onPreviewStyleLoadError',
args: [unloadedStyles]
}
}, '*');
postCommand('_markdown.onPreviewStyleLoadError', [unloadedStyles]);
});
\ No newline at end of file
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { getSettings } from './settings';
/**
* Post a message to the markdown extension
*/
export function postMessage(type: string, body: object) {
window.parent.postMessage({
type,
source: getSettings().source,
body
}, '*');
}
/**
* Post a command to be executed to the markdown extension
*/
export function postCommand(command: string, args: any[]) {
postMessage('command', { command, args });
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册