/[wopi2]/trunk/zebra.js
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/zebra.js

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6 - (show annotations)
Fri Jun 25 20:51:16 2004 UTC (19 years, 11 months ago) by dpavlin
File MIME type: application/javascript
File size: 2028 byte(s)
improvements, mostly in design.

1 // this function is needed to work around
2 // a bug in IE related to element attributes
3 function hasClass(obj) {
4 var result = false;
5 if (obj.getAttributeNode("class") != null) {
6 result = obj.getAttributeNode("class").value;
7 }
8 return result;
9 }
10
11 function stripe(id) {
12
13 // the flag we'll use to keep track of
14 // whether the current row is odd or even
15 var even = false;
16
17 // if arguments are provided to specify the colours
18 // of the even & odd rows, then use the them;
19 // otherwise use the following defaults:
20 var evenColor = arguments[1] ? arguments[1] : "#fff";
21 var oddColor = arguments[2] ? arguments[2] : "#eee";
22
23 // obtain a reference to the desired table
24 // if no such table exists, abort
25 var table = document.getElementById(id);
26 if (! table) { return; }
27
28 // by definition, tables can have more than one tbody
29 // element, so we'll have to get the list of child
30 // <tbody>s
31 var tbodies = table.getElementsByTagName("tbody");
32
33 // and iterate through them...
34 for (var h = 0; h < tbodies.length; h++) {
35
36 // find all the &lt;tr&gt; elements...
37 var trs = tbodies[h].getElementsByTagName("tr");
38
39 // ... and iterate through them
40 for (var i = 0; i < trs.length; i++) {
41
42 // avoid rows that have a class attribute
43 // or backgroundColor style
44 if (! hasClass(trs[i]) &&
45 ! trs[i].style.backgroundColor) {
46
47 // get all the cells in this row...
48 var tds = trs[i].getElementsByTagName("td");
49
50 // and iterate through them...
51 for (var j = 0; j < tds.length; j++) {
52
53 var mytd = tds[j];
54
55 // avoid cells that have a class attribute
56 // or backgroundColor style
57 if (! hasClass(mytd) &&
58 ! mytd.style.backgroundColor) {
59
60 mytd.style.backgroundColor =
61 even ? evenColor : oddColor;
62
63 }
64 }
65 }
66 // flip from odd to even, or vice-versa
67 even = ! even;
68 }
69 }
70 }

  ViewVC Help
Powered by ViewVC 1.1.26