Skip to content
This repository was archived by the owner on Jul 3, 2024. It is now read-only.

Commit 5d97545

Browse files
* simplified some of the JavaScript by reducing variables, combining declarations, etc.
* cleaned up the class names a bit * adjusted the demo to reflect the new class names and to use namespaced CSS
1 parent 7937a63 commit 5d97545

File tree

4 files changed

+51
-36
lines changed

4 files changed

+51
-36
lines changed

CHANGELOG

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
*v0.4.3* (2009-06-28)
2+
3+
* simplified some of the JavaScript by reducing variables, combining declarations, etc.
4+
* cleaned up the class names a bit
5+
* adjusted the demo to reflect the new class names and to use namespaced CSS
6+
7+
--
8+
19
*v0.4.2* (2009-04-20)
210

311
* changed the source order for the tabs (so they come before the panels, which will be more helpful in ARIA use)

demo/color.css

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ img {
44
border-color: #bfa55f;
55
}
66

7-
.folder {
7+
.tabbed-on .folder {
88
background: #ffeebf;
99
border-color: #bfa55f;
1010
}
11-
.tab-list li {
11+
.tabbed-on .index li {
1212
background: #dfc88b url(tab-list_li.png) bottom left repeat-x;
1313
border-color: #bfa55f;
1414
color: #000;
1515
}
16-
.tab-list .active-tab {
16+
.tabbed-on .index .active {
1717
background: #ffeebf;
1818
border-bottom-color: #ffeebf;
1919
}

demo/layout.css

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
body {
2+
margin: 0;
3+
padding: 1em;
4+
}
5+
h1 {
6+
margin: 0 0 .5em;
7+
}
8+
19
/* =TabInterface Styles */
210
.tabbed-on {
311
margin: 2em 0 0;
@@ -8,7 +16,7 @@
816
position: absolute;
917
left: -999em;
1018
}
11-
.folder {
19+
.tabbed-on .folder {
1220
border: solid;
1321
border-width: 1px 2px 2px 1px;
1422
min-height: 240px;
@@ -18,17 +26,17 @@
1826
top: 0;
1927
left: -999em;
2028
}
21-
.folder.visible {
29+
.tabbed-on .folder.visible {
2230
position: static;
2331
}
24-
.tab-list {
32+
.tabbed-on .index {
2533
margin: 0;
2634
padding: 0;
2735
position: absolute;
2836
top: -.6em;
2937
left: 0;
3038
}
31-
.tab-list li {
39+
.tabbed-on .index li {
3240
border: 1px solid;
3341
border-bottom: 2px solid;
3442
cursor: pointer;
@@ -42,12 +50,12 @@
4250
text-transform: uppercase;
4351
white-space: normal;
4452
}
45-
.tab-list li:hover {
53+
.tabbed-on .index li:hover {
4654
}
47-
.tab-list li:focus {
55+
.tabbed-on .index li:focus {
4856
outline: 1px dotted;
4957
}
50-
.tab-list .active-tab {
58+
.tabbed-on .index .active {
5159
border-right-width: 2px;
5260
line-height: 1.2;
5361
padding: .5em 10px .5em;

src/TabInterface.js

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,17 @@ License: MIT License (see MIT-LICENSE)
88
Note: If you change or improve on this script, please let us know by
99
emailing the author (above) with a link to your demo page.
1010
------------------------------------------------------------------------------*/
11-
function TabInterface( el, i ){
11+
function TabInterface( _cabinet, _i ){
1212
// Public Properties
1313
this.Version = '0.4.3'; // version
1414

1515
// Private Properties
1616
var
17-
_i = i, // incrementor
18-
_cabinet = el, // the "cabinet" element (container)
1917
_active = false, // ID of the active "folder"
2018
// the tab list
2119
_index = document.createElement( 'ul' ),
2220
// prototype elements
23-
_els = {
21+
_cabinets = {
2422
div: document.createElement( 'div' ),
2523
li: document.createElement( 'li' )
2624
};
@@ -34,18 +32,18 @@ function TabInterface( el, i ){
3432
arr, folder, tab, heading;
3533

3634
// set the id
37-
_id = el.getAttribute( 'id' ) || 'folder-' + _i;
38-
if( !el.getAttribute( 'id' ) ) el.setAttribute( 'id', _id );
35+
_id = _cabinet.getAttribute( 'id' ) || 'folder-' + _i;
36+
if( !_cabinet.getAttribute( 'id' ) ) _cabinet.setAttribute( 'id', _id );
3937

4038
// set the ARIA roles
41-
el.parentNode.setAttribute( 'role', 'application' );
42-
el.setAttribute( 'role', 'presentation' );
39+
_cabinet.parentNode.setAttribute( 'role', 'application' );
40+
_cabinet.setAttribute( 'role', 'presentation' );
4341
_index.setAttribute( 'role', 'tablist' );
44-
_els.div.setAttribute( 'role', 'tabpanel' );
45-
_els.div.setAttribute( 'aria-hidden', 'true' );
46-
_els.li.setAttribute( 'role', 'tab' );
47-
_els.li.setAttribute( 'aria-selected', 'false' );
48-
_els.li.setAttribute( 'tabindex', '-1' );
42+
_cabinets.div.setAttribute( 'role', 'tabpanel' );
43+
_cabinets.div.setAttribute( 'aria-hidden', 'true' );
44+
_cabinets.li.setAttribute( 'role', 'tab' );
45+
_cabinets.li.setAttribute( 'aria-selected', 'false' );
46+
_cabinets.li.setAttribute( 'tabindex', '-1' );
4947

5048
// trim whitespace
5149
node = _cabinet.firstChild;
@@ -65,26 +63,29 @@ function TabInterface( el, i ){
6563
}
6664
}
6765

66+
// flip it on
67+
addClassName( _cabinet, 'tabbed-on' );
68+
removeClassName( _cabinet, 'tabbed' );
6869
// establish the folders
6970
rexp = new RegExp( '<(' + _tag + ')', 'ig' );
7071
arr = _cabinet.innerHTML.replace( rexp, "||||<$1" ).split( '||||' );
7172
arr.shift();
7273
_cabinet.innerHTML = '';
73-
removeClassName( _cabinet, 'tabbed' );
74-
addClassName( _cabinet, 'tabbed-on' );
74+
// add the index
75+
addClassName( _index, 'index' );
7576
_cabinet.appendChild( _index );
77+
// re-insert the chunks
7678
for( i=0, len=arr.length; i<len; i++ ){
7779
// build the div
78-
folder = _els.div.cloneNode( true );
80+
folder = _cabinets.div.cloneNode( true );
7981
addClassName( folder, 'folder' );
8082
folder.setAttribute( 'id', _id + '-' + i );
8183
folder.setAttribute( 'aria-labelledby', _id + '-' + i + '-tab' );
8284
folder.innerHTML = arr[i];
8385
_cabinet.appendChild( folder );
8486
// build the tab
85-
tab = _els.li.cloneNode( true );
86-
tab.folder = folder.getAttribute( 'id' );
87-
tab.setAttribute( 'id', tab.folder + '-tab' );
87+
tab = _cabinets.li.cloneNode( true );
88+
tab.setAttribute( 'id', _id + '-' + i + '-tab' );
8889
tab.onclick = swap; // set the action
8990
tab.onkeydown = moveFocus; // add the keyboard control
9091
heading = folder.getElementsByTagName( _tag )[0];
@@ -102,11 +103,9 @@ function TabInterface( el, i ){
102103
tab.setAttribute( 'aria-selected', 'true' );
103104
tab.setAttribute( 'tabindex', '0' );
104105
_active = folder.getAttribute( 'id' );
105-
addClassName( tab, 'active-tab' );
106+
addClassName( tab, 'active' );
106107
}
107108
}
108-
// add the index
109-
addClassName( _index, 'tab-list' );
110109
}
111110
function swap( e )
112111
{
@@ -116,14 +115,14 @@ function TabInterface( el, i ){
116115
old_folder = document.getElementById( _active ),
117116
new_folder;
118117
tab = getTab( tab );
119-
new_folder = document.getElementById( tab.folder );
120-
removeClassName( document.getElementById( _active + '-tab' ), 'active-tab' );
118+
new_folder = document.getElementById( tab.getAttribute( 'id' ).replace( '-tab', '' ) );
119+
removeClassName( document.getElementById( _active + '-tab' ), 'active' );
121120
removeClassName( old_folder, 'visible' );
122121
old_folder.setAttribute( 'aria-hidden', 'true' );
123-
addClassName( tab, 'active-tab' );
122+
addClassName( tab, 'active' );
124123
addClassName( new_folder, 'visible' );
125124
new_folder.setAttribute( 'aria-hidden', 'false' );
126-
_active = tab.folder;
125+
_active = new_folder.getAttribute( 'id' );
127126
}
128127
function addClassName( e, c )
129128
{

0 commit comments

Comments
 (0)