我正在使用Quill Editor。到目前为止一直很好。我的问题是,有没有办法让Quill Editor通过工具栏中的按钮进入全屏(一种无干扰模式)? 如果不是,我怎么能继续自己实现呢?
答案 0 :(得分:6)
要全屏显示,我认为最简单的方法是使用库,例如screenfull.js - https://github.com/sindresorhus/screenfull.js/
至于在Quill工具栏中添加自定义按钮,我找到了两种方法。
方法1:
至少可以通过工具栏选项直接添加简单按钮。像这样的东西: 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>
方法2:
将工具栏设置为使用自定义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>