Undeletable element in CKEditor

大兔子大兔子 提交于 2019-12-12 18:24:44

问题


I'm wondering if there's a way to make an element 'undeletable' in CKEditor 4.

I might have some HTML like so:

<div class='content' contenteditable='true'>
    <div class='gallery'>...</div>
</div>

In this case .gallery shouldn't be able to be deleted from .content, either by backspacing or selecting and pressing delete.

UPDATE: It seems widgets can not be undeletable, or at least from what I can tell. Take a look at http://ckeditor.com/demo#widgets, the widgets can be deleted. Any other ideas?

Thanks


回答1:


What you are looking for are widgets. They will be implemented in CKEditor 4.3 and provide this kind of features. Be patient ;)

At the moment there's only placeholder plugin that does "similar" thing, but I guess this is not enough for you.




回答2:


I use a workaround to make widgets undeletable. In the widget definition, I added this to the init property:

    init: function () {
        this.on('key', function(e) {
            let k = e.data.keyCode;
            // Backspace, delete, ctrl+x
            if ([8, 46, 1114200].includes(k)) { e.cancel() }
        })
    }

It will prevent the user from deleting the widget using the keyboard. The "cut" function needs to be disabled too.



来源:https://stackoverflow.com/questions/16140267/undeletable-element-in-ckeditor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!