Показать сообщение отдельно
  #7 (permalink)  
Старый 29.09.2021, 17:22
Аватар для Aetae
Тлен
Отправить личное сообщение для Aetae Посмотреть профиль Найти все сообщения от Aetae
 
Регистрация: 02.01.2010
Сообщений: 6,480

рони, да, нет нифига.)
Если без иконки, то походу только монкипатчить через что-то типа: button.tox-tbtn[label="Из альбома"].
Цитата:
It is by design that there is currently no option to add styles or classes to custom components. It is to maintain the uniformity in look and feel of the TinyMCE UI.
...upd:
В text можно пихать html, а значит нет проблемы сделать так:
text: '<span class="my_class">' + button_text +'</span>'


...upd2 накидал функцию, добавляющую classes:
function addButton(editor, name, {
  classes, 
  _posAttr = 'data-temp-button-index', 
  ...options
}) {
  const registry = editor.ui.registry;

  if(!classes)
    return registry.addButton(name, options);
  classes = String(classes).split(/\s+/);

  const attr = `${_posAttr}="${addButton.index++}"`;
  const text = `<span ${attr}"></span>`;
  const selector = `span[${attr}]`;
  const hasText = 'text' in options;

  const removePosEl = hasText ? posEl => posEl.remove() : posEl => posEl.parentNode.remove();
  const addClasses = () => {
    const el = editor.getContainer().querySelector(selector);
    el.closest('button').classList.add(...classes);
    removePosEl(el);
  };
  const {onSetup} = options;

  return registry.addButton(name, {
    ...options,
    text: hasText ? options.text + text : text,
    onSetup: typeof onSetup === 'function' ? function() {
      addClasses();
      return onSetup.apply(this, arguments);
    } : addClasses
  });
}
addButton.index = 0;

//...

addButton(editor, 'gallery', {
  tooltip: 'Из альбома',
  text: button_text,
  classes : 'my_class',	
  onAction: function () {
    load(openDialog);
  }
})
__________________
29375, 35

Последний раз редактировалось Aetae, 29.09.2021 в 23:16.
Ответить с цитированием