TinyMCE:API/tinymce.Editor/addButton

From Moxiecode Documentation Wiki

Jump to: navigation, search

Contents

Method: addButton

Summary

Adds a button that later gets created by the ControlManager. This is a shorter and easier method of adding buttons without the need to deal with the ControlManager directly. But it's also less powerfull if you need more control use the ControlManagers factory methods instead. To see this function in action check the Setup editor events example out.

Syntax

<void> addButton(<String> n, <Object> s)

Parameters

n
Button name to add.
s
Settings object with title, cmd, onclick, class etc. A complete list can be found in the Button constructor.

Examples


// Adds a custom button to the editor and when a user clicks the button it will open
// an alert box with the selected contents as plain text.
tinyMCE.init({
   ...

   theme_advanced_buttons1 : 'example,..'

   setup : function(ed) {
      // Register example button
      ed.addButton('example', {
         title : 'example.desc',
         image : '../jscripts/tiny_mce/plugins/example/img/example.gif',
         onclick : function() {
            ed.windowManager.alert('Hello world!! Selection: ' + ed.selection.getContent({format : 'text'}));
         }
      });
   }
});
Personal tools