home *** CD-ROM | disk | FTP | other *** search
/ com!online 2002 May / comcd0502.iso / homepage / special / javascript / 01_01 / Java / puzzlex / puzzlex.js < prev    next >
Encoding:
JavaScript  |  2000-03-17  |  2.7 KB  |  91 lines

  1. // ------ this function is all you need to modify in this script ------
  2.  
  3. function defineImages() {
  4.   picPool[0] = new picPara("laputa1.jpg",540,420,5,4,10,"image from Laputa, 540x420, 5x4, 24kb");
  5.   picPool[1] = new picPara("laputa2.jpg",360,450,4,5,10,"image from Laputa, 360x450, 4x5, 26kb");
  6.   picPool[2] = new picPara("laputa3.jpg",640,480,5,4,10,"image from Laputa, 640x480, 5x4, 45kb");
  7.   picPool[3] = new picPara("laputa4.jpg",450,350,6,5,10,"image from Laputa, 450x350, 6x5, 20kb");
  8. }
  9.  
  10. //------ you don't need to care about the following codes ------
  11.  
  12. var isIE4 = false; isNN4 = false;
  13.  
  14. var picPool = new Array();
  15. var pic_image_source = "";
  16. var pic_image_width = 0;
  17. var pic_image_height = 0;
  18. var pic_grip_x = 1;
  19. var pic_grip_y = 1;
  20. var pic_table_gap = 0;
  21.  
  22. var puzzle_window = null;
  23.  
  24. function mouseHover() {
  25.   window.status = picPool[this.index].info;
  26.   return true;
  27. }
  28.  
  29. function mouseGone() {
  30.   window.status = window.defaultStatus;
  31.   return true;
  32. }
  33.  
  34. function mouseClick() {
  35.   goPuzzleX(this.index);
  36.   return false;
  37. }
  38.  
  39. function picPara(image_source,image_width,image_height,grip_x,grip_y,table_gap,image_info) {
  40.   this.source = image_source;
  41.   this.width = image_width;
  42.   this.height = image_height;
  43.   this.grip_x = grip_x;
  44.   this.grip_y = grip_y;
  45.   this.table_gap = table_gap;
  46.   this.info = image_info;
  47. }
  48.  
  49. function setupImages() {
  50.   isIE4 = (document.all)?true:false; isNN4 = (document.layers)?true:false;
  51.  
  52.   defineImages();
  53.  
  54.   var linksCount = document.links.length, hashIndex = -1, puzzleIndex = -1, hashTag = "puzzlex";
  55.   for (var i = 0; i < linksCount; i++) {
  56.     hashIndex = document.links[i].hash.indexOf(hashTag);
  57.     if (hashIndex != -1) {
  58.       puzzleIndex = parseInt(document.links[i].hash.substring(hashIndex+7));
  59.       document.links[i].index = puzzleIndex;
  60.       document.links[i].onmouseover = mouseHover;
  61.       document.links[i].onmouseout = mouseGone;
  62.       document.links[i].onclick = mouseClick;
  63.     }
  64.   }
  65. }
  66.  
  67. function Build_Puzzle() {
  68.   var window_para = "width=" + (pic_image_width + pic_table_gap * 6) +",height=" + (pic_image_height + pic_table_gap * 6) + ",titlebar=1";
  69.  
  70.   if (isIE4 || isNN4) {
  71.     if (puzzle_window != null)
  72.       if (!puzzle_window.closed)
  73.         puzzle_window.close();
  74.  
  75.     puzzle_window = window.open("puzzlex.html", "Puzzle_Window", window_para); }
  76.   else {
  77.     alert("Sorry !\nYou need a version 4 or above browser.");
  78.   }
  79. }
  80.  
  81. function goPuzzleX(pic_index) {
  82.   pic_image_source = picPool[pic_index].source;
  83.   pic_image_width = picPool[pic_index].width;
  84.   pic_image_height = picPool[pic_index].height;
  85.   pic_grip_x = picPool[pic_index].grip_x;
  86.   pic_grip_y = picPool[pic_index].grip_y;
  87.   pic_table_gap = picPool[pic_index].table_gap;
  88.  
  89.   Build_Puzzle();
  90. }
  91.