1 |
wakaba |
1.4 |
function addSourceToParseErrorList (idPrefix, dlId) { |
2 |
wakaba |
1.1 |
var parseErrorsList = document.getElementById |
3 |
wakaba |
1.4 |
(idPrefix + dlId); |
4 |
wakaba |
1.1 |
if (!parseErrorsList) return; |
5 |
|
|
var childs = parseErrorsList.childNodes; |
6 |
|
|
var childsL = childs.length; |
7 |
|
|
var line = 0; |
8 |
|
|
var column = 0; |
9 |
|
|
for (var i = 0; i < childsL; i++) { |
10 |
|
|
var child = childs[i]; |
11 |
|
|
if (child.nodeType != 1) continue; |
12 |
|
|
if (child.nodeName == 'DT') { |
13 |
wakaba |
1.5 |
line = parseInt (child.getAttribute ('data-line') || 0); |
14 |
|
|
column = parseInt (child.getAttribute ('data-column') || 0); |
15 |
wakaba |
1.1 |
} else if (child.nodeName == 'DD') { |
16 |
|
|
if (line > 0) { |
17 |
|
|
var lineEl = document.getElementById (idPrefix + 'line-' + line); |
18 |
|
|
if (lineEl) { |
19 |
|
|
lineText = lineEl.innerHTML |
20 |
wakaba |
1.3 |
.replace (/<var>U\+([0-9A-F]{4})<\/var>/g, function (s) { |
21 |
|
|
return String.fromCharCode (parseInt (s, 16)); |
22 |
|
|
}) |
23 |
wakaba |
1.1 |
.replace (/</g, '<') |
24 |
|
|
.replace (/>/g, '>') |
25 |
|
|
.replace (/ /g, '\u00A0') |
26 |
|
|
.replace (/"/g, '"') |
27 |
|
|
.replace (/&/g, '&'); |
28 |
|
|
var p = document.createElement ('p'); |
29 |
|
|
p.className = 'source-fragment'; |
30 |
|
|
var code = document.createElement ('code'); |
31 |
|
|
if (lineText.length > 50) { |
32 |
|
|
if (column - 25 > 0) { |
33 |
|
|
p.appendChild (document.createElement ('var')).innerHTML |
34 |
|
|
= '...'; |
35 |
|
|
lineText = lineText.substring (column - 25, column + 24); |
36 |
|
|
code.appendChild (document.createTextNode |
37 |
|
|
(lineText.substring (0, 24))); |
38 |
|
|
code.appendChild (document.createElement ('mark')) |
39 |
|
|
.appendChild (document.createTextNode |
40 |
|
|
(lineText.charAt (24))); |
41 |
|
|
code.appendChild (document.createTextNode |
42 |
|
|
(lineText.substring (25, lineText.length))); |
43 |
|
|
p.appendChild (code); |
44 |
|
|
p.appendChild (document.createElement ('var')).innerHTML |
45 |
|
|
= '...'; |
46 |
|
|
} else { |
47 |
|
|
lineText = lineText.substring (0, 50); |
48 |
|
|
if (column > 0) { |
49 |
|
|
code.appendChild (document.createTextNode |
50 |
|
|
(lineText.substring (0, column - 1))); |
51 |
|
|
code.appendChild (document.createElement ('mark')) |
52 |
|
|
.appendChild (document.createTextNode |
53 |
|
|
(lineText.charAt (column - 1))); |
54 |
|
|
code.appendChild (document.createTextNode |
55 |
|
|
(lineText.substring (column, lineText.length))); |
56 |
|
|
} else { |
57 |
|
|
code.appendChild (document.createTextNode |
58 |
|
|
(lineText.substring (0, 50))); |
59 |
|
|
} |
60 |
|
|
p.appendChild (code); |
61 |
|
|
p.appendChild (document.createElement ('var')).innerHTML |
62 |
|
|
= '...'; |
63 |
|
|
} |
64 |
|
|
} else { |
65 |
wakaba |
1.2 |
if (column > 0) { |
66 |
|
|
code.appendChild (document.createTextNode |
67 |
|
|
(lineText.substring (0, column - 1))); |
68 |
|
|
code.appendChild (document.createElement ('mark')) |
69 |
|
|
.appendChild (document.createTextNode |
70 |
|
|
(lineText.charAt (column - 1))); |
71 |
|
|
code.appendChild (document.createTextNode |
72 |
|
|
(lineText.substring (column, lineText.length))); |
73 |
|
|
} else { |
74 |
|
|
code.appendChild (document.createTextNode (lineText)); |
75 |
|
|
} |
76 |
wakaba |
1.1 |
p.appendChild (code); |
77 |
|
|
} |
78 |
|
|
child.appendChild (p); |
79 |
|
|
} |
80 |
|
|
} |
81 |
|
|
line = 0; |
82 |
|
|
column = 0; |
83 |
|
|
} |
84 |
|
|
} |
85 |
|
|
} // addSourceToParseErrorList |
86 |
|
|
|
87 |
wakaba |
1.7 |
function insertNavSections (parentId) { |
88 |
|
|
parentId = parentId || ''; |
89 |
wakaba |
1.6 |
var el = document.createElement ('nav'); |
90 |
wakaba |
1.7 |
el.id = parentId + 'nav-sections'; |
91 |
wakaba |
1.6 |
el.innerHTML = '<ul></ul>'; |
92 |
wakaba |
1.7 |
|
93 |
|
|
if (parentId == '') { |
94 |
|
|
document.body.appendChild (el); |
95 |
|
|
document.webhaccSections = {}; |
96 |
|
|
document.body.setAttribute ('data-scripted', ''); |
97 |
|
|
} else { |
98 |
|
|
var section = document.getElementById (parentId); |
99 |
|
|
section.appendChild (el); |
100 |
|
|
section.webhaccSections = {}; |
101 |
|
|
} |
102 |
wakaba |
1.6 |
} // insertNavSections |
103 |
|
|
|
104 |
wakaba |
1.7 |
function addSectionLink (id, label, parentId) { |
105 |
|
|
parentId = parentId || ''; |
106 |
|
|
|
107 |
wakaba |
1.6 |
var el = document.createElement ('li'); |
108 |
|
|
el.innerHTML = '<a></a>'; |
109 |
|
|
el.firstChild.href = '#' + id; |
110 |
|
|
el.firstChild.innerHTML = label; |
111 |
wakaba |
1.7 |
document.getElementById (parentId + 'nav-sections') |
112 |
|
|
.firstChild.appendChild (el); |
113 |
|
|
|
114 |
|
|
var sections = document.webhaccSections; |
115 |
wakaba |
1.8 |
if (parentId != '') { |
116 |
|
|
sections = document.getElementById (parentId).webhaccSections; |
117 |
|
|
} |
118 |
wakaba |
1.7 |
sections[id] = document.getElementById (id); |
119 |
|
|
sections[id].tabElement = el; |
120 |
|
|
|
121 |
|
|
if (id == 'input' || id == 'input-url') { |
122 |
|
|
showTab (id); |
123 |
|
|
document.webhaccNavigated = false; |
124 |
wakaba |
1.6 |
} else if (id == 'document-info' && !document.webhaccNavigated) { |
125 |
wakaba |
1.7 |
showTab (id); |
126 |
wakaba |
1.6 |
document.webhaccNavigated = false; |
127 |
wakaba |
1.8 |
} else if (id.match (/-document-info$/)) { |
128 |
|
|
sections[id].tabElement.setAttribute ('data-active', ''); |
129 |
wakaba |
1.6 |
} else { |
130 |
wakaba |
1.7 |
sections[id].style.display = 'none'; |
131 |
wakaba |
1.6 |
} |
132 |
|
|
} // addSectionLink |
133 |
|
|
|
134 |
|
|
function showTab (id) { |
135 |
wakaba |
1.8 |
var ids = []; |
136 |
wakaba |
1.6 |
if (id.match (/^line-/)) { |
137 |
wakaba |
1.8 |
ids = ['source-string']; |
138 |
wakaba |
1.6 |
} else if (id.match (/^node-/)) { |
139 |
wakaba |
1.8 |
ids = ['document-tree']; |
140 |
wakaba |
1.10 |
} else if (id.match (/^index-/)) { |
141 |
|
|
ids = ['document-structure']; |
142 |
wakaba |
1.8 |
} else if (id.match (/^subdoc-[^-]+-/)) { |
143 |
|
|
var m; |
144 |
|
|
ids = ['']; |
145 |
|
|
while (true) { |
146 |
|
|
if (m = id.match (/^subdoc-[^-]+-/)) { |
147 |
|
|
ids.push (ids[ids.length - 1] + m[0]); |
148 |
|
|
id = id.substring (m[0].length); |
149 |
|
|
} else { |
150 |
|
|
break; |
151 |
|
|
} |
152 |
|
|
} |
153 |
|
|
if (id.length > 0) { |
154 |
|
|
if (id.match (/^line-/)) { |
155 |
|
|
ids.push (ids[ids.length - 1] + 'source-string'); |
156 |
|
|
} else if (id.match (/^node-/)) { |
157 |
|
|
ids.push (ids[ids.length - 1] + 'document-tree'); |
158 |
wakaba |
1.10 |
} else if (id.match (/^index-/)) { |
159 |
|
|
ids.push (ids[ids.length - 1] + 'document-structure'); |
160 |
wakaba |
1.8 |
} else { |
161 |
|
|
ids.push (ids[ids.length - 1] + id); |
162 |
|
|
} |
163 |
|
|
} |
164 |
|
|
ids.shift (); // '' |
165 |
|
|
} else if (id.match (/^input-/)) { |
166 |
|
|
ids = ['input', id]; |
167 |
|
|
} else { |
168 |
|
|
ids = [id]; |
169 |
wakaba |
1.6 |
} |
170 |
|
|
|
171 |
wakaba |
1.8 |
var sections = document.webhaccSections; |
172 |
|
|
while (ids.length > 0) { |
173 |
|
|
var myid = ids.shift (); |
174 |
|
|
_showTab (sections, myid); |
175 |
|
|
sections = sections[myid].webhaccSections; |
176 |
|
|
if (!sections) break; |
177 |
wakaba |
1.7 |
} |
178 |
|
|
} // showTab |
179 |
|
|
|
180 |
|
|
function _showTab (sections, id) { |
181 |
|
|
if (sections[id]) { |
182 |
|
|
for (var i in sections) { |
183 |
|
|
sections[i].style.display = 'none'; |
184 |
|
|
sections[i].tabElement.removeAttribute ('data-active'); |
185 |
wakaba |
1.6 |
} |
186 |
wakaba |
1.7 |
sections[id].style.display = 'block'; |
187 |
|
|
sections[id].tabElement.setAttribute ('data-active', ''); |
188 |
wakaba |
1.9 |
sections[id].tabElement.scrollIntoView (); |
189 |
wakaba |
1.6 |
|
190 |
|
|
document.webhaccNavigated = true; |
191 |
|
|
} |
192 |
wakaba |
1.7 |
} // _showTab |
193 |
wakaba |
1.6 |
|
194 |
wakaba |
1.11 |
function getAncestorElements (e) { |
195 |
|
|
var ret = {}; |
196 |
wakaba |
1.6 |
do { |
197 |
wakaba |
1.8 |
if (e.nodeName == 'A' || e.nodeName == 'AREA') { |
198 |
wakaba |
1.11 |
ret.a = e; |
199 |
|
|
if (ret.aside) { |
200 |
|
|
return ret; |
201 |
|
|
} |
202 |
|
|
} else if (e.nodeName == 'ASIDE' || e.nodeName == 'aside') { |
203 |
|
|
ret.aside = e; |
204 |
|
|
if (ret.a) { |
205 |
|
|
ret.aInAside = true; |
206 |
|
|
return ret; |
207 |
|
|
} |
208 |
wakaba |
1.6 |
} |
209 |
|
|
e = e.parentNode; |
210 |
|
|
} while (e); |
211 |
wakaba |
1.11 |
return ret; |
212 |
|
|
} // getAncestorElements |
213 |
|
|
|
214 |
|
|
function showHelp (id, context) { |
215 |
|
|
if (document.webhaccHelp === undefined) { |
216 |
|
|
loadHelp ('../error-description', function () { |
217 |
|
|
_showHelp (id, context); |
218 |
|
|
}); |
219 |
|
|
return true; |
220 |
|
|
} else if (document.webhaccHelp === null) { |
221 |
|
|
return false; |
222 |
|
|
} else { |
223 |
|
|
_showHelp (id, context); |
224 |
|
|
} |
225 |
|
|
} // showHelp |
226 |
|
|
|
227 |
|
|
function loadHelp (url, code) { |
228 |
|
|
document.webhaccHelp = null; |
229 |
|
|
var iframe = document.createElement ('iframe'); |
230 |
wakaba |
1.12 |
iframe.className = 'ajax'; |
231 |
wakaba |
1.11 |
var iframecode = function () { |
232 |
|
|
var doc; |
233 |
|
|
var docel; |
234 |
|
|
try { |
235 |
|
|
doc = iframe.contentWindow.document; |
236 |
|
|
docel = doc.getElementById ('error-description'); |
237 |
|
|
} catch (e) { } |
238 |
|
|
if (docel) { |
239 |
|
|
document.webhaccHelp = doc; |
240 |
|
|
code (); |
241 |
|
|
} else if (url != '../error-description.en.html.u8') { |
242 |
|
|
// doc would be a 406 error. |
243 |
|
|
loadHelp ('../error-description.en.html.u8', code); |
244 |
|
|
iframe.parentNode.removeChild (iframe); |
245 |
|
|
/* |
246 |
|
|
|iframe| is removed from the document after another |iframe| |
247 |
|
|
is inserted by nested |loadHelp| call, otherwise Safari 3 |
248 |
|
|
would reuse(?) removed |iframe| and it sometimes (not always) |
249 |
|
|
requests old URL even when another URL is set to the |src| attribute. |
250 |
|
|
*/ |
251 |
|
|
} |
252 |
|
|
iframe.onreadystatechange = null; |
253 |
|
|
iframe.onload = null; |
254 |
|
|
}; |
255 |
|
|
iframe.onreadystatechange = function () { |
256 |
|
|
if (this.readyState == 'complete') { |
257 |
|
|
iframecode (); |
258 |
|
|
} |
259 |
|
|
}; |
260 |
|
|
iframe.onload = iframecode; |
261 |
|
|
iframe.src = url; |
262 |
|
|
document.body.appendChild (iframe); |
263 |
|
|
} // loadHelp |
264 |
|
|
|
265 |
|
|
function _showHelp (id, context) { |
266 |
|
|
var helpDataEl = document.webhaccHelp.getElementById (id); |
267 |
|
|
if (!helpDataEl) { |
268 |
|
|
helpDataEl = document.webhaccHelp.getElementById ('help-not-available'); |
269 |
|
|
if (!helpDataEl) { |
270 |
|
|
helpDataEl = document.createElement ('div'); |
271 |
|
|
helpDataEl.innerHTML = '<p>There is no help for this item available.'; |
272 |
|
|
} |
273 |
|
|
} |
274 |
|
|
|
275 |
|
|
if (id != 'help-not-available' && |
276 |
|
|
helpDataEl.getElementsByTagName ('p').length == 0) { |
277 |
|
|
_showHelp ('help-not-available', context); |
278 |
|
|
return; |
279 |
|
|
} |
280 |
|
|
|
281 |
|
|
var helpBox = document.createElement ('aside'); |
282 |
|
|
helpBox.className = 'help'; |
283 |
|
|
helpBox.innerHTML = helpDataEl.innerHTML; /* adoptNode + appendChild */ |
284 |
|
|
document.body.appendChild (helpBox); |
285 |
|
|
|
286 |
|
|
var vp = document.documentElement; |
287 |
|
|
if (vp.clientHeight < document.body.clientHeight) { |
288 |
|
|
vp = document.body; |
289 |
|
|
/* |
290 |
|
|
|vp| is the element that is associated with the viewport. |
291 |
|
|
In standard mode, the viewport element is the root element, i.e. |
292 |
|
|
the |document.documentElement|. However, in Opera 9, the viewport |
293 |
|
|
element is the |body| element. If the document element is not the |
294 |
|
|
viewport element, its |clientHeight| takes less value than that |
295 |
|
|
of the |body| element. (I don't know whether this is always true.) |
296 |
|
|
*/ |
297 |
|
|
} |
298 |
|
|
|
299 |
|
|
|
300 |
|
|
var left = context.x; |
301 |
|
|
var top = context.y; |
302 |
|
|
if (left > vp.clientWidth * 0.5) { |
303 |
|
|
helpBox.style.left = '45%'; |
304 |
|
|
} else if (left < 10) { |
305 |
|
|
helpBox.style.left = '10px'; |
306 |
|
|
} else { |
307 |
|
|
helpBox.style.left = left + 'px'; |
308 |
|
|
} |
309 |
|
|
if (top > vp.clientHeight - 100) { |
310 |
|
|
helpBox.style.bottom = '10px'; |
311 |
|
|
} else if (top < 10) { |
312 |
|
|
helpBox.style.top = '10px'; |
313 |
|
|
} else { |
314 |
|
|
helpBox.style.top = top + 'px'; |
315 |
|
|
} |
316 |
|
|
|
317 |
|
|
if (helpBox.offsetTop + helpBox.clientHeight > vp.clientHeight) { |
318 |
|
|
helpBox.style.top = '50%'; |
319 |
|
|
helpBox.style.bottom = '10px'; |
320 |
|
|
} |
321 |
|
|
} // _showHelp |
322 |
|
|
|
323 |
|
|
function removeHelps () { |
324 |
|
|
var asides = document.getElementsByTagName ('aside'); |
325 |
|
|
while (asides.length > 0) { |
326 |
|
|
var aside = asides[0]; |
327 |
|
|
aside.parentNode.removeChild (aside); |
328 |
|
|
} |
329 |
|
|
} // removeHelps |
330 |
wakaba |
1.6 |
|
331 |
|
|
function onbodyclick (ev) { |
332 |
wakaba |
1.11 |
var aels = getAncestorElements (ev.target || ev.srcElement); |
333 |
|
|
|
334 |
|
|
if (!aels.aside) { |
335 |
|
|
removeHelps (); |
336 |
|
|
} |
337 |
|
|
|
338 |
|
|
if (aels.a) { |
339 |
|
|
var href = aels.a.getAttribute ('href'); |
340 |
|
|
if (href) { |
341 |
|
|
var m; |
342 |
|
|
if (href.match (/^#/)) { |
343 |
|
|
var id = decodeURIComponent (href.substring (1)); |
344 |
|
|
showTab (id); |
345 |
|
|
return true; |
346 |
|
|
} else if ((aels.a.rel == 'help' /* relList.has ('help') */) && |
347 |
|
|
(m = href.match (/#(.+)$/) /* aels.a.hash, in fact... */)) { |
348 |
|
|
var id = decodeURIComponent (m[1]); |
349 |
|
|
showHelp (id, {x: ev.clientX, y: ev.clientY}); |
350 |
|
|
return false; |
351 |
|
|
} else if (href.match (/^.\/#/)) { |
352 |
|
|
var id = decodeURIComponent (href.substring (3)); |
353 |
|
|
showTab (id); |
354 |
|
|
if (aels.aInAside) { |
355 |
|
|
removeHelps (); |
356 |
|
|
} |
357 |
|
|
return true; |
358 |
|
|
} |
359 |
wakaba |
1.6 |
} |
360 |
|
|
} |
361 |
wakaba |
1.11 |
|
362 |
wakaba |
1.6 |
return true; |
363 |
|
|
} // onbodyclick |
364 |
|
|
|
365 |
|
|
function onbodyload () { |
366 |
|
|
// This block should be executed at the end of initialization process, |
367 |
|
|
// since |decodeURIComponent| might throw. |
368 |
|
|
if (!document.webhaccNavigated) { |
369 |
|
|
var fragment = location.hash; |
370 |
|
|
if (fragment) { |
371 |
|
|
var id = decodeURIComponent (fragment.substring (1)); |
372 |
|
|
showTab (id); |
373 |
wakaba |
1.8 |
var el = document.getElementById (id); |
374 |
|
|
if (el) el.scrollIntoView (); |
375 |
wakaba |
1.6 |
} else if (document.webhaccSections['result-summary']) { |
376 |
|
|
showTab ('result-summary'); |
377 |
|
|
} else { |
378 |
|
|
showTab ('input'); |
379 |
|
|
} |
380 |
|
|
} |
381 |
|
|
} // onbodyload |
382 |
|
|
|
383 |
wakaba |
1.12 |
// $Date: 2008/08/16 13:09:08 $ |