
<topic>
    <title>JavaScript API</title>
    <body>
        <p>
            <note>You can find more information about editor integration on 'Editor Integration' page.</note>
             DITA Storm exposes following methods to the enclosing HTML page: 
            <simpletable>
                <sthead>
                    <stentry>Method</stentry>
                    <stentry>Description</stentry>
                </sthead>
                <strow>
                    <stentry>
                        <pre>enableDoctype(
  &lt;dtd_base_location&gt;
)</pre>
                    </stentry>
                    <stentry>
                         Enables generation of DOCTYPE header for XML documents. Takes one parameter - a path to the directory containing DITA DTD files. Example: 
                        <pre>&lt;SCRIPT&gt;
  // specify directory for DTD files:
  //   /content/dtd/topic.dtd
  //   /content/dtd/map.dtd
  //   ...
  ditaStorm.enableDoctype('/content/dtd');
&lt;/SCRIPT&gt;</pre>
                         If this method is not called the editor will not generate DOCTYPE header or will keep header of the original XML document. 
                    </stentry>
                </strow>
                <strow>
                    <stentry>
                        <pre>registerExension(
  &lt;extension_name&gt;,
  ...
)</pre>
                    </stentry>
                    <stentry>Registers DITA Storm extension point. See <xref href='extensionPoints.xml'>Editor Customization</xref> section for details. </stentry>
                </strow>
                <strow>
                    <stentry>
                        <pre>enablePhpFileOperations(
    &lt;ditastorm_home_path&gt;
)</pre>
                    </stentry>
                    <stentry>
                         Enables file Open/Save operations implemented in PHP. This option turns on built-in file handling routines supplied with the product. Accepts one parameter specifying web browser path to the DITA Storm home directory. For example: 
                        <pre>&lt;SCRIPT&gt;
  ditaStorm.enablePhpFileOperations(
      '../DitaStorm')
&lt;/SCRIPT&gt;</pre>
                        <note type='important'>This method should be called before the editor is rendered with render() method</note>
                         PHP implementation for file open/save operations comes with the editor out-of-the-box. Similar functionality can be implemented with other applicaiton/web servers. You can request free same implementations for JSP and other technologies. 
                    </stentry>
                </strow>
                <strow>
                    <stentry>
                        <pre>render(
    &lt;ditastorm_home_path&gt;,
    &lt;width&gt;,
    &lt;height&gt;,
    &lt;css_styles&gt;,
    &lt;compliled_xsl_styles&gt;
)</pre>
                    </stentry>
                    <stentry>
                         This method renders DITA Storm into HTML page. It accepts following parameters: 
                        <ol>
                            <li>path to the location of the DITA Storm home directory</li>
                            <li>editor width (pixels or percents)</li>
                            <li>editor height (pixels or percents)</li>
                            <li>stylesheet to be used (by default the editor is supplied with simple.css)</li>
                            <li>compiled version of stylesheet to be used by the editor (by default the editor is supplied with simple.xsl.js)</li>
                        </ol>
                         Here is the example: 
                        <pre>&lt;SCRIPT&gt;
  ditaStorm.render(
      '../DITAStorm','100%','300',
      'simple.css','simple.xsl.js');
&lt;/SCRIPT&gt;</pre>
                        <note>
                             please remember, as on any HTML page your element will take specified 100% of available vertical space only if outermost element expands to the entire page (height attribute set to 100%). For example to make HTML element (DITA Storm) to consume entire remaining space on the page use code similar to this: 
                            <pre>&lt;body&gt;
  &lt;table ... height='100%'&gt;
     &lt;tr height='10%'&gt;...&lt;/tr&gt;
     &lt;tr height='90%'&gt;...[dita editor]...&lt;/tr&gt;
  &lt;/table&gt;
&lt;/body&gt;</pre>
                        </note>
                    </stentry>
                </strow>
                <strow>
                    <stentry>
                        <pre>loadXmlFile(
    &lt;xml_file_path&gt;
)</pre>
                    </stentry>
                    <stentry>
                         Loads XML file from specified URL. URL is provided as a first parameter of the funciton call. Example: 
                        <pre>&lt;SCRIPT&gt;
  ditaStorm.render(...);   
  ditaStorm.loadXmlFile('/content/default.xml');
&lt;/SCRIPT&gt;</pre>
                    </stentry>
                </strow>
                <strow>
                    <stentry>
                        <pre>getXml()</pre>
                    </stentry>
                    <stentry>
                         Retrieves current contents of the editor as XML string. For example: 
                        <pre>&lt;SCRIPT&gt;
  var xmlString = ditaStorm.getXml();
  alert('Content: '+xmlString);
&lt;/SCRIPT&gt;</pre>
                        <note type='tip'>By default the editor will return indentation-formatted XML you can switch between compact and formatted output using ditaStorm.setOutputFormatted() method.</note>
                         This method will return <i>null</i> if valid XML text can not be returned (such as when editing raw XML produced an error). By this time user has already been notified about the error. 
                    </stentry>
                </strow>
                <strow>
                    <stentry>
                        <pre>getFormattedXml()</pre>
                    </stentry>
                    <stentry>
                        <image href='images/DitaIndenting.png' align='right'/>Retrieves indentation-formatted contents of the editor as XML string. Contents returned by this method is similar to the raw content editable in 'XML' mode. 
                        <pre>&lt;SCRIPT&gt;
  var xmlString = ditaStorm.getFormattedXml();
  alert('Formatted content: '+xmlString);
