Adobe Extending Dreamweaver CS4 Uživatelský manuál Strana 341

  • Stažení
  • Přidat do mých příruček
  • Tisk
  • Strana
    / 387
  • Tabulka s obsahem
  • KNIHY
  • Hodnocené. / 5. Na základě hodnocení zákazníků
Zobrazit stránku 340
335
EXTENDING DREAMWEAVER CS4
Data translators
// 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 without
an error message when you invoke it. 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()");
}
3 At the end of the translateMarkup() function, comment out the returnwhateverTheReturnValueIs line, and
replace it with
dreamweaver.getDocumentDOM().documentElement.outerHTML =
whateverTheReturnValueIs, as shown in the following example:
// return theCode;
dreamweaver.getDocumentDOM().documentElement.outerHTML = theCode;
}
/* end of translateMarkup() */
4 In the body of the document, add the following form with no text boxes:
<body>
<form>
Hello.
</form>
</body>
Zobrazit stránku 340
1 2 ... 336 337 338 339 340 341 342 343 344 345 346 ... 386 387

Komentáře k této Příručce

Žádné komentáře