<topic><title>Editor Integration</title><shortdesc>Provides instructions how to integrate DITA Storm editor into generic web application. </shortdesc><body><section><title>Integrating DITA Storm into HTML Page</title><p>Integrating DITA Storm into web application or content management system is a relatively simple procedure. You can either attach editor to the text field of your HTML form or load DITA document directly via HTTP request. Here are basic required steps: <ol compact="no"><li><b>Include DITA Storm libraries.</b><codeblock>&lt;LINK href="DITAStorm/styles.css" rel="stylesheet" type="text/css"/&gt;
&lt;SCRIPT src="DITAStorm/DITAStorm.js" type="text/javascript"&gt;&lt;/SCRIPT&gt;</codeblock></li><li><b>Render DITA Storm. </b> At the selected location of HTML page place following code: <codeblock>&lt;SCRIPT&gt;
    ditaStorm.render(
        'DITAStorm','100%','300','simple.css','simple.xsl.js');
&lt;/SCRIPT&gt;</codeblock> Function render(&lt;path&gt;,&lt;width&gt;,&lt;height&gt;,&lt;css_file&gt;,&lt;compiled_xsl_file&gt;) accepts following parameters: <ol><li>path to the location of the DITA Storm libraries</li><li>editor width (pixels or percents)</li><li>editor height (pixels or percents) <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></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></li><li><b>Load DITA document.</b> You can do it either directly from the server:<codeblock>&lt;SCRIPT&gt;
    ditaStorm.loadXmlFile('/cm/content/product.xml');
&lt;/SCRIPT&gt;</codeblock> or from the pre-populated text field: <codeblock>&lt;INPUT name='ditaField' type='hidden'
    value='&lt;topic&gt;&lt;title&gt;Lorem Ipsum&lt;/title&gt;&lt;body&gt;&lt;p&gt;...&lt;/p&gt;&lt;/body&gt;&lt;/topic&gt;'&gt;

&lt;SCRIPT&gt;
    ditaStorm.attachField('myForm','ditaField');
&lt;/SCRIPT&gt;</codeblock></li><li><b>Retrieve modified DITA content.</b> You can do it by either calling JavaScript method:<codeblock>&lt;SCRIPT&gt;
    // Use <b>getXml() </b>or <b>getFormattedXml() </b>to retrieve content
    var xmlString = ditaStorm.getXml();
    alert('Content: '+xmlString);
&lt;/SCRIPT&gt;</codeblock> or if you previously attached DITA Storm to the form field you can store value back to the field: <codeblock>&lt;SCRIPT&gt;
    ditaStorm.updateField();
&lt;/SCRIPT&gt;</codeblock></li></ol></p></section><example><title>Attaching to HTML Form Field</title><p>Lets take a simple example of HTML form with text field and modify it utilize DITA Storm. Here is the original HTML form:</p><codeblock>&lt;HTML&gt;
&lt;HEAD&gt;
  &lt;SCRIPT&gt;
    function verifyAndSubmit() {
      ...
    }
  &lt;/SCRIPT&gt;
&lt;/HEAD&gt;
&lt;BODY onLoad='init()'&gt;
  &lt;FORM name='myForm' onSubmit='verifyAndSubmit()'&gt;
   &lt;INPUT name='ditaField'
     type='text'
     value='&lt;topic&gt;&lt;title&gt;Lorem Ipsum&lt;/title&gt;&lt;body&gt;
             &lt;p&gt;Morbi et lacus nec.&lt;/p&gt;&lt;/body&gt;&lt;/topic&gt;'&gt;
     ...
   &lt;/FORM&gt;
&lt;/BODY&gt;
&lt;/HTML&gt;</codeblock><p>This HTML can be easily modified to enable DITA editing with DITA Storm:</p><codeblock>&lt;HTML&gt;
&lt;HEAD&gt;
  &lt;LINK href="DITAStorm/styles.css" rel="stylesheet" type="text/css"/&gt;
  &lt;SCRIPT src="DITAStorm/DITAStorm.js" type="text/javascript"&gt;&lt;/SCRIPT&gt;
  &lt;SCRIPT&gt;
   function verifyAndSubmit() 
   {
      // store XML back to the field and proceed with regular form submission 
      ditaStorm.updateField(); 
      ...
    }
   &lt;/SCRIPT&gt;
&lt;/HEAD&gt;
&lt;BODY&gt;
  &lt;FORM name='myForm' onSubmit='verifyAndSubmit()'&gt;

    &lt;INPUT name='ditaField' type='hidden'
        value='&lt;topic&gt;&lt;title&gt;Lorem&lt;/title&gt;&lt;body&gt;&lt;p&gt;...&lt;/p&gt;&lt;/body&gt;&lt;/topic&gt;'&gt;

     &lt;SCRIPT&gt;
        // Render Editor and get value from the field
        ditaStorm.render('DITAStorm','100%','300','simple.css','simple.xsl.js');
        ditaStorm.attachField('myForm','ditaField');
     &lt;/SCRIPT&gt;

  &lt;/FORM&gt;
&lt;/BODY&gt;
&lt;/HTML&gt;</codeblock></example><example><title>Loading DITA Document via HTTP </title> DITA Storm can load XML content directly from server via HTTP request. JavaScript function loadXmlFile() retrieves XML over HTTP and loads it into the editor. Here is the sample code: <codeblock>&lt;HTML&gt;
&lt;HEAD&gt;
  &lt;LINK href="/cm/lib/DITAStorm/styles.css" rel="stylesheet" type="text/css"/&gt;
  &lt;SCRIPT src="/cm/lib/DITAStorm/DITAStorm.js" type="text/javascript"&gt;&lt;/SCRIPT&gt;&lt;/HEAD&gt;
&lt;BODY&gt;
  &lt;SCRIPT&gt;
    ditaStorm.render(
      '/cm/lib/DITAStorm','100%','300','simple.css','simple.xsl.js');
    ditaStorm.loadXmlFile('/cm/content/product.xml');
  &lt;/SCRIPT&gt;
&lt;/BODY&gt;
&lt;/HTML&gt;</codeblock><p>loadXmlFile function can also be called at any time during the lifetime of DITA Storm control on the web page. </p></example><example><title>Retrieving Modified XML via JavaScript </title> You can always retrieve currently edited DITA XML as text via JavaScript call using getXml() function. For example: <codeblock>&lt;SCRIPT&gt;
  var xmlString = ditaStorm.getXml();
  alert('Content: '+xmlString);
&lt;/SCRIPT&gt;</codeblock></example></body></topic>
