2 // © Copyright 2006 Lennart Borgman, http://www.OurComments.org/. All rights reserved.
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License as
6 // published by the Free Software Foundation; either version 3, or (at
7 // your option) any later version.
9 // This program is distributed in the hope that it will be useful, but
10 // WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; see the file COPYING. If not, write to
16 // the Free Software Foundation, Inc., 51 Franklin Street, Fifth
17 // Floor, Boston, MA 02110-1301, USA.
20 var HTML_WTOC_NS_sCurrTocId;
25 /////////////////////////////
26 //// Basic event functions
27 /////////////////////////////
29 getEventObject : function (ev) {
32 o = window.event.srcElement;
37 getEvent : function (ev) {
40 } else if (null != ev) {
45 eventStopPropagation : function (e) {
46 if (e.stopPropagation)
52 eventPreventDefault : function (e) {
59 /////////////////////////////
61 /////////////////////////////
63 show_content : function (on) {
64 var toc = document.getElementById("html-wtoc-id-toccol").style;
65 var tdv = document.getElementById("html-wtoc-id-tocdiv").style;
66 var shw = document.getElementById("html-wtoc-id-showtoc").style;
67 var hid = document.getElementById("html-wtoc-id-hidetoc").style;
73 HTML_WTOC_NS.focus_page_link(0);
86 /////////////////////////////
88 /////////////////////////////
89 onblur_action : function(ev) {
90 HTML_WTOC_NS_sCurrTocId = null;
92 onfocus_action : function(ev) {
93 var o = HTML_WTOC_NS.getEventObject(ev);
96 HTML_WTOC_NS_sCurrTocId = o.id;
98 onclick_action : function(ev) {
99 var o = HTML_WTOC_NS.getEventObject(ev);
100 var e = HTML_WTOC_NS.getEvent(ev);
101 if (13 == e.keyCode) return true;
103 if ("IMG" == o.tagName) o = o.parentNode;
104 var iId = HTML_WTOC_NS.getIdnumFromId(o.id);
105 var sChildId = "toc_child_"+iId;
106 var sOldCurrTocId = HTML_WTOC_NS_sCurrTocId;
107 HTML_WTOC_NS.toggle_open(sChildId, o);
108 HTML_WTOC_NS_sCurrTocId = sOldCurrTocId;
112 toggle_open : function (id, parent) {
113 var child = document.getElementById(id).style;
114 var sInner = parent.innerHTML;
115 var re = new RegExp("[^/]*\.gif", "i");
116 if ("none" == child.display) {
118 parent.innerHTML = sInner.replace(re, "down.gif")+"";
120 child.display = "none";
121 parent.innerHTML = sInner.replace(re, "right.gif")+"";
127 /////////////////////////////
129 /////////////////////////////
131 onload_actions : function (iPageNum) {
132 document.body.onkeydown = HTML_WTOC_NS.onkeydown_action;
133 document.body.onmouseover = HTML_WTOC_NS.onmouseover_action;
134 var aATags = document.getElementsByTagName("a");
135 for(var i = 0; i < aATags.length; i++) {
137 if (null != HTML_WTOC_NS.getIdnumFromId(o.id)) {
138 o.onfocus = HTML_WTOC_NS.onfocus_action;
139 o.onblur = HTML_WTOC_NS.onblur_action;
140 if (o.id.substr(0, 12) == "opener_text_") {
141 o.onclick = HTML_WTOC_NS.onclick_action;
142 o.title = "Open/Close";
143 } else if (o.id.substr(0, 7) == "opener_") {
144 o.onclick = HTML_WTOC_NS.onclick_action;
145 o.className = "html-wtoc-mark";
146 o.title = "Open/Close";
150 HTML_WTOC_NS.focus_page_link(iPageNum);
152 focus_page_link : function (iPageNum) {
153 // Element might be hidden
155 document.getElementById("toc_link_"+iPageNum).focus();
166 /////////////////////
168 /////////////////////
170 onmouseover_action : function (ev) {
171 if (null == HTML_WTOC_NS_sCurrTocId) return true;
172 var o = HTML_WTOC_NS.getEventObject(ev);
173 var iId = HTML_WTOC_NS.getIdnumFromId(o.id);
174 if (null == iId) return true;
180 /////////////////////
182 /////////////////////
184 onkeydown_action: function (ev) {
193 var keyOperaDown = 57386;
194 var keyOperaUp = 57385;
195 var keyOperaLeft = 57387;
196 var keyOperaRight = 57388;
197 var keyOperaF2 = 57346;
198 var keyOperaInsert = 57394;
200 var SwitchKey = keyInsert;
201 var SwitchKeyOpera = keyOperaInsert;
204 var e = HTML_WTOC_NS.getEvent(ev);
205 if (null == HTML_WTOC_NS_sCurrTocId) {
209 HTML_WTOC_NS.focus_page_link(0);
210 HTML_WTOC_NS.eventStopPropagation(e);
211 HTML_WTOC_NS.eventPreventDefault(e);
221 HTML_WTOC_NS.handle_leftright_keys(e);
222 HTML_WTOC_NS.eventStopPropagation(e);
223 HTML_WTOC_NS.eventPreventDefault(e);
235 if (null != HTML_WTOC_NS_sCurrTocId) {
236 var o = document.getElementById(HTML_WTOC_NS_sCurrTocId);
238 HTML_WTOC_NS_sCurrTocId = null;
240 HTML_WTOC_NS.eventStopPropagation(e);
241 HTML_WTOC_NS.eventPreventDefault(e);
248 oOpener = HTML_WTOC_NS.getNextVisOpener(HTML_WTOC_NS_sCurrTocId, bUp);
250 HTML_WTOC_NS.eventStopPropagation(e);
251 HTML_WTOC_NS.eventPreventDefault(e);
255 handle_leftright_keys: function (e) {
258 var keyOperaLeft = 57387;
259 var keyOperaRight = 57388;
260 var iId = HTML_WTOC_NS.getIdnumFromId(HTML_WTOC_NS_sCurrTocId);
261 if (null == iId) return;
262 var sId = "opener_" + iId;
263 var oOpener = document.getElementById(sId);
264 var sId = HTML_WTOC_NS_sCurrTocId; // It will be cleared before getNextVis
269 var oChild = document.getElementById("toc_child_"+iId);
270 if (null == oChild) {
272 bOpened = (oChild.style.display != "none");
278 bOpenAction = (null != bOpened) && (bOpened);
283 bOpenAction = (null != bOpened) && (!bOpened);
286 alert("bad key handling...");
290 HTML_WTOC_NS_sCurrTocId = sId;
292 var oPrev = HTML_WTOC_NS.getNextVisOpener(sId, bUp);
302 //////////////////////
304 //////////////////////
305 getNameFromId: function (sId) {
306 var re = new RegExp("(.*?_)(\\d+)", "i");
307 if (!re.test(sId)) return null;
308 var iId = sId.replace(re, "$1");
311 getIdnumFromId: function (sId) {
312 var re = new RegExp("(.*?_)(\\d+)", "i");
313 if (!re.test(sId)) return null;
314 var iId = sId.replace(re, "$2");
319 getNextVisOpener: function (sId, bUp, bTrace) {
320 if (bTrace) alert("getNextVisOpener("+sId+","+bUp+")");
321 var iId = HTML_WTOC_NS.getIdnumFromId(sId);
323 alert("getNextVisOpener err iId==null");
326 var sIdName = HTML_WTOC_NS.getNameFromId(sId);
327 if (null == sIdName) {
328 alert("getNextVisOpener err sIdName==null");
333 while (oOpener == null) {
334 if (bTrace) alert(iId);
335 if (iLoop++ > iMaxChildNum) { alert("Child num error"); return; }
341 if (iId > iMaxChildNum) { iId = 0; }
342 if (iId < 0) { iId = iMaxChildNum; }
344 oOpener = document.getElementById(s);
345 if (oOpener != null) {
346 if (bTrace) alert(oOpener.offsetLeft);
347 if (oOpener.style.display == "none") { // All
349 } else if (oOpener.offsetLeft < 0) { // IE
351 } else if (0 == oOpener.scrollWidth) { // Opera