home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 58 / CDA58.iso / scarbol.js < prev    next >
Encoding:
Text File  |  2001-04-11  |  11.0 KB  |  454 lines

  1. function Folder(folderDescription, hreference) //constructor 
  2.   //constant data 
  3.   this.desc = "<p class='textomenu'>"+folderDescription+"</p>"
  4.   this.hreference = hreference 
  5.   this.id = -1   
  6.   this.navObj = 0  
  7.   this.iconImg = 0  
  8.   this.nodeImg = 0  
  9.   this.isLastNode = 0 
  10.  
  11.   //dynamic data 
  12.   this.isOpen = true 
  13.   this.iconSrc = "imagenes/Nulo.gif"   
  14.   this.children = new Array 
  15.   this.nChildren = 0 
  16.  
  17.   //methods 
  18.   this.initialize = initializeFolder 
  19.   this.setState = setStateFolder 
  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.  
  29. function setStateFolder(isOpen) 
  30.   var subEntries 
  31.   var totalHeight 
  32.   var fIt = 0 
  33.   var i=0 
  34.  
  35.   if (isOpen == this.isOpen) 
  36.     return 
  37.  
  38.   if (browserVersion == 2)  
  39.   { 
  40.     totalHeight = 0 
  41.     for (i=0; i < this.nChildren; i++) 
  42.       totalHeight = totalHeight + this.children[i].navObj.clip.height 
  43.       subEntries = this.subEntries() 
  44.     if (this.isOpen) 
  45.       totalHeight = 0 - totalHeight 
  46.     for (fIt = this.id + subEntries + 1; fIt < nEntries; fIt++) 
  47.       indexOfEntries[fIt].navObj.moveBy(0, totalHeight) 
  48.   }  
  49.   this.isOpen = isOpen 
  50.   propagateChangesInState(this) 
  51.  
  52. function propagateChangesInState(folder) 
  53. {   
  54.   var i=0 
  55.  
  56.   if (folder.isOpen) 
  57.   { 
  58.     if (folder.nodeImg) 
  59.       if (folder.isLastNode) 
  60.         folder.nodeImg.src = "imagenes/Nulo.gif" 
  61.       else 
  62.       folder.nodeImg.src = "imagenes/Nulo.gif" 
  63.  
  64.     if (folder.id == 0)
  65.        folder.iconImg.src = "imagenes/Nulo.gif" 
  66.     else
  67.        folder.iconImg.src = "imagenes/Nulo.gif" 
  68.  
  69.     for (i=0; i<folder.nChildren; i++) 
  70.       folder.children[i].display() 
  71.   } 
  72.   else 
  73.   { 
  74.     if (folder.nodeImg) 
  75.       if (folder.isLastNode) 
  76.         folder.nodeImg.src = "imagenes/Nulo.gif" 
  77.       else 
  78.       folder.nodeImg.src = "imagenes/Nulo.gif" 
  79.  
  80.     if (folder.id == 0)
  81.        folder.iconImg.src = "imagenes/Nulo.gif" 
  82.     else
  83.        folder.iconImg.src = "imagenes/Nulo.gif" 
  84.  
  85.     for (i=0; i<folder.nChildren; i++) 
  86.       folder.children[i].hide() 
  87.   }  
  88.  
  89. function hideFolder() 
  90.   if (browserVersion == 1) { 
  91.     if (this.navObj.style.display == "none") 
  92.       return 
  93.     this.navObj.style.display = "none" 
  94.   } else { 
  95.     if (this.navObj.visibility == "hiden") 
  96.       return 
  97.     this.navObj.visibility = "hiden" 
  98.   } 
  99.    
  100.   this.setState(0) 
  101.  
  102. function initializeFolder(level, lastNode, leftSide) 
  103. var j=0 
  104. var i=0 
  105. var numberOfFolders 
  106. var numberOfDocs 
  107. var nc 
  108.       
  109.   nc = this.nChildren 
  110.    
  111.   this.createIndex() 
  112.  
  113.   var auxEv = "" 
  114.  
  115.   if (browserVersion > 0) 
  116.     auxEv = "<a href='javascript:clickOnNode("+this.id+")'>" 
  117.   else 
  118.     auxEv = "<a>" 
  119.  
  120.   if (level>0) 
  121.     if (lastNode) //the last 'brother' in the children array 
  122.     { 
  123.       this.renderOb(leftSide + auxEv + "<img name='nodeIcon" + this.id + "' src='imagenes/Nulo.gif' width=10 height=16 border=0></a>") 
  124.       leftSide = leftSide + "<img src='imagenes/Nulo.gif' width=10 height=16>"  
  125.       this.isLastNode = 1 
  126.     } 
  127.     else 
  128.     { 
  129.       this.renderOb(leftSide + auxEv + "<img name='nodeIcon" + this.id + "' src='imagenes/Nulo.gif' width=10 height=16 border=0></a>") 
  130.       leftSide = leftSide + "<img src='imagenes/Nulo.gif' width=10 height=16>" 
  131.       this.isLastNode = 0 
  132.     } 
  133.   else 
  134.     this.renderOb("") 
  135.    
  136.   if (nc > 0) 
  137.   { 
  138.     level = level + 1 
  139.     for (i=0 ; i < this.nChildren; i++)  
  140.     { 
  141.       if (i == this.nChildren-1) 
  142.         this.children[i].initialize(level, 1, leftSide) 
  143.       else 
  144.         this.children[i].initialize(level, 0, leftSide) 
  145.       } 
  146.   } 
  147.  
  148. function drawFolder(leftSide) 
  149.   if (browserVersion == 2) { 
  150.     if (!doc.yPos) 
  151.       doc.yPos=8 
  152.     doc.write("<layer id='folder" + this.id + "' top=" + doc.yPos + " visibility=hiden>") 
  153.   } 
  154.    
  155.   doc.write("<table ") 
  156.   if (browserVersion == 1) 
  157.     doc.write(" id='folder" + this.id + "' style='position:block;' ") 
  158.   doc.write(" border=0 cellspacing=0 cellpadding=0>") 
  159.   doc.write("<tr><td>") 
  160.   doc.write(leftSide) 
  161.   this.outputLink() 
  162.   doc.write("<img name='folderIcon" + this.id + "' ") 
  163.   doc.write("src='" + this.iconSrc+"' border=0></a>") 
  164.   doc.write("</td><td valign=middle nowrap>") 
  165.   if (USETEXTLINKS) 
  166.   { 
  167.     this.outputLink() 
  168.     doc.write(this.desc + "</a>") 
  169.   } 
  170.   else 
  171.     doc.write(this.desc) 
  172.   doc.write("</td>")  
  173.   doc.write("</table>") 
  174.    
  175.   if (browserVersion == 2) { 
  176.     doc.write("</layer>") 
  177.   } 
  178.  
  179.   if (browserVersion == 1) { 
  180.     this.navObj = doc.all["folder"+this.id] 
  181.     this.iconImg = doc.all["folderIcon"+this.id] 
  182.     this.nodeImg = doc.all["nodeIcon"+this.id] 
  183.   } else if (browserVersion == 2) { 
  184.     this.navObj = doc.layers["folder"+this.id] 
  185.     this.iconImg = this.navObj.document.images["folderIcon"+this.id] 
  186.     this.nodeImg = this.navObj.document.images["nodeIcon"+this.id] 
  187.     doc.yPos=doc.yPos+this.navObj.clip.height 
  188.   } 
  189.  
  190. function outputFolderLink() 
  191.   if (this.hreference) 
  192.   { 
  193.     doc.write("<a href='" + this.hreference + "' TARGET=\"mainFrame\" ") 
  194.     if (browserVersion > 0) 
  195.       doc.write("onClick='javascript:clickOnFolder("+this.id+")'") 
  196.     doc.write(">") 
  197.   } 
  198.   else 
  199.   {
  200.     //doc.write("<a>") 
  201.     doc.write("<a href='javascript:clickOnFolder("+this.id+")'>")   
  202.   }
  203.  
  204. function addChild(childNode) 
  205.   this.children[this.nChildren] = childNode 
  206.   this.nChildren++ 
  207.   return childNode 
  208.  
  209. function folderSubEntries() 
  210.   var i = 0 
  211.   var se = this.nChildren 
  212.  
  213.   for (i=0; i < this.nChildren; i++){ 
  214.     if (this.children[i].children) //is a folder 
  215.       se = se + this.children[i].subEntries() 
  216.   } 
  217.  
  218.   return se 
  219.  
  220.  
  221. // Definition of class Item (a document or link inside a Folder) 
  222. // ************************************************************* 
  223.  
  224. function Item(itemDescription, itemLink) // Constructor 
  225.   // constant data 
  226.   this.desc = "<p class='textomenu1'>"+itemDescription+"</p>"
  227.   this.link = itemLink 
  228.   this.id = -1 //initialized in initalize() 
  229.   this.navObj = 0 //initialized in render() 
  230.   this.iconImg = 0 //initialized in render() 
  231.   this.iconSrc = "imagenes/Nulo.gif" 
  232.  
  233.   // methods 
  234.   this.initialize = initializeItem 
  235.   this.createIndex = createEntryIndex 
  236.   this.hide = hideItem 
  237.   this.display = display 
  238.   this.renderOb = drawItem 
  239.   this.totalHeight = totalHeight 
  240.  
  241. function hideItem() 
  242.   if (browserVersion == 1) { 
  243.     if (this.navObj.style.display == "none") 
  244.       return 
  245.     this.navObj.style.display = "none" 
  246.   } else { 
  247.     if (this.navObj.visibility == "hiden") 
  248.       return 
  249.     this.navObj.visibility = "hiden" 
  250.   }     
  251.  
  252. function initializeItem(level, lastNode, leftSide) 
  253. {  
  254.   this.createIndex() 
  255.  
  256.   if (level>0) 
  257.     if (lastNode) //the last 'brother' in the children array 
  258.     { 
  259.       this.renderOb(leftSide + "<img src='imagenes/Nulo.gif' width=10 height=16>") 
  260.       leftSide = leftSide + "<img src='imagenes/blank.gif'>"  
  261.     } 
  262.     else 
  263.     { 
  264.       this.renderOb(leftSide + "<img src='imagenes/Nulo.gif' width=10 height=16>") 
  265.       leftSide = leftSide + "<img src='imagenes/Nulo.gif'>" 
  266.     } 
  267.   else 
  268.     this.renderOb("")   
  269.  
  270. function drawItem(leftSide) 
  271.   if (browserVersion == 2) 
  272.     doc.write("<layer id='item" + this.id + "' top=" + doc.yPos + " visibility=hiden>") 
  273.      
  274.   doc.write("<table ") 
  275.   if (browserVersion == 1) 
  276.     doc.write(" id='item" + this.id + "' style='position:block;' ") 
  277.   doc.write(" border=0 cellspacing=0 cellpadding=0>") 
  278.   doc.write("<tr><td>") 
  279.   doc.write(leftSide) 
  280.   doc.write("<a href=" + this.link + ">") 
  281.   doc.write("<img id='itemIcon"+this.id+"' ") 
  282.   doc.write("src='"+this.iconSrc+"' border=0>") 
  283.   doc.write("</a>") 
  284.   doc.write("</td><td valign=middle nowrap>") 
  285.   if (USETEXTLINKS) 
  286.     doc.write("<a href=" + this.link + ">" + this.desc + "</a>") 
  287.   else 
  288.     doc.write(this.desc) 
  289.   doc.write("</table>") 
  290.    
  291.   if (browserVersion == 2) 
  292.     doc.write("</layer>") 
  293.  
  294.   if (browserVersion == 1) { 
  295.     this.navObj = doc.all["item"+this.id] 
  296.     this.iconImg = doc.all["itemIcon"+this.id] 
  297.   } else if (browserVersion == 2) { 
  298.     this.navObj = doc.layers["item"+this.id] 
  299.     this.iconImg = this.navObj.document.images["itemIcon"+this.id] 
  300.     doc.yPos=doc.yPos+this.navObj.clip.height 
  301.   } 
  302.  
  303.  
  304. // Methods common to both objects (pseudo-inheritance) 
  305. // ******************************************************** 
  306.  
  307. function display() 
  308.   if (browserVersion == 1) 
  309.     this.navObj.style.display = "block" 
  310.   else 
  311.     this.navObj.visibility = "show" 
  312.  
  313. function createEntryIndex() 
  314.   this.id = nEntries 
  315.   indexOfEntries[nEntries] = this 
  316.   nEntries++ 
  317.  
  318. // total height of subEntries open 
  319. function totalHeight() //used with browserVersion == 2 
  320.   var h = this.navObj.clip.height 
  321.   var i = 0 
  322.    
  323.   if (this.isOpen) //is a folder and _is_ open 
  324.     for (i=0 ; i < this.nChildren; i++)  
  325.       h = h + this.children[i].totalHeight() 
  326.  
  327.   return h 
  328.  
  329.  
  330. function clickOnFolder(folderId) 
  331.   var clicked = indexOfEntries[folderId] 
  332.  
  333.  // if (!clicked.isOpen) 
  334.     clickOnNode(folderId) 
  335.  
  336.   return  
  337.  
  338.   if (clicked.isSelected) 
  339.     return 
  340.  
  341. function clickOnNode(folderId) 
  342.   var clickedFolder = 0 
  343.   var state = 0 
  344.  
  345.   clickedFolder = indexOfEntries[folderId] 
  346.   state = clickedFolder.isOpen 
  347.  
  348.   clickedFolder.setState(!state) //open<->close  
  349.  
  350. function initializeDocument() 
  351.   if (doc.all) 
  352.     browserVersion = 1 //IE4   
  353.   else 
  354.     if (doc.layers) 
  355.       browserVersion = 2 //NS4 
  356.     else 
  357.       browserVersion = 0 //other 
  358.  
  359.   cabecera.initialize(0, 1, "") 
  360.   cabecera.display()
  361.  
  362.     doc.write("<layer top="+indexOfEntries[nEntries-1].navObj.top+"> </layer>") 
  363.  
  364.   if (browserVersion > 0) 
  365.   { 
  366.     doc.write("<layer top="+indexOfEntries[nEntries-1].navObj.top+"> </layer>")  
  367.     // close the whole tree 
  368.     clickOnNode(0) 
  369.     clickOnNode(0) 
  370.   } 
  371.  
  372.  
  373.  
  374.  
  375. function gFld(description, hreference) 
  376.   folder = new Folder(description, hreference) 
  377.   return folder 
  378.  
  379. function gLnk(target, description, linkData) 
  380.   fullLink = "" 
  381.  
  382.   if (target==0) 
  383.   { 
  384.     fullLink = "'"+linkData+"' target=\"mainFrame\"" 
  385.   } 
  386.   else 
  387.   { 
  388.     if (target==1) 
  389.        fullLink = "'http://"+linkData+"' target=_blank" 
  390.     else 
  391.        fullLink = "'http://"+linkData+"' target=\"mainFrame\"" 
  392.   } 
  393.  
  394.   linkItem = new Item(description, fullLink)   
  395.   return linkItem 
  396.  
  397. function insFld(parentFolder, childFolder) 
  398.   return parentFolder.addChild(childFolder) 
  399.  
  400. function insDoc(parentFolder, document) 
  401.   parentFolder.addChild(document) 
  402.  
  403.  
  404. USETEXTLINKS = 1 
  405. indexOfEntries = new Array 
  406. nEntries = 0 
  407. doc = document 
  408. browserVersion = 0 
  409. selectedFolder=0
  410.