Reputation: 1934
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
Upvotes: 2
Views: 1385
Reputation: 466
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.
Upvotes: 2
Reputation: 15895
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.
Upvotes: 2