popups.js
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 3k
Category:

Windows Kernel

Development Platform:

Visual C++

  1. //client area=460x345px
  2.    function popup(flag){
  3.    var bs=body.scrollTop
  4.    //set mouse coordinate variables - where click event occurred on document
  5.    var oX=event.clientX;
  6.    var oY=((event.clientY)+body.scrollTop);
  7.    
  8.    //check to see if cursor is in the client area (user is invoking popup with a keyboard)
  9.    if (((event.clientY)>345)||((event.clientY)<0)){
  10.        oY=(175+body.scrollTop)
  11.    }
  12.    if (((event.clientX)>444)||((event.clientX)<0)){
  13.        oX=(230)
  14.    }
  15.    
  16.    //set variables for popup object
  17.    var oDiv=document.all("popup"+flag);
  18.    var oDef=document.all("def"+flag);
  19.    
  20.    //set variable for definition length
  21.    var dLength=oDef.innerHTML.length
  22.    //determine width of the popup based on length of definition
  23.    if ((dLength)>=650){
  24.        oDiv.style.width="400px";
  25.    }
  26.    else if ((dLength)>=500){
  27.        oDiv.style.width="350px";
  28.    }
  29.    else if ((dLength)>=350){
  30.        oDiv.style.width="300px";
  31.    }
  32.    else if ((dLength)>=200){
  33.        oDiv.style.width="250px";
  34.    }
  35.    else if ((dLength)>=150){
  36.        oDiv.style.width="225px";
  37.    }
  38.    else if ((dLength)>=100){
  39.        oDiv.style.width="200px";
  40.    }
  41.    else if ((dLength)>=60){
  42.        oDiv.style.width="175px";
  43.    }
  44.    else {
  45.        oDiv.style.width="150px";
  46.    }
  47.    //set variables for the object's height and width
  48.    var oDivW=oDef.offsetWidth;
  49.    var oDivH=oDiv.offsetHeight;
  50.    
  51.    //set variables for document width (changes depending on whether page scrolls)
  52.    var docW=document.body.clientWidth;
  53.    
  54.    //set variables for distance to center and middle of the object
  55.    var oDivC=(oDivW /2);
  56.    var oDivM=(oDivH /2);
  57.    
  58.    //position object over mouse click
  59.  
  60.        //ensure top margin of 2 pixels
  61.        if (((oY - oDivM)- 2)<=0){
  62.    oDiv.style.top=2
  63.    }
  64.    else {
  65.    oDiv.style.top=(oY - oDivM)
  66.    }
  67.  
  68.    //ensure left margin of 10 pixels
  69.        if (((oX-oDivC)-10)<=0){
  70.    oDiv.style.left=10
  71.    }
  72.    //ensure right margin of 10 pixels
  73.    else if ((oX+oDivC)>=(docW-12)){
  74.    oDiv.style.left=((docW-12)-oDivW);
  75.    }
  76.    else {
  77.    oDiv.style.left=(oX-oDivC);
  78.    }
  79.    
  80.        //ensure top of popup is visible - scroll if necessary
  81.    if ((body.scrollTop+oDivM)>=oY){
  82.    bs=((oY-2)-oDivM);
  83.    body.scrollTop=bs;
  84.    }
  85.    
  86. //ensure bottom of popup is visible - scroll if necessary
  87.    if (((oY+oDivM+10)-(body.scrollTop))>=345){
  88.    bs=((oY+oDivM+10)-345);
  89.    body.scrollTop=bs;
  90.    }
  91.    //set variables for the object's position
  92.    var oDivT=oDiv.style.pixelTop
  93.    var oDivL=oDiv.style.pixelLeft
  94.    //z-layer the popup over the drop shadow
  95.    oDiv.style.zIndex=2
  96.    shadow.style.zIndex=1
  97.    
  98.    //set the shadow size exactly the same as the definition
  99.    shadow.style.width=(oDivW+2);
  100.    shadow.style.height=oDivH;
  101.    
  102.    //position the drop shadow relative to the definition   
  103.    shadow.style.top=(oDivT+8);
  104.    shadow.style.left=(oDivL+7);
  105.    
  106.    //show the definition
  107.    oDiv.style.visibility="visible";
  108.    
  109.   //show the drop shadow
  110.    shadow.style.visibility="visible";
  111.        
  112.    //give the popup focus
  113.    oDef.focus();
  114.    
  115.    //scroll appropriate amount
  116.    body.scrollTop=bs;
  117.   
  118.    }
  119.    
  120.    
  121.    function popOff(flag){
  122.    var oDiv=document.all("popup"+flag);
  123.    oDiv.style.visibility="hidden";
  124.    shadow.style.visibility="hidden"
  125.    }
  126.    
  127.    
  128.    function nothing(){}