floriank
floriank

Reputation: 25698

ckeditor disable element, prevent user from adding content to it

I've added a plugin that allows the user to add a specially styled div via a dialog. The issue now is, this element should not be clickable inside the edtior. The problem is the users manage it to click inside the div and enter text there and by this screw it up.

I've already spent some time searching the documentation but couldn't find the right approach to do this yet. I'm not asking for code, just some advice how to do it, a pointer to the right API method would be good enough for me. I guess I can somehow access the elements or intercept an users click and prevent them from adding something to my element somehow, I just couldn't yet figure out how to do it.

Upvotes: 0

Views: 626

Answers (2)

floriank
floriank

Reputation: 25698

I've finally managed to get this done by making the elements content not editable. When I create the element in my dialog:

hrElement.setAttribute('contenteditable', false);

When loading the plugin:

init: function (editor) {
    editor.on('contentDom', function () {
        var stiching = (this.document.getElementsByTag('div'));
        console.log(stiching);
        for(var i=0;i<stiching.count();i++){
            if (stiching.getItem(i).hasClass('stitching')) {
                stiching.getItem(i).setAttribute('contenteditable', false);
            }
        }
    });
}

I'm pretty sure this is not the most best solution (don't like to iterate over the elements) but at least it works for me now. Any suggestions how to improve it for future cases are welcome.

Upvotes: 1

Reinmar
Reinmar

Reputation: 22023

Use the Widget System.

Upvotes: 1

Related Questions