From 98d9049728291841a582ad1684dad0ece4cfb27f Mon Sep 17 00:00:00 2001 From: Jeroen Akkerman Date: Tue, 11 Jan 2022 21:30:34 +0100 Subject: [PATCH] Move adding custom attributes above all others --- src/js/easymde.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/js/easymde.js b/src/js/easymde.js index f4a0c70..20a6c40 100644 --- a/src/js/easymde.js +++ b/src/js/easymde.js @@ -219,6 +219,16 @@ function createToolbarDropdown(options, enableTooltips, shortcuts, parent) { function createToolbarButton(options, enableActions, enableTooltips, shortcuts, markup, parent) { options = options || {}; var el = document.createElement(markup); + + // Add 'custom' attributes as early as possible, so that 'official' attributes will never be overwritten. + if (options.attributes) { + for (var attribute in options.attributes) { + if (Object.prototype.hasOwnProperty.call(options.attributes, attribute)) { + el.setAttribute(attribute, options.attributes[attribute]); + } + } + } + el.className = options.name; el.setAttribute('type', markup); enableTooltips = (enableTooltips == undefined) ? true : enableTooltips; @@ -237,14 +247,6 @@ function createToolbarButton(options, enableActions, enableTooltips, shortcuts, } } - if (options.attributes) { - for (var attribute in options.attributes) { - if (Object.prototype.hasOwnProperty.call(options.attributes, attribute)) { - el.setAttribute(attribute, options.attributes[attribute]); - } - } - } - if (options.noDisable) { el.classList.add('no-disable'); }