YUI recommends YUI3.
YUI 2 has been deprecated since 2011. This site acts as an archive for files and documentation.
This documentation is no longer maintained.
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 editable
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 editable_cont
.
Inside of this listener, we grab the target of the event and check to see if it has the editable
class.
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 YAHOO.widget.Toolbar
's prototype.
Now we listen for the toolbarLoaded
event so we can attach our handler to the toolbarCollapsed
event.
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.
Copyright © 2013 Yahoo! Inc. All rights reserved.