home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 Special / chip-cd_2001_spec_05.zip / spec_05 / document.cab / gp.chm / rkshared.js < prev    next >
Text File  |  1999-12-10  |  8KB  |  235 lines

  1. var sActX_HH= " type='application/x-oleobject' classid='clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11' ";
  2. var moniker= "ms-its:";  
  3.  
  4. var numbers= /\d/g;                //javascript regular expression
  5. var spaces= /\s/g;                //javascript regular expression
  6. var semicolon= /;/g;            //javascript regular expression
  7.  
  8. document.onclick= onclickTriage;
  9.  
  10.  
  11.  //****** insertImages ********************************************************************************************* 
  12.  //  Inserts shared images in User-Defined Variables section and thumbnails.
  13.  
  14. function insertImages(){
  15. // alert("insertImages");
  16.  
  17.  
  18.  if (oAnchor=="thumbnail"  || oAnchor=="thumbnailweb"){ 
  19.             var sAltText = document.anchors[i].innerHTML; 
  20.             var sThumbnailText = document.anchors[i].title; 
  21.             var oImg = document.anchors[i].href.toLowerCase();
  22.                   if (oAnchor=="thumbnail") 
  23.                          var sThumbnailImg= moniker + getURL(oImg);
  24.                   else var sThumbnailImg = document.anchors[i].href.toLowerCase();
  25.                 document.anchors[i].outerHTML = "<DIV id='thumbDiv' class='thumbnail'>"+document.anchors[i].outerHTML+"</div>";
  26.                 document.anchors[i].innerHTML = "<img class='thumbnail' src='" + sThumbnailImg + "' alt= ' " + sAltText + "'><p>" +sThumbnailText+"</p>";
  27.                 
  28.                   if (isRTL) thumbDiv.style.styleFloat= "right";
  29.        }
  30.             
  31.         document.anchors[i].innerHTML = imgInsert + document.anchors[i].innerHTML;
  32.        if (isRTL) document.anchors[i].dir="rtl";
  33.    
  34. }
  35.  
  36.  
  37. //***** onclickTriage ****************************************************************************************
  38. // redirects to the appropriate function based on the ID of the clicked <A> tag.
  39.  
  40. function onclickTriage(){
  41. // alert("onclickTriage");
  42. var e= window.event.srcElement;
  43.  
  44. //  if the innerHTML in the <a> tag is encapsulated by a style tag or hightlighted in the word seach,
  45. //  the parentElement is called.
  46.  
  47.     for (var i=0; i < 5; i++)
  48.            if (e.tagName!="A" && e.parentElement!=null) e= e.parentElement;
  49.     eID= e.id.toLowerCase();
  50.                 
  51.     if (popupOpen) closePopup();
  52.     
  53.  // expand image in a new window
  54.     if (eID=="thumbnail" || eID=="pophtm") popNewWindow(e);
  55.     else if (eID=="altloc") callAltLocation(e);
  56.     return;
  57. }
  58.  
  59.  
  60. function popNewWindow(eventSrc) {
  61. // alert("popNewWindow");
  62. var eH= eventSrc.href;
  63.       event.returnValue = false;
  64.        
  65.  // extracts the thumbnail image URL from the <a> tag HREF
  66.     sParamFILE =  getURL(eH);
  67.     if (sParamFILE=="") return;
  68.        
  69.  // if the hhWindow object exists, clears it
  70.     if (document.hhWindow) document.hhWindow.outerHTML = "";        
  71.         
  72. var  h =  "<object id='hhWindow'"+ sActX_HH +" STYLE='display:none'><param name='Command' value='Related Topics'>";
  73.      h = h + "<param name='Window' value='$global_largeart'><param name='Item1' value='$global_largeart;" + moniker + sParamFILE+ "'> </object>";
  74.     
  75.      document.body.insertAdjacentHTML("beforeEnd", h);
  76.      document.hhWindow.hhclick();
  77. }
  78.  
  79. var popupOpen= false;                //state of popups
  80. var posX, posY;                        //coordinates of popups
  81. var oPopup;                            //object to be used as popup content
  82.  
  83. //**** callPopupWeb **************************************************************************************
  84. // the web popups have been converted from the object winHelp popup for the web.
  85. // called by: <A ID="wPopupWeb" HREF="#">@@Popup text@@</A>
  86. // followed by: <div class="popup">Popup content</div>
  87.  
  88.  
  89. function callPopupWeb(eventSrc) {
  90. // alert("callPopupWeb");
  91. var e= eventSrc;
  92.   
  93.   // find the popup <div> that follows <a id="wPopupWeb"></a>
  94.   findPopup(e);
  95.   positionPopup(e)
  96.  
  97.   oPopup.style.visibility = "visible";
  98.   popupOpen = true;
  99.  
  100.   return;
  101. }
  102.  
  103. //**** findPopup ****************************************************************************************
  104.  
  105. function findPopup(oX){
  106. // alert("findPopup");
  107. var e= oX;
  108. var iNextTag;
  109.     
  110.     for (var i=1;i<4; i++){
  111.          iNextTag=    e.sourceIndex + i;
  112.          oPopup= document.all(iNextTag);
  113.          if (oPopup.className.toLowerCase()=="popup" || iNextTag == document.all.length)
  114.              break;
  115.     }
  116.     if (iNextTag != document.all.length) {
  117.         posX = window.event.clientX; 
  118.         posY = window.event.clientY + document.body.scrollTop+10;
  119.     }
  120.     else closePopup();
  121. }
  122.  
  123. //****  positionPopup ************************************************************************************
  124. // Set size and position of popup.
  125. // If it is off the page, move up, but not past the very top of the page.
  126.  
  127. function positionPopup(oX){
  128. // alert("positionPopup");
  129. var e= oX;    
  130. var popupOffsetWidth = oPopup.offsetWidth;
  131.  
  132. //determine if popup will be offscreen to right
  133. var rightlimit = posX + popupOffsetWidth;
  134.  
  135.   if (rightlimit >= document.body.clientWidth) 
  136.       posX -= (rightlimit - document.body.clientWidth);
  137.   if (posX < 0) posX = 0;
  138.     
  139. //position popup
  140.   oPopup.style.top = posY;
  141.   oPopup.style.left = posX;
  142.  
  143. var pageBottom = document.body.scrollTop + document.body.clientHeight;
  144. var popupHeight = oPopup.offsetHeight;
  145.   
  146.   if (popupHeight + posY >= pageBottom) {
  147.       if (popupHeight <= document.body.clientHeight)
  148.           oPopup.style.top = pageBottom - popupHeight;
  149.       else
  150.            oPopup.style.top = document.body.scrollTop;
  151.   }
  152. }
  153.  
  154. //**** closePopup ****************************************************************************************
  155. // Close Popup
  156. function closePopup() {
  157. // alert("closePopup");
  158.  
  159.   oPopup.style.visibility = "hidden";
  160.   popupOpen = false;
  161.   return;
  162. }
  163.  
  164. //*********************************************  GENERAL FUNCTIONS ************************************************
  165. //**************************************************************************************************************************
  166.  
  167. //**  getURL **************************************[used in callShortcut, popNewWindow& loadPage]********
  168. // extracts the file location (CHM::/HTM) URL 
  169.  
  170. function getURL(sHREF) {
  171. // alert("getUrl");
  172. var spaces= /\s/g
  173. var eH = unescape(sHREF);
  174.     eH = eH.replace(spaces,""); 
  175.  
  176. var eH_= eH.toLowerCase();
  177. var sParamFILE= "";
  178. var sParamCHM= "";
  179.  
  180. var iFILE= eH_.lastIndexOf("file=");
  181.     if (iFILE!=-1){
  182.         iEND= iFILE +1;
  183.         sParamFILE = eH.substring(iFILE+5,eH.length);
  184.     }  
  185.  
  186. var iCHM  = eH_.lastIndexOf("chm=");
  187.     if (iCHM!=-1){
  188.         iEND  = iCHM +1;                             // iEND used by callShortcut
  189.  
  190.         sParamCHM = eH.substring(iCHM+4, iFILE);
  191.         sParamFILE= sParamCHM+"::/"+sParamFILE;
  192.     }    
  193.     return sParamFILE;
  194. }
  195. //**************************alt location routine***************
  196. function callAltLocation(eventSrc) {
  197. var e= eventSrc;
  198. var eH= unescape(e.href);
  199. var eH_= eH.toLowerCase();
  200. var sFILEarray,sCHMarray;
  201.      event.returnValue = false;
  202.      
  203.   var sParamTXT= e.innerHTML;
  204.       sParamTXT= sParamTXT.replace(semicolon,"");
  205.                                        
  206.   var iFILE = eH_.lastIndexOf("file=");
  207.         if (iFILE==-1) return;
  208.         sParamFILE= eH.substring((iFILE+5),eH.length);                  // extracts the 2 HTM files
  209.         sParamFILE= sParamFILE.replace(spaces,"");
  210.         iSPLIT= sParamFILE.match(semicolon);
  211.         if (iSPLIT)
  212.               sFILEarray = sParamFILE.split(";");                                        // separates the 2 HTM files
  213.         else return;
  214.           
  215.   var iCHM  = eH_.lastIndexOf("chm=");
  216.         if(iCHM==-1) return;
  217.         else         sParamCHM = eH.substring(iCHM+4,iFILE);            // extracts the 2 CHM's
  218.         sParamCHM= sParamCHM.replace(spaces,"");
  219.         iSPLIT= sParamCHM.match(semicolon);
  220.         if (iSPLIT)
  221.             sCHMarray= sParamCHM.split(";");                                    // separates the 2 CHM's
  222.         else return;
  223.         
  224.         sParamFILE= moniker + sCHMarray[0]+ "::/" + sFILEarray[0] + ";" + moniker + sCHMarray[1]+ "::/" + sFILEarray[1];
  225.                 
  226.         if (document.hhAlt) document.hhAlt.outerHTML = "";                // if hhAlt object exists, clears it
  227.  
  228.  
  229.   var h= "<object id='hhAlt'"+ sActX_HH + "STYLE='display:none'><PARAM NAME='Command' VALUE='Related Topics'>";
  230.       h= h + "<param name='Item1' value='" + sParamTXT +";" + sParamFILE + "'></object>";
  231.     
  232.         document.body.insertAdjacentHTML("beforeEnd", h); 
  233.         document.hhAlt.hhclick();
  234. }
  235.