Vanessa 5 years ago
parent
commit
f02039e754
4 changed files with 11 additions and 4 deletions
  1. 2 0
      CHANGELOG.md
  2. 6 2
      src/ts/toolbar/Custom.ts
  3. 1 1
      src/ts/toolbar/Fullscreen.ts
  4. 2 1
      types/index.d.ts

+ 2 - 0
CHANGELOG.md

@@ -88,6 +88,7 @@
 
 ### v3.7.5 / 2020-12-xx
 
+* [884](https://github.com/Vanessa219/vditor/issues/884) 工具栏自定义按钮禁用 `改进功能`
 * [877](https://github.com/Vanessa219/vditor/issues/877) 数学公式输入删除生成节点 `修复缺陷`
 * [882](https://github.com/Vanessa219/vditor/issues/882) 改进 HTML 转换 Markdown 时加粗、斜体等空格的处理 `改进功能`
 * [878](https://github.com/Vanessa219/vditor/issues/878) 移除列表标记符中文优化 `改进功能`
@@ -97,6 +98,7 @@
 * 文档修改
   * 3.7.5
     * `options.outline` 修改为 `{ enable: boolean, position: "left" | "right" }` 
+    * `toolbar.click` 参数修改为 `event: Event, vditor: IVditor`
   
 ### v3.7.4 / 2020-12-26
 

+ 6 - 2
src/ts/toolbar/Custom.ts

@@ -1,13 +1,17 @@
 import {getEventName} from "../util/compatibility";
 import {MenuItem} from "./MenuItem";
+import {Constants} from "../constants";
 
 export class Custom extends MenuItem {
     constructor(vditor: IVditor, menuItem: IMenuItem) {
         super(vditor, menuItem);
         this.element.children[0].innerHTML = menuItem.icon;
-        this.element.children[0].addEventListener(getEventName(), (event) => {
+        this.element.children[0].addEventListener(getEventName(), (event: Event & { currentTarget: HTMLElement }) => {
             event.preventDefault();
-            menuItem.click();
+            if (event.currentTarget.classList.contains(Constants.CLASS_MENU_DISABLED)) {
+                return;
+            }
+            menuItem.click(event, vditor);
         });
     }
 }

+ 1 - 1
src/ts/toolbar/Fullscreen.ts

@@ -50,7 +50,7 @@ export class Fullscreen extends MenuItem {
             }
 
             if (menuItem.click) {
-                menuItem.click(vditor.element.classList.contains("vditor--fullscreen"));
+                menuItem.click(event, vditor);
             }
 
             setPadding(vditor);

+ 2 - 1
types/index.d.ts

@@ -316,7 +316,7 @@ interface IMenuItem {
     level?: number;
 
     /** 自定义按钮点击时触发的事件 */
-    click?(status?: boolean): void;
+    click?(event: Event, vditor: IVditor): void;
 }
 
 /** @link https://ld246.com/article/1549638745630#options-preview-hljs */
@@ -547,6 +547,7 @@ interface IOptions {
         enable: boolean,
         position: "left" | "right",
     };
+
     /** 编辑器异步渲染完成后的回调方法 */
     after?(): void;