Yahoo! Developer Network Home - Help

YUI Library Examples: Rich Text Editor (beta): Editor inside a Tabview Control

Rich Text Editor (beta): Editor inside a Tabview Control

This example demonstrates how to render an Editor inside of a TabView Control.

Tab One Content

This text field can contain stylized text and graphics. To cycle through all formatting options, use the keyboard shortcut Control + Shift + T to place focus on the toolbar and navigate between option heading names.

Common formatting keyboard shortcuts:

  • Control Shift B sets text to bold
  • Control Shift I sets text to italic
  • Control Shift U underlines text
  • Control Shift [ aligns text left
  • Control Shift | centers text
  • Control Shift ] aligns text right
  • Control Shift L adds an HTML link
  • To exit this text editor use the keyboard shortcut Control + Shift + ESC.
body

You have left the Rich Text Editor.

Tab Three Content

Setting up the HTML

First we will begin by adding a simple div to the page with the id of e_tabs.

1<style> 
2.yui-content { 
3    height: 250px; 
4
5.yui-content textarea { 
6    visibility: hidden; 
7
8</style> 
9<div id="e_tabs"></div> 
view plain | print | ?

Setting up the TabView Javascript

Next we need to create the TabView control.

1(function() { 
2    //Setup some private variables 
3    var Dom = YAHOO.util.Dom, 
4        Event = YAHOO.util.Event; 
5 
6    var myTabs = new YAHOO.widget.TabView('e_tabs'); 
7})(); 
view plain | print | ?

Now let's add some tabs

Now that we have created the Tabview control, we can add some tabs.

Note that we are saving a reference to the tab containing the Editor's textarea in the variable called editorTab

1YAHOO.log('Add the first tab..''info''example'); 
2myTabs.addTab( new YAHOO.widget.Tab({ 
3    label: 'Tab One Label'
4    content: '<p>Tab One Content</p>'
5    active: true 
6})); 
7 
8YAHOO.log('Add the editor tab..''info''example'); 
9editorTab = new YAHOO.widget.Tab({ 
10    label: 'Editor Tab'
11    content: '<textarea id="editor">This is the editor content.. You can edit me!</textarea>' 
12}); 
13 
14myTabs.addTab(editorTab); 
15 
16YAHOO.log('Add the third tab..''info''example'); 
17myTabs.addTab( new YAHOO.widget.Tab({ 
18    label: 'Tab Three Label'
19    content: '<p>Tab Three Content</p>' 
20})); 
view plain | print | ?

Rendering the Editor

Now that we have a place for the Editor to live, we can now render it.

1var myConfig = { 
2    height: '100px'
3    width: '530px'
4    animate: true
5    dompath: true 
6}; 
7 
8YAHOO.log('Create the Editor..''info''example'); 
9var myEditor = new YAHOO.widget.Editor('editor', myConfig); 
10myEditor.render(); 
view plain | print | ?

Handling the switching of tabs

This is the important part of this example. The Rich Text Editor will not behave properly if it is rendered or toggled in a container that has been set to display none.

This behaviour can be fixed by calling the Editor method show. The show method will attempt to fix the Editor when it is in this state.

So, we will add an Event listener to the Tabview's activeTabChange event and call the Editor's show method when we change to the Editor's tab.

1myTabs.on('activeTabChange'function(ev) { 
2    YAHOO.log('Active tab Change, check to see if we are showing the editor..''info''example'); 
3     if (ev.newValue == editorTab) { 
4        YAHOO.log('Editor showing, calling myEditor.show()..''info''example'); 
5        myEditor.show(); 
6     } 
7}); 
view plain | print | ?

Full Example Javascript Source

1(function() { 
2    var Dom = YAHOO.util.Dom, 
3        Event = YAHOO.util.Event, 
4        editorTab = null
5 
6 
7    YAHOO.log('Create the Tabview..''info''example'); 
8    var myTabs = new YAHOO.widget.TabView('e_tabs'); 
9     
10    YAHOO.log('Add the first tab..''info''example'); 
11    myTabs.addTab( new YAHOO.widget.Tab({ 
12        label: 'Tab One Label'
13        content: '<p>Tab One Content</p>'
14        active: true 
15    })); 
16     
17    YAHOO.log('Add the editor tab..''info''example'); 
18    editorTab = new YAHOO.widget.Tab({ 
19        label: 'Editor Tab'
20        content: '<textarea id="editor">This is the editor content.. You can edit me!</textarea>' 
21    }); 
22 
23    myTabs.addTab(editorTab); 
24     
25    YAHOO.log('Add the third tab..''info''example'); 
26    myTabs.addTab( new YAHOO.widget.Tab({ 
27        label: 'Tab Three Label'
28        content: '<p>Tab Three Content</p>' 
29    })); 
30     
31    myTabs.on('activeTabChange'function(ev) { 
32        YAHOO.log('Active tab Change, check to see if we are showing the editor..''info''example'); 
33         if (ev.newValue == editorTab) { 
34            YAHOO.log('Editor showing, calling myEditor.show()..''info''example'); 
35            myEditor.show(); 
36         } 
37    }); 
38 
39 
40    var myConfig = { 
41        height: '100px'
42        width: '530px'
43        animate: true
44        dompath: true 
45    }; 
46 
47    YAHOO.log('Create the Editor..''info''example'); 
48    var myEditor = new YAHOO.widget.Editor('editor', myConfig); 
49    myEditor.render(); 
50 
51})(); 
view plain | print | ?

Copyright © 2008 Yahoo! Inc. All rights reserved.

Privacy Policy - Terms of Service - Copyright Policy - Job Openings