/[suikacvs]/test/html-webhacc/cc-script.js
Suika

Contents of /test/html-webhacc/cc-script.js

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.9 - (show annotations) (download) (as text)
Fri Aug 15 16:44:03 2008 UTC (16 years, 3 months ago) by wakaba
Branch: MAIN
Changes since 1.8: +2 -1 lines
File MIME type: application/javascript
++ ChangeLog	15 Aug 2008 16:43:11 -0000
	* cc-script.js (_showTab): Show the tab button of the selected
	tab.

	* cc-script.css (nav): Show scrollbar if there are too many
	tabs.

	* cc.cgi: Reset |$output->input| even if |$input->{s}| is undef (i.e.
	imlementation error case).

2008-08-16  Wakaba  <wakaba@suika.fam.cx>

++ html/WebHACC/ChangeLog	15 Aug 2008 16:43:58 -0000
	* Output.pm (start_section): Don't add item to the non-tab
	navigation menu if the item's rank is higher than 2.

2008-08-16  Wakaba  <wakaba@suika.fam.cx>

1 function addSourceToParseErrorList (idPrefix, dlId) {
2 var parseErrorsList = document.getElementById
3 (idPrefix + dlId);
4 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 line = parseInt (child.getAttribute ('data-line') || 0);
14 column = parseInt (child.getAttribute ('data-column') || 0);
15 } 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 .replace (/<var>U\+([0-9A-F]{4})<\/var>/g, function (s) {
21 return String.fromCharCode (parseInt (s, 16));
22 })
23 .replace (/&lt;/g, '<')
24 .replace (/&gt;/g, '>')
25 .replace (/&nbsp;/g, '\u00A0')
26 .replace (/&quot;/g, '"')
27 .replace (/&amp;/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 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 p.appendChild (code);
77 }
78 child.appendChild (p);
79 }
80 }
81 line = 0;
82 column = 0;
83 }
84 }
85 } // addSourceToParseErrorList
86
87 function insertNavSections (parentId) {
88 parentId = parentId || '';
89 var el = document.createElement ('nav');
90 el.id = parentId + 'nav-sections';
91 el.innerHTML = '<ul></ul>';
92
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 } // insertNavSections
103
104 function addSectionLink (id, label, parentId) {
105 parentId = parentId || '';
106
107 var el = document.createElement ('li');
108 el.innerHTML = '<a></a>';
109 el.firstChild.href = '#' + id;
110 el.firstChild.innerHTML = label;
111 document.getElementById (parentId + 'nav-sections')
112 .firstChild.appendChild (el);
113
114 var sections = document.webhaccSections;
115 if (parentId != '') {
116 sections = document.getElementById (parentId).webhaccSections;
117 }
118 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 } else if (id == 'document-info' && !document.webhaccNavigated) {
125 showTab (id);
126 document.webhaccNavigated = false;
127 } else if (id.match (/-document-info$/)) {
128 sections[id].tabElement.setAttribute ('data-active', '');
129 } else {
130 sections[id].style.display = 'none';
131 }
132 } // addSectionLink
133
134 function showTab (id) {
135 var ids = [];
136 if (id.match (/^line-/)) {
137 ids = ['source-string'];
138 } else if (id.match (/^node-/)) {
139 ids = ['document-tree'];
140 } else if (id.match (/^subdoc-[^-]+-/)) {
141 var m;
142 ids = [''];
143 while (true) {
144 if (m = id.match (/^subdoc-[^-]+-/)) {
145 ids.push (ids[ids.length - 1] + m[0]);
146 id = id.substring (m[0].length);
147 } else {
148 break;
149 }
150 }
151 if (id.length > 0) {
152 if (id.match (/^line-/)) {
153 ids.push (ids[ids.length - 1] + 'source-string');
154 } else if (id.match (/^node-/)) {
155 ids.push (ids[ids.length - 1] + 'document-tree');
156 } else {
157 ids.push (ids[ids.length - 1] + id);
158 }
159 }
160 ids.shift (); // ''
161 } else if (id.match (/^input-/)) {
162 ids = ['input', id];
163 } else {
164 ids = [id];
165 }
166
167 var sections = document.webhaccSections;
168 while (ids.length > 0) {
169 var myid = ids.shift ();
170 _showTab (sections, myid);
171 sections = sections[myid].webhaccSections;
172 if (!sections) break;
173 }
174 } // showTab
175
176 function _showTab (sections, id) {
177 if (sections[id]) {
178 for (var i in sections) {
179 sections[i].style.display = 'none';
180 sections[i].tabElement.removeAttribute ('data-active');
181 }
182 sections[id].style.display = 'block';
183 sections[id].tabElement.setAttribute ('data-active', '');
184 sections[id].tabElement.scrollIntoView ();
185
186 document.webhaccNavigated = true;
187 }
188 } // _showTab
189
190 function getAncestorAnchorElement (e) {
191 do {
192 if (e.nodeName == 'A' || e.nodeName == 'AREA') {
193 return e;
194 }
195 e = e.parentNode;
196 } while (e);
197 } // getAncestorAnchorElement
198
199 function onbodyclick (ev) {
200 var a = getAncestorAnchorElement (ev.target || ev.srcElement);
201 if (a) {
202 var href = a.getAttribute ('href');
203 if (href && href.match (/^#/)) {
204 var id = decodeURIComponent (href.substring (1));
205 showTab (id);
206 return true;
207 }
208 }
209 return true;
210 } // onbodyclick
211
212 function onbodyload () {
213 // This block should be executed at the end of initialization process,
214 // since |decodeURIComponent| might throw.
215 if (!document.webhaccNavigated) {
216 var fragment = location.hash;
217 if (fragment) {
218 var id = decodeURIComponent (fragment.substring (1));
219 showTab (id);
220 var el = document.getElementById (id);
221 if (el) el.scrollIntoView ();
222 } else if (document.webhaccSections['result-summary']) {
223 showTab ('result-summary');
224 } else {
225 showTab ('input');
226 }
227 }
228 } // onbodyload
229
230 // $Date: 2008/08/14 09:16:52 $

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24