Macromedia dreamweaver 8-extending dreamweaver User Manual
152
Insert Bar Objects
Next, decide whether to use
objectTag()
or
insertObject()
for the next function. The
Strikethrough object simply wraps the
s
tag around the selected text, so it doesn’t meet the
criteria for using the
insertObject()
function (see
).
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
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
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.
To 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 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{
if (upCaseTag){
dom.source.wrapSelection('<S>','</S>');
}else{
dom.source.wrapSelection('<s>','</s>');
}
// If the user is not in Code view, apply the formatting in Design
view.
}else if (dw.getFocus() == 'document'){
view.
}else if (dw.getFocus() == 'document'){
dom.applyCharacterMarkup("s");
}
// Just return--don't do anything else.
return;
}
// 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.
several functions, or functions that might be shared by other objects.