2009-11-20 87 views
2

我想按照提交按钮旁边的常规表单按钮来制作预览按钮(因为它在大多数情况下都是“发布新主题”表单)。如何以编程方式模拟工具栏的预览按钮单击?我试过$('#article_body_preview').click()但它没有工作。 (我使用jQuery lib和#article_body_preview是工具栏上的预览按钮元素)如何以编程方式点击TinyMCE工具栏的按钮?

回答

4

我自己也有类似的问题。您可以在插件的源代码中找到命令的名称。例如。预览插件的源代码在jscripts/tiny_mce /插件/预览/ editor_plugin_src.js 查找线#37:

ed.addButton('preview', {title : 'preview.preview_desc', cmd : 'mcePreview'}); 

于是命令名称不是 '预览',而是 'mcePreview'。

我想在init上设置全屏模式。我结束了添加

init_instance_callback : 'resizeEditorBox' 

初始化。

resizeEditorBox = function (editor) { 
      setTimeout("tinyMCE.activeEditor.execCommand('mceFullScreen')", 100); 
} 

前init和注释掉:

//     a.win.setTimeout(function() { 
//      tinymce.dom.Event.remove(a.win, "resize", e.resizeFunc); 
//      tinyMCE.get(c.getParam("fullscreen_editor_id")).setContent(c.getContent({format:"raw"}), {format:"raw"}); 
//      tinyMCE.remove(c); 
//      a.remove("mce_fullscreen_container"); 
//      i.style.overflow = c.getParam("fullscreen_html_overflow"); 
//      a.setStyle(a.doc.body, "overflow", c.getParam("fullscreen_overflow")); 
//      a.win.scrollTo(c.getParam("fullscreen_scrollx"), c.getParam("fullscreen_scrolly")); 
//      tinyMCE.settings = tinyMCE.oldSettings 
//     }, 10) 
在editor_plugin.js

- 因为我不需要任何其他的模式,只是全屏模式。希望有所帮助。

+0

它的工作原理!谢谢 – HongKilDong 2010-03-29 05:04:49

3

tinyMCE.activeEditor.execCommand('commandName');

其中commandName是注册到预览按钮的命令。

+0

它适用于一些按钮,但不为其他。也许有误解“命令名”是什么。我尝试了tinyMCE.activeEditor.execCommand('preview');但它并没有做到这一点。我使用标准预览插件的按钮 – HongKilDong 2009-11-25 11:29:28

1

我想补充一点,我还需要设置按钮激活(突出显示)。我用这个代码来实现:

tinyMCE.activeEditor.controlManager.setActive('spellchecker', true); 

替换为您在TinyMCE的初始化设置theme_advanced_buttons在工具栏选项名称拼写检查。

干杯!

顺便说一句,如果你想打开默认的按钮,有一个论坛的帖子在这里,它可以帮助你: http://www.tinymce.com/forum/viewtopic.php?pid=95893#p95893

0

Button creation example

要触发点击TinyMCE的按钮从什么地方你希望下一步:

jQuery(".js_inpost_gallery_insert_shortcode").click(function() { 
      tinyMCE.get(tinyMCE.activeEditor.editorId).controlManager.get(tinyMCE.activeEditor.editorId + "_" + 'pn_tinymce_button').settings.onclick(); 
      return false; 
     }); 
4

我知道这是一个老问题,但我有同样的问题与TinyMCE的4,并不能得到任何解决方案的上述工作。这为我工作:

tinyMCE.activeEditor.buttons.charmap.onclick(); 

因此,例如,我试图创建一个插件,其中包括一些内置的命令自定义菜单:

tinymce.PluginManager.add('myplugin', function(editor) { 

    editor.addButton('mymenu', { 
     type: 'menubutton', 
     text: 'Insert', 
     icon: false, 
     menu: [ 
      { 
       text: 'Special Character', 
       icon: 'charmap', 
       onclick: function() { editor.buttons.charmap.onclick(); } 
      } 
     ] 
    }); 

}); 
+0

你先生,是圣人。 – user382738 2018-01-03 18:32:33

相关问题