Quill Test

In this example below you will see how to do a Quill Test with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by 1cco, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright 1cco ©
  • HTML
  • CSS
  • JavaScript
    //- Create toolbar container
div#toolbar
//- Create the editor container
div#editor
  p Hello World!
div#dat


/*Downloaded from https://www.codeseek.co/1cco/quill-test-gKMmWm */
    .ql-omega {
	width: auto;
	font-family: 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif;
	font-size: 14px;
    font-weight: 500;
	color: rgb(68,68,68);
	&::after {
		content: "Custom";
	}
}


/*Downloaded from https://www.codeseek.co/1cco/quill-test-gKMmWm */
    let BlockEmbed = Quill.import('blots/block/embed');

class MyEmbed extends BlockEmbed {
	static create(text) {
		let node = super.create();
		node.setAttribute('data-text', text);
		let elem = document.createElement('div');
		elem.innerHTML = '<ul>\
			<li><a href=""><img src="" alt=""></a></li>\
			<li><a href=""><img src="" alt=""></a></li>\
			<li><a href=""><img src="" alt=""></a></li>\
			</ul>';
		node.appendChild(elem);
		return node;
	}
	static value(node) {
		return node.getAttribute('src');
	}
}
MyEmbed.blotName = 'myembed';
MyEmbed.tagName = 'div';
MyEmbed.className = 'myembed';
Quill.register(MyEmbed);

var toolbarOptions = [
  ['bold', 'italic', 'underline', 'strike'],        // toggled buttons
  ['blockquote', 'code-block'],

  [{ 'header': 1 }, { 'header': 2 }],               // custom button values
  [{ 'list': 'ordered'}, { 'list': 'bullet' }],
  [{ 'script': 'sub'}, { 'script': 'super' }],      // superscript/subscript
  [{ 'indent': '-1'}, { 'indent': '+1' }],          // outdent/indent
  [{ 'direction': 'rtl' }],                         // text direction

  [{ 'size': ['small', false, 'large', 'huge'] }],  // custom dropdown
  [{ 'header': [1, 2, 3, 4, 5, 6, false] }],

  [{ 'color': [] }, { 'background': [] }],          // dropdown with defaults from theme
  [{ 'font': [] }],
  [{ 'align': [] }],

  ['clean'],                                         // remove formatting button
  ['omega']
];

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

var gui = new dat.GUI();
var controlls = [];
var customContainer = document.getElementById('dat');
customContainer.appendChild(gui.domElement);
var params = {
	message: 'test',
	proceed: function(){return true;}
};

var customButton = document.querySelector('.ql-omega');
customButton.addEventListener('click', function() {
	var range = quill.getSelection();
	if (range) {
		openGUI();
		params.proceed = function(){
			quill.insertEmbed(range.index, 'myembed', params.message, Quill.sources.USER);
			closeGUI();
		}
		// quill.insertText(range.index, "‚Ą¶");
	}
});

function openGUI() {
	controlls.push(gui.add(params, 'message'));
	controlls.push(gui.add(params, 'proceed'));
}

function closeGUI() {
	for (var key in controlls) {
		controlls[key].remove();
	}
	controlls = [];
}

Comments