| 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.6 |
function insertNavSections () { |
| 88 |
|
|
var el = document.createElement ('nav'); |
| 89 |
|
|
el.id = 'nav-sections'; |
| 90 |
|
|
el.innerHTML = '<ul></ul>'; |
| 91 |
|
|
document.body.appendChild (el); |
| 92 |
|
|
document.webhaccSections = {}; |
| 93 |
|
|
document.body.setAttribute ('data-scripted', ''); |
| 94 |
|
|
} // insertNavSections |
| 95 |
|
|
|
| 96 |
|
|
function addSectionLink (id, label) { |
| 97 |
|
|
var el = document.createElement ('li'); |
| 98 |
|
|
el.innerHTML = '<a></a>'; |
| 99 |
|
|
el.firstChild.href = '#' + id; |
| 100 |
|
|
el.firstChild.innerHTML = label; |
| 101 |
|
|
document.getElementById ('nav-sections').firstChild.appendChild (el); |
| 102 |
|
|
document.webhaccSections[id] = document.getElementById (id); |
| 103 |
|
|
document.webhaccSections[id].tabElement = el; |
| 104 |
|
|
if (id == 'input') { |
| 105 |
|
|
// |
| 106 |
|
|
} else if (id == 'document-info' && !document.webhaccNavigated) { |
| 107 |
|
|
showTab ('document-info'); |
| 108 |
|
|
document.webhaccNavigated = false; |
| 109 |
|
|
} else { |
| 110 |
|
|
document.webhaccSections[id].style.display = 'none'; |
| 111 |
|
|
} |
| 112 |
|
|
} // addSectionLink |
| 113 |
|
|
|
| 114 |
|
|
function showTab (id) { |
| 115 |
|
|
var m; |
| 116 |
|
|
if (id.match (/^line-/)) { |
| 117 |
|
|
id = 'source-string'; |
| 118 |
|
|
} else if (id.match (/^node-/)) { |
| 119 |
|
|
id = 'document-tree'; |
| 120 |
|
|
} else if (m = id.match (/^(subdoc-\d+-)/)) { |
| 121 |
|
|
id = m[1]; |
| 122 |
|
|
} |
| 123 |
|
|
|
| 124 |
|
|
if (document.webhaccSections[id]) { |
| 125 |
|
|
for (var i in document.webhaccSections) { |
| 126 |
|
|
document.webhaccSections[i].style.display = 'none'; |
| 127 |
|
|
document.webhaccSections[i].tabElement.removeAttribute ('data-active'); |
| 128 |
|
|
} |
| 129 |
|
|
document.webhaccSections[id].style.display = 'block'; |
| 130 |
|
|
document.webhaccSections[id].tabElement.setAttribute ('data-active', ''); |
| 131 |
|
|
|
| 132 |
|
|
document.webhaccNavigated = true; |
| 133 |
|
|
} |
| 134 |
|
|
|
| 135 |
|
|
} // showTab |
| 136 |
|
|
|
| 137 |
|
|
function getAncestorAnchorElement (e) { |
| 138 |
|
|
do { |
| 139 |
|
|
if (e.nodeName == 'A') { |
| 140 |
|
|
return e; |
| 141 |
|
|
} |
| 142 |
|
|
e = e.parentNode; |
| 143 |
|
|
} while (e); |
| 144 |
|
|
} // getAncestorAnchorElement |
| 145 |
|
|
|
| 146 |
|
|
function onbodyclick (ev) { |
| 147 |
|
|
var a = getAncestorAnchorElement (ev.target || ev.srcElement); |
| 148 |
|
|
if (a) { |
| 149 |
|
|
var href = a.getAttribute ('href'); |
| 150 |
|
|
if (href && href.match (/^#/)) { |
| 151 |
|
|
var id = decodeURIComponent (href.substring (1)); |
| 152 |
|
|
showTab (id); |
| 153 |
|
|
return true; |
| 154 |
|
|
} |
| 155 |
|
|
} |
| 156 |
|
|
return true; |
| 157 |
|
|
} // onbodyclick |
| 158 |
|
|
|
| 159 |
|
|
function onbodyload () { |
| 160 |
|
|
// This block should be executed at the end of initialization process, |
| 161 |
|
|
// since |decodeURIComponent| might throw. |
| 162 |
|
|
if (!document.webhaccNavigated) { |
| 163 |
|
|
var fragment = location.hash; |
| 164 |
|
|
if (fragment) { |
| 165 |
|
|
var id = decodeURIComponent (fragment.substring (1)); |
| 166 |
|
|
showTab (id); |
| 167 |
|
|
} else if (document.webhaccSections['result-summary']) { |
| 168 |
|
|
showTab ('result-summary'); |
| 169 |
|
|
} else { |
| 170 |
|
|
showTab ('input'); |
| 171 |
|
|
} |
| 172 |
|
|
} |
| 173 |
|
|
} // onbodyload |
| 174 |
|
|
|
| 175 |
|
|
// $Date: 2008/07/21 12:56:33 $ |