5
<title>Example: NodeChange Event</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>Example: NodeChange Event</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>Use the Editor's NodeChange Event</p>
33
border: 1px solid #999;
35
background-color: #f2f2f2;
42
background-color: #fff;
44
#example-canvas .yui3-console .yui3-console-title {
52
#example-canvas .yui3-console .yui3-console-entry-meta {
59
<div id="demo_holder" class="yui3-skin-sam">
60
<div id="editor_cont">
61
<p>Interact with the Editor instance below (click, type) and watch the console.</p>
62
<p>Use some special keys too. Enter, tab, arrows... Notice the event names.</p>
63
<div id="editor"></div>
65
<div id="console"></div>
71
YUI().use('editor', 'console', function(Y) {
73
(new Y.Console().render( "#console" ));
75
Y.log('Interact with the Editor.');
77
var logFn = function(e) {
78
var node = e.changedNode, tag;
81
tag = node.get('tagName').toLowerCase();
82
Y.log('nodeChange Event: ' + e.changedType + ' on (' + tag + ')');
86
//Create the Base Editor
87
var editor = new Y.EditorBase({
88
content: '<p><b>This is <i class="foo">a test</i></b></p><p><b style="color: red; font-family: Comic Sans MS">This is <span class="foo">a test</span></b></p>',
89
extracss: '.foo { font-weight: normal; color: black; background-color: yellow; }'
92
editor.on('nodeChange', logFn);
94
//Rendering the Editor.
95
editor.render('#editor');
104
<h3 id="working-with-editorbase">Working with EditorBase</h3>
105
<p><code>EditorBase</code> is not a fully functional Editor, it is simply the base utility that will be used under the hood to create an Editor.</p>
107
<h3 id="creating-the-editor">Creating the Editor</h3>
108
<p>In this step we are going to do the initial render of the Editor, set its content, and focus it when it's ready.</p>
110
<pre class="code prettyprint">YUI().use('editor', function(Y) {
112
//Create the Base Editor
113
var editor = new Y.EditorBase({
114
content: '<p><b>This is <i class="foo">a test</i></b></p><p><b style="color: red; font-family: Comic Sans MS">This is <span class="foo">a test</span></b></p>',
115
extracss: '.foo { font-weight: normal; color: black; background-color: yellow; }'
118
//Rendering the Editor.
119
editor.render('#editor');
124
<h3 id="the-node-change-event">The Node Change Event</h3>
126
<p>The <code>nodeChange</code> event is a special event that Editor emmits so that you can react to certain important moments that occured.</p>
127
<p>The most common use for the <code>nodeChange</code> event is to update the state of a Toolbar.</p>
129
<h4 id="nodechange-event-properties">nodeChange event properties</h4>
130
<p>This list contains the properties that are added to the Event object when the <code>nodeChange</code> event is fired.</p>
134
<th>Event Property</th>
140
<td nowrap="nowrap"><code>changedEvent</code></td>
141
<td>The event that caused the nodeChange</td>
144
<td nowrap="nowrap"><code>changedNode</code></td>
145
<td>The node that was interacted with</td>
148
<td nowrap="nowrap"><code>changedType</code></td>
149
<td>The type of change: mousedown, mouseup, right, left, backspace, tab, enter, etc.</td>
152
<td nowrap="nowrap"><code>commands</code></td>
153
<td>The list of execCommands that belongs to this change and the dompath that's associated with the changedNode</td>
156
<td nowrap="nowrap"><code>classNames</code></td>
157
<td>An array of classNames that is applied to the changedNode and all of its parents</td>
160
<td nowrap="nowrap"><code>dompath</code></td>
161
<td>A sorted array of node instances that make up the DOM path from the changedNode to body.</td>
164
<td nowrap="nowrap"><code>backgroundColor</code></td>
165
<td>The cascaded backgroundColor of the changedNode</td>
168
<td nowrap="nowrap"><code>fontColor</code></td>
169
<td>The cascaded fontColor of the changedNode</td>
172
<td nowrap="nowrap"><code>fontFamily</code></td>
173
<td>The cascaded fontFamily of the changedNode</td>
176
<td nowrap="nowrap"><code>fontSize</code></td>
177
<td>The cascaded fontSize of the changedNode</td>
182
<pre class="code prettyprint">//Attaching a nodeChange event
183
editor.on('nodeChange', function(e) {
184
//Here e contains the values above..
189
<h3 id="full-example-source">Full Example Source</h3>
191
<h4 id="html">HTML</h4>
192
<pre class="code prettyprint"><div id="demo_holder" class="yui3-skin-sam">
193
<div id="editor_cont">
194
<p>Interact with the Editor instance below (click, type) and watch the console.</p>
195
<p>Use some special keys too. Enter, tab, arrows... Notice the event names.</p>
196
<div id="editor"></div>
198
<div id="console"></div>
199
</div></pre>
202
<h4 id="css">CSS</h4>
203
<pre class="code prettyprint">#demo_holder {
208
border: 1px solid #999;
210
background-color: #f2f2f2;
217
background-color: #fff;
219
#example-canvas .yui3-console .yui3-console-title {
225
text-transform: none;
227
#example-canvas .yui3-console .yui3-console-entry-meta {
233
<h4 id="javascript">Javascript</h4>
234
<pre class="code prettyprint">YUI().use('editor', 'console', function(Y) {
236
(new Y.Console().render( "#console" ));
238
Y.log('Interact with the Editor.');
240
var logFn = function(e) {
241
var node = e.changedNode, tag;
244
tag = node.get('tagName').toLowerCase();
245
Y.log('nodeChange Event: ' + e.changedType + ' on (' + tag + ')');
249
//Create the Base Editor
250
var editor = new Y.EditorBase({
251
content: '<p><b>This is <i class="foo">a test</i></b></p><p><b style="color: red; font-family: Comic Sans MS">This is <span class="foo">a test</span></b></p>',
252
extracss: '.foo { font-weight: normal; color: black; background-color: yellow; }'
255
editor.on('nodeChange', logFn);
257
//Rendering the Editor.
258
editor.render('#editor');
264
<div id="sidebar" class="yui3-u">
266
<div id="toc" class="sidebox">
268
<h2 class="no-toc">Table of Contents</h2>
274
<a href="#working-with-editorbase">Working with EditorBase</a>
277
<a href="#creating-the-editor">Creating the Editor</a>
280
<a href="#the-node-change-event">The Node Change Event</a>
283
<a href="#nodechange-event-properties">nodeChange event properties</a>
288
<a href="#full-example-source">Full Example Source</a>
291
<a href="#html">HTML</a>
294
<a href="#css">CSS</a>
297
<a href="#javascript">Javascript</a>
307
<div class="sidebox">
309
<h2 class="no-toc">Examples</h2>
313
<ul class="examples">
316
<li data-description="Use the Editor's instance to query the iframe">
317
<a href="editor-instance.html">Using the Editor's instance</a>
322
<li data-description="Using the Editor's built in events.">
323
<a href="editor-events.html">Editor Events</a>
328
<li data-description="Using the Editor's nodeChange Event.">
329
<a href="editor-nodechange.html">NodeChange Event</a>
334
<li data-description="Creating and using your own ExecCommands">
335
<a href="editor-exec.html">ExecCommands</a>
349
<script src="../assets/vendor/prettify/prettify-min.js"></script>
350
<script>prettyPrint();</script>