Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

tinymce - TinyMCE4, anchor element is not visible in WYSIWYG mode

i use TinyMCE4 and try to create "custom anchor button", my code looks like:

editor.addButton('LinkAnchor', {
                text: 'Anchor',
                icon: 'anchor',
                onclick: function() {
                    // Open window
                    editor.windowManager.open({
                        title: 'Please input anchor name',
                        body: [
                            {type: 'textbox', name: 'data_anchor', label: 'data-anchor'}
                        ],
                        onsubmit: function(e) {
                            editor.insertContent('<a name="' + e.data.data_anchor + '" data-anchor="' + e.data.data_anchor + '"  class="mce-item-anchor" href="#"></a>');
                        }
                    });
                }
            });

When user use the button, in source code is created this html:

<a href="#" name="inserted_text" data-anchor="inserted_text"></a>

It's works good. When user use this button, anchor element is created and in WYSIWYG mode is default anchor icon for this element. So, user can drag anchor to another place, delete it, or something...

But there is one problem. When user switch to edit source code and back, this anchor icon is destroyed, its no more visible in WYSIWYG (but anchor is still in code).

Same problem is, when i load stored html from database, in WYSIWYG mode anchors are ignored. Or same, when i write code manualy in "source code mode".

What is wrong? Can anyone help me? Thanks.

question from:https://stackoverflow.com/questions/66048901/tinymce4-anchor-element-is-not-visible-in-wysiwyg-mode

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...