Mercurial Hosting > sceditor
comparison 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 |
comparison
equal
deleted
inserted
replaced
14:0cb206904499 | 15:ea930990b601 |
---|---|
1798 '<link rel="stylesheet" type="text/css" href="{style}" />' + | 1798 '<link rel="stylesheet" type="text/css" href="{style}" />' + |
1799 '</head>' + | 1799 '</head>' + |
1800 '<body contenteditable="true" {spellcheck}><p></p></body>' + | 1800 '<body contenteditable="true" {spellcheck}><p></p></body>' + |
1801 '</html>', | 1801 '</html>', |
1802 | 1802 |
1803 toolbarButton: '<a class="sceditor-button sceditor-button-{name}" ' + | 1803 toolbarButton: '<a class="sceditor-button sceditor-button-{iconName}" ' + |
1804 'data-sceditor-command="{name}" unselectable="on">' + | 1804 'data-sceditor-command="{name}" unselectable="on">' + |
1805 '<div unselectable="on">{dispName}</div></a>', | 1805 '<div unselectable="on">{dispName}</div></a>', |
1806 | 1806 |
1807 emoticon: '<img src="{url}" data-sceditor-emoticon="{key}" ' + | 1807 emoticon: '<img src="{url}" data-sceditor-emoticon="{key}" ' + |
1808 'alt="{key}" title="{tooltip}" />', | 1808 'alt="{key}" title="{tooltip}" />', |
6148 group = createElement('div', { | 6148 group = createElement('div', { |
6149 className: 'sceditor-group' | 6149 className: 'sceditor-group' |
6150 }); | 6150 }); |
6151 | 6151 |
6152 each(menuItems.split(','), function (_, commandName) { | 6152 each(menuItems.split(','), function (_, commandName) { |
6153 var button, shortcut, | 6153 let command = commands[commandName]; |
6154 command = commands[commandName]; | |
6155 | 6154 |
6156 // The commandName must be a valid command and not excluded | 6155 // The commandName must be a valid command and not excluded |
6157 if (!command || exclude.indexOf(commandName) > -1) { | 6156 if (!command || exclude.indexOf(commandName) > -1) { |
6158 return; | 6157 return; |
6159 } | 6158 } |
6160 | 6159 |
6161 shortcut = command.shortcut; | 6160 let iconName = command.icon || commandName |
6162 button = _tmpl('toolbarButton', { | 6161 let shortcut = command.shortcut; |
6162 let button = _tmpl('toolbarButton', { | |
6163 iconName: iconName, | |
6163 name: commandName, | 6164 name: commandName, |
6164 dispName: base._(command.name || | 6165 dispName: base._(command.name || |
6165 command.tooltip || commandName) | 6166 command.tooltip || commandName) |
6166 }, true).firstChild; | 6167 }, true).firstChild; |
6167 | 6168 |
6168 if (icons.create) { | 6169 if (icons.create) { |
6169 var icon = icons.create(commandName); | 6170 let icon = icons.create(iconName); |
6170 if (icon) { | 6171 if (icon) { |
6171 insertBefore(icons.create(commandName), | 6172 insertBefore( icon, button.firstChild ); |
6172 button.firstChild); | |
6173 addClass(button, 'has-icon'); | 6173 addClass(button, 'has-icon'); |
6174 } | 6174 } |
6175 } | 6175 } |
6176 | 6176 |
6177 button._sceTxtMode = !!command.txtExec; | 6177 button._sceTxtMode = !!command.txtExec; |
7855 * Updates if buttons are active or not | 7855 * Updates if buttons are active or not |
7856 * @private | 7856 * @private |
7857 */ | 7857 */ |
7858 updateActiveButtons = function () { | 7858 updateActiveButtons = function () { |
7859 var firstBlock, parent; | 7859 var firstBlock, parent; |
7860 var activeClass = 'active'; | |
7861 var doc = wysiwygDocument; | 7860 var doc = wysiwygDocument; |
7862 var isSource = base.sourceMode(); | 7861 var isSource = base.sourceMode(); |
7863 | 7862 |
7864 if (base.readOnly()) { | 7863 if (base.readOnly()) { |
7865 each(find(toolbar, activeClass), function (_, menuItem) { | 7864 each(find(toolbar, 'active'), function (_, menuItem) { |
7866 removeClass(menuItem, activeClass); | 7865 removeClass(menuItem, 'active'); |
7867 }); | 7866 }); |
7868 return; | 7867 return; |
7869 } | 7868 } |
7870 | 7869 |
7871 if (!isSource) { | 7870 if (!isSource) { |
7894 } else if (!isDisabled) { | 7893 } else if (!isDisabled) { |
7895 state = stateFn.call(base, parent, firstBlock); | 7894 state = stateFn.call(base, parent, firstBlock); |
7896 } | 7895 } |
7897 | 7896 |
7898 toggleClass(btn, 'disabled', isDisabled || state < 0); | 7897 toggleClass(btn, 'disabled', isDisabled || state < 0); |
7899 toggleClass(btn, activeClass, state > 0); | 7898 toggleClass(btn, 'active', state > 0); |
7900 } | 7899 } |
7901 | 7900 |
7902 if (icons.update) { | 7901 if (icons.update) { |
7903 icons.update(isSource, parent, firstBlock); | 7902 icons.update(isSource, parent, firstBlock); |
7904 } | 7903 } |