Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fullscreen button for Quill Editor?

Tags:

quill

I am working with Quill Editor. Its been nice so far. My question is that is there any way to make Quill Editor go full-screen (sort of distraction free mode) by a button in the toolbar? If not than how can I proceed to implement this on my own?

like image 472
schartz Avatar asked Nov 14 '16 06:11

schartz


People also ask

What is quill rich editor?

Quill Rich Text Editor Quill is a free, open source WYSIWYG editor built for the modern web. With its modular architecture and expressive API, it is completely customizable to fit any need.

How do I create a quill editor?

You'll need to check manually if the editor's content is empty, prevent the user from submitting the form and show a message that this field is required. You can copy quill contents to a hidden input element before submitting the form as shown in this example. Save this answer. Show activity on this post.


1 Answers

To go fullscreen I think it is easiest to use a library, for example screenfull.js - https://github.com/sindresorhus/screenfull.js/

As for adding custom buttons to the Quill toolbar, I have found two ways.

Method 1:

At least simple buttons can be added directly through the toolbar options. Something like this: 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>

Method 2:

Set the toolbar to use custom Html rather than specifying the buttons through javascript. The official documentation ( http://quilljs.com/docs/modules/toolbar/ ) is quite detailed for this.

Here's a tweaked code sample from there:

<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>
like image 84
nik10110 Avatar answered Sep 18 '22 17:09

nik10110