From db5e6dc6cf496ce4191495669caa61b3164c7553 Mon Sep 17 00:00:00 2001 From: Chris Midgley Date: Fri, 8 May 2020 12:35:29 +0100 Subject: [PATCH] feat: expose adding command and event from editor (refs #970) --- .../examples/example19-customizing-toolbar-buttons.html | 4 ++-- apps/editor/index.d.ts | 2 ++ apps/editor/src/js/editor.js | 8 ++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/apps/editor/examples/example19-customizing-toolbar-buttons.html b/apps/editor/examples/example19-customizing-toolbar-buttons.html index b19aa77746..6e5f24a705 100644 --- a/apps/editor/examples/example19-customizing-toolbar-buttons.html +++ b/apps/editor/examples/example19-customizing-toolbar-buttons.html @@ -88,8 +88,8 @@ // Using Method: Customize the first button const toolbar = editor.getUI().getToolbar(); - editor.eventManager.addEventType('clickCustomButton'); - editor.eventManager.listen('clickCustomButton', function() { + editor.addEventType('clickCustomButton'); + editor.on('clickCustomButton', function() { alert('Click!'); }); diff --git a/apps/editor/index.d.ts b/apps/editor/index.d.ts index f8570cf5e3..1407d7d770 100644 --- a/apps/editor/index.d.ts +++ b/apps/editor/index.d.ts @@ -729,6 +729,8 @@ declare namespace toastui { public addWidget(selection: Range, node: Node, style: string, offset?: number): void; + public addEventType(type: string): void; + public afterAddedCommand(): void; public blur(): void; diff --git a/apps/editor/src/js/editor.js b/apps/editor/src/js/editor.js index 81262c7123..fc17df6c85 100644 --- a/apps/editor/src/js/editor.js +++ b/apps/editor/src/js/editor.js @@ -364,6 +364,14 @@ class ToastUIEditor { } } + /** + * Add event type when given event not exists + * @param {string} type Event type name + */ + addEventType(type) { + this.eventManager.addEventType(type); + } + /** * After added command. */