This example demonstrates how to have one Editor instance control different editable areas on a page.
First we place a textarea on the page and set it to visibility hidden, then create the editable areas and assign them a class of
By using the
.yui-editor-container class, we are setting the Editor to an absolute position of -9999px top and -9999px left to render it off of the screen.
First we are going to setup the editor with a smaller toolbar.
Now that we have the Editor rendered and positioned off of the screen, we need to be able to show it when you double click on an editable area.
We add a
dblclick listener to the container
Inside of this listener, we grab the target of the event and check to see if it has the
Note: This logic may need to be refined for your use case as it relies on the user clicking the DIV with the editable class, so clicking on an element inside the div will fail. Most of the time, you would probably want the user to click on some sort of Edit button to exec this action.
Once we have the DIV, we set the Editor's HTML with the innerHTML of the DIV.
Next we position the Editor with the XY coordinates of the DIV.
Now we need to setup a way to save the Editor's data, we are going to override the toolbar's collapse button and use it as a save button.
First we need to override the text on the collapse button, we do that by overriding the var
STR_COLLAPSE on the
Now we listen for the
toolbarLoaded event so we can attach our handler to the
Inside of the
toolbarCollapsed event, we will save the Editor's data back to the editable area. Then we will set the position of the editor back to -9999px left and -9999px top.
Note: You could also do this using a Save button in the toolbar.
All YUI 2.x users should review the YUI 2.8.2 security bulletin, which discusses a vulnerability present in YUI 2.4.0-2.8.1.