D
D
devAston2019-09-09 15:58:04
JavaScript
devAston, 2019-09-09 15:58:04

How to prohibit editing and deleting a specific element within the WYSIWYG editor?

There is the following structure:

<p id="editor">
        Данный текст можно удалять и изменять
        <span class="no-delete">нельзя ни удалить ни редактировать</span>
        затем этот текст тоже можно удалять и изменять
    </p>

An instance of the editor is assigned to the ID "editor".
How to prevent WYSIWYG ( Summernote ) from deleting elements with the "no-delete" class

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
devAston, 2019-09-09
@devAston

An intermediate solution turned out to be the use of TinyMCE with the "PreventDelete" plugin.
jsFiddle
Plugin (git)
Ps when copying elements are overwritten...

...
inymce.PluginManager.add('preventdelete', function(ed, link) {
            ed.on('keydown', function(evt) {

                var range = tinymce.activeEditor.selection.getRng();

                var content = tinymce.activeEditor.selection.getContent(); //Получаем весь выделенный контент

                //Проверяем, если в контенте присутствует "mceNonEditable", то запрещать любые действия
                if (content.indexOf("mceNonEditable") + 1){
                    return self.cancelKey(evt)
                }

                self.logElem(range.startContainer)

               ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question