//Start with the constructor for our RTE:
var myEditor = new YAHOO.widget.Editor('msgpost', {
    height: '300px',
    width: '522px'
});

//Use the toolbarLoaded Custom Event; when that event fires,
//we will execute a function that adds or custom button:
myEditor.on('toolbarLoaded', function() {
    //Simple button config
    var button = {
        type: 'push',
        label: 'My Button 3',
        value: 'mybutton3',
        disabled: false
    };
    
    //Add the button to the toolbar; "this"
    //refers to myEditor, our RTE instance:
    this.toolbar.addButton(button);

    //Now listen for the new buttons click and do something with it.
    //Note that "mybutton3Click" is an event synthesized for us
    //automatically because that's the value we gave our button
    //above:
    this.toolbar.on('mybutton3Click', function(o) {
        this.execCommand('inserthtml', '<b>This is the text to insert.</b>');
    }, myEditor, true);

    //Setup the button to be enabled, disabled or selected
    this.on('afterNodeChange', function(o) {
        //Get the selected element
        var el = this._getSelectedElement();

        //Get the button we want to manipulate
        var button = this.toolbar.getButtonByValue('mybutton3');

        if (el && el.tagName == 'div') {
            this.toolbar.enableButton(button);
        }
    }, this, true);
}, myEditor, true);

myEditor.render();
