|
1 /** |
|
2 * Check required support for TOC. |
|
3 */ |
|
4 function support() { |
|
5 if (document.getElementsByTagName && document.styleSheets) { |
|
6 tocSupported = true; |
|
7 } |
|
8 } |
|
9 |
|
10 /** Flag if dynamic TOC is supported */ |
|
11 var tocSupported = false; |
|
12 support(); |
|
13 /** Current active TOC node. */ |
|
14 var currentHighlight = null; |
|
15 |
|
16 /** Regexp for backslash, used to turn Windows pseudo-URLs to URLs. */ |
|
17 var slashRegExp = new RegExp("\\\\", "g"); |
|
18 |
|
19 function getBaseUrl() { |
|
20 var topLocation = window.top.location; |
|
21 var i = topLocation.pathname.indexOf(URL_BASE); |
|
22 if (i != -1) { |
|
23 return topLocation.protocol + "//" |
|
24 + topLocation.hostname + (topLocation.port == "" ? "" : ":" + topLocation.port) |
|
25 + topLocation.pathname.substring(0, i).replace(slashRegExp, "/"); |
|
26 } else if (topLocation.pathname.substring(topLocation.pathname.length - 1) == "/") { |
|
27 return topLocation.protocol + "//" |
|
28 + topLocation.hostname + (topLocation.port == "" ? "" : ":" + topLocation.port) |
|
29 + topLocation.pathname; |
|
30 } else { |
|
31 return undefined; |
|
32 } |
|
33 } |
|
34 |
|
35 /* |
|
36 var isIE = (window.navigator.appVersion.indexOf("MSIE 6") !== -1); |
|
37 */ |
|
38 |
|
39 /** |
|
40 * Hightlight TOC node. |
|
41 * |
|
42 * @param node TOC node to highlight |
|
43 */ |
|
44 function highlightTocItem(node) { |
|
45 if (tocSupported) { |
|
46 // turn old off |
|
47 /* |
|
48 if (isIE) { |
|
49 var lis = node.ownerDocument.getElementsByTagName("*"); |
|
50 for (var i = 0; i < lis.length; i++) { |
|
51 removeClass(lis.item(i), TOC_CLASS_ACTIVE); |
|
52 } |
|
53 } else { |
|
54 */ |
|
55 if (currentHighlight === null || !isClass(currentHighlight, TOC_CLASS_ACTIVE)) { |
|
56 // turn all off |
|
57 var lis = node.ownerDocument.getElementsByTagName(TOC_ELEMENT_ITEM); |
|
58 for (var i = 0; i < lis.length; i++) { |
|
59 removeClass(lis.item(i), TOC_CLASS_ACTIVE); |
|
60 } |
|
61 } else { |
|
62 removeClass(currentHighlight, TOC_CLASS_ACTIVE); |
|
63 } |
|
64 /* |
|
65 } |
|
66 */ |
|
67 // turn this on |
|
68 addClass(node.parentNode, TOC_CLASS_ACTIVE); |
|
69 currentHighlight = node.parentNode; |
|
70 /* |
|
71 // IE6 addition, because it doesn't support > in CSS selectors |
|
72 if (isIE) { |
|
73 addClass(node, TOC_CLASS_ACTIVE); |
|
74 } |
|
75 */ |
|
76 } |
|
77 } |
|
78 |
|
79 /** |
|
80 * Toggle child node display. |
|
81 * |
|
82 * @param n Target node of the event. |
|
83 */ |
|
84 //moved to toc.js |
|
85 /* |
|
86 function toggle(n) { |
|
87 // toggle controller |
|
88 if (isClass(n, "toc-controller-open")) { |
|
89 n.firstChild.data = "+"; |
|
90 switchClass(n, "toc-controller-closed", "toc-controller-open"); |
|
91 } else { |
|
92 n.firstChild.data = "-"; |
|
93 switchClass(n, "toc-controller-open", "toc-controller-closed"); |
|
94 } |
|
95 // toggle content |
|
96 i = getNextSiblingByTagName(n.parentNode.firstChild, "ul"); |
|
97 if (i != null) { |
|
98 if (i.style.display == "none") { |
|
99 i.style.display = "block"; |
|
100 } else { |
|
101 i.style.display = "none"; |
|
102 } |
|
103 } |
|
104 } |
|
105 */ |
|
106 |
|
107 /* Move to common utils. */ |
|
108 |
|
109 /** |
|
110 * Get first child element by element name. |
|
111 * |
|
112 * @param node parent element |
|
113 * @param name element name of the desired child elements |
|
114 * @return DOM Element, null if none found |
|
115 * @type Object |
|
116 */ |
|
117 function getFirstChildElementByTagName(node, name) { |
|
118 var tag = undefined; |
|
119 if (name !== undefined) { |
|
120 tag = name.toLowerCase(); |
|
121 } |
|
122 for (var n = node.firstChild; n != null; n = n.nextSibling) { |
|
123 if (n.nodeType == 1 && (name === undefined || n.nodeName.toLowerCase() == tag)) { |
|
124 return n; |
|
125 } |
|
126 } |
|
127 return null; |
|
128 } |
|
129 |
|
130 /** |
|
131 * Get first element by class name. |
|
132 * |
|
133 * @param node DOM node whose descendants select |
|
134 * @param cls class name |
|
135 * @param elem element name (optional) |
|
136 * @return DOM Element, null if none found |
|
137 * @type Object |
|
138 */ |
|
139 function getFirstElementByClassName(node, cls, elem) { |
|
140 if (elem === undefined) { |
|
141 elem = "*"; |
|
142 } |
|
143 for (var el = document.getElementsByTagName(elem), i = 0; i < el.length; i++) { |
|
144 if (isClass(el[i], cls)) { |
|
145 return el[i]; |
|
146 } |
|
147 } |
|
148 return null; |
|
149 } |