home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2006 March / PCWMAR06.iso / Software / Full / Canvas 8 / Canvas8 / HelpEngine.Cab / F21457_index.js < prev    next >
Encoding:
Text File  |  2001-03-28  |  8.1 KB  |  328 lines

  1. function SetCurrentIndexLetter(letter)
  2.     {
  3.     parent.gCurIndexLetter=letter;
  4.     }
  5.  
  6. //-------------------------------------------------------------------------------
  7. // PLNOTE: if useCache=TRUE then links will be generated to point to CACHE_ files...
  8. function DrawIndexHeader(useCache)
  9.     {
  10.     var astr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  11.     var i;
  12.  
  13.     document.writeln('<TABLE BORDER="0" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">');
  14.     document.writeln('<TR><TD><DIV CLASS="IndexLookup"><FONT SIZE=4>');
  15.     
  16.     if (useCache)
  17.         {
  18.         for (i=0;i<26;i++)
  19.             {
  20.             ref = "CACHE_Index_" + astr.charAt(i) + ".htm";
  21.             document.writeln('<a href="' + ref + '" target="contents">' + astr.charAt(i) + '</a>'); 
  22.             }
  23.         }
  24.     else
  25.         {
  26.         for (i=0;i<26;i++)
  27.             {
  28.             document.writeln('<a href="Index.htm" onClick="JavaScript:SetCurrentIndexLetter(\''+ astr.charAt(i) +'\');" target="contents">' + astr.charAt(i) + '</a>'); 
  29.             }
  30.         }
  31.     
  32.     document.writeln('</FONT></DIV></TD></TR>');
  33.     document.writeln('</TABLE>');
  34.     
  35.     document.writeln('</table>\n</center>');
  36.     }
  37.  
  38.  
  39. //-------------------------------------------------------------------------------
  40. var gIndex = new Array;
  41. var gNumIndex=0;
  42. var gPagePrefix="Guide_";
  43.  
  44. function IndexItem(depth, name, link1, link2, link3)
  45.     {
  46.     this.depth = depth;
  47.     this.name = name;
  48.     this.link1 = link1;
  49.     this.link2 = link2;
  50.     this.link3 = link3;
  51.     }
  52.  
  53. function IndexAdd(depth, name, link1, link2, link3)
  54.     {
  55.     gIndex[gNumIndex]=new IndexItem(depth, name, link1, link2, link3);
  56.  
  57.     gNumIndex++;
  58.     }
  59.  
  60. // Writes index to file
  61. function WriteIndexToCache(destFP)
  62.     {
  63.     var i;
  64.  
  65.     for (i=0;i<gNumIndex;i++)
  66.         {
  67.         if (gIndex[i].depth>0)
  68.             {
  69.             destFP.WriteLine('<DIV>   ');
  70.             }
  71.         else
  72.             {
  73.             destFP.WriteLine('<DIV>');
  74.             }
  75.  
  76.         destFP.WriteLine(gIndex[i].name);
  77.         
  78.         if (gIndex[i].link1)
  79.             destFP.WriteLine(' <a href="#" onClick="JavaScript:parent.nav.openPageAbs(' + gIndex[i].link1 + '); return false;"><img src="img/ix1.gif" border=0 alt="Page #' + gIndex[i].link1 + '"></a>');
  80.         if (gIndex[i].link2)
  81.             destFP.WriteLine(' <a href="#" onClick="JavaScript:parent.nav.openPageAbs(' + gIndex[i].link2 + '); return false;"><img src="img/ix2.gif" border=0 alt="Page #' + gIndex[i].link2 + '"></a>');
  82.         if (gIndex[i].link3)
  83.             destFP.WriteLine(' <a href="#" onClick="JavaScript:parent.nav.openPageAbs(' + gIndex[i].link3 + '); return false;"><img src="img/ix3.gif" border=0 alt="Page #' + gIndex[i].link3 + '"></a>');
  84.         
  85.         destFP.WriteLine('</DIV>');
  86.         }
  87.     }
  88.  
  89. // Displays index to screen
  90. function DisplayIndex()
  91.     {
  92.     var i;
  93.     var statusCnt=0, statusStep;
  94.     var statusStr="Working";
  95.  
  96.     statusStep = Math.ceil(gNumIndex/10);
  97.  
  98.     for (i=0;i<gNumIndex;i++)
  99.         {
  100.         // DISPLAY STATUS...
  101.         if(!statusCnt) 
  102.             {
  103.             statusStr+=".";
  104.             window.status=statusStr;
  105.             }
  106.         statusCnt=(statusCnt+1)%statusStep;
  107.  
  108.         if (gIndex[i].depth>0)
  109.             {
  110.             document.writeln('<DIV>   ');
  111.             }
  112.         else
  113.             {
  114.             document.writeln('<DIV>');
  115.             }
  116.  
  117.         document.writeln(gIndex[i].name);
  118.         
  119.         if (gIndex[i].link1)
  120.             document.writeln(' <a href="#" onClick="JavaScript:parent.nav.openPageAbs(' + gIndex[i].link1 + '); return false;"><img src="img/ix1.gif" border=0 alt="Page #' + gIndex[i].link1 + '"></a>');
  121.         if (gIndex[i].link2)
  122.             document.writeln(' <a href="#" onClick="JavaScript:parent.nav.openPageAbs(' + gIndex[i].link2 + '); return false;"><img src="img/ix2.gif" border=0 alt="Page #' + gIndex[i].link2 + '"></a>');
  123.         if (gIndex[i].link3)
  124.             document.writeln(' <a href="#" onClick="JavaScript:parent.nav.openPageAbs(' + gIndex[i].link3 + '); return false;"><img src="img/ix3.gif" border=0 alt="Page #' + gIndex[i].link3 + '"></a>');
  125.         
  126.         document.writeln('</DIV>');
  127.         }
  128.  
  129.     window.status="";
  130.     }
  131.  
  132.  
  133. function DrawIndexItem(indexItem, lastItem)
  134.     {
  135.     document.writeln('<DIV>');
  136.     if (indexItem.depth>0)
  137.         {
  138.         document.writeln(lastItem + ": " + indexItem.name);
  139.         }
  140.     else
  141.         {
  142.         document.writeln(indexItem.name);
  143.         }
  144.  
  145.     
  146.     if (indexItem.link1)
  147.         document.writeln(' <a href="#" onClick="JavaScript:parent.nav.openPageAbs(' + indexItem.link1 + '); return false;"><img src="img/ix1.gif" border=0 alt="Page #' + indexItem.link1 + '"></a>');
  148.  
  149.     if (indexItem.link2)
  150.         document.writeln(' <a href="#" onClick="JavaScript:parent.nav.openPageAbs(' + indexItem.link2 + '); return false;"><img src="img/ix2.gif" border=0 alt="Page #' + indexItem.link2 + '"></a>');
  151.  
  152.     if (indexItem.link3)
  153.         document.writeln(' <a href="#" onClick="JavaScript:parent.nav.openPageAbs(' + indexItem.link3 + '); return false;"><img src="img/ix3.gif" border=0 alt="Page #' + indexItem.link3 + '"></a>');
  154.     
  155.     document.writeln('</DIV>');
  156.     }
  157.  
  158. function PrepKey(s)
  159.     {
  160.     s = s.toLowerCase();
  161.     s = s.replace(/(,|-|;|%..|\.|\?|\\|\/|\[|\]|\{|\}|\(|\)|\+|\*|\|)/g, " ");
  162.  
  163.     return s;
  164.     }
  165.  
  166.  
  167.  
  168. function DoSearch(key, exactMatch)
  169.     {
  170.     var i, words;
  171.     var lastItem;
  172.     var lkey, ltest;
  173.     var found=false;
  174.     var keyList;
  175.     var maxItemsToFind = 100;
  176.     var statusCnt=0;
  177.     var searchString = "Searching";
  178.  
  179.     //PLTEST: document.writeln("ORIG KEY: " + key + "<BR>");
  180.     
  181.     // Format key - eliminate special chars and replace spaces with +
  182.     lkey = PrepKey(key);    
  183.     
  184.     lkey=lkey.replace(/(\s+|\++)+/g, "+");
  185.     
  186.     //PLTEST: document.writeln("NEW KEY: " + lkey + "<BR>");
  187.  
  188.     keyList = lkey.split("+");
  189.  
  190.     if (exactMatch)
  191.         {
  192.         for (i=0;i<keyList.length;i++)
  193.             {
  194.             keyList[i]=new RegExp("(^| )" + keyList[i] + "( |$)");
  195.             }
  196.         }
  197.     else
  198.         {
  199.         // strip common suffixes off of key
  200.         for (i=0;i<keyList.length;i++)
  201.             {
  202.             var len = keyList[i].length;
  203.  
  204.             keyList[i] = keyList[i].replace(/(.*....)(ing$|s$|ed$|or$)/, "$1");
  205.             }
  206.         }
  207.  
  208.  
  209.     if (keyList.length == 1)
  210.         {
  211.         // PLNOTE: optimized for single word...
  212.         for (i=0;i<gNumIndex;i++)
  213.             {
  214.             // DISPLAY STATUS...
  215.             if(!statusCnt) 
  216.                 {
  217.                 searchString+=".";
  218.                 window.status=searchString;
  219.                 }
  220.             statusCnt=(statusCnt+1)%250;
  221.  
  222.  
  223.             if (gIndex[i].depth==0)
  224.                 lastItem=gIndex[i].name; 
  225.             
  226.             ltest = PrepKey(gIndex[i].name);    //.toLowerCase();
  227.  
  228.             if (!exactMatch)
  229.                 {
  230.                 ltest = ltest.replace(/(.*....)(ing\b|s\b|ed\b|or\b)/g, "$1");  // strip common suffixes off of key
  231.                 }
  232.  
  233.             // PLNOTE: searches in both directions to maximize substring find!!
  234.             if (gIndex[i].link1 && (ltest.search(keyList[0])>=0 || (!exactMatch && keyList[0].search(ltest)>=0) )  )
  235.                 {
  236.                 found = true;
  237.  
  238.                 DrawIndexItem(gIndex[i], lastItem);
  239.  
  240.                 if (--maxItemsToFind <= 0)
  241.                     break;
  242.                 }
  243.             }
  244.  
  245.         // Do 1 last check - check if key is a page number of if so goto that page...
  246.         var pageNum = parseInt(keyList[0]);
  247.         if (pageNum >= parent.nav.gFirstPage && pageNum <= parent.nav.gLastPage)
  248.             {
  249.             var tempItem = new IndexItem(0, "Help Page: "+pageNum, pageNum);
  250.             DrawIndexItem(tempItem, 0);
  251.             found=true;
  252.             }
  253.         }
  254.     else
  255.         {
  256.         var matchAll;
  257.  
  258.         for (i=0;i<gNumIndex;i++)
  259.             {
  260.             // DISPLAY STATUS...
  261.             if(!statusCnt) 
  262.                 {
  263.                 searchString+=".";
  264.                 window.status=searchString;
  265.                 }
  266.             statusCnt=(statusCnt+1)%250;
  267.  
  268.             if (gIndex[i].depth==0)
  269.                 lastItem=gIndex[i].name; 
  270.             
  271.             ltest = PrepKey(gIndex[i].name);    //.toLowerCase();
  272.  
  273.             if (!exactMatch)
  274.                 ltest = ltest.replace(/(.*....)(ing\b|s\b|ed\b|or\b)/g, "$1");  // strip common suffixes off of key
  275.  
  276.             matchAll=true;
  277.  
  278.             for (words=0;words<keyList.length;words++)
  279.                 {
  280.                 lkey = keyList[words];
  281.  
  282.                 // PLNOTE: searches in both directions to maximize substring find!!
  283.                 if (gIndex[i].link1 && (ltest.search(lkey)>=0 || (!exactMatch && lkey.search(ltest)>=0) )  )
  284.                     {
  285.                     // found - continue on...
  286.                     }
  287.                 else
  288.                     {
  289.                     if (!lastItem || lastItem.search(lkey)<0)    // Also check lastItem
  290.                         {
  291.                         matchAll=false;
  292.                         break;
  293.                         }
  294.                     }
  295.                 }
  296.  
  297.             if (matchAll)
  298.                 {
  299.                 found = true;
  300.  
  301.                 DrawIndexItem(gIndex[i], lastItem);
  302.  
  303.                 if (--maxItemsToFind <= 0)
  304.                     break;
  305.                 }
  306.             }
  307.         }    
  308.  
  309.     if (!found)
  310.         {
  311.         document.writeln('Nothing Found...');
  312.         }
  313.  
  314.     window.status="";
  315.     }
  316.  
  317.  
  318. function BuildIndex_All()
  319.     {
  320.     var astr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  321.     var cmd;
  322.     
  323.     for (i=0;i<26;i++)
  324.         {
  325.         cmd = "BuildIndex_" + astr.charAt(i) + "();";
  326.         eval(cmd);
  327.         }
  328.     }