From 14423c21b934e491233238241d3812a0bfc54be3 Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Thu, 12 Oct 2017 20:29:15 +0200 Subject: [PATCH] Add remove method to RichTextEditor module --- src/rich_text_editor/index.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/rich_text_editor/index.js b/src/rich_text_editor/index.js index 1ffa69c2b..934fa0569 100644 --- a/src/rich_text_editor/index.js +++ b/src/rich_text_editor/index.js @@ -2,6 +2,7 @@ * * [add](#add) * * [get](#get) * * [getAll](#getall) + * * [remove](#remove) * * [getToolbarEl](#gettoolbarel) * * This module allows to customize the toolbar of the Rich Text Editor and use commands from the HTML Editing APIs. @@ -167,6 +168,28 @@ module.exports = () => { return globalRte.getActions(); }, + /** + * Remove the action from the toolbar + * @param {string} name + * @return {Object} Removed action + * @example + * const action = rte.remove('bold'); + * // {name: 'bold', ...} + */ + remove(name) { + const actions = this.getAll(); + const action = this.get(name); + + if (action) { + const btn = action.btn; + const index = actions.indexOf(action); + btn.parentNode.removeChild(btn); + actions.splice(index, 1); + } + + return action; + }, + /** * Get the toolbar element * @return {HTMLElement}