删除由tinymce插件创建的元素

问题描述 投票:0回答:1

我已经在tinymce中创建了一个插件,该插件会在文本前面添加图片以提醒读者。(Exemple

插入此div,并修改其中的内容可以正常工作,但是如果我的用户想要删除该div(所有红色边框),则难度会更大。

我希望我的用户单击“危险标志”,然后按DEL删除元素。 (实际上不可能)我应该如何在我的插件中添加它?

这是我的插件:

tinymce.PluginManager.add('picto', function (editor, url) {
    editor.contentCSS.push(url + '/css/picto.css');


    if (tinymce.majorVersion == 5) {

        editor.ui.registry.addIcon('addwarning', '<img src="' + url + '/img/attention.png" style="width:24px ; height:24px;">');
    }

    function addWarning() {
        var selection = editor.selection;
        var node = selection.getNode();
        if (node) {
            editor.undoManager.transact(function () {
                var content = selection.getContent();
                if (!content) {
                    content = 'Contenu';
                }

                selection.setContent('<br><div class="alert-modop">' + content + '</div><br>');
            });
        }
    }

这是我对编辑器的js调用:

<script> 
            tinymce.init({
                selector: 'textarea#contenuEtask',
                relative_urls: false,
                language: 'fr_FR',
                contextmenu: false,
                browser_spellcheck: true,
                plugins: "noneditable wordcount autolink anchor fullscreen lists advlist link image hr tabfocus table searchreplace spoiler picto",
                toolbar1: 'fullscreen | undo redo | styleselect | bold italic underline| link image table | bullist numlist outdent indent ',
                toolbar2: 'alignleft aligncenter alignright alignjustify | fontselect fontsizeselect forecolor backcolor | spoiler-add spoiler-hide spoiler-close | warning-add new-add note-add |hr searchreplace',
                noneditable_noneditable_class: "mceNonEditable",
                menubar: "",
                height: 500,
                setup: function (editor) {
                    editor.on('init', function () {
                        var tinyHtml = $('.TinyHiddenValue input[type=hidden]').val();
                        this.setContent(tinyHtml);
                    });
                    editor.on('keyup', function () {
                        var tinyHtml = this.getContent();
                        $('.TinyHiddenValue input[type=hidden]').val(tinyHtml);
                    });
                    editor.on('click', function () {
                        var tinyHtml = this.getContent();
                        $('.TinyHiddenValue input[type=hidden]').val(tinyHtml);
                    });
                }
            });
            tinymce.execCommand('mceRemoveControl', true, 'contenuEtask');
        </script>

和我的CSS创建此元素:

.alert-modop {
  background: url("../Sources/Images/attention.svg") no-repeat;
} 

感谢您的帮助。 o /

javascript tinymce
1个回答
0
投票
我已经用一个div包围了我的内容,其内容可编辑为true。这不会对您的插件产生任何影响,但是现在可以选择我的内容了。

selection.setContent('<br><div contenteditable="true" style="display: inline-block"><div class="alert-modop">' + content + '</div></div><br>');

© www.soinside.com 2019 - 2024. All rights reserved.