2
0
mirror of https://github.com/Ionaru/easy-markdown-editor synced 2025-07-18 23:44:29 -06:00

Merge pull request #168 from kolaente/feature/137-custom-icons

Add support for custom icon markup
This commit is contained in:
Jeroen Akkerman 2020-03-24 15:55:16 +01:00 committed by GitHub
commit 6470e10e29
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -167,8 +167,13 @@ function createToolbarButton(options, enableActions, enableTooltips, shortcuts,
el.classList.add('no-mobile'); el.classList.add('no-mobile');
} }
// Prevent errors if there is no class name in custom options
var classNameParts = [];
if(typeof options.className !== 'undefined') {
classNameParts = options.className.split(' ');
}
// Provide backwards compatibility with simple-markdown-editor by adding custom classes to the button. // Provide backwards compatibility with simple-markdown-editor by adding custom classes to the button.
var classNameParts = options.className.split(' ');
var iconClasses = []; var iconClasses = [];
for (var classNameIndex = 0; classNameIndex < classNameParts.length; classNameIndex++) { for (var classNameIndex = 0; classNameIndex < classNameParts.length; classNameIndex++) {
var classNamePart = classNameParts[classNameIndex]; var classNamePart = classNameParts[classNameIndex];
@ -191,6 +196,11 @@ function createToolbarButton(options, enableActions, enableTooltips, shortcuts,
} }
el.appendChild(icon); el.appendChild(icon);
// If there is a custom icon markup set, use that
if (typeof options.icon !== 'undefined') {
el.innerHTML = options.icon;
}
if (options.action && enableActions) { if (options.action && enableActions) {
if (typeof options.action === 'function') { if (typeof options.action === 'function') {
el.onclick = function (e) { el.onclick = function (e) {