To determine whether the command should be active or dimmed:
1.
Create a new blank file.
2.
Add the following code:
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()
DOM for the user's document and calling the
object. Next, the function retrieves the node 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
selected anything in the document. The variable
beginning and ending offsets of the selection within 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.
function retrieve the selected text by retrieving the
getSelection()
statement (
theSel[0] != theSel[1]
theSel
function on the document
or
true
false
) checks if the user has
is a two-slot array that holds the
A simple command example
.
171
Need help?
Do you have a question about the DREAMWEAVER 8-EXTENDING DREAMWEAVER and is the answer not in the manual?