5
<title>Rich Text Editor</title>
6
<link rel="stylesheet" href="http://yui.yahooapis.com/3.4.0pr3/build/cssgrids/grids-min.css">
7
<link rel="stylesheet" href="../assets/css/main.css">
8
<link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
9
<script src="../../build/yui/yui-min.js"></script>
14
<h1>Rich Text Editor</h1>
17
<a href="#toc" class="jump">Jump to Table of Contents</a>
21
<div id="main" class="yui3-u">
22
<div class="content"><div class="intro">
23
<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>
24
<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>
27
<h2 id="getting-started">Getting Started</h2>
30
To include the source files for Rich Text Editor and its dependencies, first load
31
the YUI seed file if you haven't already loaded it.
34
<pre class="code prettyprint"><script src="http://yui.yahooapis.com/3.4.1/build/yui/yui-min.js"></script></pre>
38
Next, create a new YUI instance for your application and populate it with the
39
modules you need by specifying them as arguments to the <code>YUI().use()</code> method.
40
YUI will automatically load any dependencies required by the modules you
44
<pre class="code prettyprint">// Create a new YUI instance and populate it with the required modules.
45
YUI().use('editor', function (Y) {
46
// Rich Text Editor is available and ready for use. Add implementation
47
// code here.
52
For more information on creating YUI instances and on the
53
<a href="http://yuilibrary.com/yui/docs/api/classes/YUI.html#method_use"><code>use()</code> method</a>, see the
54
documentation for the <a href="../yui/index.html">YUI Global object</a>.
58
<h2 id="query">Creating an Editor</h2>
59
<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>
61
<pre class="code prettyprint">YUI().use('editor-base', function(Y) {
63
var editor = new Y.EditorBase({
64
content: '<strong>This is <em>a test</em></strong> <strong>This is <em>a test</em></strong> '
67
//Add the BiDi plugin
68
editor.plug(Y.Plugin.EditorBidi);
70
//Focusing the Editor when the frame is ready..
71
editor.on('frame:ready', function() {
75
//Rendering the Editor.
76
editor.render('#editor');
81
<h2 id="instance">Frame Instance</h2>
82
<p>When the Editor is created, it creates a YUI instance inside itself and attaches that instance to the editable iframe.
83
This means that you now have the full power of YUI 3 inside the Editor iframe. You can use Event, Stylesheet, Node and even DD
84
inside the iframe, without having to load all the JavaScript inside the document.</p>
86
<p>Getting access to this instance is simple. Just use the <code>getInstance</code> method on the Editor instance, like this:</p>
88
<pre class="code prettyprint">YUI().use('editor-base', function(Y) {
90
var editor = new Y.EditorBase({
91
content: '<strong>This is <em>a test</em></strong> <strong>This is <em>a test</em></strong> '
94
//Add the BiDi plugin
95
editor.plug(Y.Plugin.EditorBidi);
97
//Focusing the Editor when the frame is ready..
98
editor.on('frame:ready', function() {
101
var inst = this.getInstance();
102
//inst is now an instance of YUI that is bound to the iframe.
104
var body = inst.one('body');
105
//body is a Node instance of the BODY element "inside" the iframe.
108
var strongs = inst.all('strong');
109
//strongs is a NodeList instance of all the STRONG elements "inside" the iframe.
112
//Rendering the Editor.
113
editor.render('#editor');
118
<h2 id="events">Events</h2>
120
<p>By default, the frame instance under the hood of Editor attaches a listener for all known DOM events. The example
121
below shows how you can listen and interact with them.</p>
123
<pre class="code prettyprint">YUI().use('editor-base', function(Y) {
125
var editor = new Y.EditorBase({
126
content: '<strong>This is <em>a test</em></strong> <strong>This is <em>a test</em></strong> '
129
//Add the BiDi plugin
130
editor.plug(Y.Plugin.EditorBidi);
132
editor.on('frame:keydown', function(e) {
133
//Listen for the keydown event inside the Editor.
135
This event object contains 3 new properties:
140
These properties are the original properties before
141
the Event was fired, so you can use them like:
147
editor.on('frame:mouseup', function(e) {
148
//Listen for the mouseup event inside the Editor.
151
//Rendering the Editor.
152
editor.render('#editor');
157
<h2 id="nodechange">Node Change Event</h2>
159
<p>The <code>nodeChange</code> event is a special event that Editor emits so that you can react to certain important moments that occured.</p>
160
<p>The most common use for the <code>nodeChange</code> event is to update the state of a Toolbar.</p>
162
<h3 id="nodechange-event-properties">nodeChange event properties</h3>
163
<p>This list contains the properties that are added to the Event object when the <code>nodeChange</code> event is fired.</p>
167
<th>Event Property</th>
173
<td nowrap="nowrap"><code>changedEvent</code></td>
174
<td>The event that caused the nodeChange</td>
177
<td nowrap="nowrap"><code>changedNode</code></td>
178
<td>The node that was interacted with</td>
181
<td nowrap="nowrap"><code>changedType</code></td>
182
<td>The type of change: mousedown, mouseup, right, left, backspace, tab, enter, etc..</td>
185
<td nowrap="nowrap"><code>commands</code></td>
186
<td>The list of execCommands that belong to this change and the dompath that's associated with the changedNode</td>
189
<td nowrap="nowrap"><code>classNames</code></td>
190
<td>An array of classNames that are applied to the changedNode and all of its parents</td>
193
<td nowrap="nowrap"><code>dompath</code></td>
194
<td>A sorted array of node instances that make up the DOM path from the changedNode to body.</td>
197
<td nowrap="nowrap"><code>backgroundColor</code></td>
198
<td>The cascaded backgroundColor of the changedNode</td>
201
<td nowrap="nowrap"><code>fontColor</code></td>
202
<td>The cascaded fontColor of the changedNode</td>
205
<td nowrap="nowrap"><code>fontFamily</code></td>
206
<td>The cascaded fontFamily of the changedNode</td>
209
<td nowrap="nowrap"><code>fontSize</code></td>
210
<td>The cascaded fontSize of the changedNode</td>
216
<h2 id="modules">Module Descriptions</h2>
218
<p>Using YUI 3's plugin architecture, this version of the Rich Text Editor is even more modular and extensible than the previous version.
219
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>
229
<td nowrap="nowrap"><code>frame</code></td>
230
<td>Controls the creation and set up of the editable area</td>
233
<td nowrap="nowrap"><code>selection</code></td>
234
<td>Cross-browser selection normalization</td>
237
<td nowrap="nowrap"><code>exec-command</code></td>
238
<td>Plugs into frame to extend <code>document.execCommand</code> support.</td>
241
<td nowrap="nowrap"><code>editor-tab</code></td>
242
<td>Overrides the default tab key handler and indents/outdents the current block level element.</td>
245
<td nowrap="nowrap"><code>editor-para</code></td>
246
<td>Paragraph support (opposite of <code>editor-br</code>)</td>
249
<td nowrap="nowrap"><code>editor-br</code></td>
250
<td>Line break support (opposite of <code>editor-para</code>) </td>
253
<td nowrap="nowrap"><code>editor-bidi</code></td>
254
<td>Paragraph/Bi-Directional support</td>
257
<td nowrap="nowrap"><code>createlink-base</code></td>
258
<td>Simple <code>prompt</code> based link creation.</td>
261
<td nowrap="nowrap"><code>editor-base</code></td>
262
<td>Rollup of the above modules</td>
265
<td nowrap="nowrap"><code>editor</code></td>
266
<td>Rollup of the above modules</td>
271
<p><strong>Note:</strong> Either <code>editor-br</code> or <code>editor-para</code> should be plugged. One, but not both, is required for proper functionality.</p>
275
<div id="sidebar" class="yui3-u">
277
<div id="toc" class="sidebox">
279
<h2 class="no-toc">Table of Contents</h2>
285
<a href="#getting-started">Getting Started</a>
288
<a href="#query">Creating an Editor</a>
291
<a href="#instance">Frame Instance</a>
294
<a href="#events">Events</a>
297
<a href="#nodechange">Node Change Event</a>
300
<a href="#nodechange-event-properties">nodeChange event properties</a>
305
<a href="#modules">Module Descriptions</a>
313
<div class="sidebox">
315
<h2 class="no-toc">Examples</h2>
319
<ul class="examples">
322
<li data-description="Use the Editor's instance to query the iframe">
323
<a href="editor-instance.html">Using the Editor's instance</a>
328
<li data-description="Using the Editor's built in events.">
329
<a href="editor-events.html">Editor Events</a>
334
<li data-description="Using the Editor's nodeChange Event.">
335
<a href="editor-nodechange.html">NodeChange Event</a>
340
<li data-description="Creating and using your own ExecCommands">
341
<a href="editor-exec.html">ExecCommands</a>
355
<script src="../assets/vendor/prettify/prettify-min.js"></script>
356
<script>prettyPrint();</script>