]> git.mxchange.org Git - hub-docs.git/blob - mindmaps/Peer-State Rating.html_files/marktree.js
Fixed all getSelfInstance
[hub-docs.git] / mindmaps / Peer-State Rating.html_files / marktree.js
1 /* MarkTree JavaScript code
2  * 
3  * The contents of this file are subject to the Mozilla Public License Version
4  * 1.1 (the "License"); you may not use this file except in compliance with
5  * the License. You may obtain a copy of the License at
6  * http://www.mozilla.org/MPL/
7  *
8  * Software distributed under the License is distributed on an "AS IS" basis,
9  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
10  * for the specific language governing rights and limitations under the
11  * License.
12  * 
13  * Miika Nurminen, 12.7.2004.
14  */
15
16 /* cross-browser (tested with ie5, mozilla 1 and opera 5) keypress detection */
17 function get_keycode(evt) {
18   // IE
19     code = document.layers ? evt.which
20            : document.all ? event.keyCode // event.keyCode!=evt.keyCode!
21            : evt.keyCode;
22
23   if (code==0) 
24     code=evt.which; // for NS
25   return code;
26 }
27
28 var lastnode=null;
29 var listnodes = null;
30 var list_index=1;
31 var lastnodetype=''; // determines if node is a link, input or text;
32
33 // up, left, down, right, keypress codes
34 //ijkl
35 //var keys = new Array(105,106,107,108);
36 //num arrows
37 //var keys = new Array(56,52,50,54);
38 //wasd
39 // var press2 = new Array(119,97,115,100);
40  var press = new Array(47,45,42,43);
41
42 // keydown codes
43   //  var keys2=new Array(87,65,83,68);
44   var keys= new Array(38,37,40,39);
45
46   // keyset 1 = keydown, otherwise press
47 function checkup(keyset,n) {
48   if (keyset==1) return (n==keys[0]);
49   return ((n==press[0]) /*|| (n==press2[0])*/)
50 }
51
52 function checkdn(keyset,n) {
53   if (keyset==1) return (n==keys[2]);
54   return ((n==press[2]) /*|| (n==press2[2])*/)
55 }
56
57 function checkl(keyset,n) {
58   if (keyset==1) return (n==keys[1]);
59   return ((n==press[1]) /*|| (n==press2[1])*/)
60 }
61
62 function checkr(keyset,n) {
63   if (keyset==1) return (n==keys[3]);
64   return ((n==press[3]) /*|| (n==press2[3])*/)
65 }
66
67
68
69
70
71 function is_exp(n) {
72   if (n==null) return false;
73   return ((n.className=='exp') || (n.className=='exp_active'));
74 }
75
76 function is_col(n) {
77   if (n==null) return false;
78   return ((n.className=='col') || (n.className=='col_active'));
79 }
80
81 function is_basic(n) {
82   if (n==null) return false;
83   return ((n.className=='basic') || (n.className=='basic_active'));
84 }
85
86
87
88 /* returns i>=0 if true */
89 function is_active(node) {
90   if (node.className==null) return false
91   return node.className.indexOf('_active');
92 }
93
94 function toggle_class(node) {
95   if ((node==null) || (node.className==null)) return;
96   str=node.className;
97   result="";
98   i = str.indexOf('_active');
99   if (i>0)
100     result= str.substr(0,i);
101   else
102     result= str+"_active";
103   node.className=result; 
104   return node;
105 }
106
107 function activate(node) {
108   node.style.backgroundColor='#eeeeff';
109 }
110
111 function deactivate(node) {
112    node.style.backgroundColor='#ffffff';
113 }
114
115 function is_list_node(n) {
116   if (n==null) return false;
117   if (n.className==null) return false;
118   if ( (is_exp(n)) || 
119        (is_col(n)) ||
120        (is_basic(n)) )
121    return true; else return false;
122 }
123
124
125 function get_href(n) {
126   alist=n.attributes;
127   if (alist!=null) {
128     hr = alist.getNamedItem('href');
129     if (hr!=null) return hr.nodeValue;
130   }
131   if (n.childNodes.length==0) return '';
132   for (var i=0; i<n.childNodes.length; i++) {
133     s = get_href(n.childNodes[i]);
134     if (s!='') return s;
135   }
136   return '';
137 }
138
139 function get_link(n) {
140   if (n==null) return null;
141   if (n.style==null) return null;
142
143  // disabling uncontrolled recursion to prevent error messages on IE
144  // when trying to focus to invisible links (readonly mode)
145 //    alert(n.nodeName+' '+n.className);
146   if ((n.nodeName=='UL') && (n.className=='sub')) return null;
147
148   if (n.nodeName=='A') return n;
149   if (n.childNodes.length==0) return null;
150   for (var i=0; i<n.childNodes.length; i++) {
151     s = get_link(n.childNodes[i]);
152     if (s!=null) return s;
153   }
154   return null;
155 }
156
157 function set_lastnode(n) {
158 /*var d = new Date();
159 var t_mil = d.getMilliseconds();*/
160 // testattu nopeuksia explorerilla, ei merkittäviä eroja
161   if (lastnode==n) return; 
162 /*  deactivate(lastnode)
163   lastnode=n;
164   activate(lastnode);*/
165
166   if (is_active(lastnode)>=0)
167     toggle_class(lastnode);
168   lastnode=n;
169   if (!(is_active(lastnode)>=0))
170     toggle_class(lastnode);
171
172
173 /*var d2 = new Date();
174 var t_mil2 = d2.getMilliseconds();
175   window.alert(t_mil2-t_mil);*/
176 }
177
178 function next_list_node() {
179   tempIndex = list_index;
180   while (tempIndex<listnodes.length-1) {
181     tempIndex++;
182     var x = listnodes[tempIndex];
183     if (is_list_node(x)) {
184       list_index=tempIndex;
185       return;
186     }
187   }
188 }
189
190 function prev_list_node() {
191   tempIndex = list_index;
192   while (tempIndex>0) {
193     tempIndex--;
194     var x = listnodes[tempIndex];
195     if (is_list_node(x)) {
196       list_index=tempIndex;
197       return;
198     }
199   }
200 }
201
202
203
204 function getsub (li) {
205   if (li.childNodes.length==0) return null;
206   for (var c = 0; c < li.childNodes.length; c++)
207     if ( (li.childNodes[c].className == 'sub') || (li.childNodes[c].className == 'subexp') ) 
208       return li.childNodes[c];
209 }
210
211 function find_listnode_recursive (li) {
212   if (is_list_node(li)) return li; 
213   if (li.childNodes.length==0) return null;
214   result=null;
215   for (var c = 0; c < li.childNodes.length; c++) {
216     result=find_listnode_recursive(li.childNodes[c]);
217     if (result!=null) return result;
218   }
219   return null;
220 }
221
222 function next_child_listnode(li) {
223   var result=null;
224   for (var i=0; i<li.childNodes.length; i++) {
225     result=find_listnode_recursive(li.childNodes[i]);
226     if (result!=null) return result;
227   }
228   return null;  
229 }
230
231 function next_actual_sibling_listnode(li) {
232   if (li==null) return null;
233   var temp=li;
234   while (1) { 
235     var n = temp.nextSibling;
236     if (n==null) {
237       n=parent_listnode(temp);
238       return next_actual_sibling_listnode(n);
239     }
240     if (is_list_node(n)) return n;
241     temp=n;
242   }
243 }
244
245 function next_sibling_listnode(li) {
246 if (li==null) return null; 
247  var result=null;
248   var temp=li;
249   if (is_col(temp)) return next_child_listnode(temp);
250   while (1) { 
251     var n = temp.nextSibling;
252     if (n==null) {
253       n=parent_listnode(temp);
254       return next_actual_sibling_listnode(n);
255     }
256     if (is_list_node(n)) return n;
257     temp=n;
258   }
259 }
260
261 function last_sibling_listnode(li) {
262   if (li==null) return null;
263   var temp=li;
264   var last=null;
265   while(1) {
266     var n = temp.nextSibling;
267     if (is_list_node(temp)) 
268       last = temp;
269     if (n==null) {
270       if (is_col(last)) return last_sibling_listnode(next_child_listnode(last));
271       else return last;
272     }
273     temp = n;
274   }
275 }
276
277 function prev_sibling_listnode(li) { 
278   if (li==null) return null;
279   var temp=li;
280   var n = null;
281   while (1) { 
282     n = temp.previousSibling;
283     if (n==null) {
284       return parent_listnode(li);
285     }
286     if (is_list_node(n)) {
287       if (is_col(n)) { 
288         return last_sibling_listnode(next_child_listnode(n));
289       }
290       else {
291         return n;
292       }
293     }
294     temp=n;
295   }
296 }
297
298
299 function parent_listnode(li) {
300   // added 12.7.2004 to prevent IE error when readonly mode==true
301   if (li==null) return null;
302   n=li;
303   while (1) {
304     n=n.parentNode;
305     if (n==null) return null;
306     if (is_list_node(n)) return n;
307   }
308 }
309
310 function getVisibleParents(id) {
311   var n = document.getElementById(id);
312   while(1) {
313     expand(n);
314     n = parent_listnode(n);
315     if (n==null) return;
316   }
317 }
318
319 function onClickHandler (evt) {
320 if (lastnode==null) 
321 {
322 listnodes = document.getElementsByTagName('li');
323 lastnode=listnodes[1];
324 temp=listnodes[1];
325 }
326
327
328   var target = evt ? evt.target : event.srcElement;
329   if (!is_list_node(target)) return;
330   toggle(target);
331   set_lastnode(target);
332 }
333
334
335 function expand(node) {
336     if (!is_exp(node)) return;
337     if (node.className=='exp_active') 
338       node.className='col_active';
339     else 
340         node.className='col';
341     setSubClass(node,'subexp');
342     //    getsub(node).className='subexp';
343 }
344
345 function collapse(node) {
346   if (!is_col(node)) return;
347   
348 if (node.className=='col_active')
349     node.className='exp_active'
350   else 
351     node.className='exp';
352
353  setSubClass(node,'sub');
354 //  getsub(node).className='sub';
355
356 }
357
358 function setSubClass(node,name) {
359   sub = getsub(node);
360   if (sub==null) return;
361   sub.className=name;  
362 }
363
364 function toggle(target) {
365   if (!is_list_node(target)) return;
366     if (is_col(target)) {
367       target.className='exp';
368       setSubClass(target,'sub');
369       //      getsub(target).className='sub';
370     }
371     else if (is_exp(target)) {
372       target.className='col';
373       setSubClass(target,'subexp');
374       //      getsub(target).className='subexp';
375     }
376  
377 }
378
379 function expandAll(node) {
380     if (node.className=='exp') {
381         node.className='col';
382         setSubClass(node,'subexp');
383 //        getsub(node).className='subexp';
384     }
385     var i;
386     if (node.childNodes!=null) 
387 //    if (node.hasChildNodes()) 
388         for ( i = 0; i<node.childNodes.length; i++)
389             expandAll(node.childNodes[i]);
390 }
391
392 function collapseAll(node) {
393     if  (node.className=='col') {
394         node.className='exp';
395         setSubClass(node,'sub');
396 //        getsub(node).className='sub';
397     }
398     var i;        
399     if (node.childNodes!=null) 
400 // for opera   if (node.hasChildNodes()) 
401         for ( i = 0; i<node.childNodes.length; i++)
402             collapseAll(node.childNodes[i]);
403 }
404
405
406
407 function unFocus(node) {
408      // unfocuses potential link that is to be hidden (if a==null there is no link so it should not be blurred).
409      // tested with mozilla 1.7, 12.7.2004. /mn (
410       intemp=parent_listnode(node);  
411       a = get_link(intemp);     // added 6.4. to get keyboard working with
412       // moved before collapse to prevent an error message with IE when readonly==true      
413       if (a!=null) a.blur(); // netscape after collapsing a focused node
414       return intemp;
415 }
416
417 // mode: 0==keypress, 1==keyup
418 function keyfunc(evt,mode) {
419  var c = get_keycode(evt);
420  var temp = null;
421  var a = null;
422
423   if (lastnode==null) {
424     listnodes = document.getElementsByTagName('li');
425     lastnode=listnodes[1];
426     temp=listnodes[1];
427   }
428
429   //window.alert(c);
430   if (checkup(mode,c)) { // i 
431    temp=prev_sibling_listnode(lastnode);
432   }
433   else if (checkdn(mode,c)) { // k
434     temp=next_sibling_listnode(lastnode);
435   }
436   else if (checkr(mode,c)) { // l
437     expand(lastnode);
438     //  temp=next_child_listnode(lastnode);
439     // if (temp==null) {
440       a = get_link(lastnode);
441         if (a!=null) a.focus(); else self.focus(); 
442       //}
443   }
444   else if (checkl(mode,c)) { // j
445     if (is_col(lastnode)) {
446       unFocus(lastnode);
447       collapse(lastnode);
448     }
449     else {
450       temp=unFocus(lastnode);
451       collapse(temp);
452     }
453    //    if (temp==null) lastnode.focus(); // forces focus to correct div (try mozilla typesearch) (doesn't seem to work -mn/6.4.2004)
454   }
455   else return;
456   if (temp!=null) set_lastnode(temp);
457
458   // alert('pressed ' + String.fromCharCode(c) + '(' + c + ')');
459   return true;
460 }
461
462
463 function keytest (evt) {
464   return keyfunc(evt,1);
465 };
466
467
468 function presstest (evt) {
469   return keyfunc(evt,0);
470 };
471
472
473   document.onclick = onClickHandler;
474   document.onkeypress = presstest;
475   document.onkeyup = keytest;