views:

415

answers:

1

I am in a situation where I do not control the creation of one or many YUI Rich Text Editors; it is done in someone else's library.

For the purposes of this discussion:

  • patching code-- monkey or otherwise-- is not an option.
  • removing (editor.destroy()) the editor that's already there and adding my own is also not an option. The code that creates the editor does Other Things to it and refers to the reference etc-- I need to modify the current editor.

By creation I mean:

var myEditor = new YAHOO.widget.Editor(control, {
  // toolbar config would go here if I controled this code
});

myEditor.render();

The problem is that I would like these editors to have a different toolbar configuration to what they have. To be precise, I would like to remove a bunch of buttons (The default is a bit bloated).

I managed to get the editor with the EditorInfo tool, but I couldn't really do anything with it. There is apparently a variable on the Editor that allows you to get the Toolbar instance but when I tried it all I got was null.

So, is there a way to modify a YUI Rich Text Editor after render() has been called to remove toolbar buttons?

+1  A: 

Since I can't see the code, it's a little hard to give an answer. But once you have access to the Editor instance, the toolbar property should give you full access to the addButton/detroyButton methods.

var editor = YAHOO.widget.EditorInfo._instances['editor_id'];
editor.toolbar.destroyButton('bold'); //This should destroy the bold button

That code should work. If editor.toolbar is null, then you may be accessing it before the toolbar is created. You can try this:

editor.on('toolbarLoaded', function() {
  this.toolbar.destroyButton('bold');
});

Again, it's a little tough to debug without seeing the code or having access (Firebug) to the page.

I don't use this site, so you may want to ask the question on the official YUI mailing list so others can learn too ;)

davglass