如何在tinymce中添加一个新按钮

时间:2013-07-11 20:39:47

标签: jquery content-management-system tinymce

我已经解决了我几乎要添加按钮的问题。

    setup : function(ed) {
    // Add a custom button
    ed.addButton('Information', {
        title : 'Viktig Information',
        image : '../img/page_white_text.png',
        onclick : function() {
            // Add you own code to execute something on click
            ed.focus();
            ed.selection.setContent('Text here');
    }
    });
}

但现在我想知道我怎么能让它像大胆的按钮和东西一样工作?因此,当我按下粗体时,文字变为粗体..

我希望我的按钮一样,当我按下我的按钮时我想要一个div出现。谁知道我怎么做到这一点?!

2 个答案:

答案 0 :(得分:0)

初始化TinyMCE时,您可以指定哪一个按钮位于哪一行。

以下是一些文档

http://www.tinymce.com/wiki.php/Configuration3x:theme_advanced_buttons_1_n

答案 1 :(得分:0)

这是一项很容易执行的任务。 只需在编辑器初始化函数中添加这样的内容即可。 请参阅此page of moxycode

tinyMCE.init({
  ...
  theme_advanced_buttons1: 'bold,italic,..'

  setup: function(ed) {

      ed.onInit.add(function(ed) {
        // Scroll runter
        ed.addCommand('my_own_command', function() {
          alert('my_own_command called!');
        });
      });

      // Register example button
      ed.addButton('example', {
        title: 'example.desc',
        // make sure the image exists
        image: '../jscripts/tiny_mce/plugins/example/img/example.gif',
        onclick: function() {
          ed.windowManager.alert('Hello world!!');
          // execute my_own_command
          ed.execCommand('my_own_command');
        }
      });
    }, // end setup
    ...
});