Mercurial Hosting > sceditor
diff src/sceditor.js @ 15:ea930990b601
Add optional "icon" to command spec
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 07 Aug 2022 17:00:41 -0600 |
parents | 8d32537e0ca7 |
children | 8bd52902156a |
line wrap: on
line diff
--- a/src/sceditor.js Sun Aug 07 14:58:42 2022 -0600 +++ b/src/sceditor.js Sun Aug 07 17:00:41 2022 -0600 @@ -1800,7 +1800,7 @@ '<body contenteditable="true" {spellcheck}><p></p></body>' + '</html>', - toolbarButton: '<a class="sceditor-button sceditor-button-{name}" ' + + toolbarButton: '<a class="sceditor-button sceditor-button-{iconName}" ' + 'data-sceditor-command="{name}" unselectable="on">' + '<div unselectable="on">{dispName}</div></a>', @@ -6150,26 +6150,26 @@ }); each(menuItems.split(','), function (_, commandName) { - var button, shortcut, - command = commands[commandName]; + let command = commands[commandName]; // The commandName must be a valid command and not excluded if (!command || exclude.indexOf(commandName) > -1) { return; } - shortcut = command.shortcut; - button = _tmpl('toolbarButton', { + let iconName = command.icon || commandName + let shortcut = command.shortcut; + let button = _tmpl('toolbarButton', { + iconName: iconName, name: commandName, dispName: base._(command.name || command.tooltip || commandName) }, true).firstChild; if (icons.create) { - var icon = icons.create(commandName); + let icon = icons.create(iconName); if (icon) { - insertBefore(icons.create(commandName), - button.firstChild); + insertBefore( icon, button.firstChild ); addClass(button, 'has-icon'); } } @@ -7857,13 +7857,12 @@ */ updateActiveButtons = function () { var firstBlock, parent; - var activeClass = 'active'; var doc = wysiwygDocument; var isSource = base.sourceMode(); if (base.readOnly()) { - each(find(toolbar, activeClass), function (_, menuItem) { - removeClass(menuItem, activeClass); + each(find(toolbar, 'active'), function (_, menuItem) { + removeClass(menuItem, 'active'); }); return; } @@ -7896,7 +7895,7 @@ } toggleClass(btn, 'disabled', isDisabled || state < 0); - toggleClass(btn, activeClass, state > 0); + toggleClass(btn, 'active', state > 0); } if (icons.update) {