Operation Manual

334
USING DREAMWEAVER
Adding JavaScript behaviors
Last updated 3/28/2012
12 Enter JavaScript code or a function name (for example, evaluateAPelementPos()) in the second Call JavaScript
box to execute the code or function when the AP element is dropped. Select Only If Snapped if the JavaScript should
be executed only if the AP element has reached the drop target.
13 Click OK and verify that the default event is correct.
Gathering information about the draggable AP element
When you attach the Drag AP element behavior to an object, Dreamweaver inserts the MM_dragLayer() function into
the
head section of your document. (The function retains the old naming convention for AP elements [that is, “Layer”]
so that layers created in previous versions of Dreamweaver will remain editable.) In addition to registering the AP
element as draggable, this function defines three properties for each draggable AP element—
MM_LEFTRIGHT,
MM_UPDOWN, and MM_SNAPPED—that you can use in your own JavaScript functions to determine the relative horizontal
position of the AP element, the relative vertical position of the AP element, and whether the AP element has reached
the drop target.
Note: The information provided here is intended for experienced JavaScript programmers only.
For example, the following function displays the value of the MM_UPDOWN property (the current vertical position of the
AP element) in a form field called
curPosField. (Form fields are useful for displaying continuously updated
information because they are dynamic—that is, you can change their contents after the page has finished loading.)
function getPos(layerId){
var layerRef = document.getElementById(layerId);
var curVertPos = layerRef.MM_UPDOWN;
document.tracking.curPosField.value = curVertPos;
}
Instead of displaying the values of MM_UPDOWN or MM_LEFTRIGHT in a form field, you could use those values in a variety
of other ways. For example, you could write a function that displays a message in the form field depending on how
close the value is to the drop zone, or you could call another function to show or hide an AP element depending on the
value.
It is especially useful to read the MM_SNAPPED property when you have several AP elements on the page, all of which
must reach their targets before the visitor can advance to the next page or task. For example, you could write a function
to count how many AP elements have an
MM_SNAPPED value of true and call it whenever an AP element is dropped.
When the snapped count reaches the desired number, you could send the visitor to the next page or display a message
of congratulations.
Apply the Go To URL behavior
The Go To URL behavior opens a new page in the current window or in the specified frame. This behavior is useful
for changing the contents of two or more frames with one click.
1 Select an object and choose Go To URL from the Add Behavior menu of the Behaviors panel.
2 Select a destination for the URL from the Open In list.
The Open In list automatically lists the names of all frames in the current frameset as well as the main window. If there
are no frames, the main window is the only option.
Note: This behavior may produce unexpected results if any frame is named top, blank, self, or parent. Browsers sometimes
mistake these names for reserved target names.
3 Click Browse to select a document to open, or enter the path and filename of the document in the URL box.
4 Repeat steps 2 and 3 to open additional documents in other frames.