Справочник Пользователя для Macromedia dreamweaver 8-extending dreamweaver

Скачать
Страница из 504
A simple command example
173
Linking functions to the OK and Cancel buttons
When the user clicks OK or Cancel, the extension needs to perform the appropriate action. 
You determine the appropriate action by specifying which JavaScript function to perform 
when either button is clicked.
To link the OK and Cancel button to functions:
1.
Open the file Change Case.js in the Configuration/Commands folder.
2.
At the end of the file, add the following code:
function commandButtons() {
return new Array("OK", "changeCase()", "Cancel", "window.close()");
}
3.
Save the file.
The 
commandButtons()
 function causes Dreamweaver to supply the OK and Cancel buttons 
and tells Dreamweaver what to do when the user clicks them. The 
commandButtons()
 
function tells Dreamweaver to call 
changeCase()
 when the user clicks OK and to call 
window.close()
 when the user clicks Cancel.
Letting the user specify uppercase or lowercase
When the user clicks a menu item, the extension needs a mechanism to let the user select 
uppercase or lowercase. The UI provides this mechanism by defining two radio buttons to let 
the user make that choice.
To let the user specify uppercase or lowercase:
1.
Open the file Change Case.js.
2.
At the end of the file, add the following code:
function changeCase() {
  var uorl;
  
// Check whether user requested uppercase or lowercase.
  if (document.forms[0].elements[0].checked)
uorl = 'u';
else 
uorl = 'l';
// Get the DOM.
var theDOM = dw.getDocumentDOM();
// Get the outerHTML of the HTML tag (the
// entire contents of the document).
var theDocEl = theDOM.documentElement;
var theWholeDoc = theDocEl.outerHTML;