Selection functions

 < Day Day Up > 

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" on page 760.

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.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.

NOTE

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="/books/4/533/1/html/2/myImage.gif" within <IMG src="/books/4/533/1/html/2/myImage.gif">, the selection expands to include the entire IMG tag.

Returns

Nothing.

dreamweaver.getSelection() (deprecated)

Availability

Dreamweaver 2; deprecated in 3. See "dom.getSelection()" on page 841.

Description

Gets the selection in the current document, which is expressed as byte offsets into the document's source code.

Arguments

None.

Returns

An array that contains two integers. The first integer is the byte offset for the beginning of the selection; the second integer is the byte offset for the end of the selection. If the two numbers are the same, the current selection is an insertion point.

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.nodeToOffsets() (deprecated)

Availability

Dreamweaver 2; deprecated in 3 in favor of "dom.nodeToOffsets()" on page 841.

Description

Gets the position of a specific node in the DOM tree, which is expressed as byte offsets into the document's source code.

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 byte offset for the opening of the tag, text, or comment; the second integer is the byte offset for the closing of the node.

dreamweaver.offsetsToNode() (deprecated)

Availability

Dreamweaver 2; deprecated in 3 in favor of "dom.offsetsToNode()" on page 842.

Description

Gets the object in the DOM tree that completely contains the range of characters between the specified opening and closing points.

Arguments

 offsetBegin, offsetEnd 

  • These arguments are the opening and closing points, respectively, of a range of characters, which is expressed as byte offsets into the document's source code.

Returns

The tag, text, or comment object that completely contains the specified range of characters.

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.

NOTE

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

See "dreamweaver.canSelectAll()" on page 1077.

dreamweaver.setSelection() (deprecated)

Availability

Dreamweaver 2; deprecated in 3 in favor of "dom.setSelection()" on page 844.

Description

Sets the selection in the current document. This function can move the selection only within the current document; it cannot change the focus to a different document.

Arguments

 offsetBegin, offsetEnd 

  • These arguments are the opening and closing points, respectively, for the new selection, which is expressed as byte 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="/books/4/533/1/html/2/myImage.gif" within <IMG src="/books/4/533/1/html/2/myImage.gif">, the selection expands to include the entire IMG tag.

Returns

Nothing.

     < Day Day Up > 


    Developing Extensions for Macromedia Dreamweaver 8
    Developing Extensions for Macromedia Dreamweaver 8
    ISBN: 0321395409
    EAN: 2147483647
    Year: 2005
    Pages: 282

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net