home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / Basic / Visual Basic.60 / COMMON / TOOLS / VB / UNSUPPRT / DANIM / HELP / DA / COMMON.JS < prev    next >
Encoding:
JavaScript  |  1998-03-19  |  4.1 KB  |  160 lines

  1. // Hilites the text in the code sample
  2. // oStart - reference to start of block
  3. // sText - string to find and hilite
  4. function HiliteText(oStart, sText)
  5. {
  6.  
  7.     var oRng = document.body.createTextRange();
  8.     oRng.moveToElementText(oStart);
  9.     var oRngFixed = oRng.duplicate();
  10.  
  11.     if (typeof(HiliteText.tokens) == 'undefined')
  12.     {
  13.         HiliteText.tokens = new Array(1);
  14.     }
  15.     else
  16.     {
  17.         for (i = 0; i < HiliteText.tokens.length; i++)
  18.         {
  19.             if (HiliteText.tokens[i].m_sSectionID == oStart.id && HiliteText.tokens[i].m_sToken == sText)
  20.             {
  21.                 return;
  22.             }
  23.         }
  24.  
  25.         HiliteText.tokens.length++;
  26.     }
  27.  
  28.  
  29.     while (oRng.findText(sText, 1000000, 6) && oRngFixed.inRange(oRng)) 
  30.     {    
  31.         oRng.execCommand('bold');
  32.         oRng.collapse(false);
  33.     }
  34.  
  35.     HiliteText.tokens[HiliteText.tokens.length-1] = new CHilitedToken(oStart.id, sText);
  36.  
  37. }
  38.  
  39. // a tuple representing the id of the section and the token to be hilited
  40. // the object is stored in an array to prevent the code from running twice on the same section
  41. function CHilitedToken(sSectionID, sToken)
  42. {
  43.     this.m_sSectionID = sSectionID;
  44.     this.m_sToken = sToken;
  45. }
  46.  
  47.  
  48. // Toggles the display of the content contained within oCode
  49. // oCode - reference to code block
  50. // sToken - string to bolden
  51. function ToggleSample(oCode, sToken)
  52. {
  53.     if (ShowHideSection(window.event.srcElement, 'Sample Code'))
  54.     {
  55.         HiliteText(oCode, sToken);
  56.     }
  57. }
  58.  
  59. // If hidden, show. If shown, hide. Modify the caption of the element appropriately
  60. // Returns true if showing on return, false if hidden on return
  61. function ShowHideSection(oHead, sText)
  62. {
  63.     var bRet = false;
  64.     var oChild = document.all(oHead.getAttribute('child', false));
  65.  
  66.     if (typeof(oChild) == null)
  67.     {
  68.         return bRet;
  69.     }
  70.  
  71.     var sClass = oChild.className;
  72.     var sAction = "Show";
  73.     if (sClass == "collapsed")
  74.     {
  75.         sAction = "Hide";
  76.         bRet = true; // we'll be showing upon return, so return true
  77.     }
  78.  
  79.     sAction = sAction + ' ' + sText;
  80.     oChild.className = (sClass == "collapsed" ? "expanded" : "collapsed");
  81.     oHead.innerText = sAction;
  82.     return bRet;
  83. }
  84.  
  85. // Set the caption of the specified element
  86. // oElem - reference to element to modify. Typically a Hn
  87. // sCaption - New caption for the element
  88. // bShow - boolean indicating whether or not the element should be made visible
  89. function SetExpandableCaption(oElem, sCaption, bShow)
  90. {
  91.     oElem.innerText = sCaption;
  92.     if (bShow) oElem.style.display = 'inline';
  93. }
  94.  
  95. function AddStyleSheet()
  96. {
  97.    var sVR = '/basicSDK'    // Set root for the style sheet
  98.    var sCSS = '<LINK REL="stylesheet" HREF="' + sVR;
  99.  
  100.    if(navigator.appVersion.lastIndexOf("MSIE 4.") > -1) // For all MSIE 4.0 versions
  101.       sCSS += 'IE4';
  102.    else if(navigator.appVersion.lastIndexOf("MSIE 3.") > -1) // For all MSIE 3.0 versions
  103.       sCSS += 'IE3';
  104.    else if(navigator.appName.lastIndexOf("Netscape") != -1) // For all Nav versions
  105.       sCSS += 'NAV';
  106.    else
  107.    {
  108.       // do nothing. result will be basicSDK.css
  109.    }
  110.  
  111.    sCSS += '.css" TYPE="text/css">';
  112.    document.writeln(sCSS);
  113. }
  114.  
  115. // Set the caption for the TOC link, and fix up the href. IE4 only
  116. function SetTOC()
  117. {
  118.     if (typeof(TOC) != 'object')
  119.         return;
  120.  
  121.     // build a string for the 'Show Contents' case
  122.     var sPath = location.pathname;
  123.     
  124.     var sMask = (location.href.indexOf('ttp://') > 0) ? "/da/" : "\\da\\";    
  125.     
  126.     if (sPath.lastIndexOf(sMask) < 0) // doc isn't located under help
  127.     {
  128.         TOC.style.visibility = "hidden"; // in case the style sheet wasn't hooked up
  129.         TOC_.style.visibility = "hidden";
  130. return;
  131.     }
  132.  
  133.     var iStart = sPath.lastIndexOf(sMask)+sMask.length;
  134.     sFramed = sPath.substring(0,sPath.lastIndexOf(sMask)) +
  135.              sMask+"c-frame.htm#" +
  136.              (sPath.substring(iStart) == "" ? "default.htm" : sPath.substring(iStart));
  137.     
  138.     if (window.top != self) 
  139.     {
  140.         if (window.top.frames.length>1 && window.top.frames[0].name=="TOC") 
  141.         {
  142.             TOC.innerText = "Hide Contents";
  143.             TOC.href = location.pathname;
  144.             TOC.target = "_top";
  145.         }
  146.     }
  147.     else 
  148.     {
  149.         TOC.innerText = "Show Contents";
  150.         TOC.href = sFramed;
  151.     }
  152.  
  153.     TOC.style.visibility = "visible";
  154. }
  155.  
  156. function CheckCAB(n)
  157. {
  158.     return true;
  159. }
  160.