beautypg.com

Adobe Extending Dreamweaver CS4 User Manual

Page 120

background image

114

EXTENDING DREAMWEAVER CS4

Insert bar objects

Within the

objectTag()

function, use

dw.getFocus()

to determine whether the Code view is the current view. If the

Code view has input focus, the function should wrap the appropriate (uppercase or lowercase) tag around the selected
text. If the Design view has input focus, the function can use

dom.applyCharacterMarkup()

to assign the formatting

to the selected text. Remember that this function works only for supported tags (see

dom.applyCharacterMarkup()

in the Dreamweaver API Reference). For other tags or operations, you may need to use other API functions. After
Dreamweaver applies the formatting, it should return the insertion point (cursor) to the document without any
messages or prompting. The following procedure shows how the

objectTag()

function now reads.

Add the objectTag() function

1

In the head section of the Strikethrough.htm file, after the

isDOMRequired()

function, add the following function:

function objectTag() {

// Determine if the user is in Code view.
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('','');

}else{

dom.source.wrapSelection('','');

}

// If the user is not in Code view, apply the formatting in Design view.
}else if (dw.getFocus() == 'document'){

dom.applyCharacterMarkup("s");

}
// Just return--don't do anything else.
return;

}

2

Save the file as Strikethrough.htm in the Configuration/Objects/Text folder.

Instead of including the JavaScript functions in the head section of the HTML file, you can create a separate JavaScript
file. This separate organization is useful for objects that contain several functions, or functions that might be shared
by other objects.

Separate the HTML object definition file from the supporting JavaScript functions

1

Create a new blank file.

2

Paste all the JavaScript functions into the file.

3

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:


Strikethrough




4

Save the Strikethrough.htm file.

This manual is related to the following products: