Adobe 38040334 - Dreamweaver CS3 User Manual page 135

Extending dreamweaver
Hide thumbs Also See for 38040334 - Dreamweaver CS3:
Table of Contents

Advertisement

• "Linking functions to the OK and Cancel buttons" on page 130
• "Letting the user specify uppercase or lowercase" on page 131
Determining whether the command should be enabled or dimmed
The first task in creating a command is to determine when the item should be active and when it should be dimmed.
When a user clicks the Commands menu, Dreamweaver calls the
item to determine whether it should be enabled. If
displays the menu item text as active or enabled. If
dims the menu item. In this example, the menu item is active when the user has selected text in the document.
To determine whether the command should be active or dimmed:
1
Create a new blank file.
Add the following code:
2
function canAcceptCommand(){
var theDOM = dw.getDocumentDOM(); // Get the DOM of the current document
var theSel = theDOM.getSelection(); // Get start and end of selection
var theSelNode = theDOM.getSelectedNode(); // Get the selected node
var theChildren = theSelNode.childNodes; // Get children of selected node
return (theSel[0] != theSel[1] && (theSelNode.nodeType == Node.TEXT_NODE¬
|| theSelNode.hasChildNodes() && (theChildren[0].nodeType == ¬
Node.TEXT_NODE)));
}
3
Save the file as Change Case.js in the Configuration/Commands folder.
The first lines of the
canAcceptCommand()
document and calling the
getSelection()
that contains the selected text, followed by any children of the node, as shown in the following code. Then, the last
line checks to see if the selection or its first child is text and returns the result as a value of
The first part of the
return
document. The variable
theSel
the document. If the two values are not equal, content has been selected. If the values in the two slots are equal, there
is only an insertion point and nothing has been selected.
canAcceptCommand()
canAcceptCommand()
function retrieve the selected text by retrieving the DOM for the user's
function on the document object. Next, the function retrieves the node
statement (
theSel[0] != theSel[1]
is a two-slot array that holds the beginning and ending offsets of the selection within
function for each menu
canAcceptCommand()
returns the value
true
returns the value
false
true
) checks if the user has selected anything in the
DREAMWEAVER CS3
Extending Dreamweaver
, Dreamweaver
, Dreamweaver
or
.
false
129

Advertisement

Table of Contents
loading

This manual is also suitable for:

Dreamweaver cs3

Table of Contents