home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2000 January / january_2000.iso / Site Building / HoTMetaL Pro / hm6ev.exe / data1.cab / Programming_Samples / Scripts / Included_Text / macros.txt < prev   
Encoding:
Text File  |  1999-10-15  |  1.5 KB  |  45 lines

  1. <MACRO name="On_Document_Open_Complete" lang="JScript"><![CDATA[
  2.  
  3.   function Do_On_Document_Open_Complete() {
  4.     // Include any included text
  5.     var rng = ActiveDocument.Range;
  6.     var magicClass = "SQ-IncludedText";
  7.     var i, j;
  8.  
  9.     // Look for SPAN tag marked for included text
  10.     var nodeList = ActiveDocument.getElementsByTagName("SPAN");
  11.     for (i = 0; i < nodeList.length; i++) {
  12.       var node = nodeList.item(i);
  13.       if (node.getAttribute("CLASS") == magicClass) {
  14.  
  15.         // Look for a LINK with a matching ID
  16.         var idLink = "LINK_" + node.getAttribute("ID");
  17.         var linkList = ActiveDocument.getElementsByTagName("LINK");
  18.         for (j = 0; j < linkList.length; j++) {
  19.           var linkNode = linkList.item(j);
  20.           if (linkNode.getAttribute("ID") == idLink) {
  21.  
  22.             // Get the path to the file with the included text
  23.             var fileURL = linkNode.getAttribute("HREF");
  24.             var filePath = Application.URLToPath(fileURL, ActiveDocument.Path + "\\");
  25.  
  26.             // Replace the contents of SPAN with the included text
  27.             rng.SelectBeforeNode(node);
  28.             rng.MoveToElement("SPAN");
  29.             rng.SelectContainerContents();
  30.             var str = Application.FileToString(filePath);
  31.             rng.TypeText(str);
  32.           }
  33.         }
  34.       }
  35.     }
  36.   }
  37.  
  38.   var viewWYSIWYG = 0;
  39.   var viewTagsOn = 1;
  40.   var viewSource = 2;
  41.   if (ActiveDocument.ViewType == viewWYSIWYG || ActiveDocument.ViewType == viewTagsOn) {
  42.     Do_On_Document_Open_Complete();
  43.   }
  44. ]]></MACRO> 
  45.