User Guide
A simple Insert Object example 129
To separate the HTML object definition file from the supporting JavaScript functions, create a
new JS file in the same folder as the original HTML file (for example, Strikethrough.js) and paste
all the JavaScript functions into that file. Remove the functions from Strikethrough.htm, and add
the JavaScript filename to the
src attribute of the script tag, as shown in the following example:
<html>
<head>
<title>Strikethrough</title>
<script language="javascript" src=”Strikethrough.js”>
</script>
</head>
<body>
</body>
</html>
In Dreamweaver, select Reload Extensions (see “To reload extensions” on page 120), and test
the object.
Adding a dialog box
You can add a form to your Object to let the user enter parameters before Dreamweaver inserts
the specified code (for example, the Hyperlink object requests the Text, Link, Target, category
Index, Title, and Access Key values from the user). In this example, you will add a form to the
Strikethrough object from the previous example. The form opens a dialog boxthat provides the
user with the option to change the text color to red as well as add the strikethrough tag.
This example assumes you have already created a separate JavaScript file called Strikethrough.js, as
shown in “Creating a separate JavaScript file” on page 128.
First, in Strikethrough.js, add the function the form will call if the user selects to change the text
color. This function will be very similar to the
objectTag() function for the Strikethrough
object, but it is an optional function. So, after the
objectTag() function, create a function called
fontColorRed(). The entire Strikethrough.js file should contain the following code:
function isDOMRequired() {
// Return false, indicating that this object is available in code view.
return false;
}
function objectTag() {
// Manually wrap tags around selection.
var dom = dw.getDocumentDOM();
if (dw.getFocus() == 'textView' || dw.getFocus(true) == 'html'){
var upCaseTag = (dw.getPreferenceString("Source Format", "Tags Upper
Case", "") == 'TRUE');
// Manually wrap tags around selection.
if (upCaseTag){
dom.source.wrapSelection('<S>','</S>');
}else{
dom.source.wrapSelection('<s>','</s>');
}
}else if (dw.getFocus() == 'document'){
dom.applyCharacterMarkup("s");
}