home *** CD-ROM | disk | FTP | other *** search
/ PC & Mediji 2000 June / PCM_0006.iso / programi / WMP.EXE / wmplayer.chm / glossary.js < prev    next >
Encoding:
Text File  |  2000-02-23  |  6.3 KB  |  192 lines

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