UNPKG

vditor

Version:

♏ 易于使用的 Markdown 编辑器,为适配不同的应用场景而生

29 lines (27 loc) 1.04 kB
import {Constants} from "../constants"; import {setPreviewMode} from "../ui/setPreviewMode"; import {getEventName} from "../util/compatibility"; import {MenuItem} from "./MenuItem"; export class Both extends MenuItem { constructor(vditor: IVditor, menuItem: IMenuItem) { super(vditor, menuItem); if (vditor.options.preview.mode === "both") { this.element.children[0].classList.add("vditor-menu--current"); } this.element.children[0].addEventListener(getEventName(), (event) => { const btnElement = this.element.firstElementChild; if (btnElement.classList.contains(Constants.CLASS_MENU_DISABLED)) { return; } event.preventDefault(); if (vditor.currentMode !== "sv") { return; } if (vditor.options.preview.mode === "both") { setPreviewMode("editor", vditor); } else { setPreviewMode("both", vditor); } }); } }