Behavior functions

Behavior functions let you add behaviors to, and remove them from, an object, find out which behaviors are attached to an object, get information about the object to which a behavior is attached, and so on. Methods of the dreamweaver.behaviorInspector object either control or act on only the selection in the Behaviors panel, not the selection in the current document.

dom.addBehavior()

Availability

Dreamweaver 3.

Description

Adds a new event/action pair to the selected element. This function is valid only for the active document.

Arguments

event, action, {eventBasedIndex}

  • The event argument is the JavaScript event handler that should attach the behavior to the element (for example, onClick, onMouseOver, or onLoad).

  • The action argument is the function call that applyBehavior() returns if the action is added using the Behaviors panel (for example, "MM_popupMsg('Hello World')").

  • The eventBasedIndex argument, which is optional, is the position at which this action should be added. The eventBasedIndex argument is a zero-based index; if two actions already are associated with the specified event, and you specify eventBasedIndex as 1, this action executes between the other two. If you omit this argument, the action is added after all existing actions for the specified event.

Returns

Nothing.

dom.getBehavior()

Availability

Dreamweaver 3.

Description

Gets the action at the specified position within the specified event. This function acts on the current selection and is valid only for the active document.

Arguments

event, {eventBasedIndex}

  • The event argument is the JavaScript event handler through which the action is attached to the element (for example, onClick, onMouseOver, or onLoad).

  • The eventBasedIndex argument, which is optional, is the position of the action to get. For example, if two actions are associated with the specified event, 0 is first and 1 is second. If you omit this argument, the function returns all the actions for the specified event.

Returns

A string that represents the function call (for example, "MM_swapImage('document.Image1','document.Image1','foo.gif','#933292969950')") or an array of strings if eventBasedIndex is omitted.

dom.reapplyBehaviors()

Availability

Dreamweaver 3.

Description

Checks to make sure that the functions that are associated with any behavior calls on the specified node are in the HEAD section of the document and inserts them if they are missing.

Arguments

elementNode

  • The elementNode argument is an element node within the current document. If you omit the argument, Dreamweaver checks all element nodes in the document for orphaned behavior calls.

Returns

Nothing.

dom.removeBehavior()

Availability

Dreamweaver 3.

Description

Removes the action at the specified position within the specified event. This function acts on the current selection and is valid only for the active document.

Arguments

event, {eventBasedIndex}

  • The event argument is the event handler through which the action is attached to the element (for example, onClick, onMouseOver, or onLoad). If you omit this argument, all actions are removed from the element.

  • The eventBasedIndex argument, which is optional, is the position of the action to be removed. For example, if two actions are associated with the specified event, 0 is first and 1 is second. If you omit this argument, all the actions for the specified event are removed.

Returns

Nothing.

dreamweaver.getBehaviorElement()

Availability

Dreamweaver 2, and updated in CS4.

Description

Gets the DOM object that corresponds to the tag to which the behavior is being applied. This function is applicable only in Behavior action files.

Arguments

None.

Returns

A DOM object or a null value. This function returns a null value under the following circumstances:

  • When the current script is not executing within the context of the Behaviors panel

  • When dreamweaver.popupAction()starts the currently executing script

  • When the Behaviors panel is attaching an event to a link wrapper and the link wrapper does not yet exist

  • When this function appears outside an action file

Example

The dreamweaver.getBehaviorElement() function can be used in the same way as dreamweaver.getBehaviorTag() to determine whether the selected action is appropriate for the selected HTML tag. The difference is that it gives you access to more information about the tag and its attributes. If you write an action that can be applied only to a hypertext link (A HREF) that does not target another frame or window, you can use the getBehaviorElement() function. You can use the getBehaviorElement() function as part of the function that initializes the user interface for the Parameters dialog box. It is shown in the following example:

 function initializeUI(){ 
    var theTag = dreamweaver.getBehaviorElement(); 
    var CANBEAPPLIED = (theTag.tagName == "A" && ¬ 
    theTag.getAttribute("HREF") != null && ¬ 
    theTag.getAttribute("TARGET") == null); 
    if (CANBEAPPLIED) { 
        // display the action user interface 
    } else{ 
        // display a helpful message that tells the user 
        // that this action can only be applied to a 
        // link without an explicit target] 
    } 
}

dreamweaver.getBehaviorTag()

Availability

Dreamweaver 1.2.

Description

Gets the source of the tag to which the behavior is being applied. This function is applicable only in action files.

Arguments

None.

Returns

A string that represents the source of the tag. This is the same string that passes as an argument (HTMLelement) to the canAcceptBehavior() function. If this function appears outside an action file, the return value is an empty string.

Example

If you write an action that can be applied only to a hypertext link (A HREF), you can use the getBehaviorTag() function, as the following example shows, in the function that initializes the user interface for the Parameters dialog box:

 function initializeUI(){ 
    var theTag = dreamweaver.getBehaviorTag().toUpperCase(); 
    var CANBEAPPLIED = (theTag.indexOf('HREF') != -1)); 
    if (CANBEAPPLIED) { 
        // display the action UI 
    } else{ 
        // display a helpful message that tells the user 
        // that this action can only be applied to a 
        // hyperlink 
    } 
}

dreamweaver.popupAction()

