Menu

[r37]: / osmb / trunk / build / cruisecontrol / docs / tables.js  Maximize  Restore  History

Download this file

92 lines (81 with data), 2.9 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/**********************************************************************
* This is a script to automatically add the "oddrow" class to every
* second table row in the body of a table with a class of
* "documentation". With the corresponding css declarations, this can
* be used to display selected tables with rows in alternating colors,
* without having to manually maintain the class of each row (which
* can become tedious for large tables).
*
* To use this script, include this file in the head section of a html
* file, by adding a line similar to the following:
* <script type="text/javascript" src="tables.js"></script>
*
* This script was developed based upon the description, example code
* and comments of the "Zebra Tables" article of "A List Apart":
* http://www.alistapart.com/articles/zebratables/
*
* Joe Schmetzer
* http://www.exubero.com/
*********************************************************************/
onload = stripeDocTables;
/**
* Search for all tables with the class of "documentation", and pass
* them to the stripeTable function.
*/
function stripeDocTables() {
if( !document.getElementsByTagName ) return false;
var tables = document.getElementsByTagName("table");
for( var i = 0; i < tables.length; i++ ) {
var table = tables[i];
if( hasClass(table, "documentation") ) {
stripeTable( table );
}
}
}
/**
* Given a table, find all rows dirctly in the tbody (avoiding nested
* tables), and appending the "oddrow" class to every second row.
*/
function stripeTable(table) {
var oddrow = true;
var bodies = getChildElementsByTagName(table, "tbody");
for( var i = 0; i < bodies.length; i++ ) {
var rows = getChildElementsByTagName(bodies[i], "tr");
for (var j = 0; j < rows.length; j++) {
if( oddrow ) {
rows[j].className += " oddrow";
}
oddrow = !oddrow;
}
}
}
/**
* Returns true if the given object has the specified class name.
* This method is used to work around an IE bug.
*/
function hasClass(obj, className) {
var result = false;
if (obj.getAttributeNode("class") != null) {
var classList = obj.getAttributeNode("class").value;
result = classList.indexOf(className) >= 0;
}
return result;
}
var ELEMENT_NODE = 1;
/**
* Returns the direct children of the given object with the specified
* element name.
*/
function getChildElementsByTagName(obj, tagname) {
tagname = tagname.toUpperCase();
var matching = [];
var child = obj.firstChild;
while( child ) {
if( child.nodeType == ELEMENT_NODE &&
(child.nodeName.toUpperCase() == tagname)) {
matching.push(child);
}
child = child.nextSibling;
}
return matching;
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.