This example demonstrates how to render an Editor inside of a TabView Control.
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 | ? |
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 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
1 | YAHOO.log('Add the first tab..', 'info', 'example'); |
2 | myTabs.addTab( new YAHOO.widget.Tab({ |
3 | label: 'Tab One Label', |
4 | content: '<p>Tab One Content</p>', |
5 | active: true |
6 | })); |
7 | |
8 | YAHOO.log('Add the editor tab..', 'info', 'example'); |
9 | editorTab = 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 | |
14 | myTabs.addTab(editorTab); |
15 | |
16 | YAHOO.log('Add the third tab..', 'info', 'example'); |
17 | myTabs.addTab( new YAHOO.widget.Tab({ |
18 | label: 'Tab Three Label', |
19 | content: '<p>Tab Three Content</p>' |
20 | })); |
view plain | print | ? |
Now that we have a place for the Editor to live, we can now render it.
1 | var myConfig = { |
2 | height: '100px', |
3 | width: '530px', |
4 | animate: true, |
5 | dompath: true |
6 | }; |
7 | |
8 | YAHOO.log('Create the Editor..', 'info', 'example'); |
9 | var myEditor = new YAHOO.widget.Editor('editor', myConfig); |
10 | myEditor.render(); |
view plain | print | ? |
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.
1 | myTabs.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 | ? |
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 | ? |
Note: Logging and debugging is currently turned off for this example.
Copyright © 2008 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Copyright Policy - Job Openings