SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 1917 | Next

Joseph W. Lowery

"Dreamweaver CS3 Bible"

setSelection(currSelection[0],currSelection[0]);
places it before the selection.
NOTE NOTE
NOTE NOTE
BC 42
Creating a Behavior
The dom.offsetsToNode() function
The offsetsToNode() function serves as a translator, converting the byte memory offsets retrieved by
getSelection() into readable data. For this reason, you often see the following code combination:
selArr = theDOM.getSelection();
selObj = theDOM.offsetsToNode(selArr[0],selArr[1]);
where getSelection() returns the array of the selection and the object referenced by that array. As indicated,
offsetsToNode() takes two arguments: offsetBegin and offsetEnd, usually expressed as
the initial (0) and next (1) array elements.
After you??™ve used offsetsToNode to get the selected object, you can examine or manipulate it. For
example, in the custom Replicator command (included on the DVD that accompanies this book), I used
offsetsToNode to see if the selection made is appropriate (text only) and, if it is not, I call a help function:
var offsets = theDOM.getSelection();
var selObj = theDOM.offsetsToNode(offsets[0],offsets[1]);
if (selObj.nodeType != Node.TEXT_NODE) {
helpMe2();
}
The dom.nodeToOffsets() function
As the name indicates, nodeToOffsets() is the inverse of offsetsToNode(). Instead of converting
memory offsets to an object, nodeToOffsets takes an object reference and returns its memory offsets.


Pages:
1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929