home *** CD-ROM | disk | FTP | other *** search
/ Beginning Direct3D Game Programming / Direct3D.iso / directx / dxf / extras / documentation / directx7 / directx7.chm / dxmedia / foundation / d3drm / js / common.js next >
Text File  |  2000-09-22  |  4KB  |  143 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. // Set the caption for the TOC menu, and fix up the href. IE4 only
  96. function SetTOC()
  97. {
  98.     var sProjectRoot1 = "/d3drm/";
  99.     var sProjectRoot2 = "\\d3drm\\";
  100.     if (typeof(AM_ICP_mnuToc) != 'object'){
  101.         alert('\n\n\nMessage 001 generated by common.js script module in function SetTOC() .\n\n\nTable of  Contents menu is not properly set up.\nShow/Hide Contents menu was not detected.\n\n\n');
  102.         return;
  103.     }
  104.  
  105.     // build a string for the 'Show Contents' case
  106.     var sPath = location.pathname;
  107.     
  108.     var sMask = (location.href.indexOf('ttp://') > 0) ? sProjectRoot1 : sProjectRoot2;    
  109.     
  110.     if (sPath.lastIndexOf(sMask) < 0) // doc isn't located under proper project
  111.     {
  112.         AM_ICP_mnuToc.style.visibility = "hidden"; // in case the style sheet wasn't hooked up
  113.         alert('\n\n\nMessage 002 generated by common.js script module in function SetTOC() .\n\n\nCurrent project location does not match mask expected settings.\nCurrent project root settings:\n    sProjectRoot1: "' + sProjectRoot1 + '"\n        or\n    sProjectRoot2: "' + sProjectRoot2 + '"\n\n\n');
  114.         return;
  115.     }
  116.  
  117.     var iStart = sPath.lastIndexOf(sMask)+sMask.length;
  118.     sFramed = sPath.substring(0,sPath.lastIndexOf(sMask)) +
  119.              sMask+"c-frame.htm#" +
  120.              (sPath.substring(iStart) == "" ? "default.htm" : sPath.substring(iStart));
  121.     
  122.     if (window.top != self) 
  123.     {
  124.         if (window.top.frames.length > 1 && typeof(window.top.frames[0].name) != "unknown" && window.top.frames[0].name=="TOC") 
  125.         {
  126.             AM_ICP_mnuToc.innerText = " Hide Contents";
  127.             AM_ICP_mnuToc.href     = location.pathname;
  128.             AM_ICP_mnuToc.target     = "_top";
  129.         }
  130.     }
  131.     else 
  132.     {
  133.         AM_ICP_mnuToc.innerText = " Show Contents";
  134.         AM_ICP_mnuToc.href     = sFramed;
  135.     }
  136.  
  137.     AM_ICP_mnuToc.style.visibility = "visible";
  138. }
  139.  
  140. function resizeDocContents()
  141. {
  142.     ; // document resize event handler
  143. }