Specifications
Data Translators 241
The Property inspector for translated server-side includes (Configuration/Inspectors/
ssi_translated.js) demonstrates this technique in its
setComment() function. Rather than
rewriting the
orig attribute, the Property inspector assembles a new SSI comment. It inserts that
comment into the document in place of the old one by rewriting the entire document contents,
which generates a new
orig attribute. The following code summarizes this technique:
// Assemble the new include comment. radioStr and URL are
// variables defined earlier in the code.
newInc = "<!--#include " + radioStr + "=" + '"' + URL + '"' ¬
+" -->";
// Get the contents of the document.
var entireDocObj = dreamweaver.getDocumentDOM();
var docSrc = entireDocObj.documentElement.outerHTML;
// Store everything up to the SSI comment and everything after
// the SSI comment in the beforeSelStr and afterSelStr variables.
var beforeSelStr = docSrc.substring(0, curSelection[0] );
var afterSelStr = docSrc.substring(curSelection[1]);
// Assemble the new contents of the document.
docSrc = beforeSelStr + newInc + afterSelStr;
// Set the outerHTML of the HTML tag (represented by
// the documentElement object) to the new contents,
// and then set the selection back to the locked region
// surrounding the SSI comment.
entireDocObj.documentElement.outerHTML = docSrc;
entireDocObj.setSelection(curSelection[0], curSelection[0]+1);
Finding bugs in your translator
If the translateMarkup() function contains certain types of errors, the translator loads properly,
but it fails silently when invoked. Although failing silently prevents Dreamweaver from becoming
unstable, it can hinder development, especially when you need to find one small syntax error in
multiple lines of code.
If your translator fails, one effective debugging method is to turn the translator into a command,
as described in the following steps:
1 Copy the entire contents of the translator file to a new document, and save it in the
Configuration/Commands folder inside the Dreamweaver application folder.
2 At the top of the document, between the SCRIPT tags, add the following function:
function commandButtons(){
return new Array( "OK","translateMarkup(dreamweaver.¬
getDocumentPath('document'), dreamweaver.getSiteRoot(), ¬
dreamweaver.getDocumentDOM().documentElement.outerHTML); ¬
window.close()", "Cancel", "window.close()");
}