2011-05-30 55 views
2

如果我没有点击编辑器,然后点击我的自定义按钮,HTML内容出现,但其他一切消失...事情是,我开发这个插件供公众使用我不想让人们通过错误消除他们的内容,有没有办法设置插入点?下面是插入内容的代码行:TinyMCE插件InsertContent删除编辑器内容

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

我试图在mceInsertContent之前没有成功补充一点:

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

朗代码在这里:

(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); })(); 

谢谢对于那些正在帮助的人!

+0

什么自败? – Thariama 2011-05-30 15:24:01

+0

编辑器中的文本!如果我不在编辑器中单击第一个按钮来设置插入点,则只需在放入新的html东西之前删除所有内容 – 2011-05-30 15:40:40

+0

您是否看到此线程?它有帮助吗? http://tinymce.moxiecode.com/forum/viewtopic.php?id=14984你在测试什么浏览器? – jcolebrand 2011-05-31 02:06:08

回答

0

经过几次测试,FF,IE,Safari和Opera工作正常,唯一删除编辑器内容的浏览器是Chrome浏览器......这是我使用的浏览器...这就是为什么我没有看到这是一个铬问题抱歉!

0

我发现了tinyMCE失去焦点并且将其在整个文件,所以做mceContentInsert之前之后,应该解决这个问题,如果这happend:

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

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