mirror of
https://github.com/Ionaru/easy-markdown-editor
synced 2025-07-15 05:54:28 -06:00
Also still add custom classes when using custom icon markup
This commit is contained in:
parent
85e59747ab
commit
cc0706bfc2
@ -167,33 +167,39 @@ function createToolbarButton(options, enableActions, enableTooltips, shortcuts,
|
||||
el.classList.add('no-mobile');
|
||||
}
|
||||
|
||||
// If there is a custom icon, use that
|
||||
// Prevent errors if there is no class name in custom options
|
||||
var className = '';
|
||||
if(typeof options.className !== 'undefined') {
|
||||
className = options.className;
|
||||
}
|
||||
|
||||
// Provide backwards compatibility with simple-markdown-editor by adding custom classes to the button.
|
||||
var classNameParts = className.split(' ');
|
||||
var iconClasses = [];
|
||||
for (var classNameIndex = 0; classNameIndex < classNameParts.length; classNameIndex++) {
|
||||
var classNamePart = classNameParts[classNameIndex];
|
||||
// Split icon classes from the button.
|
||||
// Regex will detect "fa", "fas", "fa-something" and "fa-some-icon-1", but not "fanfare".
|
||||
if (classNamePart.match(/^fa([srlb]|(-[\w-]*)|$)/)) {
|
||||
iconClasses.push(classNamePart);
|
||||
} else {
|
||||
el.classList.add(classNamePart);
|
||||
}
|
||||
}
|
||||
|
||||
el.tabIndex = -1;
|
||||
|
||||
// Create icon element and append as a child to the button
|
||||
var icon = document.createElement('i');
|
||||
for (var iconClassIndex = 0; iconClassIndex < iconClasses.length; iconClassIndex++) {
|
||||
var iconClass = iconClasses[iconClassIndex];
|
||||
icon.classList.add(iconClass);
|
||||
}
|
||||
el.appendChild(icon);
|
||||
|
||||
// If there is a custom icon markup set, use that
|
||||
if (typeof options.icon !== 'undefined') {
|
||||
el.innerHTML = options.icon;
|
||||
} else {
|
||||
// Provide backwards compatibility with simple-markdown-editor by adding custom classes to the button.
|
||||
var classNameParts = options.className.split(' ');
|
||||
var iconClasses = [];
|
||||
for (var classNameIndex = 0; classNameIndex < classNameParts.length; classNameIndex++) {
|
||||
var classNamePart = classNameParts[classNameIndex];
|
||||
// Split icon classes from the button.
|
||||
// Regex will detect "fa", "fas", "fa-something" and "fa-some-icon-1", but not "fanfare".
|
||||
if (classNamePart.match(/^fa([srlb]|(-[\w-]*)|$)/)) {
|
||||
iconClasses.push(classNamePart);
|
||||
} else {
|
||||
el.classList.add(classNamePart);
|
||||
}
|
||||
}
|
||||
|
||||
el.tabIndex = -1;
|
||||
|
||||
// Create icon element and append as a child to the button
|
||||
var icon = document.createElement('i');
|
||||
for (var iconClassIndex = 0; iconClassIndex < iconClasses.length; iconClassIndex++) {
|
||||
var iconClass = iconClasses[iconClassIndex];
|
||||
icon.classList.add(iconClass);
|
||||
}
|
||||
el.appendChild(icon);
|
||||
}
|
||||
|
||||
if (options.action && enableActions) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user