User Guide
126 Chapter 6: Insert Bar Objects
A simple Insert Object example
This example adds an object to the Insert bar so users can add a line through (strikethrough)
selected text by clicking a button. This object is useful if a user needs to make editorial comments
on a document.
Because this example performs text manipulation, you can explore some existing objects from the
Text pop-up menu in the HTML category on the Insert bar as models. For example, look at the
Bold, Emphasis, and even the Heading object files to see similar functionality, where
Dreamweaver wraps a tag around selected text.
First, create an HTML object definition file, and give it the title Strikethrough. Specify that the
scripting language is JavaScript.
<html>
<head>
<title>Strikethrough</title>
<script language="javascript">
</script>
</head>
<body>
</body>
</html>
Next, add the JavaScript functions that define the behavior and insert code for the Strikethrough
object. All the API functions need to go in the head of the document. The existing object files,
such as Configuration/Objects/Text/Em.htm, follow a similar pattern of functions and
comments. The first function the object definition file uses is i
sDOMRequired() to indicate if the
Design view needs to be synchronized to the existing Code view before continuing. Because the
Superscript object might be used with many other objects within the Code view, it does not
require a forced synchronization.
function isDOMRequired() {
// Return false, indicating that this object is available in code view.
return false;
}
Next, decide whether to use objectTag() or insertObject() for the next function.
Strikethrough simply wraps the
s tag around the selected text, so it doesn’t meet the criteria for
using the
insertObject() function (see “insertObject()” on page 123).
Within the
objectTag() function, use dw.getFocus() to determine if the Code view is the
current view. If the Code view is in focus, the function should wrap the appropriate (uppercase or
lowercase) tag around the selected text. If the Design view is in focus, the function can use
dom.applyCharacterMarkup() to assign the formatting to the selected text. Remember that this
function works only for specific supported tags (for more information, see
dom.applyCharacterMarkup() in the Dreamweaver API Reference). For other tags or operations,
other API functions may be necessary.