]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - docs/module-doc/treeview.js
Updated documentation to document Server::SendMode
[user/henk/code/inspircd.git] / docs / module-doc / treeview.js
1 //**************************************************************** 
2 // You are free to copy the "Folder-Tree" script as long as you  
3 // keep this copyright notice: 
4 // Script found in: http://www.geocities.com/Paris/LeftBank/2178/ 
5 // Author: Marcelino Alves Martins (martins@hks.com) December '97. 
6 //**************************************************************** 
7  
8 //Log of changes: 
9 //       17 Feb 98 - Fix initialization flashing problem with Netscape
10 //       
11 //       27 Jan 98 - Root folder starts open; support for USETEXTLINKS; 
12 //                   make the ftien4 a js file 
13 //       
14 // DvH:  Dec 2000 -  Made some minor changes to support external 
15 //                   references
16  
17 // Definition of class Folder 
18 // ***************************************************************** 
19  
20 function Folder(folderDescription, tagName, hreference) //constructor 
21
22   //constant data 
23   this.desc = folderDescription 
24   this.tagName = tagName
25   this.hreference = hreference 
26   this.id = -1   
27   this.navObj = 0  
28   this.iconImg = 0  
29   this.nodeImg = 0  
30   this.isLastNode = 0 
31  
32   //dynamic data 
33   this.isOpen = true 
34   this.iconSrc = "ftv2folderopen.png"   
35   this.children = new Array 
36   this.nChildren = 0 
37  
38   //methods 
39   this.initialize = initializeFolder 
40   this.setState = setStateFolder 
41   this.addChild = addChild 
42   this.createIndex = createEntryIndex 
43   this.hide = hideFolder 
44   this.display = display 
45   this.renderOb = drawFolder 
46   this.totalHeight = totalHeight 
47   this.subEntries = folderSubEntries 
48   this.outputLink = outputFolderLink 
49
50  
51 function setStateFolder(isOpen) 
52
53   var subEntries 
54   var totalHeight 
55   var fIt = 0 
56   var i=0 
57  
58   if (isOpen == this.isOpen) 
59     return 
60  
61   if (browserVersion == 2)  
62   { 
63     totalHeight = 0 
64     for (i=0; i < this.nChildren; i++) 
65       totalHeight = totalHeight + this.children[i].navObj.clip.height 
66       subEntries = this.subEntries() 
67     if (this.isOpen) 
68       totalHeight = 0 - totalHeight 
69     for (fIt = this.id + subEntries + 1; fIt < nEntries; fIt++) 
70       indexOfEntries[fIt].navObj.moveBy(0, totalHeight) 
71   }  
72   this.isOpen = isOpen 
73   propagateChangesInState(this) 
74
75  
76 function propagateChangesInState(folder) 
77 {   
78   var i=0 
79  
80   if (folder.isOpen) 
81   { 
82     if (folder.nodeImg) 
83       if (folder.isLastNode) 
84         folder.nodeImg.src = "ftv2mlastnode.png" 
85       else 
86           folder.nodeImg.src = "ftv2mnode.png" 
87     folder.iconImg.src = "ftv2folderopen.png" 
88     for (i=0; i<folder.nChildren; i++) 
89       folder.children[i].display() 
90   } 
91   else 
92   { 
93     if (folder.nodeImg) 
94       if (folder.isLastNode) 
95         folder.nodeImg.src = "ftv2plastnode.png" 
96       else 
97           folder.nodeImg.src = "ftv2pnode.png" 
98     folder.iconImg.src = "ftv2folderclosed.png" 
99     for (i=0; i<folder.nChildren; i++) 
100       folder.children[i].hide() 
101   }  
102
103  
104 function hideFolder() 
105
106   if (browserVersion == 1 || browserVersion == 3) { 
107     if (this.navObj.style.display == "none") 
108       return 
109     this.navObj.style.display = "none" 
110   } else { 
111     if (this.navObj.visibility == "hidden") 
112       return 
113     this.navObj.visibility = "hidden" 
114   } 
115    
116   this.setState(0) 
117
118  
119 function initializeFolder(level, lastNode, leftSide) 
120
121 var j=0 
122 var i=0 
123 var numberOfFolders 
124 var numberOfDocs 
125 var nc 
126       
127   nc = this.nChildren 
128    
129   this.createIndex() 
130  
131   var auxEv = "" 
132  
133   if (browserVersion > 0) 
134     auxEv = "<a href='javascript:clickOnNode("+this.id+")'>" 
135   else 
136     auxEv = "<a>" 
137  
138   if (level>0) 
139     if (lastNode) //the last 'brother' in the children array 
140     { 
141       this.renderOb(leftSide + auxEv + "<img name='nodeIcon" + this.id + "' src='ftv2mlastnode.png' width=16 height=22 border=0></a>") 
142       leftSide = leftSide + "<img src='ftv2blank.png' width=16 height=22>"  
143       this.isLastNode = 1 
144     } 
145     else 
146     { 
147       this.renderOb(leftSide + auxEv + "<img name='nodeIcon" + this.id + "' src='ftv2mnode.png' width=16 height=22 border=0></a>") 
148       leftSide = leftSide + "<img src='ftv2vertline.png' width=16 height=22>" 
149       this.isLastNode = 0 
150     } 
151   else 
152     this.renderOb("") 
153    
154   if (nc > 0) 
155   { 
156     level = level + 1 
157     for (i=0 ; i < this.nChildren; i++)  
158     { 
159       if (i == this.nChildren-1) 
160         this.children[i].initialize(level, 1, leftSide) 
161       else 
162         this.children[i].initialize(level, 0, leftSide) 
163       } 
164   } 
165
166  
167 function drawFolder(leftSide) 
168
169   if (browserVersion == 2) { 
170     if (!doc.yPos) 
171       doc.yPos=8 
172     doc.write("<layer id='folder" + this.id + "' top=" + doc.yPos + " visibility=hidden>") 
173   } 
174   if (browserVersion == 3) 
175   {
176     doc.write("<div id='folder" + this.id + "' style='visibility:hide;'>") 
177   }
178    
179   doc.write("\n<table ") 
180   if (browserVersion == 1) 
181     doc.write(" id='folder" + this.id + "' style='position:block;' ") 
182   doc.write(" border=0 cellspacing=0 cellpadding=0>") 
183   doc.write("\n<tr><td>") 
184   doc.write(leftSide) 
185   this.outputLink() 
186   doc.write("<img name='folderIcon" + this.id + "' ") 
187   doc.write("src='" + this.iconSrc+"' border=0></a>") 
188   doc.write("</td>\n<td valign=middle nowrap>") 
189   if (USETEXTLINKS) 
190   { 
191     this.outputLink() 
192     doc.write(this.desc + "</a>") 
193   } 
194   else 
195     doc.write(this.desc) 
196   if (this.tagName!="")
197   {
198     doc.write(" [external]")
199   }
200   doc.write("</td>")  
201   doc.write("\n</table>\n") 
202    
203   if (browserVersion == 2) { 
204     doc.write("</layer>") 
205   } 
206   if (browserVersion == 3) { 
207     doc.write("</div>") 
208   } 
209  
210   if (browserVersion == 1) { 
211     this.navObj = doc.all["folder"+this.id] 
212     this.iconImg = doc.all["folderIcon"+this.id] 
213     this.nodeImg = doc.all["nodeIcon"+this.id] 
214   } else if (browserVersion == 2) { 
215     this.navObj = doc.layers["folder"+this.id] 
216     this.iconImg = this.navObj.document.images["folderIcon"+this.id] 
217     this.nodeImg = this.navObj.document.images["nodeIcon"+this.id] 
218     doc.yPos=doc.yPos+this.navObj.clip.height 
219   } else if (browserVersion == 3) {
220     this.navObj = doc.getElementById("folder"+this.id)
221     this.iconImg = doc.images.namedItem("folderIcon"+this.id)
222     this.nodeImg = doc.images.namedItem("nodeIcon"+this.id)
223   }
224
225  
226 function outputFolderLink() 
227
228   if (this.hreference) 
229   { 
230     doc.write("<a ")
231     if (this.tagName)
232     {
233       doc.write("doxygen='" + this.tagName + "' ");
234     }
235     doc.write("href='" + this.hreference + "' TARGET=\"basefrm\" ") 
236     if (browserVersion > 0) 
237       doc.write("onClick='javascript:clickOnFolder("+this.id+")'") 
238     doc.write(">") 
239   } 
240   else 
241     doc.write("<a>") 
242
243  
244 function addChild(childNode) 
245
246   this.children[this.nChildren] = childNode 
247   this.nChildren++ 
248   return childNode 
249
250  
251 function folderSubEntries() 
252
253   var i = 0 
254   var se = this.nChildren 
255  
256   for (i=0; i < this.nChildren; i++){ 
257     if (this.children[i].children) //is a folder 
258       se = se + this.children[i].subEntries() 
259   } 
260  
261   return se 
262
263  
264  
265 // Definition of class Item (a document or link inside a Folder) 
266 // ************************************************************* 
267  
268 function Item(itemDescription, tagName, itemLink) // Constructor 
269
270   // constant data 
271   this.desc = itemDescription 
272   this.tagName = tagName
273   this.link = itemLink 
274   this.id = -1 //initialized in initalize() 
275   this.navObj = 0 //initialized in render() 
276   this.iconImg = 0 //initialized in render() 
277   this.iconSrc = "ftv2doc.png" 
278  
279   // methods 
280   this.initialize = initializeItem 
281   this.createIndex = createEntryIndex 
282   this.hide = hideItem 
283   this.display = display 
284   this.renderOb = drawItem 
285   this.totalHeight = totalHeight 
286
287  
288 function hideItem() 
289
290   if (browserVersion == 1 || browserVersion == 3) { 
291     if (this.navObj.style.display == "none") 
292       return 
293     this.navObj.style.display = "none" 
294   } else { 
295     if (this.navObj.visibility == "hidden") 
296       return 
297     this.navObj.visibility = "hidden" 
298   }     
299
300  
301 function initializeItem(level, lastNode, leftSide) 
302 {  
303   this.createIndex() 
304  
305   if (level>0) 
306     if (lastNode) //the last 'brother' in the children array 
307     { 
308       this.renderOb(leftSide + "<img src='ftv2lastnode.png' width=16 height=22>") 
309       leftSide = leftSide + "<img src='ftv2blank.png' width=16 height=22>"  
310     } 
311     else 
312     { 
313       this.renderOb(leftSide + "<img src='ftv2node.png' width=16 height=22>") 
314       leftSide = leftSide + "<img src='ftv2vertline.png' width=16 height=22>" 
315     } 
316   else 
317     this.renderOb("")   
318
319  
320 function drawItem(leftSide) 
321
322   if (browserVersion == 2) 
323     doc.write("<layer id='item" + this.id + "' top=" + doc.yPos + " visibility=hidden>") 
324   if (browserVersion == 3) 
325     doc.write("<div id='item" + this.id + "' style='display:block;'>") 
326      
327   doc.write("\n<table ") 
328   if (browserVersion == 1) 
329     doc.write(" id='item" + this.id + "' style='position:block;' ") 
330   doc.write(" border=0 cellspacing=0 cellpadding=0>\n") 
331   doc.write("<tr><td>") 
332   doc.write(leftSide) 
333   if (this.link!="")
334   {
335     doc.write("<a href=" + this.link + ">") 
336   }
337   doc.write("<img id='itemIcon"+this.id+"' ") 
338   doc.write("src='"+this.iconSrc+"' border=0>") 
339   if (this.link!="")
340   {
341     doc.write("</a>")
342   } 
343   doc.write("</td>\n<td valign=middle nowrap>") 
344   if (USETEXTLINKS && this.link!="") 
345     doc.write("<a href=" + this.link + ">" + this.desc + "</a>") 
346   else 
347     doc.write(this.desc) 
348   if (this.tagName!="")
349   {
350     doc.write(" [external]");
351   }
352   doc.write("\n</table>\n") 
353    
354   if (browserVersion == 2) 
355     doc.write("</layer>") 
356   if (browserVersion == 3) 
357     doc.write("</div>")
358  
359   if (browserVersion == 1) { 
360     this.navObj = doc.all["item"+this.id] 
361     this.iconImg = doc.all["itemIcon"+this.id] 
362   } else if (browserVersion == 2) { 
363     this.navObj = doc.layers["item"+this.id] 
364     this.iconImg = this.navObj.document.images["itemIcon"+this.id] 
365     doc.yPos=doc.yPos+this.navObj.clip.height 
366   } else if (browserVersion == 3) {
367     this.navObj = doc.getElementById("item"+this.id)
368     this.iconImg = doc.images.namedItem("itemIcon"+this.id)
369   }
370
371  
372  
373 // Methods common to both objects (pseudo-inheritance) 
374 // ******************************************************** 
375  
376 function display() 
377
378   if (browserVersion == 1 || browserVersion == 3) 
379     this.navObj.style.display = "block" 
380   else 
381     this.navObj.visibility = "show" 
382
383  
384 function createEntryIndex() 
385
386   this.id = nEntries 
387   indexOfEntries[nEntries] = this 
388   nEntries++ 
389
390  
391 // total height of subEntries open 
392 function totalHeight() //used with browserVersion == 2 
393
394   var h = this.navObj.clip.height 
395   var i = 0 
396    
397   if (this.isOpen) //is a folder and _is_ open 
398     for (i=0 ; i < this.nChildren; i++)  
399       h = h + this.children[i].totalHeight() 
400  
401   return h 
402
403  
404  
405 // Events 
406 // ********************************************************* 
407  
408 function clickOnFolder(folderId) 
409
410   var clicked = indexOfEntries[folderId] 
411  
412   if (!clicked.isOpen) 
413     clickOnNode(folderId) 
414  
415   return  
416  
417   if (clicked.isSelected) 
418     return 
419
420  
421 function clickOnNode(folderId) 
422
423   var clickedFolder = 0 
424   var state = 0 
425  
426   clickedFolder = indexOfEntries[folderId] 
427   state = clickedFolder.isOpen 
428  
429   clickedFolder.setState(!state) //open<->close  
430
431  
432 function initializeDocument() 
433
434   doc = document;
435   if (doc.all) 
436     browserVersion = 1 //IE4   
437   else 
438     if (doc.layers) 
439       browserVersion = 2 //NS4 
440     else if(navigator.userAgent.toLowerCase().indexOf('gecko') != -1)
441         browserVersion = 3 //mozilla
442       else 
443         browserVersion = 0 //other 
444
445   foldersTree.initialize(0, 1, "") 
446   foldersTree.display()
447   
448   if (browserVersion > 0) 
449   { 
450     if(browserVersion != 3)
451       doc.write("<layer top="+indexOfEntries[nEntries-1].navObj.top+">&nbsp;</layer>") 
452  
453     // close the whole tree 
454     clickOnNode(0) 
455     // open the root folder 
456     clickOnNode(0) 
457   } 
458
459  
460 // Auxiliary Functions for Folder-Treee backward compatibility 
461 // ********************************************************* 
462  
463 function gFld(description, tagName, hreference) 
464
465   folder = new Folder(description, tagName, hreference) 
466   return folder 
467
468  
469 function gLnk(description, tagName, linkData) 
470
471   fullLink = "" 
472  
473   if (linkData!="")
474   {
475     fullLink = "'"+linkData+"' target=\"basefrm\"" 
476   } 
477  
478   linkItem = new Item(description, tagName, fullLink)   
479   return linkItem 
480
481  
482 function insFld(parentFolder, childFolder) 
483
484   return parentFolder.addChild(childFolder) 
485
486  
487 function insDoc(parentFolder, document) 
488
489   parentFolder.addChild(document) 
490
491  
492 // Global variables 
493 // **************** 
494  
495 USETEXTLINKS = 1
496 indexOfEntries = new Array 
497 nEntries = 0 
498 doc = document 
499 browserVersion = 0 
500 selectedFolder=0