Selection functions get and set the selection in open documents. For information on getting or setting the selection in the Site panel, see Site functions.
dom.getSelectedNode()
Availability
Dreamweaver 3.
Description
Gets the selected node. Using this function is equivalent to calling the dom.getSelection() function and passing the return value to the dom.offsetsToNode() function.
Arguments
None.
Returns
The tag, text, or comment object that completely contains the specified range of characters.
dom.getSelection()
Availability
Dreamweaver 3.
Description
Gets the selection, which is expressed as character offsets into the document’s source code.
Arguments
{bAllowMultiple}
The bAllowMultiple argument, which is optional, is a Boolean value that indicates whether the function should return multiple offsets if more than one table cell, image map hotspot, or layer is selected.
If this argument is omitted, it defaults to false.
Returns
For simple selections, an array that contains two integers. The first integer is the character offset of the opening of the selection. The second integer is the character offset at the closing of the selection. If the two numbers are the same, the current selection is an insertion point.
For complex selections (multiple table cells, multiple layers, or multiple image map hotspots), an array that contains 2n integers, where n is the number of selected items. The first integer in each pair is the character offset of the opening of the selection (including the opening TD, DIV, SPAN, LAYER, ILAYER, or MAP tag); the second integer in each pair is the character offset of the closing of the selection (including the closing TD, DIV, SPAN, LAYER, ILAYER, or MAP tag). If multiple table rows are selected, the offsets of each cell in each row return. The selection never includes the TR tags.
dom.getSelectorsDefinedInStylesheet()
Availability
Dreamweaver 8.
Description
Gets an array of selectors that match the type passed in as an attribute.
Arguments
selector
The selector argument is a string of value class or ID. It specifies whether the function returns selectors of the type class or ID.
Returns
An array of selectors that can be either of the type class or ID.
Example
The following code is used to get an array of selectors of the type class:var dom=dw.getDocumentDOM(); var classSelectors = dom.getSelectorsDefinedInStylesheet('class');
The following code is used to get an array of selectors of the type ID:var dom=dw.getDocumentDOM(); var classSelectors = dom.getSelectorsDefinedInStylesheet('ID');
var dom=dw.getDocumentDOM(); var classSelectors = dom.getSelectorsDefinedInStylesheet('class');
var dom=dw.getDocumentDOM(); var classSelectors = dom.getSelectorsDefinedInStylesheet('ID');
dom.nodeToOffsets()
Availability
Dreamweaver 3.
Description
Gets the position of a specific node in the DOM tree, which is expressed as character offsets into the document’s source code. It is valid for any document on a local drive.
Arguments
node
The node argument must be a tag, comment, or range of text that is a node in the tree that the dreamweaver.getDocumentDOM() function returns.
Returns
An array that contains two integers. The first integer is the character offset of the beginning of the tag, text, or comment. The second integer is the character offset of the end of the node, from the beginning of the HTML document.
Example
The following code selects the first image object in the current document:
var theDOM = dw.getDocumentDOM(); var theImg = theDOM.images[0]; var offsets = theDom.nodeToOffsets(theImg); theDom.setSelection(offsets[0], offsets[1]);
dom.offsetsToNode()
Availability
Dreamweaver 3.
Description
Gets the object in the DOM tree that completely contains the range of characters between the specified opening and closing points. It is valid for any document on a local drive.
Arguments
offsetBegin, offsetEnd
The offsetBegin argument specifies the offset from the beginning of the document to the beginning of a range of characters that is an object in the DOM tree.
The offsetEnd argument specifies the offset from the beginning of the document to the end of a range of characters that is an object in the DOM tree.
Returns
The tag, text, or comment object that completely contains the specified range of characters.
Example
The following code displays an alert if the selection is an image:
var offsets = dom.getSelection(); var theSelection = dreamweaver.offsetsToNode(offsets[0], ¬ offsets[1]); if (theSelection.nodeType == Node.ELEMENT_NODE && ¬ theSelection.tagName == 'IMG'){ alert('The current selection is an image.'); }
dom.selectAll()
Availability
Dreamweaver 3.
Description
Performs a Select All operation.
In most cases, this function selects all the content in the active document. In some cases (for example, when the insertion point is inside a table), it selects only part of the active document. To set the selection to the entire document, use dom.setSelection().
Arguments
None.
Returns
Nothing.
dom.setSelectedNode()
Availability
Dreamweaver 3.
Description
Sets the selected node. This function is equivalent to calling the dom.nodeToOffsets() function and passing the return value to the dom.setSelection() function.
Arguments
node, {bSelectInside}, {bJumpToNode}
The node argument is a text, comment, or element node in the document.
The bSelectInside argument, which is optional, is a Boolean value that indicates whether to select the innterHTML of the node. This argument is relevant only if node is an element node, and it defaults to false if it is omitted.
The bJumpToNode argument, which is optional, is a Boolean value that indicates whether to scroll the Document window, if necessary, to make the selection visible. If it is omitted, this argument defaults to false.
Returns
Nothing.
dom.setSelection()
Availability
Dreamweaver 3.
Description
Sets the selection in the document.
Arguments
offsetBegin, offsetEnd
These arguments are the opening and closing points, respectively, for the new selection, which is expressed as character offsets into the document’s source code. If the two numbers are the same, the new selection is an insertion point. If the new selection is not a valid HTML selection, it is expanded to include the characters in the first valid HTML selection. For example, if offsetBegin and offsetEnd define the range SRC="myImage.gif" within <IMG SRC="myImage.gif">, the selection expands to include the entire IMG tag.
Returns
Nothing.
dreamweaver.nodeExists()
Available
Dreamweaver 3.
Description
Determines whether the reference to the specified node is still good. Often when writing extensions, you reference a node and then perform an operation that deletes it (such as setting the innerHTML or outerHTML properties of its parent). This function lets you confirm that the node hasn’t been deleted before you attempt to reference any of its properties or methods. The referenced node does not need to be in the current document.
Arguments
node
The node argument is the node that you want to check.
Returns
A Boolean value: true if the node exists; false otherwise.
Example
The following example gets the current node, locates a table within it, and later calls dw.nodeExists() to see if the original node still exists:
function applyFormatToSelectedTable(){ // get current selection var selObj = dw.getDocumentDOM().getSelectedNode(); alternateRows(dwscripts.findDOMObject("presetNames").selectedIndex, findTable()); // restore original selection, if it still exists; if not, just select the // table. var selArr; if (dw.nodeExists(selObj)) selArr = dom.nodeToOffsets(selObj); else selArr = dom.nodeToOffsets(findTable()); dom.setSelection(selArr[0],selArr[1]); }
dreamweaver.selectAll()
Availability
Dreamweaver 3.
Description
Performs a Select All operation in the active document window, the Site panel or, on the Macintosh, the text field that has focus in a dialog box or floating panel.
If the operation takes place in the active document, it usually selects all the content in the active document. In some cases (for example, when the insertion point is inside a table), however, it selects only part of the active document. To set the selection to the entire document, use the dom.setSelection() function.
Arguments
None.
Returns
Nothing.
Enabler