index.mustache revision 22f87c5d1e49ed41349a3cb61608c3ce66287eba
d6fa26d0adaec6c910115be34fe7a5a5f402c14fMark Andrews<div class="intro">
1e9517ea2156b990be21f44676d3370318eacf17Tinderbox User <p>The Rich Text Editor is a UI control that allows for the rich formatting of text content, including common structural treatments like lists, formatting treatments like bold and italic text.</p>
71cef386fae61275b03e203825680b39fedaa8c6Tinderbox User <p>The current release of the Rich Text Editor for YUI 3 is the base utility layers that provide a foundation on which you can create an Editor. <strong>This version of Editor does not contain a GUI of any kind.</strong></p>
1e9517ea2156b990be21f44676d3370318eacf17Tinderbox User{{>getting-started}}
1e9517ea2156b990be21f44676d3370318eacf17Tinderbox User<h4 id="query">Creating an Editor</h4>
d6fa26d0adaec6c910115be34fe7a5a5f402c14fMark Andrews<p>This simple example will create an Editable area inside of another Node. It will not contain a GUI, only the iframe. You can use various Editor events to wire up your own toolbar.</p>
1e9517ea2156b990be21f44676d3370318eacf17Tinderbox UserYUI().use('editor-base', function(Y) {
1e9517ea2156b990be21f44676d3370318eacf17Tinderbox User var editor = new Y.EditorBase({
1e9517ea2156b990be21f44676d3370318eacf17Tinderbox User content: '<strong>This is <em>a test</em></strong> <strong>This is <em>a test</em></strong> '
1e9517ea2156b990be21f44676d3370318eacf17Tinderbox User //Add the BiDi plugin
1e9517ea2156b990be21f44676d3370318eacf17Tinderbox User //Focusing the Editor when the frame is ready..
1e9517ea2156b990be21f44676d3370318eacf17Tinderbox User editor.on('frame:ready', function() {
1e9517ea2156b990be21f44676d3370318eacf17Tinderbox User //Rendering the Editor.
1e9517ea2156b990be21f44676d3370318eacf17Tinderbox User<h4 id="instance">Frame Instance</h4>
1e9517ea2156b990be21f44676d3370318eacf17Tinderbox User<p>When the Editor is created, it creates a YUI instance inside itself and attaches that instance to the editable iframe.
1e9517ea2156b990be21f44676d3370318eacf17Tinderbox UserThis means that you now have the full power of YUI 3 inside the Editor iframe. You can use Event, Stylesheet, Node and even DD
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox Userinside the iframe, without having to load all the JavaScript inside the document.</p>
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox User<p>Getting access to this instance is simple. Just use the `getInstance` method on the Editor instance, like this:</p>
1e9517ea2156b990be21f44676d3370318eacf17Tinderbox UserYUI().use('editor-base', function(Y) {
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox User var editor = new Y.EditorBase({
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox User content: '<strong>This is <em>a test</em></strong> <strong>This is <em>a test</em></strong> '
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox User //Add the BiDi plugin
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox User //Focusing the Editor when the frame is ready..
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox User editor.on('frame:ready', function() {
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox User //inst is now an instance of YUI that is bound to the iframe.
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox User var body = inst.one('body');
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox User //body is a Node instance of the BODY element "inside" the iframe.
7e71f05d8643aca84914437c900cb716444507e4Tinderbox User var strongs = inst.all('strong');
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox User //strongs is a NodeList instance of all the STRONG elements "inside" the iframe.
1e9517ea2156b990be21f44676d3370318eacf17Tinderbox User //Rendering the Editor.
1e9517ea2156b990be21f44676d3370318eacf17Tinderbox User<h4 id="events">Events</h4>
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox User<p>By default, the frame instance under the hood of Editor attaches a listener for all known DOM events. The example
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox Userbelow shows how you can listen and interact with them.</p>
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox UserYUI().use('editor-base', function(Y) {
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox User var editor = new Y.EditorBase({
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox User content: '<strong>This is <em>a test</em></strong> <strong>This is <em>a test</em></strong> '
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox User //Add the BiDi plugin
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox User editor.on('frame:keydown', function(e) {
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox User //Listen for the keydown event inside the Editor.
7e71f05d8643aca84914437c900cb716444507e4Tinderbox User This event object contains 3 new properties:
1e9517ea2156b990be21f44676d3370318eacf17Tinderbox User frameCurrentTarget
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox User These properties are the original properties before
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox User the Event was fired, so you can use them like:
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox User editor.on('frame:mouseup', function(e) {
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox User //Listen for the mouseup event inside the Editor.
1e9517ea2156b990be21f44676d3370318eacf17Tinderbox User //Rendering the Editor.
1e9517ea2156b990be21f44676d3370318eacf17Tinderbox User<h4 id="nodechange">Node Change Event</h4>
1e9517ea2156b990be21f44676d3370318eacf17Tinderbox User<p>The `nodeChange` event is a special event that Editor emits so that you can react to certain important moments that occured.</p>
1e9517ea2156b990be21f44676d3370318eacf17Tinderbox User<p>The most common use for the `nodeChange` event is to update the state of a Toolbar.</p>
1e9517ea2156b990be21f44676d3370318eacf17Tinderbox User<h5>nodeChange event properties</h5>
1e9517ea2156b990be21f44676d3370318eacf17Tinderbox User<p>This list contains the properties that are added to the Event object when the `nodeChange` event is fired.</p>
1e9517ea2156b990be21f44676d3370318eacf17Tinderbox User <th>Event Property</th>
1e9517ea2156b990be21f44676d3370318eacf17Tinderbox User <th>Description</th>
<td>The list of execCommands that belong to this change and the dompath that's associated with the changedNode</td>
<p>Using YUI 3's plugin architecture, this version of the Rich Text Editor is even more modular and extensible than the previous version.
Almost every part of the Editor infrastructure is a plugin or extension. Below you will find the current list of plugins shipped with Editor.</p>
<td>Plugs into frame to extend `document.execCommand` support.</td>
<td>Overrides the default tab key handler and indents/outdents the current block level element.</td>
<td>Paragraph/Bi-Directional support</td>