home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 November / Chip_2001-11_cd1.bin / data / popup.js < prev    next >
Text File  |  2001-09-01  |  6KB  |  240 lines

  1. ////////////////////////////////////////////////////////////////////////////////////
  2. // CONFIGURATION
  3. ////////////////////////////////////////////////////////////////////////////////////
  4.  
  5. // Main background color (the large area)
  6. // Usually a bright color (white, yellow etc)
  7.     if (typeof fcolor == 'undefined') { var fcolor = "#CCCCFF";}
  8.     
  9. // Border color and color of caption
  10. // Usually a dark color (black, brown etc)
  11.     if (typeof backcolor == 'undefined') { var backcolor = "#333399";}
  12.     
  13.     
  14. // Text color
  15. // Usually a dark color
  16.     if (typeof textcolor == 'undefined') { var textcolor = "#000000";}
  17.     
  18. // Color of the caption text
  19. // Usually a bright color
  20.     if (typeof capcolor == 'undefined') { var capcolor = "#FFFFFF";}
  21.     
  22. // Color of "Close" when using Sticky
  23. // Usually a semi-bright color
  24.     if (typeof closecolor == 'undefined') { var closecolor = "#9999FF";}
  25.     
  26.     
  27. // Width of the popups in pixels
  28. // 100-300 pixels is typical
  29.     if (typeof width == 'undefined') { var width = "200";}
  30.     
  31. // How thick the border should be in pixels
  32. // 1-3 pixels is typical
  33.     if (typeof border == 'undefined') { var border = "1";}
  34.     
  35.     
  36. // How many pixels to the right/left of the cursor to show the popup
  37. // Values between 3 and 12 are best
  38.     if (typeof offsetx == 'undefined') { var offsetx = 10;}
  39.     
  40. // How many pixels to the below the cursor to show the popup
  41. // Values between 3 and 12 are best
  42.     if (typeof offsety == 'undefined') { var offsety = 10;}
  43.     
  44. ////////////////////////////////////////////////////////////////////////////////////
  45. // END CONFIGURATION
  46. ////////////////////////////////////////////////////////////////////////////////////
  47.  
  48. ns4 = (document.layers)? true:false
  49. ie4 = (document.all)? true:false
  50.  
  51. // Microsoft Stupidity Check.
  52. if (ie4) {
  53.     if (navigator.userAgent.indexOf('MSIE 5')>0) {
  54.         ie5 = true;
  55.     } else {
  56.         ie5 = false; }
  57. } else {
  58.     ie5 = false;
  59. }
  60.  
  61. var x = 0;
  62. var y = 0;
  63. var snow = 0;
  64. var sw = 0;
  65. var cnt = 0;
  66. var dir = 1;
  67. var tr = 1;
  68. if ( (ns4) || (ie4) ) {
  69.     if (ns4) over = document.overDiv
  70.     if (ie4) over = overDiv.style
  71.     document.onmousemove = mouseMove
  72.     if (ns4) document.captureEvents(Event.MOUSEMOVE)
  73. }
  74.  
  75. // Public functions to be used on pages.
  76.  
  77. // Simple popup right
  78. function drs(text) {
  79.     dts(1,text);
  80. }
  81.  
  82. // Caption popup right
  83. function drc(text, title) {
  84.     dtc(1,text,title);
  85. }
  86.  
  87. // Sticky caption right
  88. function src(text,title) {
  89.     stc(1,text,title);
  90. }
  91.  
  92. // Simple popup left
  93. function dls(text) {
  94.     dts(0,text);
  95. }
  96.  
  97. // Caption popup left
  98. function dlc(text, title) {
  99.     dtc(0,text,title);
  100. }
  101.  
  102. // Sticky caption left
  103. function slc(text,title) {
  104.     stc(0,text,title);
  105. }
  106.  
  107. // Simple popup center
  108. function dcs(text) {
  109.     dts(2,text);
  110. }
  111.  
  112. // Caption popup center
  113. function dcc(text, title) {
  114.     dtc(2,text,title);
  115. }
  116.  
  117. // Sticky caption center
  118. function scc(text,title) {
  119.     stc(2,text,title);
  120. }
  121.  
  122. // Clears popups if appropriate
  123. function nd() {
  124.     if ( cnt >= 1 ) { sw = 0 };
  125.     if ( (ns4) || (ie4) ) {
  126.         if ( sw == 0 ) {
  127.             snow = 0;
  128.             hideObject(over);
  129.         } else {
  130.             cnt++;
  131.         }
  132.     }
  133. }
  134.  
  135. // Non public functions. These are called by other functions etc.
  136.  
  137. // Simple popup
  138. function dts(d,text) {
  139.     txt = "<TABLE WIDTH="+width+" BORDER=0 CELLPADDING="+border+" CELLSPACING=0 BGCOLOR=\""+backcolor+"\"><TR><TD><TABLE WIDTH=100% BORDER=0 CELLPADDING=5 CELLSPACING=0 BGCOLOR=\""+fcolor+"\"><TR><TD><FONT ID=\"preview\" COLOR=\""+textcolor+"\">"+text+"</FONT></TD></TR></TABLE></TD></TR></TABLE>"
  140.     layerWrite(txt);
  141.     dir = d;
  142.     disp();
  143. }
  144.  
  145. // Caption popup
  146. function dtc(d,text, title) {
  147.     txt = "<TABLE WIDTH="+width+" BORDER=0 CELLPADDING="+border+" CELLSPACING=0 BGCOLOR=\""+backcolor+"\"><TR><TD><TABLE WIDTH=100% BORDER=0 CELLPADDING=0 CELLSPACING=0><TR><TD><SPAN ID=\"PTT\"><B><FONT COLOR=\""+capcolor+"\">"+title+"</FONT></B></SPAN></TD></TR></TABLE><TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=0 BGCOLOR=\""+fcolor+"\"><TR><TD><SPAN ID=\"PST\"><FONT COLOR=\""+textcolor+"\">"+text+"</FONT><SPAN></TD></TR></TABLE></TD></TR></TABLE>"
  148.     layerWrite(txt);
  149.     dir = d;
  150.     disp();
  151. }
  152.  
  153. // Sticky
  154. function stc(d,text, title) {
  155.     sw = 1;
  156.     cnt = 0;
  157.     txt = "<TABLE WIDTH="+width+" BORDER=0 CELLPADDING="+border+" CELLSPACING=0 BGCOLOR=\""+backcolor+"\"><TR><TD><TABLE WIDTH=100% BORDER=0 CELLPADDING=0 CELLSPACING=0><TR><TD><SPAN ID=\"PTT\"><B><FONT COLOR=\""+capcolor+"\">"+title+"</FONT></B></SPAN></TD><TD ALIGN=RIGHT><A HREF=\"/\" onMouseOver=\"cClick();\" ID=\"PCL\"><FONT COLOR=\""+closecolor+"\">Close</FONT></A></TD></TR></TABLE><TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=0 BGCOLOR=\""+fcolor+"\"><TR><TD><SPAN ID=\"PST\"><FONT COLOR=\""+textcolor+"\">"+text+"</FONT><SPAN></TD></TR></TABLE></TD></TR></TABLE>"
  158.     layerWrite(txt);
  159.     dir = d;
  160.     disp();
  161.     snow = 0;
  162. }
  163.  
  164. // Common calls
  165. function disp() {
  166.     if ( (ns4) || (ie4) ) {
  167.         if (snow == 0)     {
  168.             if (dir == 2) { // Center
  169.                 moveTo(over,x+offsetx-(width/2),y+offsety);
  170.             }
  171.             if (dir == 1) { // Right
  172.                 moveTo(over,x+offsetx,y+offsety);
  173.             }
  174.             if (dir == 0) { // Left
  175.                 moveTo(over,x-offsetx-width,y+offsety);
  176.             }
  177.             showObject(over);
  178.             snow = 1;
  179.         }
  180.     }
  181. // Here you can make the text goto the statusbar.
  182. }
  183.  
  184. // Moves the layer
  185. function mouseMove(e) {
  186.     if (ns4) {x=e.pageX; y=e.pageY;}
  187.     if (ie4) {x=event.x; y=event.y;}
  188.     if (ie5) {x=event.x+document.body.scrollLeft; y=event.y+document.body.scrollTop;}
  189.     if (snow) {
  190.         if (dir == 2) { // Center
  191.             moveTo(over,x+offsetx-(width/2),y+offsety);
  192.         }
  193.         if (dir == 1) { // Right
  194.             moveTo(over,x+offsetx,y+offsety);
  195.         }
  196.         if (dir == 0) { // Left
  197.             moveTo(over,x-offsetx-width,y+offsety);
  198.         }
  199.     }
  200. }
  201.  
  202. // The Close onMouseOver function for Sticky
  203. function cClick() {
  204.     hideObject(over);
  205.     sw=0;
  206. }
  207.  
  208. // Writes to a layer
  209. function layerWrite(txt) {
  210.         if (ns4) {
  211.                 var lyr = document.overDiv.document
  212.                 lyr.write(txt)
  213.                 lyr.close()
  214.         }
  215.         else if (ie4) document.all["overDiv"].innerHTML = txt
  216.         if (tr) { trk(); }
  217. }
  218.  
  219. // Make an object visible
  220. function showObject(obj) {
  221.         if (ns4) obj.visibility = "show"
  222.         else if (ie4) obj.visibility = "visible"
  223. }
  224.  
  225. // Hides an object
  226. function hideObject(obj) {
  227.         if (ns4) obj.visibility = "hide"
  228.         else if (ie4) obj.visibility = "hidden"
  229. }
  230.  
  231. // Move a layer
  232. function moveTo(obj,xL,yL) {
  233.         obj.left = xL
  234.         obj.top = yL
  235. }
  236.  
  237. function trk() {
  238.     tr = 0;
  239. }
  240.