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

Скачать
Страница из 504
174
Commands
// Get the node that contains the selection.
var theSelNode = theDOM.getSelectedNode();
// Get the children of the selected node.
var theChildren = theSelNode.childNodes;
var i = 0;
if (theSelNode.hasChildNodes()){
while (i < theChildren.length){
if (theChildren[i].nodeType == Node.TEXT_NODE){
  
var selText = theChildren[i].data;
var theSel = theDOM.nodeToOffsets(theChildren[0]);
break;
}
++i;
}
}
else {
// Get the offsets of the selection
   var theSel = theDOM.getSelection();
   // Extract the selection
   var selText = theWholeDoc.substring(theSel[0],theSel[1]);
}
if (uorl == 'u'){
theDocEl.outerHTML = theWholeDoc.substring(0,theSel[0]) + 
selText.toUpperCase() + theWholeDoc.substring(theSel[1]);
}
else {
theDocEl.outerHTML = theWholeDoc.substring(0,theSel[0]) + 
selText.toLowerCase() + theWholeDoc.substring(theSel[1]);
}
// Set the selection back to where it was when you started
  theDOM.setSelection(theSel[0],theSel[1]);
window.close(); // close extension UI
}
3.
Save the file as Change Case.js in the Configuration/Commands folder.
The 
changeCase()
 function is a user-defined function that is called by the 
commandButtons()
 function when the user clicks OK. This function changes the selected 
text to uppercase or lowercase. Because the UI uses radio buttons, the code can rely on one 
choice or the other being checked; it does not need to test for the possibility that the user 
makes neither choice.