home *** CD-ROM | disk | FTP | other *** search
/ The Net Power 1997 January / NETPower0197.iso / pc / html / issue / feat1 / selector / selector.txt < prev   
Encoding:
Text File  |  1996-10-09  |  3.0 KB  |  125 lines

  1. <SCRIPT language="javascript">
  2. <!-- Image Selector
  3. // Cameron Gregory - cameron@local.com
  4. // http://www.bloke.com
  5. // http://www.bloke.com/javascript/Selector/
  6. //
  7. // ChangeLog
  8. //
  9. // Wed Jul 10 11:29:51 EDT 1996
  10. //    Added -1 check on array
  11. // Wed Jul 10 06:25:30 EDT 1996
  12. //    merged pulldown and selector into one.
  13. //
  14. // Wed Jul 10 06:03:05 EDT 1996
  15. //    3.0b5a hosed something! Stopped using Image objects
  16. //    and just stored in array.
  17. //
  18. // Usage:
  19. //  Selector(width,height,images)
  20. //  SelectorLong(width,height,boxHeight,images)
  21. //  SelectorLongNames(width,height,boxHeight,images,names)
  22. //  PullDownSelector(width,height,images)
  23. //  PullDownSelectorNames(width,height,images,names)
  24. //
  25. //     width, height    is image size (-1,-1) if you don't want to specify
  26. //     boxHeight    is the height of the select box
  27. //     images        is space or comma separated file list
  28. //     names        is corresponding name array (comma separated)
  29.  
  30. function selectImage(f)
  31. {
  32. if (document.flipForm.which.selectedIndex >= 0)
  33.   document.flipForm.flip.src = imageSet[document.flipForm.which.selectedIndex];
  34. }
  35.  
  36. function SelectorLongNames(width,height,listHeight,images,names)
  37. {
  38. /* si: start index 
  39. ** i: current index
  40. ** ei: end index
  41. ** cc: current count
  42. */
  43.  si = 0; 
  44.  ci=0;
  45.  cc=0;
  46.  imageSet = new Array();
  47.  ei = images.length;
  48.   for (i=1;i<ei;i++) {
  49.     if (images.charAt(i) == ' ' || images.charAt(i) == ',') {
  50.       imageSet[cc] = images.substring(si,i);
  51.       cc++;
  52.       si=i+1;
  53.       }
  54.     }
  55.   currentFlip = 0;
  56.  si = 0; 
  57.  ci=0;
  58.  cc=0;
  59.  nameSet = new Array();
  60.  ei = names.length;
  61.   for (i=1;i<ei;i++) {
  62.     if (names.charAt(i) == ',') {
  63.       nameSet[cc] = names.substring(si,i);
  64.       cc++;
  65.       si=i+1;
  66.       }
  67.     }
  68.   currentFlip = 0;
  69.  
  70.   // should check nameSet.length == imageSet.length
  71.  
  72.   document.writeln("<FORM name=flipForm>");
  73.   document.writeln("<table border=0><tr><td>");
  74.   document.write("<img name='flip'");
  75.   if (width >0)
  76.     document.write("width="+width);
  77.   if (height >0)
  78.     document.write(" height=" +height);
  79.   document.writeln(" src=" +imageSet[0]+ ">");
  80.   document.writeln("</td><td>");
  81.  
  82.   document.write("<Select");
  83.   if (listHeight > 0)
  84.     document.write(" size="+listHeight);
  85.   document.write(" name='which' onChange='selectImage(this.form)'>");
  86.  
  87.   for (i=0;i<imageSet.length;i++)
  88.     if (i<nameSet.length)
  89.       document.write("<OPTION value="+i+">"+nameSet[i]);
  90.     else
  91.       document.write("<OPTION value="+i+">"+imageSet[i]);
  92.  
  93.   document.writeln("</SELECT>");
  94.   
  95.   document.writeln("</FORM>");
  96.  
  97.  document.writeln("</td></tr></table>");
  98. }
  99.  
  100.  
  101. function SelectorLong(width,height,listHeight,images)
  102. {
  103.   SelectorLongNames(width,height,listHeight,images,",");
  104. }
  105.  
  106. function PullDownSelector(width,height,images)
  107. {
  108.   SelectorLongNames(width,height,-1,images,",")
  109. }
  110.  
  111. function PullDownSelectorNames(width,height,images,names)
  112. {
  113.   SelectorLongNames(width,height,-1,images,names)
  114. }
  115.  
  116. // use -1 -1 if you don't know the width and height for the image
  117. function Selector(width,height,images)
  118. {
  119.  listHeight=5;
  120.   SelectorLong(width,height,listHeight,images);
  121. }
  122.  
  123. // End Script -->
  124. </SCRIPT>
  125.