This is useful when you manipulate a substring of the selection, usually text.
For example, in the custom command Change Case (included on the DVD that comes with this book), after
the selected object is retrieved via getSelection and offsetsToNode, nodeToOffsets expresses it
in an array that can be uppercased or lowercased at the click of a button. Here??™s a fragment of the code from
the custom upperCase() function:
var theDom = dreamweaver.getDocumentDOM(???document???);
var offsets = theDom.getSelection();
var theNode = theDom.offsetsToNode(offsets[0],offsets[1]);
if (theNode.nodeType == Node.TEXT_NODE) {
var nodeOffsets = theDom.nodeToOffsets(theNode);
offsets[0] = offsets[0] - nodeOffsets[0];
offsets[1] = offsets[1] - nodeOffsets[0];
var nodeText = theNode.data;
theNode.data = nodeText.substring(0,offsets[0]) +
nodeText.substring(offsets[0], offsets[1]).toUpperCase() +
nodeText.substring(offsets[1], nodeText.length);
}
Because nodeToOffsets returns two memory offsets, you can use these as the arguments in
setSelection to choose an object on the page. If, for instance, you wanted to select the first link on the
page, you use the code as follows:
var theDom = dreamweaver.getDocumentDOM(???document???);
var theLink = theDom.links[0];
var offsets = theDom.
Pages:
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930