MACROMEDIA DREAMWEAVER MX 2004-EXTENDING DREAMWEAVER Specifiche Pagina 171

  • Scaricare
  • Aggiungi ai miei manuali
  • Stampa
  • Pagina
    / 504
  • Indice
  • SEGNALIBRI
  • Valutato. / 5. Basato su recensioni clienti
Vedere la pagina 170
A simple command example 171
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() function retrieve the selected text by retrieving the
DOM for the users document and calling the
getSelection() function on the document
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
true or false.
The first part of the
return statement (theSel[0] != theSel[1]) checks if the user has
selected anything in the document. The variable
theSel is a two-slot array that holds the
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.
Vedere la pagina 170
1 2 ... 166 167 168 169 170 171 172 173 174 175 176 ... 503 504

Commenti su questo manuale

Nessun commento