<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Tab Pane (WebFX)</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- webfxlayout.js -->
<script type="text/javascript">
/* this is a dummy webfxlayout file to be used in download zip files */
/* set up browser checks and add a simple emulation for IE4 */
// check browsers
var op = /opera 5|opera\/5/i.test(navigator.userAgent);
var ie = !op && /msie/i.test(navigator.userAgent); // preventing opera to be identified as ie
var mz = !op && /mozilla\/5/i.test(navigator.userAgent); // preventing opera to be identified as mz
webfxLayout = {
writeTitle : function (s, s2) {
document.write("<div id='webfx-title-background'></div>"); if (op) {
document.write("<h1 id='webfx-title' style='top:9px;'>" + s + "</h1>");
} else {
document.write("<h1 id='webfx-title'>" + s + "</h1>");
}
if (s2 == null)
s2 = "WebFX - What you never thought possible!";
if (op) {
document.write("<span id='webfx-sub-title' style='top:46px;'>" + s2 + "</span>");
} else {
document.write("<span id='webfx-sub-title'>" + s2 + "</span>");
}
},
writeMainTitle : function () { this.writeTitle("WebFX", "What you never thought possible!");
},
writeTopMenuBar : function () {
document.write("<div id='webfx-menu-bar-1'></div>"); if (op) {
document.write("<style>.webfx-menu-bar a {padding-top:3px;}</style>");
document.write("<div id='webfx-menu-bar-2' style='height:2px;'></div>");
} else
document.write("<div id='webfx-menu-bar-2'></div>");
document.write("<div id='webfx-menu-bar'>");// div is closed in writeBottomMenuBar
},
writeBottomMenuBar : function () {
document.write("</div>"); if (op)
document.write("<div id='webfx-menu-bar-3' style='height:0px;'></div>"); else
document.write("<div id='webfx-menu-bar-3'></div>");
document.write("<div id='webfx-menu-bar-4'></div>");
document.write("<div id='webfx-menu-bar-5'></div>");
},
writeMenu : function () { this.writeTopMenuBar();
//document.write(webfxMenuBar);
this.writeBottomMenuBar();
},
writeDesignedByEdger : function () { if (ie && document.body.currentStyle.writingMode != null)
document.write("<div id='webfx-about'>Page designed and maintained by " +
"<a href='mailto:[email protected]'>Erik Arvidsson</a> & " +
"<a href='mailto:[email protected]'>Emil A Eklund</a>.</div>");
}
};
if (ie && window.attachEvent) {
window.attachEvent("onload", function () {
var scrollBorderColor = "rgb(120,172,255)";
var scrollFaceColor = "rgb(234,242,255)";
with (document.body.style) {
scrollbarDarkShadowColor = scrollBorderColor;
scrollbar3dLightColor = scrollBorderColor;
scrollbarArrowColor = "black";
scrollbarBaseColor = scrollFaceColor;
scrollbarFaceColor = scrollFaceColor;
scrollbarHighlightColor = scrollFaceColor;
scrollbarShadowColor = scrollFaceColor;
scrollbarTrackColor = "white";
}
});
}
/* we also need some dummy constructors */
webfxMenuBar = {
add : function () {}
}; function WebFXMenu() { this.add = function () {};
} function WebFXMenuItem() {} function WebFXMenuSeparator() {} function WebFXMenuButton() {}
</script>
<!-- webfxapi.js -->
<script type="text/javascript">
/*
* This script is used for WebFX Api pages
*
* It defines one funtion and includes helptip.js, helptip.css and webfxapi.css
*/
function toggleMethodArguments( e, a ) { if ( a && a.nextSibling &&
typeof a.nextSibling.innerHTML != "undefined" &&
typeof showHelpTip != "undefined" ) {
showHelpTip( e, a.nextSibling.innerHTML );
}
}
</script>
<!-- tabpane.js -->
<script type="text/javascript">
/*----------------------------------------------------------------------------\
| Tab Pane 1.02 |
|-----------------------------------------------------------------------------|
| Created by Erik Arvidsson |
| (http://webfx.eae.net/contact.html#erik) |
| For WebFX (http://webfx.eae.net/) |
|-----------------------------------------------------------------------------|
| Copyright (c) 1998 - 2003 Erik Arvidsson |
|-----------------------------------------------------------------------------|
| This software is provided "as is", without warranty of any kind, express or |
| implied, including but not limited to the warranties of merchantability, |
| fitness for a particular purpose and noninfringement. In no event shall the |
| authors or copyright holders be liable for any claim, damages or other |
| liability, whether in an action of contract, tort or otherwise, arising |
| from, out of or in connection with the software or the use or other |
| dealings in the software. |
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| This software is available under the three different licenses mentioned |
| below. To use this software you must chose, and qualify, for one of those. |
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| The WebFX Non-Commercial License http://webfx.eae.net/license.html |
| Permits anyone the right to use the software in a non-commercial context |
| free of charge. |
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| The WebFX Commercial license http://webfx.eae.net/commercial.html |
| Permits the license holder the right to use the software in a commercial |
| context. Such license must be specifically obtained, however it's valid for |
| any number of implementations of the licensed software. |
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| GPL - The GNU General Public License http://www.gnu.org/licenses/gpl.txt |
| Permits anyone the right to use and modify the software without limitations |
| as long as proper credits are given and the original and modified source |
| code are included. Requires that the final product, software derivate from |
| the original source or any software utilizing a GPL component, such as |
| this, is also licensed under the GPL license. |
|-----------------------------------------------------------------------------|
| 2002-01-?? | First working version |
| 2002-02-17 | Cleaned up for 1.0 public version |
| 2003-02-18 | Changed from javascript uri for anchors to return false |
| 2003-03-03 | Added dispose methods to release IE memory |
|-----------------------------------------------------------------------------|
| Dependencies: *.css a css file to define the layout |
|-----------------------------------------------------------------------------|
| Created 2002-01-?? | All changes are in the log above. | Updated 2003-03-03 |
\----------------------------------------------------------------------------*/
// This function is used to define if the browser supports the needed
// features function hasSupport() {
if (typeof hasSupport.support != "undefined") return hasSupport.support;
var ie55 = /msie 5\.[56789]/i.test( navigator.userAgent );
// IE55 has a serious DOM1 bug... Patch it! if ( ie55 ) {
document._getElementsByTagName = document.getElementsByTagName;
document.getElementsByTagName = function ( sTagName ) { if ( sTagName == "*" ) return document.all; else return document._getElementsByTagName( sTagName );
};
}
return hasSupport.support;
}
///////////////////////////////////////////////////////////////////////////////////
// The constructor for tab panes
//
// el : HTMLElement The html element used to represent the tab pane
// bUseCookie : Boolean Optional. Default is true. Used to determine whether to us
// persistance using cookies or not
// function WebFXTabPane( el, bUseCookie ) { if ( !hasSupport() || el == null ) return;
// loop through child nodes and add them
var cs = el.childNodes;
var n; for (var i = 0; i < cs.length; i++) { if (cs[i].nodeType == 1 && cs[i].className == "tab-page") { this.addTabPage( cs[i] );
}
}
}
WebFXTabPane.getCookie = function (sName) {
var re = new RegExp( "(\;|^)[^;]*(" + sName + ")\=([^;]*)(;|$)" );
var res = re.exec( document.cookie ); return res != null ? res[3] : null;
};
WebFXTabPane.removeCookie = function ( name ) {
setCookie( name, "", -1 );
};
///////////////////////////////////////////////////////////////////////////////////
// The constructor for tab pages. This one should not be used.
// Use WebFXTabPage.addTabPage instead
//
// el : HTMLElement The html element used to represent the tab pane
// tabPane : WebFXTabPane The parent tab pane
// nindex : Number The index of the page in the parent pane page array
// function WebFXTabPage( el, tabPane, nIndex ) { if ( !hasSupport() || el == null ) return;
var cs = el.childNodes; for (var i = 0; i < cs.length; i++) { if (cs[i].nodeType == 1 && cs[i].className == "tab") { this.tab = cs[i]; break;
}
}
// insert a tag around content to support keyboard navigation
var a = document.createElement( "A" ); this.aElement = a;
a.href = "#";
a.onclick = function () { return false; }; while ( this.tab.hasChildNodes() )
a.appendChild( this.tab.firstChild ); this.tab.appendChild( a );
// hook up events, using DOM0
var oThis = this; this.tab.onclick = function () { oThis.select(); }; this.tab.onmouseover = function () { WebFXTabPage.tabOver( oThis ); }; this.tab.onmouseout = function () { WebFXTabPage.tabOut( oThis ); };
}
WebFXTabPage.prototype.show = function () {
var el = this.tab;
var s = el.className + " selected";
s = s.replace(/ +/g, " ");
el.className = s;
this.element.style.display = "block";
};
WebFXTabPage.prototype.hide = function () {
var el = this.tab;
var s = el.className;
s = s.replace(/ selected/g, "");
el.className = s;
this.element.style.display = "none";
};
WebFXTabPage.prototype.select = function () { this.tabPane.setSelectedIndex( this.index );
};
WebFXTabPage.tabOver = function ( tabpage ) {
var el = tabpage.tab;
var s = el.className + " hover";
s = s.replace(/ +/g, " ");
el.className = s;
};
WebFXTabPage.tabOut = function ( tabpage ) {
var el = tabpage.tab;
var s = el.className;
s = s.replace(/ hover/g, "");
el.className = s;
};
// This function initializes all uninitialized tab panes and tab pages function setupAllTabs() { if ( !hasSupport() ) return;
var all = document.getElementsByTagName( "*" );
var l = all.length;
var tabPaneRe = /tab\-pane/;
var tabPageRe = /tab\-page/;
var cn, el;
var parentTabPane;
for ( var i = 0; i < l; i++ ) {
el = all[i]
cn = el.className;
// no className if ( cn == "" ) continue;
// uninitiated tab pane if ( tabPaneRe.test( cn ) && !el.tabPane ) new WebFXTabPane( el );
// unitiated tab page wit a valid tab pane parent else if ( tabPageRe.test( cn ) && !el.tabPage &&
tabPaneRe.test( el.parentNode.className ) ) {
el.parentNode.tabPane.addTabPage( el );
}
}
}
function disposeAllTabs() { if ( !hasSupport() ) return;
var all = document.getElementsByTagName( "*" );
var l = all.length;
var tabPaneRe = /tab\-pane/;
var cn, el;
var tabPanes = [];
for ( var i = 0; i < l; i++ ) {
el = all[i]
cn = el.className;
function showArticleTab( sName ) { if (typeof tabPane != "undefined" ) {
switch ( sName ) {
case "main":
tabPane.setSelectedIndex( 0 ); break;
case "usage":
tabPane.setSelectedIndex( 1 ); break;
case "api":
tabPane.setSelectedIndex( 2 ); break;
case "implementation":
tabPane.setSelectedIndex( 3 ); break;
case "looknfeel":
tabPane.setSelectedIndex( 4 ); break;
}
}
}
// help tips
htDom = "Document Object Model 1 is a standard developed by the W3C.<br />" +
"<a href=\"http://www.w3.org/DOM/\" target=\"_blank\">http://www.w3.org/DOM/</a>";
</script>
</head>
<body>
<!-- WebFX Layout Include -->
<script type="text/javascript">
This is text of tab 2. This is text of tab 2.
This is text of tab 2. This is text of tab 2.
</div>
</div>
</pre>
<p>Notice that the <code>id</code> is not needed unless two or more tab panes
are present in the same document and you are using the persistence feature.
</p>
<h3>Initialization</h3>
<p>The best way to.</p>
</div>
<!-- end usage tab -->
<!-- begin api tab -->
<div class="tab-page" id="api-page">
<h2 class="tab">API</h2>
<p>The way to check the browser whether it support a certain feature in the
DOM is to use the method <code>document.implementation.hasFeature</code>.
However since IE5.5 supports all the features that this script needs but it
does not support this way of checking for support we have to add a separate
check for IE55.</p>
<pre> function hasSupport() {
if (typeof hasSupport.support != "undefined") return hasSupport.support;
var ie55 = /msie 5\.[56789]/i.test( navigator.userAgent );
// IE55 has a serious DOM1 bug... Patch it! if ( ie55 ) {
document._getElementsByTagName = document.getElementsByTagName;
document.getElementsByTagName = function ( sTagName ) { if ( sTagName == "*" ) return document.all; else return document._getElementsByTagName( sTagName );
};
}
return hasSupport.support;
}
</pre>
<p>As you can see in the code above IE55 has a bug an therefore we also
patch that. Too many people are still using IE55 to just ignore it.</p>
<h3>WebFXTabPane</h3>
<p>The constructor for the tab pane creates the <code>tabRow</code> div
that is used to place all the actual tabs in. It also checks the cookie
state so that the selected tab can be persisted. Besides from this it
sets up some properties needed to keep track of the states. Last but not
least it checks the <code>childNodes</code> of the element and adds
the found tab pages.</p>
<pre> function WebFXTabPane( el, bUseCookie ) { if ( !hasSupport() || el == null ) return;
// loop through child nodes and add them
var cs = el.childNodes;
var n; for (var i = 0; i < cs.length; i++) { if (cs[i].nodeType == 1 && cs[i].className == "tab-page") { this.addTabPage( cs[i] );
}
}
}
</pre>
<p>There are a few methods added to the <code>WebFXTabPane</code> class and one of the
more important ones is the method <code>addTabPage</code>. This method takes the element
that represents the tab page and uses that to create a <code>WebFXTabPage</code>
object that is added to the <code>pages</code> array. Once the tab page has been
added it also checks if this page is the selected one and if it is it shows it.</p>
<pre>
WebFXTabPane.prototype = {
...
addTabPage: function ( oElement ) { if ( !hasSupport() ) return;
if ( oElement.tabPage == this ) // already added return oElement.tabPage;
var n = this.pages.length;
var tp = this.pages[n] = new WebFXTabPage( oElement, this, n );
tp.tabPane = this;
// move the tab out of the box this.tabRow.appendChild( tp.tab );
if ( n == this.selectedIndex )
tp.show(); else
tp.hide();
return tp;
}
};
</pre>
<h3>WebFXTabPage</h3>
<p>This class is used to keep track of the actual tab page. Once created it moves
the tab element to the <code>tabRow</code> of the tab pane. It also adds
an anchor around the text so that the user can use the keyboard to activate the
tabs.</p>
<pre> function WebFXTabPage( el, tabPane, nIndex ) { if ( !hasSupport() || el == null ) return;
var cs = el.childNodes; for (var i = 0; i < cs.length; i++) { if (cs[i].nodeType == 1 && cs[i].className == "tab") { this.tab = cs[i]; break;
}
}
// insert a tag around content to support keyboard navigation
var a = document.createElement( "A" );
a.href = "javascript:void 0;"; while ( this.tab.hasChildNodes() )
a.appendChild( this.tab.firstChild ); this.tab.appendChild( a );
// hook up events, using DOM0
var oThis = this; this.tab.onclick = function () { oThis.select(); }; this.tab.onmouseover = function () { WebFXTabPage.tabOver( oThis ); }; this.tab.onmouseout = function () { WebFXTabPage.tabOut( oThis ); };
}
</pre>
<h3>Initialization</h3>
<p>The initialization uses the global function <code>setupAllTabs</code> that
goes through all elements and checks their class names and if the class names
match the classes used by the tab pane controls it checks whether this element
belongs to an uninitialized control and in that case it initializes it now.</p>
<pre> function setupAllTabs() { if ( !hasSupport() ) return;
var all = document.getElementsByTagName( "*" );
var l = all.length;
var tabPaneRe = /tab\-pane/;
var tabPageRe = /tab\-page/;
var cn, el;
var parentTabPane;
for ( var i = 0; i < l; i++ ) {
el = all[i]
cn = el.className;
// no className if ( cn == "" ) continue;
// uninitiated tab pane if ( tabPaneRe.test( cn ) && !el.tabPane ) new WebFXTabPane( el );
<p>This function can be called manually at any time but the script makes hooks
to the <code>load</code> event for the window. This is done using DOM level 2
events if available. If not we test if it supports the IE5 way of attaching events
and last we fall back on classic way of setting events.</p>
<p>To be able to change the look and feel one needs to understand the structure
of the tab pane. When the original XHTML source tree is transformed into the
tab pane the class name of the element representing the tab pane is tagged with
the property <code>classNameTag</code>. The default tag is
<code>dynamic-tab-pane-control</code> and therefore all your css rules should
take this into account. If you want different look on different tab panes in
the same document this tag can be changed to make the css rules easier to set
up.</p>
This is text of tab 1. This is text of tab 1.
This is text of tab 1. This is text of tab 1.
</div>
<div class="tab-page">
This is text of tab 2. This is text of tab 2.
This is text of tab 2. This is text of tab 2.
</div>
</div>
</pre>
<p>The selected tab will have the class name <code>tab selected</code> and the
tab that the mouse hovers over will have the class name <code>tab hover</code>. If the selected
tab is hovered it will have the class name <code>tab selected hover</code>. These
rules allow you to differentiate the look of tabs between the different
states.</p>
<h3>The CSS Rules</h3>
<p>Here we will walk through the <a href="css/tab.winclassic.css">Windows Classic
css file</a>. First we set the width and position of the tab pane to prevent a few
rendering bugs in IE6.</p>
<p>Then we setup the css for the tab. Notice how the position is set to
relative to allow the top position to be slightly changed and to allow the
z-index property to be changed to position the tabs below the tab pages.</p>
<p>For the selected tab we set the z-index to 3 to put it above the
tab pages. We also move it a little and change some other properties to make it look
more like the classic window tab control.</p>
.dynamic-tab-pane-control .tab-row .hover a {
color: blue;
}
</pre>
<p>Then we set the z-index for the tab pages to 2 so that it will be
shown above tabs but below the selected tab. We also set the borders and
and a few other properties.</p>