home *** CD-ROM | disk | FTP | other *** search
/ Chip 2003 May / Chip_2003-05_cd1.bin / bonus / www.paladix.cz / obchod / class.tree / ftiens4.js next >
Encoding:
JavaScript  |  2003-04-06  |  14.1 KB  |  540 lines

  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/marcelino_martins/foldertree.html
  5. // Author: Marcelino Alves Martins (http://www.mmartins.com) 
  6. // 1997--2001. 
  7. // Modified: Patrick Hess (posi@posi.de) March 2000, October 2001^M
  8. //           changed: global variables define the path to the^M
  9. //                    .gif files (classPath), the names of the^M
  10. //                    images (ftv2folderopen, ftv2*, ...) and the^M
  11. //                    destination frame (basefrm)^M
  12. //**************************************************************** 
  13. //
  14. // For PALADIX: Petr Pazour, 2002/01 
  15. //
  16. //**************************************************************** 
  17.  
  18. // Definition of class Folder 
  19. // ***************************************************************** 
  20.  
  21. function Folder(folderDescription, hreference, act) //constructor 
  22.   //constant data 
  23.   this.desc = folderDescription 
  24.   this.hreference = hreference 
  25.   this.act = act
  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 = classPath + "/" + ftv2folderopen  
  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.escondeBlock = escondeBlock
  44.   this.esconde = escondeFolder 
  45.   this.mostra = mostra 
  46.   this.renderOb = drawFolder 
  47.   this.totalHeight = totalHeight 
  48.   this.subEntries = folderSubEntries 
  49.   this.outputLink = outputFolderLink 
  50.   this.blockStart = blockStart
  51.   this.blockEnd = blockEnd
  52.  
  53. function initializeFolder(level, lastNode, leftSide) 
  54.   var j=0 
  55.   var i=0 
  56.   var numberOfFolders 
  57.   var numberOfDocs 
  58.   var nc 
  59.       
  60.   nc = this.nChildren 
  61.    
  62.   this.createIndex() 
  63.  
  64.   var auxEv = "" 
  65.  
  66.   if (browserVersion > 0) 
  67.     auxEv = "<a href='javascript:clickOnNode("+this.id+")'>" 
  68.   else 
  69.     auxEv = "<a>" 
  70.  
  71.   if (level>0) 
  72.     if (lastNode) //the last child in the children array 
  73.     { 
  74.       this.renderOb(leftSide + auxEv + "<img name='nodeIcon" + this.id + "' id='nodeIcon" + this.id + "' src='" + classPath + "/" + ftv2mlastnode + "' width=16 height=22 border=0></a>") 
  75.       leftSide = leftSide + "<img src='" + classPath + "/" + ftv2blank + "' width=16 height=22>"  
  76.       this.isLastNode = 1 
  77.     } 
  78.     else 
  79.     { 
  80.       this.renderOb(leftSide + auxEv + "<img name='nodeIcon" + this.id + "' id='nodeIcon" + this.id + "' src='" + classPath + "/" + ftv2mnode + "' width=16 height=22 border=0></a>") 
  81.       leftSide = leftSide + "<img src='" + classPath + "/" + ftv2vertline + "' width=16 height=22>" 
  82.       this.isLastNode = 0 
  83.     } 
  84.   else 
  85.     this.renderOb("") 
  86.    
  87.   if (nc > 0) 
  88.   { 
  89.     level = level + 1 
  90.     for (i=0 ; i < this.nChildren; i++)  
  91.     { 
  92.       if (i == this.nChildren-1) 
  93.         this.children[i].initialize(level, 1, leftSide) 
  94.       else 
  95.         this.children[i].initialize(level, 0, leftSide) 
  96.       } 
  97.   } 
  98.  
  99. function setStateFolder(isOpen) 
  100.   var subEntries 
  101.   var totalHeight 
  102.   var fIt = 0 
  103.   var i=0 
  104.  
  105.   if (isOpen == this.isOpen) 
  106.     return 
  107.  
  108.   if (browserVersion == 2)  
  109.   { 
  110.     totalHeight = 0 
  111.     for (i=0; i < this.nChildren; i++) 
  112.       totalHeight = totalHeight + this.children[i].navObj.clip.height 
  113.       subEntries = this.subEntries() 
  114.     if (this.isOpen) 
  115.       totalHeight = 0 - totalHeight 
  116.     for (fIt = this.id + subEntries + 1; fIt < nEntries; fIt++) 
  117.       indexOfEntries[fIt].navObj.moveBy(0, totalHeight) 
  118.   }  
  119.   this.isOpen = isOpen 
  120.   propagateChangesInState(this) 
  121.  
  122. function propagateChangesInState(folder) 
  123. {   
  124.   var i=0 
  125.  
  126.   if (folder.isOpen) 
  127.   { 
  128.     if (folder.nodeImg) 
  129.       if (folder.isLastNode) 
  130.         folder.nodeImg.src = classPath + "/"  + ftv2mlastnode 
  131.       else 
  132.     folder.nodeImg.src = classPath + "/" + ftv2mnode 
  133.     folder.iconImg.src = classPath + "/" + ftv2folderopen 
  134.     for (i=0; i<folder.nChildren; i++) 
  135.       folder.children[i].mostra() 
  136.   } 
  137.   else 
  138.   { 
  139.     if (folder.nodeImg) 
  140.       if (folder.isLastNode) 
  141.         folder.nodeImg.src = classPath + "/" + ftv2plastnode 
  142.       else 
  143.         folder.nodeImg.src = classPath + "/" + ftv2pnode 
  144.     folder.iconImg.src = classPath + "/" + ftv2folderclosed  
  145.     for (i=0; i<folder.nChildren; i++) 
  146.       folder.children[i].esconde() 
  147.   }  
  148.  
  149. function escondeFolder() 
  150.   this.escondeBlock()
  151.    
  152.   this.setState(0) 
  153.  
  154. function drawFolder(leftSide) 
  155.  
  156.   var idParam = "id='folder" + this.id + "'"
  157.  
  158.   if (browserVersion == 2) { 
  159.     if (!doc.yPos) 
  160.       doc.yPos=20 
  161.   } 
  162.  
  163.   this.blockStart("folder")
  164.  
  165.   doc.write("<tr><td>") 
  166.   doc.write(leftSide) 
  167.   this.outputLink() 
  168.   doc.write("<img id='folderIcon" + this.id + "' name='folderIcon" + this.id + "' src='" + this.iconSrc+"' border=0></a>") 
  169. //  doc.write("</td><td valign=middle nowrap>") 
  170.   doc.write("</td><td valign=middle class=small>") 
  171.   if (USETEXTLINKS) 
  172.   { 
  173.     this.outputLink() 
  174.     if(this.act ==1) {
  175.         doc.write("<b>" + this.desc + "</b></a>")
  176.     } else {
  177.         doc.write(this.desc + "</a>")    
  178.     }
  179.   } 
  180.   else 
  181.     doc.write(this.desc) 
  182.   doc.write("</td>")  
  183.  
  184.   this.blockEnd()
  185.  
  186.   if (browserVersion == 1) { 
  187.     this.navObj = doc.all["folder"+this.id] 
  188.     this.iconImg = doc.all["folderIcon"+this.id] 
  189.     this.nodeImg = doc.all["nodeIcon"+this.id] 
  190.   } else if (browserVersion == 2) { 
  191.     this.navObj = doc.layers["folder"+this.id] 
  192.     this.iconImg = this.navObj.document.images["folderIcon"+this.id] 
  193.     this.nodeImg = this.navObj.document.images["nodeIcon"+this.id] 
  194.     doc.yPos=doc.yPos+this.navObj.clip.height 
  195.   } else if (browserVersion == 3) { 
  196.     this.navObj = doc.getElementById("folder"+this.id)
  197.     this.iconImg = doc.getElementById("folderIcon"+this.id) 
  198.     this.nodeImg = doc.getElementById("nodeIcon"+this.id)
  199.   } 
  200.  
  201. function outputFolderLink() 
  202. /*
  203.   if (this.hreference) 
  204.   { 
  205.     doc.write("<a href='" + this.hreference + "' TARGET=\""+basefrm+"\" ") 
  206.     if (browserVersion > 0) 
  207.       doc.write("onClick='javascript:clickOnFolder("+this.id+")'") 
  208.     doc.write(">") 
  209.   } 
  210.   else 
  211.     doc.write("<a>") 
  212. */
  213. //  doc.write("<a href='javascript:clickOnFolder("+this.id+")'>")   
  214.     doc.write("<a href='javascript:clickOnNode("+this.id+")'>") 
  215.  
  216. function addChild(childNode) 
  217.   this.children[this.nChildren] = childNode 
  218.   this.nChildren++ 
  219.   return childNode 
  220.  
  221. function folderSubEntries() 
  222.   var i = 0 
  223.   var se = this.nChildren 
  224.  
  225.   for (i=0; i < this.nChildren; i++){ 
  226.     if (this.children[i].children) //is a folder 
  227.       se = se + this.children[i].subEntries() 
  228.   } 
  229.  
  230.   return se 
  231.  
  232.  
  233. // Definition of class Item (a document or link inside a Folder) 
  234. // ************************************************************* 
  235.  
  236. function Item(itemDescription, itemLink, itemAct) // Constructor 
  237.   // constant data 
  238.   this.desc = itemDescription 
  239.   this.link = itemLink 
  240.   this.act = itemAct
  241.   this.id = -1 //initialized in initalize() 
  242.   this.navObj = 0 //initialized in render() 
  243.   this.iconImg = 0 //initialized in render() 
  244.   this.iconSrc = classPath + "/" + ftv2doc 
  245.  
  246.   // methods 
  247.   this.initialize = initializeItem 
  248.   this.createIndex = createEntryIndex 
  249.   this.esconde = escondeBlock
  250.   this.mostra = mostra 
  251.   this.renderOb = drawItem 
  252.   this.totalHeight = totalHeight 
  253.   this.blockStart = blockStart
  254.   this.blockEnd = blockEnd
  255.  
  256. function initializeItem(level, lastNode, leftSide) 
  257. {  
  258.   this.createIndex() 
  259.  
  260.   if (level>0) 
  261.     if (lastNode) //the last 'brother' in the children array 
  262.     { 
  263.       this.renderOb(leftSide + "<img src='" + classPath + "/" + ftv2lastnode + "' width=16 height=22>") 
  264.       leftSide = leftSide + "<img src='" + classPath + "/" + ftv2blank + "' width=16 height=22>"  
  265.     } 
  266.     else 
  267.     { 
  268.       this.renderOb(leftSide + "<img src='" + classPath + "/" + ftv2node + "' width=16 height=22>") 
  269.       leftSide = leftSide + "<img src='" + classPath + "/" + ftv2vertline + "' width=16 height=22>" 
  270.     } 
  271.   else 
  272.     this.renderOb("")   
  273.  
  274. function drawItem(leftSide) 
  275.   this.blockStart("item")
  276.  
  277.   doc.write("<tr><td>") 
  278.   doc.write(leftSide) 
  279.   doc.write("<a href=" + this.link + ">") 
  280.   doc.write("<img id='itemIcon"+this.id+"' ") 
  281.   doc.write("src='"+this.iconSrc+"' border=0>") 
  282.   doc.write("</a>") 
  283. //  doc.write("</td><td valign=middle nowrap>") 
  284.   doc.write("</td><td valign=middle class=small>") 
  285.   if (USETEXTLINKS) 
  286.     if(this.act ==1) {
  287.         doc.write("<a href=" + this.link + "><b>" + this.desc + "</b></a>") 
  288.     } else {
  289.         doc.write("<a href=" + this.link + ">" + this.desc + "</a>")     
  290.     }
  291.   else 
  292.     doc.write(this.desc) 
  293.  
  294.   this.blockEnd()
  295.  
  296.   if (browserVersion == 1) { 
  297.     this.navObj = doc.all["item"+this.id] 
  298.     this.iconImg = doc.all["itemIcon"+this.id] 
  299.   } else if (browserVersion == 2) { 
  300.     this.navObj = doc.layers["item"+this.id] 
  301.     this.iconImg = this.navObj.document.images["itemIcon"+this.id] 
  302.     doc.yPos=doc.yPos+this.navObj.clip.height 
  303.   } else if (browserVersion == 3) { 
  304.     this.navObj = doc.getElementById("item"+this.id)
  305.     this.iconImg = doc.getElementById("itemIcon"+this.id)
  306.   } 
  307.  
  308.  
  309. // Methods common to both objects (pseudo-inheritance) 
  310. // ******************************************************** 
  311.  
  312. function mostra() 
  313.   if (browserVersion == 1 || browserVersion == 3) 
  314.     this.navObj.style.display = "block" 
  315.   else 
  316.     this.navObj.visibility = "show" 
  317.  
  318. function escondeBlock() 
  319.   if (browserVersion == 1 || browserVersion == 3) { 
  320.     if (this.navObj.style.display == "none") 
  321.       return 
  322.     this.navObj.style.display = "none" 
  323.   } else { 
  324.     if (this.navObj.visibility == "hidden") 
  325.       return 
  326.     this.navObj.visibility = "hidden" 
  327.   }     
  328.  
  329. function blockStart(idprefix) {
  330.   var idParam = "id='" + idprefix + this.id + "'"
  331.  
  332.   if (browserVersion == 2) 
  333.     doc.write("<layer "+ idParam + " top=" + doc.yPos + " visibility=show>") 
  334.      
  335.   if (browserVersion == 3) //N6 has bug on display property with tables
  336.     doc.write("<div " + idParam + " style='display:block; position:block;'>")
  337.      
  338.   doc.write("<table border=0 cellspacing=0 cellpadding=0 ") 
  339.  
  340.   if (browserVersion == 1) 
  341.     doc.write(idParam + " style='display:block; position:block; '>") 
  342.   else
  343.     doc.write(">") 
  344. }
  345.  
  346. function blockEnd() {
  347.   doc.write("</table>") 
  348.    
  349.   if (browserVersion == 2) 
  350.     doc.write("</layer>") 
  351.   if (browserVersion == 3) 
  352.     doc.write("</div>") 
  353. }
  354.  
  355. function createEntryIndex() 
  356.   this.id = nEntries 
  357.   indexOfEntries[nEntries] = this 
  358.   nEntries++ 
  359.  
  360. // total height of subEntries open 
  361. function totalHeight() //used with browserVersion == 2 
  362.   var h = this.navObj.clip.height 
  363.   var i = 0 
  364.    
  365.   if (this.isOpen) //is a folder and _is_ open 
  366.     for (i=0 ; i < this.nChildren; i++)  
  367.       h = h + this.children[i].totalHeight() 
  368.  
  369.   return h 
  370.  
  371.  
  372. // Events 
  373. // ********************************************************* 
  374.  
  375. function clickOnFolder(folderId) 
  376.   var clicked = indexOfEntries[folderId] 
  377.  
  378.   if (!clicked.isOpen) 
  379.     clickOnNode(folderId) 
  380.  
  381.   return  
  382.  
  383.   if (clicked.isSelected) 
  384.     return 
  385.  
  386. function clickOnNode(folderId) 
  387.   var clickedFolder = 0 
  388.   var state = 0 
  389.  
  390.   clickedFolder = indexOfEntries[folderId] 
  391.   state = clickedFolder.isOpen 
  392.  
  393.   clickedFolder.setState(!state) //open<->close  
  394.  
  395.  
  396. // Auxiliary Functions for Folder-Tree backward compatibility 
  397. // *********************************************************** 
  398.  
  399. function gFld(description, hreference, act) 
  400.   folder = new Folder(description, hreference, act) 
  401.   return folder 
  402.  
  403. function gLnk(target, description, linkData, act) 
  404.   fullLink = "" 
  405. /* 
  406.  // PP 
  407.   if (target==0) 
  408.   { 
  409.     fullLink = "'"+linkData+"' target=\""+basefrm+"\"" 
  410.   } 
  411.   else 
  412.   { 
  413.     if (target==1) 
  414.        fullLink = "'http://"+linkData+"' target=_blank" 
  415.     else 
  416.        fullLink = "'http://"+linkData+"' target=\""+basefrm+"\"" 
  417.   } 
  418. */
  419.     myRe=/^http:\/\//i;
  420.  
  421.     if(isNaN(linkData)) {
  422.         if(myRe.test("linkData")) {
  423.             fullLink = "'"+linkData+"' target=\"_new\""
  424.         } else {
  425.             fullLink = "'"+linkData+"' target=\""+basefrm+"\""
  426.         }
  427.     } else {
  428.         fullLink = "'http://www.paladix.cz/obchod/index.php?idr="+linkData+"' target=\""+basefrm+"\""
  429.     }    
  430.  
  431.   linkItem = new Item(description, fullLink, act)   
  432.   return linkItem 
  433.  
  434. function insFld(parentFolder, childFolder) 
  435.   return parentFolder.addChild(childFolder) 
  436.  
  437. function insDoc(parentFolder, document) 
  438.   parentFolder.addChild(document) 
  439.  
  440.  
  441. // Global variables 
  442. // **************** 
  443.  
  444. //These two variables are overwriten on defineMyTree.js if needed be
  445. //USETEXTLINKS = 0 
  446. //STARTALLOPEN = 0
  447. indexOfEntries = new Array 
  448. nEntries = 0 
  449. doc = document 
  450. browserVersion = 0 
  451. selectedFolder=0
  452.  
  453.  
  454. // Main function
  455. // ************* 
  456.  
  457. // This function uses an object (navigator) defined in
  458. // ua.js, imported in the main html page (left frame).
  459. function initializeDocument() 
  460.   switch(navigator.family)
  461.   {
  462.     case 'ie4':
  463.       browserVersion = 1 //IE4   
  464.       break;
  465.     case 'nn4':
  466.       browserVersion = 2 //NS4 
  467.       break;
  468.     case 'gecko':
  469.       browserVersion = 3 //NS6
  470.       break;
  471.     default:
  472.       browserVersion = 0 //other 
  473.       break;
  474.   }      
  475.  
  476.   //foldersTree (with the site's data) is created in an external .js 
  477.   foldersTree.initialize(0, 1, "") 
  478.   
  479.   if (browserVersion == 2) 
  480.     doc.write("<layer top="+indexOfEntries[nEntries-1].navObj.top+"> </layer>") 
  481.  
  482.   //The tree starts in full display 
  483.   if (!STARTALLOPEN)
  484.       if (browserVersion > 0) {
  485.         // close the whole tree 
  486.         clickOnNode(0) 
  487.         // open the root folder 
  488.         clickOnNode(0) 
  489.       } 
  490.  
  491.   /* not used, ph 10/2001
  492.   if (browserVersion == 0) 
  493.     doc.write("<table border=0><tr><td><br><br><font size=-1>This tree only expands or contracts with DHTML capable browsers</font></table>")
  494.   */
  495.  
  496.