home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 August / Chip_2001-08_cd2.bin / audio / wm8enc / encoder / wm8eutil_setup.exe / WMEnUtil.chm / glossary.js < prev    next >
Encoding:
JavaScript  |  2001-03-02  |  7.0 KB  |  216 lines

  1. /* Localize the following variables */
  2. /* Start Localize */
  3. var sErr_EntryNotFound        = "<P STYLE='color:red'><B> Definition not found.</B></P>";
  4. var sGlossaryPopUpTitle        = "Glossary Term";
  5. /* End Localize */
  6.  
  7. //----------------------------------------------------------------------------------
  8.  
  9. // Global variables 
  10. var bDataSetComplete         = false;            // flag to ensure the user will not access DB before load complete
  11. var sDBGlossary             = "../dbGlossary.csv";    // path to glossary DB file
  12. var sPopUpBGColor             = "lightblue";        // popup background color
  13. var sPopUpShadowBGColor     = "lightblue";        // popup background color
  14. var oBInfo                     = GetBrowserInfo();    // browser information 
  15.  
  16. // Call Intialize PopUp Glossary
  17. Initialize();
  18.  
  19. // Main popup glossary subroutine, gets called everytime the user clicks on the on a glossary keyword
  20. function Glossary(oObj)
  21. {    
  22.     // If DB not loaded exit
  23.     // Removing safety check for IE4, under IE4 on WinNT4 TDC.ondatasetcomplete event never fires.
  24.     // Safety will only work for IE5
  25.     if(oBInfo.GB && bDataSetComplete == false) return;
  26.     
  27.     // Reposition pop-up tray 
  28.     PosPopUpTray(idPopUpTray);
  29.  
  30.     //Split URL and obtain anchor value
  31.     var sARRAY, sRID;
  32.     sARRAY = oObj.href.split("#");
  33.  
  34.     // Set value for ID search
  35.     if (sARRAY.length > 1 ) {sRID = sARRAY[1]} else {sRID = "*****"};
  36.     
  37.     // Get keyword definition from glossary database
  38.     idPopUp.innerHTML = GetKeyDef(dbGlossary.recordset, sRID);
  39.  
  40.     // Set shadow 
  41.     idPopUpShadow.innerHTML = idPopUp.innerHTML
  42.  
  43.     // Display pop-up glossary
  44.     DspPopUp(1);
  45.  
  46.     return false;
  47. }
  48.  
  49. // Method reposition glossary popup tray underneath the glossary keyword.
  50. function PosPopUpTray(oObj)
  51. {
  52.     var offSetLeft     = window.event.clientX + document.body.scrollLeft ;
  53.     var offSetTop    = window.event.clientY + document.body.scrollTop ;
  54.     var offSetWidth    = document.body.offsetWidth;
  55.     
  56.     // Avoid runing off to the right of the screen
  57.     if (((offSetLeft + 430) > offSetWidth) && (offSetWidth > 430 )) 
  58.     {
  59.         offSetLeft     = offSetWidth - parseInt(oObj.style.width) - 34 ;
  60.     }
  61.     oObj.style.left    = offSetLeft;    // set new x coordinate
  62.     oObj.style.top     = offSetTop;    // set new y coordinate
  63. }
  64.  
  65. // Method obtains keyword deffinition
  66. function GetKeyDef(oRecordSet, sKeyWord)
  67. {
  68.     var sDef = "";
  69.     oRecordSet.MoveFirst();
  70.  
  71.     for(var i=0; i < oRecordSet.RecordCount; i++)    // >
  72.     {
  73.         // If we found our keyword in the record set extract deffinition and exit
  74.         if(sKeyWord == oRecordSet.fields.item('rid').value)
  75.         {
  76.             sDef = "<P><B>" + oRecordSet.fields.item('key').value + "</B><BR>"
  77.             sDef = sDef + oRecordSet.fields.item('def').value + "</P>"
  78.             return sDef;
  79.         }
  80.         // Advance to next element
  81.         oRecordSet.MoveNext();
  82.     }
  83.     
  84.     sDef = sErr_EntryNotFound ;
  85.     return sDef;
  86. }
  87.  
  88. // Method turns pop-up tray display on/off
  89. function DspPopUp(nState)
  90. {
  91.     if(nState == 0)
  92.     {
  93.         idPopUpTray.style.display     = "none";
  94.     }
  95.     else if(nState == 1)
  96.     {
  97.         idPopUpTray.style.display     = "";
  98.         fadeIn(idPopUp);
  99.         idPopUpShadow.focus();
  100.     }
  101. }
  102.  
  103. // Method hides pop-up glossary
  104. function HidePopUp()
  105. {    
  106.     if(window.event.srcElement == null)
  107.     {
  108.         DspPopUp(0);
  109.     }
  110.     else if (window.event.srcElement.id != "idGlossary")
  111.     {
  112.         DspPopUp(0);
  113.     }
  114. }
  115.  
  116. // Method fades in the pop-up
  117. function fadeIn(oObj)
  118. {
  119.     if(!oBInfo.GB) return ;
  120.     oObj.style.filter="blendTrans(duration=.30";
  121.     // make sure filter is not already playing
  122.     if (oObj.filters.blendTrans.status != 2) 
  123.     {
  124.         oObj.style.visibility="hidden";
  125.         oObj.filters.blendTrans.apply();
  126.         oObj.style.visibility="visible";
  127.         oObj.filters.blendTrans.play();
  128.     }
  129. }
  130.  
  131. // Set all objects required for the pop-up glossary 
  132. function Initialize()
  133. {
  134.     // Create style string
  135.     var sStyle = '' + 
  136.     '<STYLE> #PopUp{cursor: hand; color: green; text-decoration: underline;}</STYLE>';
  137.  
  138.     // Create Glossary onclick event handler
  139.     var sOnClickEvent = '' + 
  140.     '<SCR' + 'IPT LANGUAGE="JScript" FOR="PopUp" EVENT="onclick">' +
  141.     '    Glossary(this);' +
  142.     '</SCR' + 'IPT>' ;
  143.  
  144.     // Create Glossary onmouseover event handler
  145.     var sOnMouseOverEvent = '' + 
  146.     '<SCR' + 'IPT LANGUAGE="JScript" FOR="PopUp" EVENT="onmouseover">' +
  147.     '    this.title = "' + sGlossaryPopUpTitle + '";' +
  148.     '</SCR' + 'IPT>' ;
  149.  
  150.     // Create TBDCtl string
  151.     var sObj = '' + 
  152.     '<OBJECT ID="dbGlossary" CLASSID="clsid:333C7BC4-460F-11D0-BC04-0080C7055A83" STYLE="height: 0; width: 0;" ondatasetcomplete="bDataSetComplete = true">' + 
  153.     '    <PARAM NAME="DataURL" VALUE="' + sDBGlossary + '">' +
  154.     '    <PARAM NAME="UseHeader" VALUE="True">' + 
  155.     '    <PARAM NAME="TextQualifier" VALUE="|">' +
  156.     '</OBJECT>' ;
  157.  
  158.     // Create event handlers string
  159.     var sEvtHandle = '' +
  160.     '<SCR' + 'IPT LANGUAGE="JScript">' +
  161.     '    document.onmousedown    = HidePopUp;' + 
  162.     '    window.onresize             = HidePopUp;' +
  163.     '</SCR' + 'IPT >';
  164.  
  165.     // Create popup string , lemonchiffon
  166.     var sPopUp = '' +
  167.     '<DIV ID="idPopUpTray" STYLE="display: none; z-index:1; width:400; height:10; position:absolute; padding: 0; border-style: inset; border-width:0;">' + 
  168.     '    <DIV ID="idPopUp"             STYLE="z-index:3; width:400; height: 10; position:absolute; font:8pt Tahoma; line-height: 8pt; background-color:' + sPopUpBGColor + '; top: 0; left: 0; padding: 7; margin: 6; border-style: inset; border-left-width: 1; border-top-width: 1; border-right-width: 2; border-bottom-width: 2; border-right-color: black; border-bottom-color: black; "> </DIV>' + 
  169.     '    <DIV ID="idPopUpShadow"     STYLE="z-index:2; width:400; height: 10; position:absolute; font:8pt Tahoma; line-height: 8pt; background-color:' + sPopUpShadowBGColor + '; color:' + sPopUpShadowBGColor + ';top: 6; left:-6; padding: 7; margin: 6; border-style: solid; border-left-width: 1; border-top-width: 1; border-right-width: 2; border-bottom-width: 2; border-right-color: black; border-color:' + sPopUpShadowBGColor + '; filter:alpha(opacity=50, style=0);"> </DIV>' + 
  170.     '</DIV>' ;
  171.  
  172.     // Write objects to document
  173.     window.self.document.write(sStyle);
  174.     window.self.document.write(sOnClickEvent);
  175.     window.self.document.write(sOnMouseOverEvent);
  176.     window.self.document.write(sObj);
  177.     window.self.document.write(sPopUp);
  178.     window.self.document.write(sEvtHandle);
  179. }
  180.  
  181. // Container for browser/os information
  182. function BrowserInfo()
  183. {
  184.     this.Type     = "";
  185.     this.Ver     = 0;
  186.     this.Plat    = "";
  187.     this.GB        = false;
  188. }
  189.  
  190. // Determines browser/os platforms
  191. // Question: Will this code work with localized versions of the browser ??
  192. // ToDo: Test the code to see if it works under Netscape. On mac OS. 
  193. function GetBrowserInfo()
  194. {
  195.     var brw = new BrowserInfo; 
  196.     sUA = window.navigator.appVersion;
  197.     
  198.     if (parseInt(sUA.indexOf("MSIE ")) >= 0) // Check if IE
  199.     {
  200.         brw.Type = "IE";
  201.         brw.Ver = parseInt(sUA.substring(sUA.indexOf("MSIE ")+5,sUA.indexOf (".",sUA.indexOf("MSIE "))));
  202.         if (sUA.lastIndexOf("Win") >= 0)
  203.             brw.Plat = "Win";
  204.     }
  205.     else if(parseInt(navigator.appName.lastIndexOf("Netscape"))>=0)
  206.     {
  207.         brw.Type = "Nav";
  208.         brw.Ver = parseInt(sUA.substring(0, sUA.indexOf('.')));
  209.     }
  210.  
  211.     if (sUA.indexOf("Mac") != -1) {brw.Plat = "Mac"};
  212.     
  213.     brw.GB = (brw.Type == "IE" && brw.Ver >= 5 && brw.Plat == "Win");
  214.     return brw;
  215. }
  216.