-
Notifications
You must be signed in to change notification settings - Fork 0
/
masthead.js
59 lines (51 loc) · 2.18 KB
/
masthead.js
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
// Emulate the following CSS rules in JavaScript:
// div.department h3:after { content: ": " }
// div.department li:after { content: ", " }
// div.department li.last:after { content: "; " }
// div.department li.last-last:after { content: "." }
function emulateAfter() {
// XXX: Most browsers that support the CSS2 maxHeight also support the CSS2
// :after pseudo-element (I think), but it's not the best test ever...
if (typeof document.body.style.maxHeight == "undefined") {
var allDivs = document.getElementsByTagName("div");
for (var i = 0; i < allDivs.length; i++) {
var div = allDivs[i];
if (div.className != "department") {
continue;
}
var allH3s = div.getElementsByTagName("h3");
for (var j = 0; j < allH3s.length; j++) {
// Find the last child of the <h3> that's a text node
var lastText = allH3s[j].lastChild;
while (lastText &&
lastText.nodeType != 3 /* Node.TEXT_NODE */) {
lastText = lastText.previousSibling;
}
if (lastText) {
lastText.appendData(": ");
}
}
var allLIs = div.getElementsByTagName("li");
for (var j = 0; j < allLIs.length; j++) {
var li = allLIs[j];
// Find the last child of the <li> that's a text node
var lastText = li.lastChild;
while (lastText &&
lastText.nodeType != 3 /* Node.TEXT_NODE */) {
lastText = lastText.previousSibling;
}
if (lastText) {
// IE adds an extra space to <li>s for some reason
lastText.deleteData(lastText.length - 1, 1);
if (li.className == "last-last") {
lastText.appendData(".");
} else if (li.className == "last") {
lastText.appendData("; ");
} else {
lastText.appendData(", ");
}
}
}
}
}
}