From a9d9993daed8e0d233497336809fffe85007802a Mon Sep 17 00:00:00 2001 From: Zignature Date: Tue, 11 Jan 2022 11:00:56 +0100 Subject: [PATCH] Fix for issue #380 Custom attributes for toolbar buttons Added "attributes" option to custom toolbar button --- README.md | 4 ++++ src/js/easymde.js | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/README.md b/README.md index 2a13104..59e129b 100644 --- a/README.md +++ b/README.md @@ -377,6 +377,10 @@ const easyMDE = new EasyMDE({ }, className: "fa fa-star", title: "Custom Button", + attributes: { // for custom attributes + id: "custom-id", + "data-value": "custom value" // HTML5 data-* attributes need to be enclosed in quotation marks ("") because of the dash (-) in its name. + } }, "|" // Separator // [, ...] diff --git a/src/js/easymde.js b/src/js/easymde.js index 3ee79e1..5016318 100644 --- a/src/js/easymde.js +++ b/src/js/easymde.js @@ -231,6 +231,12 @@ function createToolbarButton(options, enableActions, enableTooltips, shortcuts, } } + if (options.attributes) { + for (var attribute in options.attributes) { + el.setAttribute(attribute, options.attributes[attribute]); + } + } + if (options.noDisable) { el.classList.add('no-disable'); }