
170 Commands
The contents of the Title tag, Make Uppercase or Lowercase, appears in the top bar of
the dialog box. Within the form, a table with two cells controls the layout of the elements.
Within the table cells are the two radio buttons, Uppercase and Lowercase. The Uppercase
button has the
checked attribute, making it the default selection and ensuring that the user
must either select one of the two buttons or cancel the command.
The form looks like the following figure.
The commandButtons() function supplies the OK and Cancel buttons that let the user
submit the choice or cancel the operation.
Writing the JavaScript code
The following example consists of two extension API functions, canAcceptCommand() and
commandButtons(), which Dreamweaver calls, and one user-defined function,
changeCase(), which is called from the commandButtons() function.
In this example, you will write JavaScript to perform the following tasks:
■ Determining whether the command should be enabled or dimmed
■ Linking functions to the OK and Cancel buttons
■ Letting the user specify uppercase or lowercase
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
canAcceptCommand() function for each menu item to determine whether it should be
enabled. If
canAcceptCommand() returns the value true, Dreamweaver displays the menu
item text as active or enabled. If
canAcceptCommand() returns the value false, Dreamweaver
dims the menu item. In this example, the menu item is active when the user has selected text
in the document.
Commenti su questo manuale