/[suikacvs]/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.10 by wakaba, Sat Aug 16 07:42:20 2008 UTC revision 1.11 by wakaba, Sat Aug 16 13:09:08 2008 UTC
# Line 191  function _showTab (sections, id) { Line 191  function _showTab (sections, id) {
191    }    }
192  } // _showTab  } // _showTab
193    
194  function getAncestorAnchorElement (e) {  function getAncestorElements (e) {
195      var ret = {};
196    do {    do {
197      if (e.nodeName == 'A' || e.nodeName == 'AREA') {      if (e.nodeName == 'A' || e.nodeName == 'AREA') {
198        return e;        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;      e = e.parentNode;
210    } while (e);    } while (e);
211  } // getAncestorAnchorElement    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) {  function onbodyclick (ev) {
331    var a = getAncestorAnchorElement (ev.target || ev.srcElement);    var aels = getAncestorElements (ev.target || ev.srcElement);
332    if (a) {  
333      var href = a.getAttribute ('href');    if (!aels.aside) {
334      if (href && href.match (/^#/)) {      removeHelps ();
335        var id = decodeURIComponent (href.substring (1));    }
336        showTab (id);  
337        return true;    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;    return true;
362  } // onbodyclick  } // onbodyclick
363    

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24