home *** CD-ROM | disk | FTP | other *** search
/ Online Praxis 1998 March / Image.iso / CD-ROM / NETSCAPE / CCK / ASE.Z / tabsuprt.js < prev    next >
Encoding:
JavaScript  |  1997-08-21  |  3.6 KB  |  159 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.     //FIXME FIXME: THIS FUCNTION HAS A TEMPORARY FIX FOR A BUG IN DOGBERT.
  15.     //FIXME WHEN IT'S RESOLVED BUG # 69298
  16.  
  17.     if ((imageRef) && (imageRef != null))
  18.     {
  19.         if (imageRef.lowsrc && imageRef.src);
  20.         {
  21.             var lsrc = imageRef.lowsrc;
  22.             var src = imageRef.src;
  23.             
  24.             imageRef.lowsrc = src;
  25.             imageRef.src = lsrc;    
  26.         }
  27.     }
  28. }
  29.  
  30.  
  31. //given a link object, tells you which link it is in the document.
  32. function findLinkIndex(linkRef)
  33. {
  34.  
  35.     var curIdx = -1;
  36.  
  37.     if ((linkRef) && (linkRef != null))
  38.     {
  39.         for (curIdx = 0; curIdx < document.links.length; curIdx++)
  40.         {
  41.         
  42.             if (document.links[curIdx] == linkRef)
  43.                 return curIdx;
  44.         }
  45.     }
  46.  
  47.     return -1;
  48.  
  49. }
  50.  
  51.  
  52.  
  53. //THIS IS A FUCKED UP HACK.
  54. // there was no good way to tell which image was last on, without making some sort of persistent data
  55. //storage, so this is the hack.
  56. // We already assume that there is a 1-to-1 correspondence between the links  array and the
  57. //image array in the document.
  58. //SO, we go to the links array, check the target's location, and see
  59. // if that is equivalent to the link location.  IF SO, we assume it IS ON.
  60. // else it is off.
  61. function imageIsOn(imageRef)
  62. {
  63.     var out = false;
  64.     
  65.     var dot = imageRef.src.lastIndexOf(".");
  66.     
  67.     var indicator = imageRef.src.substring(dot-1, dot);
  68.     
  69.     //alert("dot: " + dot + " indicator: " + indicator + " src: " + imageRef.src);
  70.     
  71.     if (indicator == "a")
  72.         out = true;
  73.  
  74.  
  75.     return out;
  76. }
  77.  
  78.  
  79. //checks the name property of the passed in image object, if it is "ON", swaps the images.
  80. // if it is anything else, does nothing
  81. function swapImageIfOn(imageIndex, imageRef)
  82. {
  83.     if ((imageRef) && (imageRef != null))
  84.     {
  85.         if ((imageRef.name))
  86.         {
  87.             if (imageIsOn(imageRef))
  88.             {
  89.                 swapSrcLowsrc(imageRef);
  90.                 //alert("Image " + imageIndex + " was on.");
  91.                 
  92.                 return true;
  93.             }
  94.         }
  95.     }
  96.     return false;
  97. }
  98.  
  99.  
  100.  
  101. function tabClicked(linkRef)
  102. {
  103.  
  104.     var theIndex = findLinkIndex(linkRef);
  105.     var onImage = document.images[theIndex];
  106.     
  107.     //first see if the tab that was clicked is the currently active tab, if so, abort
  108.     //FIXME FIXME: THIS FUCNTION HAS A TEMPORARY FIX FOR A BUG IN DOGBERT.
  109.     //FIXME WHEN IT'S RESOLVED BUG # 69298
  110.     if (imageIsOn(onImage))
  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.     //alert("tabsuprt: checkresult was true");    
  124.     
  125.     
  126.     var wason = false;
  127.     var target = null;
  128.     
  129.     if ((theIndex >= 0) && (onImage) && (onImage != null))
  130.     {
  131.         //found our image,
  132.         
  133.         //turn all images off
  134.         for (var curImageIndex = 0; curImageIndex < document.images.length; curImageIndex++)
  135.         {
  136.             wason = swapImageIfOn(curImageIndex, document.images[curImageIndex]);    
  137.             
  138.             //this is the funny thing we do to save the data if a savedata event handler is there
  139.             if (wason == true)
  140.             {
  141.                 target = eval("parent." + document.links[curImageIndex].target);
  142.                 if ((target) && (target != null) && (target.saveData))
  143.                 {
  144.                     //alert("tabsuprt: savedata");
  145.                     target.saveData();
  146.                     //alert("tabsuprt: savedata finished");
  147.                 }
  148.             
  149.             
  150.             }
  151.         }
  152.  
  153.         //turn this image visually on
  154.         swapSrcLowsrc(onImage);    
  155.     }
  156.  
  157.     return true;
  158. }
  159.