home *** CD-ROM | disk | FTP | other *** search
/ Kazoku Keikaku / kazoku_g.img / directx.cab / dxdiacht.chm / apiref.js < prev    next >
Text File  |  1999-09-09  |  10KB  |  419 lines

  1. function writeCSS(strPath)
  2. {
  3.     if (navigator.appName == "Microsoft Internet Explorer") {
  4.         var sVer = navigator.appVersion;
  5.         sVer = sVer.substring(0, sVer.indexOf("."));
  6.         if (sVer >= 4) {
  7.             document.writeln('<SCRIPT FOR=reftip EVENT=onclick>window.event.cancelBubble = true;</SCRIPT>');
  8.             strPath += '4.css';
  9.         }
  10.         else
  11.             strPath += '3.css';
  12.     }
  13.     else
  14.         strPath += "n.css";
  15.  
  16.     document.writeln('<LINK REL="stylesheet" HREF="' + strPath + '">');
  17. }
  18.  
  19. function bodyOnLoad()
  20. {
  21.     // Return if the browser isn't IE4 or later.
  22.     if (navigator.appName != "Microsoft Internet Explorer")
  23.         return false;
  24.     var sVersion = navigator.appVersion;
  25.     sVersion = sVersion.substring(0, sVersion.indexOf(".", 0));
  26.     if (sVersion < 4)
  27.         return false;
  28.  
  29.     // Find the syntax block, if any.
  30.     var syn = findSyn();
  31.     if (!syn)
  32.         return;
  33.  
  34.     // Get the syntax HTML.
  35.     var strSyn = syn.outerHTML;
  36.     var ichStart = strSyn.indexOf('>', 0) + 1;
  37.  
  38.     // Find the parameter list, if any.
  39.     var dl = findDL();
  40.     if (dl) {
  41.         var terms = dl.children.tags("DT");
  42.         var iTerm;
  43.         for (iTerm = 0; iTerm < terms.length; iTerm++) {
  44.             var words = terms[iTerm].innerText.replace(/\[.+\]/g, " ").replace(/,/g, " ").split(" ");
  45.             var iWord;
  46.             for (iWord = 0; iWord < words.length; iWord++) {
  47.                 var word = words[iWord];
  48.                 if (word.length > 0) {
  49.                     var ichMatch = findTerm(strSyn, ichStart, word);
  50.                     while (ichMatch > 0) {
  51.                         var strTag = '<A HREF="" ONCLICK="showTip(this)" CLASS="synParam">' + word + '</A>';
  52.  
  53.                         strSyn =
  54.                             strSyn.slice(0, ichMatch) +
  55.                             strTag +
  56.                             strSyn.slice(ichMatch + word.length);
  57.  
  58.                         ichMatch = findTerm(strSyn, ichMatch + strTag.length, word);
  59.                     }
  60.                 }
  61.             }
  62.         }
  63.     }
  64.  
  65.     if (findReturn()) {
  66.         var txtLine, aLines, iLine, iWord, strTok;
  67.         txtLine = syn.innerText;
  68.         aLines = txtLine.split("\n");
  69.         for (iLine = 0; iLine < aLines.length; iLine++) {
  70.             var aWords = aLines[iLine].split(" ");
  71.             if (aWords.length > 0) {
  72.                 for (iWord = 0; iWord < aWords.length; iWord++)
  73.                     if (aWords[iWord].length > 0)
  74.                         break;
  75.                 if (iWord < aWords.length) {
  76.                     if (isalnum(aWords[iWord].charAt(0))) {
  77.                         strTok = aWords[iWord];
  78.                         break;
  79.                     }
  80.                 }
  81.             }
  82.         }
  83.         if (strTok) {
  84.             var ichMatch = strSyn.indexOf(strTok, ichStart);
  85.             if (ichMatch > 0) {
  86.                 var strTag = '<A HREF="" ONCLICK="showTip(this)" CLASS="synRetVal">' + strTok + '</A>';
  87.                 strSyn =
  88.                     strSyn.slice(0, ichMatch) +
  89.                     strTag +
  90.                     strSyn.slice(ichMatch + strTok.length);
  91.             }
  92.         }
  93.     }
  94.  
  95.     // Replace the syntax block with our modified version.
  96.     syn.outerHTML = strSyn;
  97.  
  98.     // Insert the reftip element.
  99.     document.body.insertAdjacentHTML(
  100.         'BeforeEnd',
  101.         '<DIV ID=reftip CLASS=reftip STYLE="position:absolute;visibility:hidden;overflow:visible;"></DIV>'
  102.         );
  103. }
  104.  
  105. function isBold(str, index)
  106. {
  107.     var iStart = str.lastIndexOf("<B>", index);
  108.     if (iStart >= 0) {
  109.         var iEnd = str.lastIndexOf("</B>", index);
  110.         if (iEnd < iStart)
  111.             return true;
  112.     }
  113.     return false;
  114. }
  115.  
  116. function isItalic(str, index)
  117. {
  118.     var iStart = str.lastIndexOf("<I>", index);
  119.     if (iStart >= 0) {
  120.         var iEnd = str.lastIndexOf("</I>", index);
  121.         if (iEnd < iStart)
  122.             return true;
  123.     }
  124.     return false;
  125. }
  126.  
  127. function findTerm(strSyn, ichPos, strTerm)
  128. {
  129.     var ichMatch = strSyn.indexOf(strTerm, ichPos);
  130.     while (ichMatch >= 0) {
  131.         if ((ichMatch == 0 || !isalnum(strSyn.charAt(ichMatch - 1))) && 
  132.                 !isalnum(strSyn.charAt(ichMatch + strTerm.length))) {
  133.             var ichComment = strSyn.indexOf("/*", ichPos);
  134.             while (ichComment >= 0) {
  135.                 if (ichComment > ichMatch) { 
  136.                     ichComment = -1;
  137.                     break; 
  138.                 }
  139.                 var ichEnd = strSyn.indexOf("*/", ichComment);
  140.                 if (ichEnd < 0 || ichEnd > ichMatch)
  141.                     break;
  142.                 ichComment = strSyn.indexOf("/*", ichEnd);
  143.             }
  144.             if (ichComment < 0) {
  145.                 ichComment = strSyn.indexOf("//", ichPos);
  146.                 while (ichComment >= 0) {
  147.                     if (ichComment > ichMatch) {
  148.                         ichComment = -1;
  149.                         break; 
  150.                     }
  151.                     var ichEnd = strSyn.indexOf("\n", ichComment);
  152.                     if (ichEnd < 0 || ichEnd > ichMatch)
  153.                         break;
  154.                     ichComment = strSyn.indexOf("//", ichEnd);
  155.                 }
  156.             }
  157.             if (ichComment < 0)
  158.                 break;
  159.         }
  160.         ichMatch = strSyn.indexOf(strTerm, ichMatch + strTerm.length);
  161.     }
  162.     return ichMatch;
  163. }
  164.  
  165. function findSyn()
  166. {
  167.     var col = document.body.children.tags("PRE");
  168.     if (!col.length)
  169.         return null;
  170.  
  171.     var syn = col[0];
  172.     if (syn.className && syn.className == "syntax")
  173.         return syn;
  174.  
  175.     var rmh = document.body.children.tags("H4");
  176.     var i;
  177.     for (i = 0; i < rmh.length; i++) {
  178.         if (rmh[i].innerText.indexOf("QuickInfo", 0) >= 0)
  179.             return syn;
  180.     }
  181.  
  182.     return null;    
  183. }
  184.  
  185. function findDL()
  186. {
  187.     var col = document.body.children.tags("DL");
  188.     return (col.length > 0) ? col[0] : null;
  189. }
  190.  
  191. function findReturn()
  192. {
  193.     var col = document.body.children.tags("H4");
  194.     var i = 0;
  195.     for (i = 0; i < col.length; i++) {
  196.         if (col[i].innerText.substring(0, 6) == "Return")
  197.             return col[i];
  198.     }
  199.  
  200.     return null;
  201. }
  202.  
  203. function isalnum(ch)
  204. {
  205.     return ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch == '_'));
  206. }
  207.  
  208. function showTip(link)
  209. {
  210.     if (window.event) {
  211.         window.event.returnValue = false;
  212.         window.event.cancelBubble = true;
  213.     }
  214.  
  215.     var tip = document.all.reftip;
  216.     if (!tip || !link)
  217.         return;
  218.  
  219.     if (window.linkElement)
  220.         hideTip();
  221.  
  222.     window.linkElement = link;
  223.  
  224.     // Hide the tip if necessary and initialize its size.
  225.     tip.style.visibility = "hidden";
  226.     tip.style.pixelWidth = 260;
  227.     tip.style.pixelHeight = 24;
  228.  
  229.     // Find the link target and initialize the tip's contents.
  230.     var sTip;
  231.     if (link.className == "synRetVal") {
  232.         var elemHead = null;
  233.         var iFirst = 0;
  234.         var iLast = 0;
  235.  
  236.         var iElem;
  237.         for (iElem = 0; iElem < document.body.children.length; iElem++) {
  238.             var head = document.body.children[iElem];
  239.             if (head.tagName == "H4" && head.innerText.substring(0,6) == "Return") {
  240.                 elemHead = head;
  241.                 iFirst = iElem + 1;
  242.                 for (iLast = iFirst; document.body.children[iLast + 1] != tip; iLast++)
  243.                     if (document.body.children[iLast + 1].tagName == "H4")
  244.                         break;
  245.                 break;
  246.             }
  247.         }
  248.  
  249.         if (!elemHead)
  250.             return;
  251.  
  252.         window.linkTarget = elemHead;
  253.  
  254.         sTip = '<A HREF="javascript:jumpParam()"><B>';
  255.         sTip += elemHead.innerHTML + "</B></A>";
  256.         for (iElem = iFirst; iElem <= iLast; iElem++)
  257.             sTip += document.body.children[iElem].outerHTML;
  258.     }
  259.     else {
  260.         var elemDT = null;
  261.         var elemDD = null;
  262.  
  263.         var iElem;
  264.         for (iElem = 0; iElem < document.body.children.length; iElem++) {
  265.             var dl = document.body.children[iElem];
  266.             if (dl.tagName == "DL") {
  267.                 for (iElem = 0; iElem + 1 < dl.children.length; iElem++) {
  268.                     var dt = dl.children[iElem];
  269.                     if (dt.tagName == "DT") {
  270.                         if (findTerm(dt.innerText, 0, link.innerText) >= 0) {
  271.                             elemDT = dt;
  272.                             elemDD = dl.children[iElem + 1];
  273.                             break;
  274.                         }
  275.                     }
  276.                 }
  277.                 break;
  278.             }
  279.         }
  280.         
  281.         if (!elemDT)
  282.             return;
  283.  
  284.         window.linkTarget = elemDT;
  285.  
  286.         sTip = '<DL><DT><A HREF="javascript:jumpParam()">';
  287.         sTip += elemDT.innerHTML + "</A></DT>";
  288.         sTip += elemDD.outerHTML + "</DL>";
  289.     }
  290.     tip.innerHTML = sTip;
  291.  
  292.     // Position the tip after it's updated.
  293.     window.setTimeout("moveTip()", 0);
  294. }
  295.  
  296. function jumpParam()
  297. {
  298.     hideTip();
  299.  
  300.     window.linkTarget.scrollIntoView();
  301.     document.body.scrollLeft = 0;
  302.  
  303.     flash(3);
  304. }
  305.  
  306. function flash(c)
  307. {
  308.     window.linkTarget.style.background = (c & 1) ? "#FFFF80" : "";
  309.     if (c)
  310.         window.setTimeout("flash(" + (c-1) + ")", 200);
  311. }
  312.  
  313. function moveTip()
  314. {
  315.     var tip = document.all.reftip;
  316.     var link = window.linkElement;
  317.     if (!tip || !link)
  318.         return; //error
  319.  
  320.     var w = tip.offsetWidth;
  321.     var h = tip.offsetHeight;
  322.  
  323.     if (w > tip.style.pixelWidth) {
  324.         tip.style.pixelWidth = w;
  325.         window.setTimeout("moveTip()", 0);
  326.         return;
  327.     }
  328.  
  329.     var maxw = document.body.clientWidth;
  330.     var maxh = document.body.clientHeight;
  331.  
  332.     if (h > maxh) {
  333.         if (w < maxw) {
  334.             w = w * 3 / 2;
  335.             tip.style.pixelWidth = (w < maxw) ? w : maxw;
  336.             window.setTimeout("moveTip()", 0);
  337.             return;
  338.         }
  339.     }
  340.  
  341.     var x,y;
  342.  
  343.     var linkLeft = link.offsetLeft - document.body.scrollLeft;
  344.     var linkRight = linkLeft + link.offsetWidth;
  345.  
  346.     var linkTop = link.offsetTop - document.body.scrollTop;
  347.     var linkBottom = linkTop + link.offsetHeight;
  348.  
  349.     var cxMin = link.offsetWidth - 24;
  350.     if (cxMin < 16)
  351.         cxMin = 16;
  352.  
  353.     if (linkLeft + cxMin + w <= maxw) {
  354.         x = maxw - w;
  355.         if (x > linkRight + 8)
  356.             x = linkRight + 8;
  357.         y = maxh - h;
  358.         if (y > linkTop)
  359.             y = linkTop;
  360.     }
  361.     else if (linkBottom + h <= maxh) {
  362.         x = maxw - w;
  363.         if (x < 0)
  364.             x = 0;
  365.         y = linkBottom;
  366.     }
  367.     else if (w <= linkRight - cxMin) {
  368.         x = linkLeft - w - 8;
  369.         if (x < 0)
  370.             x = 0;
  371.         y = maxh - h;
  372.         if (y > linkTop)
  373.             y = linkTop;
  374.     }
  375.     else if (h <= linkTop) {
  376.         x = maxw - w;
  377.         if (x < 0)
  378.             x = 0;
  379.         y = linkTop - h;
  380.     }
  381.     else if (w >= maxw) {
  382.         x = 0;
  383.         y = linkBottom;
  384.     }
  385.     else {
  386.         w = w * 3 / 2;
  387.         tip.style.pixelWidth = (w < maxw) ? w : maxw;
  388.         window.setTimeout("moveTip()", 0);
  389.         return;
  390.     }
  391.     
  392.     link.style.background = "#FFFF80";
  393.     tip.style.pixelLeft = x + document.body.scrollLeft;
  394.     tip.style.pixelTop = y + document.body.scrollTop;
  395.     tip.style.visibility = "visible";
  396. }
  397.  
  398. function bodyOnClick()
  399. {
  400.     var tip = document.all.reftip;
  401.     if (tip && tip.style.visibility == "visible")
  402.         hideTip();
  403. }
  404.  
  405. function hideTip()
  406. {
  407.     if (window.linkElement) {
  408.         window.linkElement.style.background = "";
  409.         window.linkElement = null;
  410.     }
  411.  
  412.     var tip = document.all.reftip;
  413.     if (tip) {
  414.         tip.style.visibility = "hidden";
  415.         tip.innerHTML = "";
  416.     }
  417. }
  418.  
  419.