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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.4 by wakaba, Mon Mar 17 13:25:19 2008 UTC revision 1.11 by wakaba, Sat Aug 16 13:09:08 2008 UTC
# Line 10  function addSourceToParseErrorList (idPr Line 10  function addSourceToParseErrorList (idPr
10      var child = childs[i];      var child = childs[i];
11      if (child.nodeType != 1) continue;      if (child.nodeType != 1) continue;
12      if (child.nodeName == 'DT') {      if (child.nodeName == 'DT') {
13        var text = child.textContent || child.innerText;        line = parseInt (child.getAttribute ('data-line') || 0);
14        var m;        column = parseInt (child.getAttribute ('data-column') || 0);
       if (m = text.match (/Line (\d+)(?: column (\d+))?/)) {  
         line = parseInt (m[1]);  
         column = parseInt (m[2] || 0);  
       } else {  
         line = 0;  
         column = 0;  
       }  
15      } else if (child.nodeName == 'DD') {      } else if (child.nodeName == 'DD') {
16        if (line > 0) {        if (line > 0) {
17          var lineEl = document.getElementById (idPrefix + 'line-' + line);          var lineEl = document.getElementById (idPrefix + 'line-' + line);
# Line 91  function addSourceToParseErrorList (idPr Line 84  function addSourceToParseErrorList (idPr
84    }    }
85  } // addSourceToParseErrorList  } // 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 (/^index-/)) {
141        ids = ['document-structure'];
142      } 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          } else if (id.match (/^index-/)) {
159            ids.push (ids[ids.length - 1] + 'document-structure');
160          } 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      }
170    
171      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      }
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        }
186        sections[id].style.display = 'block';
187        sections[id].tabElement.setAttribute ('data-active', '');
188        sections[id].tabElement.scrollIntoView ();
189    
190        document.webhaccNavigated = true;
191      }
192    } // _showTab
193    
194    function getAncestorElements (e) {
195      var ret = {};
196      do {
197        if (e.nodeName == 'A' || e.nodeName == 'AREA') {
198          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        }
209        e = e.parentNode;
210      } while (e);
211      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      var iframecode = function () {
231        var doc;
232        var docel;
233        try {
234          doc = iframe.contentWindow.document;
235          docel = doc.getElementById ('error-description');
236        } catch (e) { }
237        if (docel) {
238          document.webhaccHelp = doc;
239          code ();
240        } else if (url != '../error-description.en.html.u8') {
241          // doc would be a 406 error.
242          loadHelp ('../error-description.en.html.u8', code);
243          iframe.parentNode.removeChild (iframe);
244          /*
245            |iframe| is removed from the document after another |iframe|
246            is inserted by nested |loadHelp| call, otherwise Safari 3
247            would reuse(?) removed |iframe| and it sometimes (not always)
248            requests old URL even when another URL is set to the |src| attribute.
249          */
250        }
251        iframe.onreadystatechange = null;
252        iframe.onload = null;
253      };
254      iframe.onreadystatechange = function () {
255        if (this.readyState == 'complete') {
256          iframecode ();
257        }
258      };
259      iframe.onload = iframecode;
260      iframe.src = url;
261      document.body.appendChild (iframe);
262    } // loadHelp
263    
264    function _showHelp (id, context) {
265      var helpDataEl = document.webhaccHelp.getElementById (id);
266      if (!helpDataEl) {
267        helpDataEl = document.webhaccHelp.getElementById ('help-not-available');
268        if (!helpDataEl) {
269          helpDataEl = document.createElement ('div');
270          helpDataEl.innerHTML = '<p>There is no help for this item available.';
271        }
272      }
273    
274      if (id != 'help-not-available' &&
275          helpDataEl.getElementsByTagName ('p').length == 0) {
276        _showHelp ('help-not-available', context);
277        return;
278      }
279    
280      var helpBox = document.createElement ('aside');
281      helpBox.className = 'help';
282      helpBox.innerHTML = helpDataEl.innerHTML; /* adoptNode + appendChild */
283      document.body.appendChild (helpBox);
284    
285      var vp = document.documentElement;
286      if (vp.clientHeight < document.body.clientHeight) {
287        vp = document.body;
288        /*
289          |vp| is the element that is associated with the viewport.
290          In standard mode, the viewport element is the root element, i.e.
291          the |document.documentElement|.  However, in Opera 9, the viewport
292          element is the |body| element.  If the document element is not the
293          viewport element, its |clientHeight| takes less value than that
294          of the |body| element.  (I don't know whether this is always true.)
295        */
296      }
297    
298    
299      var left = context.x;
300      var top = context.y;
301      if (left > vp.clientWidth * 0.5) {
302        helpBox.style.left = '45%';
303      } else if (left < 10) {
304        helpBox.style.left = '10px';
305      } else {
306        helpBox.style.left = left + 'px';
307      }
308      if (top > vp.clientHeight - 100) {
309        helpBox.style.bottom = '10px';
310      } else if (top < 10) {
311        helpBox.style.top = '10px';
312      } else {
313        helpBox.style.top = top + 'px';
314      }
315    
316      if (helpBox.offsetTop + helpBox.clientHeight > vp.clientHeight) {
317        helpBox.style.top = '50%';
318        helpBox.style.bottom = '10px';
319      }
320    } // _showHelp
321    
322    function removeHelps () {
323      var asides = document.getElementsByTagName ('aside');
324      while (asides.length > 0) {
325        var aside = asides[0];
326        aside.parentNode.removeChild (aside);
327      }
328    } // removeHelps
329    
330    function onbodyclick (ev) {
331      var aels = getAncestorElements (ev.target || ev.srcElement);
332    
333      if (!aels.aside) {
334        removeHelps ();
335      }
336    
337      if (aels.a) {
338        var href = aels.a.getAttribute ('href');
339        if (href) {
340          var m;
341          if (href.match (/^#/)) {
342            var id = decodeURIComponent (href.substring (1));
343            showTab (id);
344            return true;
345          } else if ((aels.a.rel == 'help' /* relList.has ('help') */) &&
346                     (m = href.match (/#(.+)$/) /* aels.a.hash, in fact... */)) {
347            var id = decodeURIComponent (m[1]);
348            showHelp (id, {x: ev.clientX, y: ev.clientY});
349            return false;
350          } else if (href.match (/^.\/#/)) {
351            var id = decodeURIComponent (href.substring (3));
352            showTab (id);
353            if (aels.aInAside) {
354              removeHelps ();
355            }
356            return true;
357          }
358        }
359      }
360    
361      return true;
362    } // onbodyclick
363    
364    function onbodyload () {
365      // This block should be executed at the end of initialization process,
366      // since |decodeURIComponent| might throw.
367      if (!document.webhaccNavigated) {
368        var fragment = location.hash;
369        if (fragment) {
370          var id = decodeURIComponent (fragment.substring (1));
371          showTab (id);
372          var el = document.getElementById (id);
373          if (el) el.scrollIntoView ();
374        } else if (document.webhaccSections['result-summary']) {
375          showTab ('result-summary');
376        } else {
377          showTab ('input');
378        }
379      }
380    } // onbodyload
381    
382  // $Date$  // $Date$

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.11

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24