简体   繁体   English

Quill Editor - 添加自定义按钮显示“工具栏忽略附加到不存在的格式”

[英]Quill Editor - Add custom button shows “toolbar ignoring attaching to nonexistent format”

I'd like to add a new button to the quill editor toolbar as shown in Codepen and Stackoverflow post我想向羽毛笔编辑器工具栏添加一个新按钮,如CodepenStackoverflow 帖子所示

The console shows this warning:控制台显示此警告:

quill.js:5445 quill:toolbar ignoring attaching to nonexistent format omega <button type="button" class="ql-omega">::after quill.js:5445 quill:toolbar 忽略附加到不存在的格式 omega <button type="button" class="ql-omega">::after

What is missing in the code?代码中缺少什么? How/where would I have to define "omega"?我将如何/在哪里定义“欧米茄”?

var toolbarOptions = [
  [{ 'font': [] }],
  ['bold', 'italic', 'underline'],
  ['blockquote', 'code-block'],
  [{ 'list': 'ordered'}, { 'list': 'bullet' }],
  [{ 'align': [] }],
  ['omega']
];

var quill = new Quill('#editor', {
  modules: {
    toolbar: toolbarOptions
  },
  theme: 'snow'
});

var customButton = document.querySelector('.ql-omega');
customButton.addEventListener('click', function() {
  if (screenfull.enabled) {
    console.log('requesting fullscreen');
    screenfull.request();
  } else {
    console.log('Screenfull not enabled');
  }
});

Add the handler function inside the Quill instance.在 Quill 实例中添加处理程序 function。

var quill = new Quill('#editor', {
  modules: {
    toolbar: {
       container: toolbarOptions,
       handlers: {
        'omega': () => { console.log('omega is clicked'); }
       }
    }
  },
  theme: 'snow'
});

In other way, register the handler function to you quill instance以其他方式,将处理程序 function 注册到您的 quill 实例

quill.getModule('toolbar').addHandler('omega', omegaHandlerFunction);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM