home *** CD-ROM | disk | FTP | other *** search
/ Online Praxis 1998 March / Image.iso / CD-ROM / NETSCAPE / CCK / ASE.Z / ncitabs.jar / tabsuprt.js
Encoding:
JavaScript  |  1997-11-03  |  3.4 KB  |  156 lines

  1. //tabs.js
  2. // a set of functions for making a set of tabs in one frame that control the content of another frame
  3.  
  4.  
  5. //tab images have to have names like: 
  6. //tabnamea.gif (active)
  7. //tabnamei.gif (inactive)
  8.  
  9.  
  10.  
  11. //swaps the lowsrc and src images of an image reference
  12. function swapSrcLowsrc(imageRef)
  13. {
  14.  
  15.     if ((imageRef) && (imageRef != null))
  16.     {
  17.         if (imageRef.lowsrc && imageRef.src);
  18.         {
  19.             var lsrc = imageRef.lowsrc;
  20.             var src = imageRef.src;
  21.             
  22.             imageRef.lowsrc = src;
  23.             imageRef.src = lsrc;    
  24.         }
  25.     }
  26. }
  27.  
  28.  
  29. //given a link object, tells you which link it is in the document.
  30. function findLinkIndex(linkRef)
  31. {
  32.  
  33.     var curIdx = -1;
  34.  
  35.     if ((linkRef) && (linkRef != null))
  36.     {
  37.         for (curIdx = 0; curIdx < document.links.length; curIdx++)
  38.         {
  39.         
  40.             if (document.links[curIdx] == linkRef)
  41.                 return curIdx;
  42.         }
  43.     }
  44.  
  45.     return -1;
  46.  
  47. }
  48.  
  49.  
  50.  
  51. //THIS IS A FUCKED UP HACK.
  52. // there was no good way to tell which image was last on, without making some sort of persistent data
  53. //storage, so this is the hack.
  54. // We already assume that there is a 1-to-1 correspondence between the links  array and the
  55. //image array in the document.
  56. //SO, we go to the links array, check the target's location, and see
  57. // if that is equivalent to the link location.  IF SO, we assume it IS ON.
  58. // else it is off.
  59. function imageIsOn(imageRef)
  60. {
  61.     var out = false;
  62.     
  63.     var dot = imageRef.src.lastIndexOf(".");
  64.     
  65.     var indicator = imageRef.src.substring(dot-1, dot);
  66.     
  67.     //alert("dot: " + dot + " indicator: " + indicator + " src: " + imageRef.src);
  68.     
  69.     if (indicator == "a")
  70.         out = true;
  71.  
  72.  
  73.     return out;
  74. }
  75.  
  76.  
  77. //checks the name property of the passed in image object, if it is "ON", swaps the images.
  78. // if it is anything else, does nothing
  79. function swapImageIfOn(imageIndex, imageRef)
  80. {
  81.     if ((imageRef) && (imageRef != null))
  82.     {
  83.         if ((imageRef.name))
  84.         {
  85.             if (imageIsOn(imageRef))
  86.             {
  87.                 swapSrcLowsrc(imageRef);
  88.                 //alert("Image " + imageIndex + " was on.");
  89.                 
  90.                 return true;
  91.             }
  92.         }
  93.     }
  94.     return false;
  95. }
  96.  
  97.  
  98.  
  99. function tabClicked(linkRef)
  100. {
  101.  
  102.  
  103.     var theIndex = findLinkIndex(linkRef);
  104.     var onImage = document.images[theIndex];
  105.     
  106.     //first see if the tab that was clicked is the currently active tab, if so, abort
  107.     //FIXME FIXME: THIS FUCNTION HAS A TEMPORARY FIX FOR A BUG IN DOGBERT.
  108.     //FIXME WHEN IT'S RESOLVED BUG # 69298
  109.     if (imageIsOn(onImage))
  110.     {
  111.         return false;
  112.     }
  113.  
  114.     //second do a checkdata, if such a function exists in the tabbody
  115.     if (parent.tabbody && parent.tabbody.document && parent.tabbody.checkData)
  116.     {
  117.         var checkResult = parent.tabbody.checkData();
  118.         if (checkResult != true)
  119.             return checkResult;
  120.     }
  121.  
  122.     
  123.     
  124.     
  125.     var wason = false;
  126.     var target = null;
  127.     
  128.     if ((theIndex >= 0) && (onImage) && (onImage != null))
  129.     {
  130.         //found our image,
  131.         
  132.         //turn all images off
  133.         for (var curImageIndex = 0; curImageIndex < document.images.length; curImageIndex++)
  134.         {
  135.             wason = swapImageIfOn(curImageIndex, document.images[curImageIndex]);    
  136.             
  137.             //this is the funny thing we do to save the data if a savedata event handler is there
  138.             if (wason == true)
  139.             {
  140.                 target = eval("parent." + document.links[curImageIndex].target);
  141.                 if ((target) && (target != null) && (target.saveData))
  142.                 {
  143.                     target.saveData();
  144.                 }
  145.             
  146.             
  147.             }
  148.         }
  149.  
  150.         //turn this image visually on
  151.         swapSrcLowsrc(onImage);    
  152.     }
  153.  
  154.     return true;
  155. }
  156.