home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2003 June (Bonus) / Services_2003.bin / services_2003 / library / script / treelogic.js < prev   
Encoding:
JavaScript  |  2002-09-25  |  14.2 KB  |  465 lines

  1. // navigation tree functions
  2.  
  3.  
  4. var bDebug = false;
  5. var withPageID = false;
  6. var OpenPageID;
  7.  
  8. var imgNodeDir = "../library/images/navi/";
  9. var imgWidth = 11;
  10. var imgHeight = 20;
  11. var imgExt = ".gif";
  12.  
  13. var imgTargetBlank = "";
  14. //var imgExtLink = "<img src='../library/images/icons/ico_leave_cd.gif' width='24' height='16' border='0' align='absmiddle' alt='Weblink'>";
  15.  
  16. var sBaustingGesamt;
  17. var iLetztesLevel = 0;
  18. var iLetztesItemLevel = 0;
  19. var lastLinkStyleOnIndex = -1;
  20. var sFolderOpen = "";
  21. var fontOn = '<span class=treetext>'
  22. var fontOnSize = '<span class=treetext>'
  23. var fontOff = '</span>'
  24.  
  25. var imgNone;
  26. var imgBlank;
  27. var imgHLine;
  28. var imgVLine;
  29. var imgVHalfLine;
  30. var imgPlus;
  31. var imgMinus;
  32.  
  33.  
  34. function neuesFenster(url)    {
  35. var fenster = window.open(url,'neuesfenster','status=0,toolbar=0,menubar=0,location=0,scrollbars=0,resizable=1,top=0,left=0'); fenster.focus(); 
  36. }
  37.  
  38.  
  39. function preload_image(img_name, img_src) {
  40.     eval(img_name + ' = new Image()');
  41.     eval(img_name + '.src = img_src');
  42. }
  43.  
  44. function switch_image(img_name, img_name_switch) {
  45.     if (eval(img_name_switch)) eval('document["'+img_name+'"].src='+img_name_switch+'.src');
  46. }
  47.  
  48. function trView() {
  49. // Eigenschaft
  50.     this.count = -1;
  51.     this.child                = new Array;                // Child nodes = ROOT nodes.
  52.     this.startLevel            = 0;
  53.     this.target                = '_top';
  54.     this.serverurl            = '';
  55.     this.noDocumentWrite    = false;                    // Keine Ausgabe, nur String zusammensetzen
  56. // Methode
  57.     this.addItem            = trView_addItem;
  58.  
  59.     return this;
  60. }
  61.  
  62.  
  63. function loadimages() {
  64. // Bilder laden
  65.     if (trView.noDocumentWrite == false) {
  66.         preload_image ("imgNone", imgNodeDir + "tvNone" + imgExt);
  67.         preload_image ("imgBlank", imgNodeDir + "tvBlank" + imgExt);
  68.         preload_image ("imgHLine", imgNodeDir + "tvHLine" + imgExt);
  69.         preload_image ("imgVLine", imgNodeDir + "tvVLine" + imgExt);
  70.         preload_image ("imgVHalfLine", imgNodeDir + "tvVHalfLine" + imgExt);
  71.         preload_image ("imgPlus", imgNodeDir + "tvPlus" + imgExt);
  72.         preload_image ("imgMinus", imgNodeDir + "tvMinus" + imgExt);
  73.         if (document.all) {
  74.             document.getElementById = document.all
  75.         }
  76.     }else{
  77.         imgNone = imgNodeDir + "tvNone" + imgExt;
  78.         imgBlank = imgNodeDir + "tvBlank" + imgExt;
  79.         imgHLine = imgNodeDir + "tvHLine" + imgExt;
  80.         imgVLine = imgNodeDir + "tvVLine" + imgExt;
  81.         imgVHalfLine = imgNodeDir + "tvVHalfLine" + imgExt;
  82.         imgPlus = imgNodeDir + "tvPlus" + imgExt;
  83.         imgMinus = imgNodeDir + "tvMinus" + imgExt;
  84.     }
  85. }
  86.  
  87. function trNode(parentObj, caption, id, link, level, lastChild) {
  88.  
  89. //Eigenschaften
  90.     this.index        = trView.count + 1;            // The node's index in respect of it's treeview
  91.     this.parent        = parentObj;                // The node's parent
  92.  
  93.     this.caption    = caption;                    // The node's caption (may also be hyper link)
  94.     this.id            = id;                        // The node's id
  95.     this.link        = link;                        // The node's link
  96.     if (trView.serverurl && link!='') this.link    = trView.serverurl + link;
  97.     this.level        = eval(level);                // How many levels down the node is from it's ROOT
  98.     if (iLetztesLevel < eval(level)) iLetztesLevel = eval(level); // Last level in
  99.     if (lastChild == "TRUE") {                    // is Last Child
  100.         this.isLast = true;
  101.     }else{
  102.         this.isLast = false;
  103.     }
  104.     this.isOpen        = false;                    // Node is open    
  105.     this.childCount = 0;                        // Node Child Count
  106.  
  107.     parentObj.childCount++;
  108.     
  109.     return this;
  110. }
  111.  
  112. function trView_addItem(Parent, caption, id, link, level, lastChild) {
  113.     newNode = new trNode(Parent, caption, id, link, level, lastChild);
  114.     this.child[newNode.index] = newNode;
  115.     this.count++;
  116.  
  117.     return newNode;
  118. }
  119.  
  120. function addCheckIsLastItem(index, parent) {
  121.     var oItem = new Object();
  122.     oItem.index = index;
  123.     oItem.parent = parent;
  124.     return oItem;
  125. }
  126. function checkIsLastItem() {
  127. // Letzte Items  isLast auf True
  128.     var sLevelArray = new Array();
  129.     var iLevelItem;
  130.     var iLevel;
  131.     var iLevelCount;
  132.     var iLastItem = trView.count;
  133.  
  134.     for (iLevel = 1; iLevel <= iLetztesLevel; iLevel++) {
  135.         for (i = 0; i <= iLastItem; i++) {
  136.             if (trView.child[i].level == iLevel) {
  137.                 sLevelArray[sLevelArray.length] = addCheckIsLastItem(i, trView.child[i].parent.id);
  138.             }
  139.         }
  140.         iLevelCount = sLevelArray.length - 1;
  141.         if (iLevelCount > 0) {
  142.             iLevelItem = sLevelArray[iLevelCount].index;
  143.             trView.child[iLevelItem].isLast = true;
  144.             for (i = 0; i < iLevelCount; i++) {
  145.                 if (sLevelArray[i].parent != sLevelArray[i + 1].parent) {
  146.                     iLevelItem = sLevelArray[i].index;
  147.                     trView.child[iLevelItem].isLast = true;
  148.                 }
  149.             }
  150.         }
  151.     }
  152. }
  153.  
  154. function trViewdraw() {
  155.     loadimages();
  156.     if (trView.count > 0) {checkIsLastItem();}
  157.  
  158.     sBaustingGesamt = '<div id="treebox">';
  159.  
  160.  
  161. // 1. Knoten wir Portal
  162.  
  163.     
  164.         //sBaustingGesamt = sBaustingGesamt + '<div id="treeinner">'
  165.     
  166.             sBaustingGesamt = sBaustingGesamt + '<table border="0" cellspacing="0" cellpadding="0"><tr><td valign="top">'
  167.             //sBaustingGesamt = sBaustingGesamt + '<table width="90%" border="0" cellspacing="0" cellpadding="0"><tr><td valign="top">'
  168.  
  169.     
  170.  
  171.                 sBaustingGesamt = sBaustingGesamt + '<div id="treetitle">'
  172.         
  173.         if (trView.child[0].link != "" && trView.child[0].link != "/") {
  174.             sBaustingGesamt = sBaustingGesamt + '<a '
  175.             
  176.             if (trView.target != '') sBaustingGesamt = sBaustingGesamt + 'target="' + trView.target + '"'
  177.             sBaustingGesamt = sBaustingGesamt + ' href="' + trView.child[0].link + '" class="treetext">'
  178.         }    
  179.         sBaustingGesamt = sBaustingGesamt + "<b>" + trView.child[0].caption + "</b>"
  180.         if (withPageID) sBaustingGesamt = sBaustingGesamt + "(" + trView.child[0].id + ")"
  181.     if (bDebug) sBaustingGesamt = sBaustingGesamt + "(" + trView.child[0].index + ")"
  182.         if (trView.child[0].link != "" && trView.child[0].link != "/") sBaustingGesamt = sBaustingGesamt + '</a>'
  183.         
  184.                 sBaustingGesamt = sBaustingGesamt + "</div>"
  185.  
  186.         
  187. // alle anderen Knoten
  188.     forcount = trView.count;
  189.     for (i=1; i <= forcount; i++) drawItem(trView.child[i]);
  190.  
  191.     
  192.  
  193.             sBaustingGesamt = sBaustingGesamt + '</td></tr></table>'
  194.         
  195.         //sBaustingGesamt = sBaustingGesamt + '</div>'
  196.     
  197.     sBaustingGesamt = sBaustingGesamt + '</div>'
  198.     
  199.     if (trView.noDocumentWrite == false) {
  200.         document.writeln(sBaustingGesamt);
  201.     }
  202.     
  203.  
  204. // 1. Knoten ÷ffnen  -   nodeClick(1);
  205.  
  206. //▄bergabepage ÷ffnen
  207.     if (trView.noDocumentWrite == false) {
  208.         searchAndOpenId(OpenPageID)
  209.     } 
  210. }
  211.  
  212. function drawItem(dItem, vRoot) {
  213.     var sBaustring = "";
  214.     var imgPicName = imgNone;
  215.     var imgPicLineHalf = "X";
  216.     var nClick = "";
  217.  
  218.     iIndex = dItem.index + 1;
  219.     iCLevel = dItem.level;
  220.     iCCount = dItem.childCount;
  221.     iCisLast = dItem.isLast;
  222.  
  223.     if (iLetztesItemLevel > iCLevel) for (var ix = iCLevel;  ix < iLetztesItemLevel; ix++) sBaustring = sBaustring + "</div>"
  224.  
  225.     if (iIndex == 0) {
  226.         sBaustring = sBaustring + "<div id='childObj" + iIndex + "'";
  227.         if (trView.noDocumentWrite == false) {
  228.             if (dItem.level != 0) sBaustring = sBaustring + " style='display:none'";
  229.         }
  230.         sBaustring = sBaustring + " style='border:0px solid red'>";    
  231.     }
  232.     
  233.     
  234.     
  235.         sBaustring = sBaustring + "<table width='189' border='0' cellpadding='0' cellspacing='0'><tr>";
  236.         //sBaustring = sBaustring + "<table width='100%' border='0' cellpadding='0' cellspacing='0'><tr>";
  237.  
  238.  
  239. //    if (iCLevel != 0) sBaustring = sBaustring + "<td width='" + imgWidth + "' NOWRAP>" + drawImg(imgBlank, imgWidth) + "</td>"
  240.  
  241.     for (var ix=0; ix < iCLevel - 1; ix++) {
  242.         sBaustring = sBaustring + "<td width='" + imgWidth + "' nowrap"
  243.         imgPicName = imgBlank;
  244.         if (ix >= trView.startLevel && sFolderOpen.substr(ix, 1) == "N") {
  245.             if (trView.noDocumentWrite == false) {
  246.                 sBaustring = sBaustring + " background='" + imgVLine.src + "'"
  247.             }else{
  248.                 sBaustring = sBaustring + " background='" + imgVLine + "'"
  249.             }
  250.         }
  251.         sBaustring = sBaustring + ">" + drawImg(imgPicName, imgWidth) + "</td>";
  252.     }
  253.  
  254.     imgPicName = imgNone;
  255.     nClick = "";
  256.     if (iCLevel == 0) {
  257.         imgPicName = imgMinus;
  258.         nClick = "nodeClick(" + iIndex + ")";
  259.     }else if (iCCount == 0 && !iCisLast) {
  260.         imgPicName = imgHLine;
  261.         imgPicLineHalf = "N";
  262.     }else if (iCCount == 0 && iCisLast) {
  263.         imgPicName = imgHLine;
  264.         imgPicLineHalf = "J";
  265.     }else if (iCCount != 0 && !iCisLast) {
  266.         imgPicName = imgPlus;
  267.         imgPicLineHalf = "N";
  268.         nClick = "nodeClick(" + iIndex + ")";
  269.     }else if (iCCount != 0 && iCisLast) {
  270.         imgPicName = imgPlus;
  271.         imgPicLineHalf = "J";
  272.         nClick = "nodeClick(" + iIndex + ")";
  273.         if (iCLevel == trView.startLevel + 1) trView.startLevel = iCLevel;
  274.     }    
  275.     if (trView.noDocumentWrite == true) {
  276.         imgPicName = imgHLine;
  277.     }
  278.     if (iCisLast) {
  279.         sFolderOpen = setzteBuchstabe(sFolderOpen, iCLevel, "J")
  280.     }else{
  281.         sFolderOpen = setzteBuchstabe(sFolderOpen, iCLevel, "N")
  282.     }
  283.     sBaustring = sBaustring + "<td width='" + imgWidth + "' NOWRAP valign='top'"
  284.     
  285.     if (trView.noDocumentWrite == false) {
  286.         if (imgPicLineHalf == "N") sBaustring = sBaustring + " background='" + imgVLine.src + "'"
  287.     }else{
  288.         if (imgPicLineHalf == "N") sBaustring = sBaustring + " background='" + imgVLine + "'"
  289.     }
  290.     
  291.     sBaustring = sBaustring + ">" + drawImg(imgPicName, imgWidth, iIndex, nClick) + "</td>"
  292.  
  293.     sBaustring = sBaustring + "<td><img src='../library/images/1ptrans.gif' width='2' height='1' alt='' /></td><td valign='top' style='padding-top:2px;' width='100%' id='linkid" + dItem.index + "'"
  294.     if (dItem.link != "" && dItem.link != "/") {
  295.         sBaustring = sBaustring + ">"
  296.     } else {        
  297.         sBaustring = sBaustring + " onClick='" + nClick + "'";
  298.         sBaustring = sBaustring + " onMouseOver='this.style.cursor=\"hand\"'";
  299.         sBaustring = sBaustring + ">"
  300.     }
  301.     sBaustring = sBaustring + fontOnSize
  302.     if (dItem.link != "" && dItem.link != "/") {
  303.         sBaustring = sBaustring + '<a '
  304.         if (trView.target != '')
  305.         {
  306.             if (dItem.id != 'target_blank')
  307.             { 
  308.                 sBaustring = sBaustring + 'target="' + trView.target + '"'
  309.                 sBaustring = sBaustring + ' href="' + dItem.link + '" class="treetext">'
  310.             }
  311.             else
  312.             {
  313.                 //sBaustring = sBaustring + 'target="_blank"'
  314.                 //sBaustring = sBaustring + ' href="' + dItem.link + '" class="treetext">'
  315.                 sBaustring = sBaustring + ' href="javascript:neuesFenster(\'' + dItem.link + '\')" class="treetext">'
  316.             }
  317.         }
  318.     }    
  319.     sBaustring = sBaustring + dItem.caption
  320.     if (withPageID) sBaustring = sBaustring + "(" + dItem.id + ")"
  321.     //if (dItem.id == 'extern') sBaustring = sBaustring + imgExtLink
  322.     if (dItem.id == 'target_blank') sBaustring = sBaustring + imgTargetBlank
  323. if (bDebug) sBaustring = sBaustring + "(" + dItem.index + ")"
  324. if (bDebug) sBaustring = sBaustring + "[" + sFolderOpen + "]"
  325.     if (dItem.link != "" && dItem.link != "/") sBaustring = sBaustring + '</a>'
  326.     sBaustring = sBaustring + fontOff
  327.     sBaustring = sBaustring + "</td><td><img src='../library/images/1ptrans.gif' width='2' height='1' alt='' /></td>"
  328.  
  329.     sBaustring = sBaustring + "</tr></table>"
  330.  
  331.     iLetztesItemLevel = iCLevel;
  332.     
  333.     if (iCCount != 0) {
  334.         sOpenDiv = true
  335.         sBaustring = sBaustring + "\n<div id='childObj" + iIndex + "' style='display:none; border:solid 0px aqua;'>";
  336.     }    
  337.     
  338.     sBaustingGesamt = sBaustingGesamt + sBaustring;
  339.     
  340.     
  341.     
  342. }
  343.  
  344. function setzteBuchstabe(sInString, iInStelle, sInBuchstabe) {
  345.     var sTmpString = "";
  346.     if (iInStelle < 0) return null;
  347.     
  348.     if (iInStelle > sInString.length) {
  349.         sTmpString = sInString + sInBuchstabe;
  350.         return sTmpString;
  351.     }
  352.     
  353.     sTmpString = sInString.substr(0, iInStelle - 1);
  354.     sTmpString = sTmpString + sInBuchstabe + sInString.substr(iInStelle, sInString.length - iInStelle);
  355.     return sTmpString;
  356. }
  357.  
  358. function drawImg(image, width, id, onClick){
  359.     if (trView.noDocumentWrite == false) {
  360.         imagesrc = image.src;
  361.     }else{
  362.         imagesrc = image;
  363.     }
  364.     imageCode = new String('<img src="' + imagesrc + '" border="0" alt=""');
  365.     if (width) imageCode = imageCode + ' width="' + width + '"';
  366.     if (id) imageCode = imageCode + ' id="iconimg' + id + '" name="iconimg' + id + '"';
  367.  
  368.     if (trView.noDocumentWrite == false && onClick) {
  369.         imageCode = imageCode + ' onClick="' + onClick + '"';
  370.         imageCode = imageCode + ' onMouseOver="this.style.cursor=\'hand\'"';
  371.     }
  372.     
  373.     imageCode = imageCode + '>';
  374.         
  375.     return imageCode;
  376. }
  377.  
  378. function nodeClick(nodeIndex) {
  379.     var cItem = document.getElementById("childObj" + nodeIndex);
  380.     
  381.     var sImage = document.getElementById("iconimg" + nodeIndex).src;
  382.  
  383.     if (trView.child[nodeIndex - 1].isOpen) {
  384.         trView.child[nodeIndex - 1].isOpen = false
  385.         cItem.style.display = "none"
  386.         switch_image ("iconimg" + nodeIndex, "imgPlus")
  387.     }else{
  388.         trView.child[nodeIndex - 1].isOpen = true
  389.         cItem.style.display = ""
  390.         switch_image ("iconimg" + nodeIndex, "imgMinus")
  391.     }
  392. }
  393.  
  394.  
  395. function searchAndOpenId(id) {
  396.     var searchIndex = -1;
  397.     var searchNode;
  398.     var sIndexPath = "";
  399. //1. Knoten nicht suchen
  400.     if (trView.child[0].id == id) {
  401.         return
  402.     }
  403. //Suche die Seite
  404. if (bDebug) alert("start search-ID")
  405.     var forcount = trView.count;
  406.     for (i = 0; i <= forcount; i++) {
  407.         if (trView.child[i].id == id) {
  408.             searchIndex = i;
  409.             searchNode = trView.child[i];
  410.             break;
  411.         }
  412.     }
  413. if (bDebug) alert("end search-ID")
  414. //Suche die Eltern
  415. if (bDebug) alert("start parent")
  416.     if (searchNode != null) {
  417.         sIndexPath = searchParent(searchNode, "");
  418.     }
  419. if (bDebug) alert("ende parent")
  420. //╓ffne Pfad
  421. if (bDebug) alert("start open")
  422.     if (sIndexPath != "") {
  423.         if (searchNode.childCount > 0) sIndexPath = sIndexPath + "," + searchIndex
  424.         sIndexArray = sIndexPath.split(",");
  425.         for (i = 1; i < sIndexArray.length; i++) {
  426. if (bDebug) alert("start node")
  427.  
  428.             if (!trView.child[eval(sIndexArray[i])].isOpen) nodeClick(eval(sIndexArray[i]) + 1);
  429.             if (!trView.child[sIndexArray[i]].isOpen) nodeClick(eval(sIndexArray[i]) + 1);
  430. if (bDebug) alert("end node")
  431.         }
  432.         setStyleOn(searchIndex)
  433.     }
  434. if (bDebug) alert("ende open")
  435.  
  436. }
  437. //Suche die Eltern
  438. function searchParent(cNode, sIndexPath) {
  439.     var aString = sIndexPath;
  440.     var pNode = cNode.parent;
  441.     
  442.     if (pNode.index != 0) {
  443.         aString = searchParent(pNode, sIndexPath);
  444.     }
  445.  
  446.     if (aString != "") aString = aString + ",";
  447.     aString = aString + pNode.index;
  448.     return aString;
  449. }
  450. function setStyleOn(linkIndex) {
  451.     if (lastLinkStyleOnIndex > -1) {
  452.         document.getElementById("linkid" + lastLinkStyleOnIndex).style.background='none';
  453.     }
  454.     //document.getElementById("linkid" + linkIndex).style.background='rgb(20,120,235)';
  455.     document.getElementById("linkid" + linkIndex).style.background=linkaktivfeld;
  456.     document.getElementById("linkid" + linkIndex).style.fontWeight='bold';
  457.     document.getElementById("linkid" + linkIndex).style.paddingLeft='2px';
  458.     lastLinkStyleOnIndex = linkIndex;
  459. }
  460.  
  461. function NNonload() {
  462. }
  463.  
  464.  
  465.