Availability

Dreamweaver 2, and updated in CS4.

Description

Starts a Parameters dialog box for the specified behavior action. To the user, the effect is the same as selecting the action from the Actions pop-up menu in the Behaviors panel. This function lets extension files other than actions attach behaviors to objects in the document of the user. It blocks other edits until the user dismisses the dialog box.

Note:

This function can be called within the objectTag() function or in any script in a command file or in the Property inspector file.

Arguments

actionName, {funcCall}

  • The actionName argument is a string that contains the name of a file in the Configuration/Behaviors/Actions folder. The file contains a JavaScript behavior action (for example, "Swap Image.htm").

  • The funcCall argument, which is optional, is a string that contains a function call for the action that is specified in actionName; for example, "MM_SwapImage(...)". The applyBehavior() function in the action file supplies this argument, if specified.

Returns

The function call for the behavior action. When the user clicks OK in the Parameters dialog box, the behavior is added to the current document. The appropriate functions are added to the HEAD section of the document. HTML is added to the top of the BODY section, and other edits can be made to the document. The function call (for example, "MM_SwapImage(...)") is not added to document, but becomes the return value of this function.

dreamweaver.behaviorInspector.getBehaviorAt()

Availability

Dreamweaver 3.

Description

Gets the event/action pair at the specified position in the Behaviors panel.

Arguments

positionIndex

  • The positionIndex argument is the position of the action in the Behaviors panel. The first action in the list is at position 0.

Returns

An array of two items:

  • An event handler

  • A function call or JavaScript statement

Example

Because positionIndex is a zero-based index, if the Behaviors panel displays the list, a call to the dreamweaver.behaviorInspector.getBehaviorAt(2) function returns an array that contains two strings: "onMouseOver" and "MM_changeProp('document.moon','document.moon','src','sun.gif','MG')".

dreamweaver.behaviorInspector.getBehaviorCount()

Availability

Dreamweaver 3.

Description

Counts the number of actions that are attached to the currently selected element through event handlers.

Arguments

None.

Returns

An integer that represents the number of actions that are attached to the element. This number is equivalent to the number of actions that are visible in the Behaviors panel and includes Dreamweaver behavior actions and custom JavaScript.

Example

A call to dreamweaver.behaviorInspector.getBehaviorCount() for the selected link <A HREF="javascript:setCookie()" onClick="MM_popupMsg('A cookie has been set.');parent.rightframe.location.href='aftercookie.html'"> returns 2.

dreamweaver.behaviorInspector.getSelectedBehavior()

Availability

Dreamweaver 3.

Description

Gets the position of the selected action in the Behaviors panel.

Arguments

None.

Returns

An integer that represents the position of the selected action in the Behaviors panel, or –1 if no action is selected.

Example

If the first action in the Behaviors panel is selected, a call to the dreamweaver.behaviorInspector.getSelectedBehavior() function returns 0.

dreamweaver.behaviorInspector.moveBehaviorDown()

Availability

Dreamweaver 3.

Description

Moves a behavior action lower in sequence by changing its execution order within the scope of an event.

Arguments

positionIndex

  • The positionIndex argument is the position of the action in the Behaviors panel. The first action in the list is at position 0.

Returns

Nothing.

Example

Calling the dreamweaver.behaviorInspector.moveBehaviorDown(2) function swaps the positions of the Preload Images and the Change Property actions on the onMouseDown event. Calling the dreamweaver.behaviorInspector.moveBehaviorDown() function for any other position has no effect because the onClick and onFocus events each have only one associated behavior, and the behavior at position 3 is already at the bottom of the onMouseDown event group.

dreamweaver.behaviorInspector.moveBehaviorDown
dreamweaver.behaviorInspector.moveBehaviorDown

dreamweaver.behaviorInspector.moveBehaviorUp()

Availability

Dreamweaver 3.

Description

Moves a behavior higher in sequence by changing its execution order within the scope of an event.

Arguments

positionIndex

  • The positionIndex argument is the position of the action in the Behaviors panel. The first action in the list is at position 0.

Returns

Nothing.

Example

Calling the dreamweaver.behaviorInspector.moveBehaviorUp(3) function swaps the positions of the Preload Images and the Change Property actions on the onMouseOver event. Calling the dreamweaver.behaviorInspector.moveBehaviorUp() function for any other position has no effect because the onClick and onFocus events each have only one associated behavior, and the behavior at position 2 is already at the top of the onMouseDown event group.

dreamweaver.behaviorInspector.moveBehaviorUp
dreamweaver.behaviorInspector.moveBehaviorUp

dreamweaver.behaviorInspector.setSelectedBehavior()

Availability

Dreamweaver 3.

Description

Selects the action at the specified position in the Behaviors panel.

Arguments

positionIndex

  • The positionIndex argument is the position of the action in the Behaviors panel. The first action in the list is at position 0. To deselect all actions, specify a positionIndex of –1. Specifying a position for which no action exists is equivalent to specifying –1.

Returns

Nothing.

Example

Calling the dreamweaver.behaviorInspector.setSelection(2) function selects the Change Property action that is associated with the onMouseDown event:

dreamweaver.behaviorInspector.setSelection(2)
dreamweaver.behaviorInspector.setSelection(2)

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy