Tinymce:在输入时添加新段落时不要复制类 [英] Tinymce : Don't replicate class when adding a new paragraph on enter

查看:25
本文介绍了Tinymce:在输入时添加新段落时不要复制类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用自定义按钮,我添加了一个带有类和一些内容的段落,如下所示:

Using a custom button, I add a paragraphe with a class and some content, like so :

<p class="mce-new-class">my custom content</p>

当我在这样一个段落后按回车键时,TinyMCE 将使用完全相同的类自动添加一个新段落:

When I press enter after such a paragraph, TinyMCE will automatically add a new paragraph using the exact same class :

<p class="mce-new-class">my custom content</p>
<p class="mce-new-class">&nbsp;</p>

我只想有一个新段落,但没有课程:

I'd like to only have a new paragraph but without the class :

<p class="mce-new-class">my custom content</p>
<p>&nbsp;</p>

我已经试过了:

tinymce.init({
    ...
    setup: function (ed) {
        ed.on('keydown',function(e) {
            if(e.keyCode == 13){
                ed.selection.setContent('<p>&nbsp;</p>'); 
                return false;
            }
        });
    }
});

但这适用于所有情况,并且会阻止其他有用的情况,例如在enter press"上复制列表元素

But this applies to all situations and will brake other usefull situations such as replicating a list element on "enter press"

任何帮助将不胜感激

推荐答案

找到解决方案:

...
setup: function (ed) {
    ed.on('keydown',function(e) {
        if(e.keyCode == 13){
            if(ed.dom.hasClass(ed.selection.getNode(), 'mce-new-class')){               
                ed.selection.setContent('<p>&nbsp;</p>'); 
                return false;                   
            } else {                
                return true;
            }
        }
    });
},
...

这篇关于Tinymce:在输入时添加新段落时不要复制类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