@@ -5,12 +5,10 @@ if(!javaxt.dhtml) javaxt.dhtml={};
55//** TabPanel
66//******************************************************************************
77/**
8- * Standard tab control used to show/hide individual panels, one panel at a
9- * time.
8+ * Standard tab control used to show/hide individual panels.
109 *
1110 ******************************************************************************/
1211
13-
1412javaxt . dhtml . TabPanel = function ( parent , config ) {
1513 this . className = "javaxt.dhtml.TabPanel" ;
1614
@@ -19,7 +17,15 @@ javaxt.dhtml.TabPanel = function(parent, config) {
1917 var tabContent ;
2018
2119 var defaultConfig = {
20+
21+ /** If true, will insert a "close" icon into the tab that will allow
22+ * users to close/remove the tab from the tab panel.
23+ */
2224 closable : false ,
25+
26+ /** Style for individual elements within the component. Note that you can
27+ * provide CSS class names instead of individual style definitions.
28+ */
2329 style : {
2430 tabBar : {
2531 border : "1px solid #ccc" ,
@@ -56,8 +62,6 @@ javaxt.dhtml.TabPanel = function(parent, config) {
5662 //**************************************************************************
5763 //** Constructor
5864 //**************************************************************************
59- /** Creates a new instance of this class. */
60-
6165 var init = function ( ) {
6266
6367 if ( typeof parent === "string" ) {
@@ -117,27 +121,41 @@ javaxt.dhtml.TabPanel = function(parent, config) {
117121 //** addTab
118122 //**************************************************************************
119123 /** Used to add a new tab to the panel.
120- * @param name Title or name associated with the tab.
121- * @param _el DOM element rendered when the tab is active.
124+ * @param label Tab title.
125+ * @param el Tab contents. Rendered when the tab is active. Accepts strings,
126+ * DOM elements, and nulls
122127 */
123- this . addTab = function ( name , _el ) {
128+ this . addTab = function ( label , el ) {
124129
125- var el = createElement ( "div" , tabContent , {
130+ var div = createElement ( "div" , tabContent , {
126131 width : "100%" ,
127132 height : "100%" ,
128133 position : "absolute"
129134 } ) ;
130- el . appendChild ( _el ) ;
131135
132136
137+ if ( el == null ) div . innerHTML = "" ;
138+ else {
139+ if ( isElement ( el ) ) {
140+ var p = el . parentNode ;
141+ if ( p ) p . removeChild ( el ) ;
142+ div . appendChild ( el ) ;
143+ }
144+ else {
145+ if ( typeof el === "string" ) {
146+ div . innerHTML = el ;
147+ }
148+ }
149+ }
150+
133151
134152 var tab = createElement ( "li" , tabList ) ;
135153 setStyle ( tab , "inactiveTab" ) ;
136154 tab . style . position = "relative" ;
137155 tab . style . float = "left" ;
138156 tab . style . height = "100%" ;
139- tab . innerHTML = name ;
140- tab . el = el ;
157+ tab . innerHTML = label ;
158+ tab . el = div ;
141159 tab . onclick = function ( ) {
142160 raiseTab ( this ) ;
143161 } ;
@@ -154,7 +172,7 @@ javaxt.dhtml.TabPanel = function(parent, config) {
154172 }
155173 }
156174
157- el . style . display = 'none' ; //<-- style used to test whether the tab is visible (see raiseTab)
175+ div . style . display = 'none' ; //<-- style used to test whether the tab is visible (see raiseTab)
158176
159177 raiseTab ( tab ) ;
160178 } ;
@@ -163,7 +181,15 @@ javaxt.dhtml.TabPanel = function(parent, config) {
163181 //**************************************************************************
164182 //** getTabs
165183 //**************************************************************************
166- /** Returns a list of tabs in the tab panel.
184+ /** Returns an of tabs in the tab panel. Each entry in the array will
185+ * include the following:
186+ * <ul>
187+ * <li>name: Name of the tab and tab label</li>
188+ * <li>header: DOM element for the tab header</li>
189+ * <li>body: DOM element for the tab content</li>
190+ * <li>hidden: Boolean</li>
191+ * <li>active: Boolean</li>
192+ * </ul>
167193 */
168194 this . getTabs = function ( ) {
169195 var tabs = [ ] ;
@@ -178,6 +204,9 @@ javaxt.dhtml.TabPanel = function(parent, config) {
178204 //**************************************************************************
179205 //** raiseTab
180206 //**************************************************************************
207+ /** Used to raise a tab
208+ * @param id Accepts a tab index (stating at 0) or a tab name
209+ */
181210 this . raiseTab = function ( id ) {
182211 var tab = findTab ( id ) ;
183212 if ( tab ) raiseTab ( tab ) ;
@@ -240,7 +269,9 @@ javaxt.dhtml.TabPanel = function(parent, config) {
240269 var active = ( tab . el . style . display !== 'none' ) ;
241270 return {
242271 name : tab . innerText ,
243- el : tab . el ,
272+ el : tab . el , //should be renamed to body or content
273+ header : tab ,
274+ body : tab . el ,
244275 hidden : hidden ,
245276 active : active
246277 } ;
@@ -250,18 +281,26 @@ javaxt.dhtml.TabPanel = function(parent, config) {
250281 //**************************************************************************
251282 //** setActiveTab
252283 //**************************************************************************
284+ /** Same as raiseTab()
285+ * @param id Accepts a tab index (stating at 0) or a tab name
286+ */
253287 this . setActiveTab = this . raiseTab ;
254288
255289
256290 //**************************************************************************
257291 //** onTabChange
258292 //**************************************************************************
293+ /** Called whenever a tab is raised.
294+ */
259295 this . onTabChange = function ( currTab , prevTab ) { } ;
260296
261297
262298 //**************************************************************************
263299 //** removeTab
264300 //**************************************************************************
301+ /** Used to remove a tab from the tab panel.
302+ * @param id Accepts a tab index (stating at 0) or a tab name
303+ */
265304 this . removeTab = function ( id ) {
266305 var tab = findTab ( id ) ;
267306 if ( tab ) {
@@ -279,6 +318,10 @@ javaxt.dhtml.TabPanel = function(parent, config) {
279318 //**************************************************************************
280319 //** hideTab
281320 //**************************************************************************
321+ /** Used to hide a tab in the tab panel. Unlike the removeTab() method, the
322+ * tab will remain in the tab panel, but in a hidden state.
323+ * @param id Accepts a tab index (stating at 0) or a tab name
324+ */
282325 this . hideTab = function ( id ) {
283326 var tab = findTab ( id ) ;
284327 if ( tab ) {
@@ -300,6 +343,9 @@ javaxt.dhtml.TabPanel = function(parent, config) {
300343 //**************************************************************************
301344 //** showTab
302345 //**************************************************************************
346+ /** Used to make a hidden tab visible. See hideTab()
347+ * @param id Accepts a tab index (stating at 0) or a tab name
348+ */
303349 this . showTab = function ( id ) {
304350 var tab = findTab ( id ) ;
305351 if ( tab ) tab . style . display = '' ;
@@ -351,6 +397,7 @@ javaxt.dhtml.TabPanel = function(parent, config) {
351397 var merge = javaxt . dhtml . utils . merge ;
352398 var createTable = javaxt . dhtml . utils . createTable ;
353399 var createElement = javaxt . dhtml . utils . createElement ;
400+ var isElement = javaxt . dhtml . utils . isElement ;
354401 var setStyle = function ( el , style ) {
355402 javaxt . dhtml . utils . setStyle ( el , config . style [ style ] ) ;
356403 } ;
0 commit comments