3

I'm following the tutorial on http://tinymce.moxiecode.com/tryit/custom_toolbar_button.php but need to add multiple custom buttons.

Here is my block for adding one button, but I need to add more than one button and don't know how

setup : function(fn) {
    // Add a custom button
    fn.addButton('firstname', {
        title : 'Member First Name',
        image : 'resources/scripts/tiny_mce/themes/advanced/img/firstname.gif',
        onclick : function() {
            // Add you own code to execute something on click
            fn.focus();
            fn.selection.setContent('{firstname}');
        }
    });
}

Thanks for your help

drhoo
  • 43
  • 1
  • 4

1 Answers1

8

Just call fn.addButton multiple times:

setup : function(fn) {
    // Add a custom button
    fn.addButton('firstname', {
        title : 'Member First Name',
        image : 'resources/scripts/tiny_mce/themes/advanced/img/firstname.gif',
        onclick : function() {
            // Add you own code to execute something on click
            fn.focus();
            fn.selection.setContent('{firstname}');
        }
    });
    fn.addButton('lastname', {
        title : 'Member Last Name',
        image : 'resources/scripts/tiny_mce/themes/advanced/img/lastname.gif',
        onclick : function() {
            // Add you own code to execute something on click
            fn.focus();
            fn.selection.setContent('{lastname}');
        }
    });
}

If you are defining the toolbar layout, eg

toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | firstname",

remember to add the new id (eg. lastname)

Jim W
  • 4,866
  • 1
  • 27
  • 43
Dr.Molle
  • 116,463
  • 16
  • 195
  • 201
  • Thanks a lot Dr. Molle, I was thinking something more difficult. Your answer helped me a lot! – drhoo May 13 '11 at 11:04