TinyMCE 4中有没有一种方法可以在编辑时自动附加字符



这是TinyMCE 4.3.13中的一个问题,自TinyMCE 4.1.3以来新增。在我们的应用程序中,我们将forced_root_block设置为false。当图像是页面上的最后一个元素时,如果您试图删除它,您会得到:"Uncaught TypeError:无法读取null的属性'nodeName'",除非它是页面上唯一的元素。

如果你把它包装在另一个元素中,你不会得到这个错误,并且图像会被删除。如果图像后面有任何其他项目,即使是一个字符,也不会出现错误,图像会被删除。

例如,如果你打开源代码并将其放入:

a <img src="http://ridgeaviation.ie/images/czaw-SportsCruiser-pic01.jpg"/>
b

然后可以从UI中删除图像。

但有了这个:

a <img src="http://ridgeaviation.ie/images/czaw-SportsCruiser-pic01.jpg"/>

你不能。

如果你把" "放在最后,你将无法删除,因为编辑器显然会修剪空间,但如果你把"‌"放在最后它不会被修剪,是不可见的,你可以删除图像。

这是html:

<!DOCTYPE html>
<html>
<head>
<script src="//cdn.tinymce.com/4/tinymce.min.js"></script>
<script>
tinymce.init({
selector:'textarea',    toolbar: "fontselect fontsizeselect | bold italic underline| bullist numlist outdent indent | alignleft aligncenter alignright alignjustify | forecolor backcolor | link  anchor code",
menubar: "edit insert view format table tools",
plugins: [
'advlist autolink lists link image charmap print preview hr anchor pagebreak',
'searchreplace wordcount visualblocks visualchars code fullscreen',
'insertdatetime media nonbreaking save table contextmenu directionality',
'emoticons template paste textcolor colorpicker textpattern imagetools'
],
image_advtab: true,
force_br_newlines: true,
force_p_newlines: false,
forced_root_block: false
});
</script>
</head>
<body>
<textarea>Easy (and free!) You should check out our premium features.</textarea>
</body>
</html>

因此,问题是,是否有某种方法可以自动将"‌"附加到正在编辑的文本中,即使是在使用"工具"->"源代码"进行编辑之后?TinyMCE 3.x有cleanup_callback,但这在4.x 中不可用

您能使用TinyMCEchange事件并在末尾查找您的特殊字符吗?如果没有,请添加它?

例如:

tinymce.init({
selector: 'textarea',
...
setup: function (editor) {
editor.on('change', function () {
console.log('Content changed to:  ' + editor.getContent());
//Check the content here and add your character to the end if needed
});
}
})

以下是如何使用change事件的技巧。。。http://fiddle.tinymce.com/q0faab

最新更新