home *** CD-ROM | disk | FTP | other *** search
/ PC World 2003 February / PCWorld_2003-02_cd.bin / Software / Komercni / gimp / gimpmanual / wwhtree.js < prev   
Text File  |  1999-10-25  |  10KB  |  253 lines

  1. // Copyright (c) 1999 Quadralay Corporation.  All rights reserved.
  2. //
  3. // Originally based on and portions copyright (c) 1997, Marcelino 
  4. // Alves Martins (martins@hks.com) "Folder-Tree" script which can 
  5. // located at http://www.geocities.com/Paris/LeftBank/2178/
  6.  
  7. function Folder(folderDescription,hreference,topicID){ 
  8.   this.desc=folderDescription;
  9.   this.hreference=hreference;
  10.   this.id=-1;
  11.   this.navObj=0;
  12.   this.iconImg=0;
  13.   this.nodeImg=0;
  14.   this.isLastNode=0;
  15.   this.isOpen=true;
  16.   this.iconSrc=imgdir+"tocfldo.gif";
  17.   this.children=new Array;
  18.   this.initialize=initializeFolder;
  19.   this.setState=setFolderState;
  20.   this.addChild=addChild;
  21.   this.createIndex=createEntryIndex;
  22.   this.hide=hideFolder;
  23.   this.display=display;
  24.   this.renderOb=drawFolder;
  25.   this.totalHeight=totalHeight;
  26.   this.subEntries=folderSubEntries;
  27.   this.outputLink=outputFolderLink;
  28.   this.type="Folder";
  29.   this.leftSide="";
  30.   this.initialized=false;
  31.   if(topicID)this.topicID=topicID;
  32.  
  33. function setFolderState(isOpen){ 
  34.   if (isOpen==this.isOpen)return; 
  35.   if (isNav4){ 
  36.     var totalHeight=0; 
  37.     for (var i=0;i<this.children.length;i++)totalHeight=totalHeight+this.children[i].navObj.clip.height; 
  38.     if (this.isOpen)totalHeight=0-totalHeight; 
  39.     for (var fIt=this.id+this.subEntries()+1;fIt<indexOfEntries.length;fIt++)indexOfEntries[fIt].navObj.moveBy(0,totalHeight); 
  40.   }  
  41.   this.isOpen=isOpen; 
  42.   propagateChangesInState(this); 
  43. function propagateChangesInState(folder){   
  44.   var i=0; 
  45.   if(folder.isOpen){ 
  46.     if(folder.nodeImg) 
  47.       if(folder.isLastNode)folder.nodeImg.src=imgdir+"tocmlnde.gif"; 
  48.       else folder.nodeImg.src=imgdir+"tocmnode.gif"; 
  49.     folder.iconImg.src=imgdir+"tocfldo.gif"; 
  50.     for(i=0;i<folder.children.length;i++)folder.children[i].display(); 
  51.   }else{ 
  52.     if(folder.nodeImg) 
  53.       if(folder.isLastNode)folder.nodeImg.src=imgdir+"tocplnod.gif"; 
  54.       else folder.nodeImg.src=imgdir+"tocpnode.gif"; 
  55.     folder.iconImg.src=imgdir+"tocfldc.gif"; 
  56.     for(i=0;i<folder.children.length;i++)folder.children[i].hide(); 
  57.   }  
  58. function hideFolder(){ 
  59.    if(isIE4)this.navObj.style.display="none"; 
  60.    else if(isNav4)this.navObj.visibility="hide"; 
  61.    this.setState(false); 
  62. function initializeFolder(level,lastNode,leftSide){ 
  63.    var j=0;
  64.    var i=0;
  65.    var nc=this.children.length;
  66.       
  67.    this.createIndex();
  68.    var auxEv=""; 
  69.    if(isIE4||isNav4)auxEv="<a href='javascript:parent.clickOnNode("+this.id+")'>"; 
  70.    else auxEv="<a>"; 
  71.  
  72.   if(level>0) 
  73.     if(lastNode){ 
  74.       this.leftSide=leftSide+auxEv+"<img name='nodeIcon"+this.id+"' src='"+imgdir+"tocmlnde.gif' width=16 height=22 border=0></a>"; 
  75.       leftSide=leftSide+"<img src='"+imgdir+"tocblank.gif' width=16 height=22>";  
  76.       this.isLastNode=1; 
  77.     }else{ 
  78.       this.leftSide=leftSide+auxEv+"<img name='nodeIcon"+this.id+"' src='"+imgdir+"tocmnode.gif' width=16 height=22 border=0></a>"; 
  79.       leftSide=leftSide+"<img src='"+imgdir+"tocvline.gif' width=16 height=22>"; 
  80.       this.isLastNode=0; 
  81.       } 
  82.   if (nc>0){ 
  83.     level=level+1; 
  84.     for(i=0;i<this.children.length;i++){ 
  85.       if(i==this.children.length-1)this.children[i].initialize(level,true,leftSide); 
  86.       else this.children[i].initialize(level,false,leftSide); 
  87.       } 
  88.   }
  89. function drawFolder(){ 
  90.   if(isNav4){
  91.     if(!tabDisplay.document.yPos)tabDisplay.document.yPos=0;
  92.     tabDisplay.document.write("\n<layer id='folder"+this.id+"' top="+tabDisplay.document.yPos+" visibility=hide>"); 
  93.   }
  94.   tabDisplay.document.write("\n\t<table ");
  95.   if(isIE4)tabDisplay.document.write(" id='folder"+this.id+"' style='position:block;' ");
  96.   tabDisplay.document.write(" border=0 cellspacing=0 cellpadding=0>");
  97.   tabDisplay.document.write("\n\t\t<tr>\n\t\t\t<td");
  98.   // put the IE blur code in here to get rid of the box around the node icon afer a click
  99.   tabDisplay.document.write(">");
  100.   tabDisplay.document.write(this.leftSide);
  101.   this.outputLink();
  102.   tabDisplay.document.write("<img name='folderIcon" + this.id + "' ");
  103.   if(tocalt)tabDisplay.document.write("alt='"+this.desc+"' ");
  104.   tabDisplay.document.write("src='"+this.iconSrc+"' border=0></a>");
  105.   tabDisplay.document.write("</td>\n\t\t\t<td valign=middle nowrap><font  face='"+parent.tff+"' size="+parent.tfs+">"); 
  106.   if(useTOCTextLinks){
  107.     this.outputLink(); 
  108.     tabDisplay.document.write(this.desc+"</a>"); 
  109.   }else tabDisplay.document.write(this.desc); 
  110.   tabDisplay.document.write("</font></td>");  
  111.   tabDisplay.document.write("\n\t\t</tr>\n\t</table>"); 
  112.   if(isNav4)tabDisplay.document.write("\n</layer>"); 
  113.   if(isIE4){ 
  114.     this.navObj=tabDisplay.document.all["folder"+this.id]; 
  115.     this.iconImg=tabDisplay.document.all["folderIcon"+this.id]; 
  116.     this.nodeImg=tabDisplay.document.all["nodeIcon"+this.id]; 
  117.   }else if(isNav4){ 
  118.     this.navObj=tabDisplay.document.layers["folder"+this.id]; 
  119.     this.iconImg=this.navObj.document.images["folderIcon"+this.id]; 
  120.     this.nodeImg=this.navObj.document.images["nodeIcon"+this.id]; 
  121.     tabDisplay.document.yPos=tabDisplay.document.yPos+this.navObj.clip.height; 
  122.   }
  123. function outputFolderLink(){ 
  124.   if(this.hreference){ 
  125.     tabDisplay.document.write("<a href='javascript:parent.displayTOCSelection(\""+this.hreference+"\")'"); 
  126.     if(isIE4||isNav4)tabDisplay.document.write("onClick='javascript:parent.clickOnFolder("+this.id+")'"); 
  127.     tabDisplay.document.write(">"); 
  128.   }else tabDisplay.document.write("<a>"); 
  129. function addChild(childNode){ 
  130.   this.children[this.children.length]=childNode; 
  131.   return childNode; 
  132. function folderSubEntries(){ 
  133.   var i=0; 
  134.   var se=this.children.length; 
  135.   for (i=0;i<this.children.length;i++)if(this.children[i].children)se=se+this.children[i].subEntries(); 
  136.   return se; 
  137. function Item(itemDescription,itemLink,topicID){ 
  138.   this.desc=itemDescription;
  139.   this.link=itemLink;
  140.   this.id=-1;
  141.   this.navObj=0;
  142.   this.iconImg=0;
  143.   this.iconSrc=imgdir+"tocdoc.gif";
  144.   this.initialize=initializeItem;
  145.   this.createIndex=createEntryIndex;
  146.   this.hide=hideItem;
  147.   this.display=display;
  148.   this.renderOb=drawItem;
  149.   this.totalHeight=totalHeight;
  150.   this.type="Item";
  151.   this.isSelected=false;
  152.   this.leftSide="";
  153.   this.topicID=topicID;
  154. function hideItem(){ 
  155.   if(isIE4)this.navObj.style.display="none"; 
  156.   else this.navObj.visibility="hide"; 
  157. function initializeItem(level, lastNode, leftSide){
  158.   this.createIndex();
  159.   if(level>0)
  160.     if(lastNode){
  161.       this.leftSide=leftSide+"<img src='"+imgdir+"toclnode.gif' width=16 height=22>";
  162.       leftSide=leftSide+"<img src='"+imgdir+"tocblank.gif' width=16 height=22>";
  163.     }else{
  164.       this.leftSide=leftSide + "<img src='"+imgdir+"tocnode.gif' width=16 height=22>";
  165.       leftSide=leftSide+"<img src='"+imgdir+"tocvline.gif' width=16 height=22>";
  166.     }else this.renderOb("");
  167. }
  168. function drawItem(){
  169.   if(isNav4)tabDisplay.document.write("\n<layer id='item"+this.id+"' top="+tabDisplay.document.yPos+" visibility=hide>");
  170.   tabDisplay.document.write("\n\t<table ");
  171.   if(isIE4)tabDisplay.document.write(" id='item"+this.id+"' style='position:block;' ");
  172.   tabDisplay.document.write(" border=0 cellspacing=0 cellpadding=0>");
  173.   tabDisplay.document.write("\n\t\t<tr>\n\t\t\t<td>");
  174.   tabDisplay.document.write(this.leftSide);
  175.   tabDisplay.document.write("<a href='javascript:parent.displayTOCSelection(\""+this.link+"\")'>");
  176.   tabDisplay.document.write("<img id='itemIcon"+this.id+"' ");
  177.   if(tocalt)tabDisplay.document.write("alt='"+this.desc+"' ");
  178.   tabDisplay.document.write("src='"+this.iconSrc+"' border=0>");
  179.   tabDisplay.document.write("</a>");
  180.   tabDisplay.document.write("</td>\n\t\t\t<td valign=middle nowrap><font face='"+parent.tff+"' size="+parent.tfs+">");
  181.   if(useTOCTextLinks)tabDisplay.document.write("<a href='javascript:parent.displayTOCSelection(\""+this.link+"\")'>"+this.desc+"</a>");
  182.   else tabDisplay.document.write(this.desc);
  183.   tabDisplay.document.write("</td>\n\t\t</tr>\n\t</table>");
  184.   if(isNav4)tabDisplay.document.write("\n</layer>");
  185.   if(isIE4){
  186.     this.navObj = tabDisplay.document.all["item"+this.id];
  187.     this.iconImg = tabDisplay.document.all["itemIcon"+this.id];
  188.   }else if(isNav4){
  189.     this.navObj = tabDisplay.document.layers["item"+this.id];
  190.     this.iconImg = this.navObj.document.images["itemIcon"+this.id];
  191.     tabDisplay.document.yPos=tabDisplay.document.yPos+this.navObj.clip.height;
  192.   }
  193. }
  194. function display(){
  195.   if(isIE4)this.navObj.style.display="block";
  196.   else this.navObj.visibility="show";
  197. }
  198. function createEntryIndex(){
  199.    this.id=indexOfEntries.length;
  200.    indexOfEntries[indexOfEntries.length]=this;
  201. }
  202. function totalHeight(){
  203.   var h=this.navObj.clip.height;
  204.   if (this.isOpen)for(var i=0;i<this.children.length;i++)h=h+this.children[i].totalHeight();
  205.   return h;
  206. }
  207. function clickOnNode(folderId){
  208.   var clickedFolder=indexOfEntries[folderId];
  209.   clickedFolder.setState(!clickedFolder.isOpen);
  210. }
  211. function clickOnFolder(folderId){
  212.    var clicked=indexOfEntries[folderId];
  213.    if(!clicked.isOpen)clickOnNode(folderId);
  214. function displayTOC(){
  215.    tabDisplay.document.yPos=0;
  216.    foldersTree.renderOb();
  217.    foldersTree.display();
  218.    for (var i=1;i<indexOfEntries.length;i++){
  219.       folderOpen[i]=false;
  220.       if (indexOfEntries[i].type=="Folder"){
  221.          folderOpen[i]=indexOfEntries[i].isOpen;
  222.          indexOfEntries[i].isOpen=true;
  223.       }
  224.       indexOfEntries[i].renderOb();
  225.    }
  226.    if(isNav4)tabDisplay.document.write("\n<layer top="+indexOfEntries[indexOfEntries.length-1].navObj.top+"> \n</layer>");
  227.    foldersTree.setState(false);
  228.    if(foldersTree.initialized){for(var i=0;i<indexOfEntries.length;i++)if(folderOpen[i])indexOfEntries[i].setState(true);}
  229.    else foldersTree.setState(true);
  230.    foldersTree.initialized=true;
  231. }
  232.  
  233.  
  234.  
  235. //**************************************************************** 
  236. // You are free to copy the "Folder-Tree" script as long as you  
  237. // keep this copyright notice: 
  238. // Script found in: http://www.geocities.com/Paris/LeftBank/2178/ 
  239. // Author: Marcelino Alves Martins (martins@hks.com) December '97. 
  240. //**************************************************************** 
  241.