A simple behavior example
307
Inserting multiple functions in the user’s file
Actions can insert multiple functions—the main behavior function plus any number of helper
functions—into the
HEAD
section. Two or more behaviors can even share helper functions as
long as the function definition is exactly the same in each Action file. One way of ensuring
that shared functions are identical is to store each helper function in an external JavaScript file
and insert it into the appropriate Action files using
<SCRIPT SRC="
externalFile
.js">
.
When the user deletes a behavior, Dreamweaver attempts to remove any unused helper
functions that are associated with the behavior. If other behaviors are using a helper function,
it is not deleted. Because the algorithm for deleting helper functions errs on the side of
caution, Dreamweaver might occasionally leave an unused function in the user’s document.
What to do when an action requires a return value
Sometimes an event handler must have a return value (for example,
onMouseOver="window.status='This is a link'; return true"
). But if Dreamweaver
inserts the
"return behaviorName(args)"
action into the event handler, behaviors later in
the list are skipped.
To get around this limitation, set the
document.MM_returnValue
variable to the desired
return value within the string that the
behaviorFunction()
function returns. This setting
causes Dreamweaver to insert
return document.MM_returnValue
at the end of the list of
actions in the event handler. For an example that uses the
MM_returnValue
variable, see the
Validate Form.js file in the Configuration/Behaviors/Actions folder within the Dreamweaver
application folder.
A simple behavior example
To understand how behaviors work and how you can create one, it’s helpful to look at an
example. The Configuration/Behaviors/Actions folder inside the Dreamweaver application
folder contains examples; however, many are very complex. This example is simpler so that
you can learn about creating behaviors. Start with the simple Action file Call JavaScript.htm
(along with its counterpart, Call JavaScript.js, which contains all the JavaScript functions).
To create the behavior, you perform the following steps:
■
Creating the behavior extension
■
Creating the HTML files to browse
■
Testing the behavior
Содержание DREAMWEAVER 8-EXTENDING DREAMWEAVER
Страница 1: ...Extending Dreamweaver...
Страница 8: ...8 Contents...
Страница 14: ...14 Introduction...
Страница 16: ......
Страница 54: ...54 Customizing Dreamweaver...
Страница 96: ...96 Customizing Code View...
Страница 98: ......
Страница 110: ...110 Extending Dreamweaver...
Страница 138: ......
Страница 166: ...166 Insert Bar Objects...
Страница 180: ...180 Commands...
Страница 248: ...248 Toolbars...
Страница 260: ...260 Reports...
Страница 278: ...278 Tag Libraries and Editors...
Страница 288: ...288 Property Inspectors...
Страница 378: ...378 Server Behaviors...
Страница 398: ...398 Data Sources...
Страница 432: ...432 Server Models...
Страница 456: ...456 Data Translators...
Страница 482: ......
Страница 492: ...492 The Shared Folder...