<template>
<tinymce :init="config"></tinymce>
</template>
<script>
import tinymce from '@tinymce/tinymce-vue';
export default {
name: 'tinyEditor',
components: { tinymce },
props: { params: Object },
computed: {
config () {
return Object.assign({
// fullscreen_native: true, // 使用浏览器的全屏功能,默认false
language: /^zh/i.exec(window.navigator.language) ? 'zh_CN' : 'en',
toolbar_mode: 'sliding',
convert_urls: false,
height: 400,
toolbar: 'fullscreen | fontselect fontsizeselect formatselect | undo redo | bold italic underline strikethrough | alignleft aligncenter alignright alignjustify | outdent indent | numlist bullist checklist | forecolor backcolor casechange permanentpen formatpainter removeformat | pagebreak | charmap emoticons | preview save print | insertfile image media pageembed template link anchor codesample | a11ycheck ltr rtl | showcomments addcomment kityformula-editor tiny_mce_wiris_formulaEditor tiny_mce_wiris_formulaEditorChemistry',
plugins: 'print preview powerpaste casechange importcss searchreplace autolink autosave save directionality advcode visualblocks visualchars fullscreen image link media mediaembed template codesample table charmap hr pagebreak nonbreaking anchor toc insertdatetime advlist lists checklist wordcount a11ychecker imagetools textpattern noneditable help formatpainter permanentpen pageembed charmap mentions quickbars linkchecker emoticons advtable export',
setup: this.editorSetup,
draggable_modal: true
}, this.params);
}
},
methods: {
editorSetup (editor) {
/**
* 解决与element UI弹窗的冲突:
* 在编辑器初始化阶段向整个编辑器添加Mousemove监听事件,通过获取根节点最高层数赋给编辑器和弹窗层;
* 编辑区阻止事件冒泡,所以会出现当鼠标停留在编辑区中,无法显示菜单。
* 这种选择弹层方式,需要在tinymce/themes/silver/theme.min.js中的弹窗class名(tox-tinymce-aux)处加上实例ID,如下图中的 d.id;
* 监听多个事件是为了尽可能规避,无法显示菜单和弹窗的问题;
*/
function overlay (aux) {
return function (e) {
let index = 1;
document.body.childNodes.forEach(function(element) {
if (element.style && element.style.zIndex > index) {
index = parseInt(element.style.zIndex);
}
});
if ((parseFloat(aux.style.zIndex) || 0) < index) {
e.target.style.zIndex = aux.style.zIndex = index;
}
};
}
editor.on('init', function (e) {
const aux = document.querySelector('.' + e.target.id);
e.target.editorContainer.addEventListener('mouseenter', overlay(aux), false);
e.target.editorContainer.addEventListener('mousedown', overlay(aux), false);
});
}
}
};
</script>