7

我正在使用 Quill Editor。到目前为止还不错。我的问题是,有什么方法可以通过工具栏中的按钮使 Quill Editor 全屏显示(某种无干扰模式)?如果不是,我该如何自行实施呢?

4

1 回答 1

9

要全屏显示,我认为使用库最简单,例如 screenfull.js - https://github.com/sindresorhus/screenfull.js/

至于向 Quill 工具栏添加自定义按钮,我找到了两种方法。

方法一:

至少可以通过工具栏选项直接添加简单的按钮。像这样的东西: http: //codepen.io/nik10110/pen/PbyNoW

<div id="editor"></div>

<style>
  #editor {
    height: 375px;
  }

  .ql-omega:after {
    content: "Ω";
  }
</style>

<script type="text/javascript">
  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');
    }
  });
</script>

方法二:

将工具栏设置为使用自定义 Html,而不是通过 javascript 指定按钮。官方文档(http://quilljs.com/docs/modules/toolbar/)对此非常详细。

这是一个经过调整的代码示例:

<div id="toolbar">
  <!-- Add buttons as you would before -->
  <button class="ql-bold"></button>
  <button class="ql-italic"></button>

  <!-- But you can also add your own -->
  <button id="toggle-fullscreen"></button>
</div>
<div id="editor"></div>

<script type="text/javascript">
var quill = new Quill('#editor', {
  modules: {
    toolbar: '#toolbar'
  }
});

var customButton = document.querySelector('#toggle-fullscreen');
customButton.addEventListener('click', function() {
  if (screenfull.enabled) {
    console.log('requesting fullscreen');
    screenfull.request();
  } else {
    console.log('Screenfull not enabled');
  }
});
</script>
于 2016-12-13T14:27:46.633 回答