4 |
andreas |
1 |
/* http://www.alistapart.com/articles/zebratables/ */
|
|
|
2 |
function removeClassName (elem, className) {
|
|
|
3 |
elem.className = elem.className.replace(className, "").trim();
|
|
|
4 |
}
|
|
|
5 |
|
|
|
6 |
function addCSSClass (elem, className) {
|
|
|
7 |
removeClassName (elem, className);
|
|
|
8 |
elem.className = (elem.className + " " + className).trim();
|
|
|
9 |
}
|
|
|
10 |
|
|
|
11 |
String.prototype.trim = function() {
|
|
|
12 |
return this.replace( /^\s+|\s+$/, "" );
|
|
|
13 |
}
|
|
|
14 |
|
|
|
15 |
function stripedTable() {
|
|
|
16 |
if (document.getElementById && document.getElementsByTagName) {
|
|
|
17 |
var allTables = document.getElementsByTagName('table');
|
|
|
18 |
if (!allTables) { return; }
|
|
|
19 |
|
|
|
20 |
for (var i = 0; i < allTables.length; i++) {
|
|
|
21 |
if (allTables[i].className.match(/[\w\s ]*scrollTable[\w\s ]*/)) {
|
|
|
22 |
var trs = allTables[i].getElementsByTagName("tr");
|
|
|
23 |
for (var j = 0; j < trs.length; j++) {
|
|
|
24 |
removeClassName(trs[j], 'alternateRow');
|
|
|
25 |
addCSSClass(trs[j], 'normalRow');
|
|
|
26 |
}
|
|
|
27 |
for (var k = 0; k < trs.length; k += 2) {
|
|
|
28 |
removeClassName(trs[k], 'normalRow');
|
|
|
29 |
addCSSClass(trs[k], 'alternateRow');
|
|
|
30 |
}
|
|
|
31 |
}
|
|
|
32 |
}
|
|
|
33 |
}
|
|
|
34 |
}
|
|
|
35 |
|
|
|
36 |
/* onload state is fired, append onclick action to the table's DIV */
|
|
|
37 |
/* container. This allows the HTML document to validate correctly. */
|
|
|
38 |
/* addIEonScroll added on 2005-01-28 */
|
|
|
39 |
/* Terence Ordona, portal[AT]imaputz[DOT]com */
|
|
|
40 |
function addIEonScroll() {
|
|
|
41 |
var thisContainer = document.getElementById('tableContainer');
|
|
|
42 |
if (!thisContainer) { return; }
|
|
|
43 |
|
|
|
44 |
var onClickAction = 'toggleSelectBoxes();';
|
|
|
45 |
thisContainer.onscroll = new Function(onClickAction);
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
/* Only WinIE will fire this function. All other browsers scroll the TBODY element and not the DIV */
|
|
|
49 |
/* This is to hide the SELECT elements from scrolling over the fixed Header. WinIE only. */
|
|
|
50 |
/* toggleSelectBoxes added on 2005-01-28 */
|
|
|
51 |
/* Terence Ordona, portal[AT]imaputz[DOT]com */
|
|
|
52 |
function toggleSelectBoxes() {
|
|
|
53 |
var thisContainer = document.getElementById('tableContainer');
|
|
|
54 |
var thisHeader = document.getElementById('fixedHeader');
|
|
|
55 |
if (!thisContainer || !thisHeader) { return; }
|
|
|
56 |
|
|
|
57 |
var selectBoxes = thisContainer.getElementsByTagName('select');
|
|
|
58 |
if (!selectBoxes) { return; }
|
|
|
59 |
|
|
|
60 |
for (var i = 0; i < selectBoxes.length; i++) {
|
|
|
61 |
if (thisContainer.scrollTop >= eval(selectBoxes[i].parentNode.offsetTop - thisHeader.offsetHeight)) {
|
|
|
62 |
selectBoxes[i].style.visibility = 'hidden';
|
|
|
63 |
} else {
|
|
|
64 |
selectBoxes[i].style.visibility = 'visible';
|
|
|
65 |
}
|
|
|
66 |
}
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
window.onload = function() { stripedTable(); addIEonScroll(); }
|