Using JavaScript in HoTMetaL PRO 6.0: The Code | WebReference

Using JavaScript in HoTMetaL PRO 6.0: The Code


Using JavaScript in HoTMetaL PRO 6.0

The Code

<MACRO name="On_Application_Open" lang="JScript"><![CDATA[
  // Some useful constants
  var viewWYSIWYG = 0;
  var viewTagsOn = 1;
  var viewSource = 2;
]]></MACRO> 
<MACRO name="Format Current Document" lang="JScript" id="153" desc="Apply source layout to entire document">
<![CDATA[
   if (ActiveDocument.ViewType == viewSource) {
     ActiveDocument.Layout();
   }
   else {
     Application.Alert("Applying source layout only works in source view.\nSwitch to source view and try again.");
   }
]]></MACRO>
<MACRO name="Format Current Selection" lang="JScript" id="153" desc="Apply source layout to current selection ">
<![CDATA[
   if (ActiveDocument.ViewType == viewSource) {
     Selection.Layout();
   }
   else {
     Application.Alert("Applying source layout only works in source view.\nSwitch to source view and try again.");
   }
]]></MACRO>
<MACRO name="On_Document_Open_Complete" lang="JScript"><![CDATA[
  var name = ActiveDocument.LocalFullName;
  if (Application.ReadableFileExists(name)) {  // if document has never been saved, do nothing
    Application.Run("On_Document_Save");
  }
]]></MACRO> 
 
<MACRO name="On_Document_Activate" lang="JScript" id="44" tooltip="Hide_On_Document_Activate" desc="Runs Macro: Hide_On_Document_Activate"><![CDATA[
  // Do this for local documents only
  if (ActiveDocument.FullName == ActiveDocument.LocalFullName) {
    var name = ActiveDocument.LocalFullName;
    if (Application.ReadableFileExists(name)) {  // if document has never been saved, do nothing
      var fso = new ActiveXObject("Scripting.FileSystemObject");
      var f = fso.GetFile(name);
      var newMod = Date.parse(f.DateLastModified);
      var props = ActiveDocument.CustomDocumentProperties;
      if (props.count != 0) {
        oldMod = props.Item("LastMod").value;
        if (oldMod != newMod) {
          var Yes = 6;
          var No = 7;
          var msg = "The disk version of this document has changed from the\n";
          msg += "version in memory.  Do you want to re-open the document?";
          var ret = Application.MessageBox(msg, 36, "Document Changed");
          if (ret == Yes) {
            ActiveDocument.Reload();
          }
          // Reset the timestamp regardless of the user's response
          // This will prevent the dialog from always showing
          Application.Run("On_Document_Open_Complete");
        }
      }
    }
  }
]]></MACRO>
 
<MACRO name="On_Application_Activate" lang="JScript"><![CDATA[
  Application.Run("On_Document_Activate");
]]></MACRO> 
 
<MACRO name="On_Document_Save" lang="JScript"><![CDATA[
  var fso = new ActiveXObject("Scripting.FileSystemObject");
  var f = fso.GetFile(ActiveDocument.LocalFullName);
  var mod = Date.parse(f.DateLastModified);
  var props = ActiveDocument.CustomDocumentProperties;
  if (props.count != 0) {
    props.Add("LastMod", mod);
  }
]]></MACRO> 
 
<MACRO name="On_Document_SaveAs" lang="JScript"><![CDATA[
  Application.Run("On_Document_Save");
]]></MACRO> 
 
<MACRO name="Save As Template" lang="JScript" id="90"><![CDATA[
  var obj = new ActiveXObject("HMExtras.FileDlg");
  var filter = "Web Page Template (*.htm, *.html)|*.htm;*.html|All Files (*.*)|*.*||";
  if (obj.DisplayFileDlg(0, "File Save As", filter, Application.Path + "\\Template")) {
    ActiveDocument.SaveAs(obj.FullPathName, true); // save and put on recent file list  
  }
]]></MACRO>

http://www.internet.com

Produced by Yehuda Shiran and Tomer Shiran

Created: January 18, 2000
Revised: January 18, 2000

URL: http://www.webreference.com/js/column56/code1.html