开发者

TinyMCE Plugin InsertContent erase editor content

If I don't click in the editor before clicking on my custom button, the HTML CONTENT appear but everything else disapear... The thing is that I'm developping this plugin for public use so I don't want that people erase them content by error, is there a way to set a insert point ? Here is the line that insert content code :

ed.execCommand('mceInsertContent', false, 'HTML CONTENT');

i've tried to add this before the mceInsertContent with no success :

tinyMCE.execInstanceCommand("mce_editor_0", "mceFocus");

Long code here :

(function() {
tinymce.create('tinymce.plugins.EmbedText', {
    init : function(ed, url) {
        ed.addButton('EmbedText', {
            title : 'Embed Text',
            image : url+'/../images/text.png',
            onclick : function() {
                var textprompt = prompt("Question", "Exemple");
                if (textprompt != null && textprompt != '开发者_如何学编程undefined')
                    tinyMCE.execInstanceCommand("mce_editor_0", "mceFocus"); //Tried this to set the focus to be shure to don't erase everything but still not working...
                    ed.execCommand('mceInsertContent', false, textprompt );
            }
        });
    },
    createControl : function(n, cm) {
        return null;
    },
    getInfo : function() {
        return {
            longname : "Embed Text",
            author : 'ME',
            authorurl : 'http://perdu.com/',
            infourl : 'http://perdu.com/',
            version : "1.0"
        };
    }
});
tinymce.PluginManager.add('EmbedText', tinymce.plugins.EmbedText);  })();

Thank you for those who's helping !


I found that tinyMCE lose focus and drops it on whole document, so do the following before mceContentInsert, it should fix the problem if that happend:

var ed = tinyMCE.activeEditor, selectedNode = ed.selection.getNode();

if(ed.dom.doc === selectedNode) {
    ed.selection.setNode(ed.dom.doc.body);
}


After a couple of test, FF, IE, Safari and Opera working fine, the only browser who erase the content of the editor is Chrome... It's the browser I use... that's why I havn't seen it's a chrome issue sorry !

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