&lt;/SCRIPT&gt;</pre>
                         This method will return <i>null</i> if valid XML text can not be returned (such as when editing raw XML produced an error). By this time user has already been notified about the error. 
                    </stentry>
                </strow>
                <strow>
                    <stentry>
                        <pre>setOutputFormatted(
  &lt;formatted&gt;)</pre>
                    </stentry>
                    <stentry>
                         Enables or disables output formatting. This method affects both getXml() and updateField(). By default DITA Storm will generate formatted XML. 
                        <pre>&lt;SCRIPT&gt;
  ditaStorm.setOutputFormatted(false);
 var xmlCompact = ditaStorm.getXml();

  ditaStorm.setOutputFormatted(true);
 var xmlFormatted = ditaStorm.getXml();
&lt;/SCRIPT&gt;
                        </pre>
                    </stentry>
                </strow>
                <strow>
                    <stentry>
                        <pre>setXml(
  &lt;xml_content_as_string&gt;
)</pre>
                    </stentry>
                    <stentry>
                         Sets contents of the editor accepting XML as a string. For example: 
                        <pre>&lt;SCRIPT&gt;
  ditaStorm.setXml('&lt;topic&gt;&lt;title/&gt;&lt;/topic&gt;');
&lt;/SCRIPT&gt;</pre>
                    </stentry>
                </strow>
                <strow>
                    <stentry>
                        <pre>attachField(
  &lt;form_name&gt;,
  &lt;field_name&gt;
)</pre>
                    </stentry>
                    <stentry>
                         Attaches DITA Storm editor to the specified form field. Accepts two parameters - form and field name. 
                        <pre>&lt;FORM name='myForm' ...&gt;
&lt;INPUT name='ditaField' type='hidden'
    value='&lt;topic&gt;&lt;title&gt;Lorem&lt;/title&gt;&lt;/topic&gt;'&gt;
...
&lt;SCRIPT&gt;
  ditaStorm.attachField('myForm','ditaField');
&lt;/SCRIPT&gt;</pre>
                         See <xref href='integration.xml'>Editor Integration</xref> for more information. 
                    </stentry>
                </strow>
                <strow>
                    <stentry>
                        <pre>updateField()</pre>
                    </stentry>
                    <stentry>
                         Updates form field previously attached with attachField() method. Often called onSubmit when updated data is ready to be sent to the server. 
                        <pre>&lt;SCRIPT&gt;
  function verfyAndSubmit()
  {
    ...
    ditaStorm.updateField();
    myForm.submit();
  }
&lt;/SCRIPT&gt;</pre>
                        <note type='tip'>By default the editor will return indentation-formatted XML you can switch between compact and formatted output using ditaStorm.setOutputFormatted() method.</note>
                         See <xref href='integration.xml'>Editor Integration</xref> for more information. 
                    </stentry>
                </strow>
                <strow>
                    <stentry>
                        <pre>isModified()</pre>
                    </stentry>
                    <stentry>
                         Returns true if contents of the editor has been modified since last load file or load xml operation. 
                        <pre>&lt;SCRIPT&gt;
  function onUnload() 
  {
    if( ditaStorm.isModified() )
    {
       confirm('Do you want to save changes?');
    }
  }
&lt;/SCRIPT&gt;</pre>
                    </stentry>
                </strow>
                <strow>
                    <stentry>
                        <pre>setModified(
  &lt;modified_indicator&gt;
)</pre>
                    </stentry>
                    <stentry>
                         Explicitly sets current status of the 'modified' flag of the editor. Editor would automatically change it to 'true' when content gets changed or to 'false' when new file or XML gets loaded. 
                        <pre>&lt;SCRIPT&gt;
  function quickSave() 
  {
     // Save data
     ...
     // Set indication that data has been saved
    ditaStorm.setModified(false);
  }
&lt;/SCRIPT&gt;</pre>
                    </stentry>
                </strow>
                <strow>
                    <stentry>
                        <pre>enableUnloadConfirmation(
)</pre>
                    </stentry>
                    <stentry>
                         Convenience method assigning simple 'on page unload' handler asking user to confirm page navigation if editor's 'modified' flag is set to true. You can clear the flag with setModified() method call if required. 
                        <pre>&lt;SCRIPT&gt;
  ditaStorm.enableUnloadConfirmation();
  ditaStorm.render('../DITAStorm','100%','100%',
    'simple.css','simple.xsl.js');
&lt;/SCRIPT&gt;</pre>
                        <note>This method sets window's <tt>onbeforeunload</tt> event handler. If your application uses it for other purposes we suggest using isModified() method and explicitly asking user's confirmation instead. </note>
                    </stentry>
                </strow>
            </simpletable>
        </p>
    </body>
</topic>
