< Day Day Up > |
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}
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}
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
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}
Returns Nothing. dreamweaver.getBehaviorElement()Availability Dreamweaver 2. 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:
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, except that it gives you access to more information about the tag and its attributes. As shown in the following example, 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 as part of the function that initializes the user interface for the Parameters dialog box: function initializeUI(){ var theTag = dreamweaver.getBehaviorElement(); var CANBEAPPLIED = (theTag.tagName == "A" && theTag.getAttribute("HREF") != null && theTag.getAttribute("TARGET") == null); 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 without an explicit target] } } dreamweaver.getBehaviorEvent() (deprecated)Availability Dreamweaver 1.2; deprecated in Dreamweaver 2 because actions are now selected before events. Description In a Behavior action file, this function gets the event that triggers this action. Arguments None. Returns A string that represents the event. This is the same string that is passed as an argument (event) to the canAcceptBehavior() function. 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. Description Invokes 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 user's document. 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}
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 might be added to the top of the BODY section, and other edits might be made to the document). The function call (for example, "MM_playTimeline(...)") 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
Returns An array of two items:
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, as shown in the following figure, 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
Returns Nothing. Example If the Behaviors panel is set up as shown in the following figure, 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.moveBehaviorUp()Availability Dreamweaver 3. Description Moves a behavior higher in sequence by changing its execution order within the scope of an event. Arguments positionIndex
Returns Nothing. Example If the Behaviors panel is set up as shown in the following figure, 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.setSelectedBehavior()Availability Dreamweaver 3. Description Selects the action at the specified position in the Behaviors panel. Arguments positionIndex
Returns Nothing. Example If the Behaviors panel is set up as shown in the following figure, calling the dreamweaver.behaviorInspector.setSelection(2) function selects the Change Property action that is associated with the onMouseDown event: |
< Day Day Up > |