home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 25: Programming / pc_actual_25.iso / Javascript / InteractiveWebDesignJavascript / Scripting / cgi1 / cgi_intro / basefile / navbar.js < prev    next >
Encoding:
JavaScript  |  2001-07-18  |  3.8 KB  |  123 lines

  1. // navbar.js
  2. // (Global variables are declared in slide.js.)
  3. // Display previous/next slide in sequence, or goto other slide.
  4.  
  5. // 30 July 97: rewrite to use top instead of parent so that these functions
  6. // can be called from within index.htm and notes.htm too [enabling those
  7. // documents to do an onload="goto_slide(1, true)" ]
  8.  
  9. // By default, filenames are relative to inside of basefile directory,
  10. // so when loading HTML slide page files from main directory,
  11. // we prefix "../" to the filename.  However, the onload event handler
  12. // for documents index.htm and notes.htm must also call this function
  13. // to load the first page; those documents are in the main directory,
  14. // so we prefix "" to the filename.
  15.  
  16. function
  17. goto_slide(slide_num, caller_in_main_directory)
  18. {       var filename_prefix = ""
  19.     if (caller_in_main_directory == null) { filename_prefix = "../" }
  20.     if(slide_num < 1 || slide_num > top.last_slide){
  21.         alert("Please enter number between 1 and " + top.last_slide);
  22.     }
  23.     else {
  24.         top.current_slide = Math.abs(slide_num);
  25.         top.frames["slide"].location = filename_prefix + top.filename[slide_num];
  26.                 // update displayed page count in goto field
  27.                 top.frames["next"].document.forms["gotoform"].slidenum.value = top.current_slide;
  28.     }
  29. }
  30.  
  31. function
  32. prev_slide()
  33. {
  34.     if(top.current_slide == 1){
  35.         alert("You are already at the first slide.\nThere is no previous slide.");
  36.     } 
  37.         else goto_slide(top.current_slide - 1);
  38. }
  39.  
  40.  
  41. // Display next slide in sequence.
  42. function
  43. next_slide()
  44. {
  45.     
  46.     if (top.current_slide == top.last_slide){
  47.         alert("You are already at the last slide.\nThere is no next slide.");
  48.     } else goto_slide(top.current_slide + 1);
  49. }
  50.  
  51.  
  52. function
  53. goto_slide(slide_num, caller_in_main_directory)
  54. {       var filename_prefix = ""
  55.     if (caller_in_main_directory == null) { filename_prefix = "../" }
  56.     if(slide_num < 1 || slide_num > top.last_slide){
  57.         alert("Please enter number between 1 and " + top.last_slide);
  58.     }
  59.     else {
  60.         top.current_slide = Math.abs(slide_num);
  61.         top.frames["slide"].location = filename_prefix + top.filename[slide_num];
  62.                 // update displayed page count in goto field
  63.                 top.frames["next"].document.forms["gotoform"].slidenum.value = top.current_slide;
  64.     }
  65. }
  66.  
  67. function
  68. prev_slide(caller_in_main_directory)
  69. {
  70.     if(top.current_slide == 1){
  71.         alert("You are already at the first slide.\nThere is no previous slide.");
  72.     } 
  73.         else goto_slide(top.current_slide - 1, caller_in_main_directory);
  74. }
  75.  
  76.  
  77. // Display next slide in sequence.
  78. function
  79. next_slide(caller_in_main_directory)
  80. {
  81.     
  82.     if (top.current_slide == top.last_slide){
  83.         alert("You are already at the last slide.\nThere is no next slide.");
  84.     } else goto_slide(top.current_slide + 1, caller_in_main_directory);
  85. }
  86.  
  87.  
  88.  
  89. // KEYBOARD CONTROL IN NAV4
  90.  
  91. // *** NOTE: SUBTLE DIFFERENCE BETWEEN THIS CODE AND CODE IN style.js ***
  92. // Here, we do not pass parameter true to next_slide and prev_slide.
  93.  
  94. // support SPACE key codes (*not* RETURN because of Goto field!)
  95. var nextKeys = new String("nN ")
  96. var prevKeys = new String("pP")
  97.  
  98.  
  99. function handleKeys(e) {
  100.     var keyChar = String.fromCharCode(e.which);
  101.     if (prevKeys.indexOf(keyChar) != -1)
  102.     {  prev_slide(); return false  }
  103.     else if(nextKeys.indexOf(keyChar) != -1)
  104.     {  next_slide(); return false  }
  105.     else return true;
  106. }
  107.  
  108.  
  109.  
  110. // Workaround for Nav3.x bug in which JavaScript files
  111. // with <SCRIPT LANGUAGE="JavaScript1.2" SRC=...> are
  112. // loaded, even though they should be ignored.
  113. // Make sure this code is only executed by 4.x and later.
  114. if (parseInt(navigator.appVersion) > 3) {
  115.  
  116.    // support ESC key code  (*not* BS because of Goto field!)
  117.    prevKeys.concat(String.fromCharCode(27))
  118.    document.captureEvents(Event.KEYPRESS);
  119.    document.onkeypress = handleKeys;
  120.  
  121. } // end of Nav4+ only if
  122.  
  123.