Adobe 38040334 - Dreamweaver CS3 User Manual page 138

Extending dreamweaver
Hide thumbs Also See for 38040334 - Dreamweaver CS3:
Table of Contents

Advertisement

}
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
function is a user-defined function that is called by the
changeCase()
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.
The
function first tests the property
changeCase()
document.forms[0].elements[0]
object, which is the UI for the extension. The
(or enabled) and
if it is not. In the interface,
false
Uppercase button. Because one of the radio buttons is always checked when the user clicks OK, the code assumes
that if the choice is not uppercase, it must be lowercase. The function sets the variable
user's response.
The remaining code in the function retrieves the selected text, converts it to the specified case, and copies it back in
place in the document.
To retrieve the selected text for the user's document, the function gets the DOM. It then gets the root element of the
document, which is the
html
Next,
calls
changeCase()
any child nodes (
theSelNode.childNodes)
If there are child nodes (
hasChildNodes()
looking for a text node. If one is found, the text (
text node are stored in
theSel
If there are no child nodes, the command calls
selection in
. It then extracts the string between those two offsets and stores it in
theSel
The function then checks the
writes the HTML code back to the document in sections: first, the beginning of the document to the beginning of
the selection; then the selected text, converting it to uppercase (
selected text to the end of the document.
If the user selects lowercase, the function performs the same operation, but calls
convert the selected text to lowercase.
Finally,
resets the selection and calls
changeCase()
document.forms[0].elements[0].checked
property refers to the first element in the first form of the current document
checked
elements[0]
tag. Finally, it extracts the whole document into the
to retrieve the node that contains the selected text. It also retrieves
getSelectedNode()
in case the selection is a tag that contains text, such as
returns the value
theChildren[i].data
.
getSelection()
variable to determine whether the user selected uppercase. If so, the function
uorl
window.close()
commandButtons()
property has the value
true
refers to the first radio button, which is the
), the command loops through the children
true
) is stored in
and stores the beginning and ending offsets of the
selText.toUppercase()
selText.toLowerCase()
to close the UI.
DREAMWEAVER CS3
Extending Dreamweaver
function when the
. The
if the element is checked
to
or
to store the
uorl
u
l
variable.
theWholeDoc
<b>text</b>
, and the offsets of the
selText
.
selText
); and last, the end of the
132
.
to

Advertisement

Table of Contents
loading

This manual is also suitable for:

Dreamweaver cs3

Table of Contents