Print Templates, Part VI: Interactive Margin Settings: The onmouseup Event Handler - Doc JavaScript
Print Templates, Part VI: Interactive Margin Settings
The onmouseup
Event Handler
The MouseUpHandler()
handles the mouseup
event. The mouseup
event completes the marker move transaction. The transaction is initiated upon a mousedown
event, continues while the mouse moves (while being pressed), and completes on a mouseup
event.
The function first checks that indeed one of the page elements triggered the event. It returns if the event source is null
:
if (!sSrcID) return;
Then, it computes again the pixels-per-inch ratio:
iPixelToInchRatio = ratiomarker.offsetLeft;
The function handles the different markers with a switch statement, switch(sSrcID)
. Let's take the left margin marker first. We do two basic operations. First, we set the templateprinter
object's marginLeft
property:
printer.marginLeft = 100 * (mmarkerLeft.offsetLeft - 5)/iPixelToInchRatio;
The second operation hides the tool tip:
oPopup.hide();
Here is the complete listing of the switch()
statement:
switch (sSrcID) { case "mmarkerLeft": printer.marginLeft = 100 * (mmarkerLeft.offsetLeft - 5)/iPixelToInchRatio; oPopup.hide(); break; case "mmarkerRight": printer.marginRight = printer.pageWidth - (100 * (mmarkerRight.offsetLeft - 5)/iPixelToInchRatio); oPopup.hide(); break; case "mmarkerTop": printer.marginTop = 100 * (mmarkerTop.offsetTop - 5)/iPixelToInchRatio; oPopup.hide(); break; case "mmarkerBottom": printer.marginBottom = printer.pageHeight - (100 * (mmarkerBottom.offsetTop - 5)/iPixelToInchRatio); oPopup.hide(); break; }
Once the margin is updated, we need to re-initialize the markers, reset iDeltaX
and iDelatY
, reset the move flags, and reset the source element ID
to null
:
InitClasses(); InitMMarkers(); iDeltaX = 0; iDeltaY = 0; bMoveMMarkerLeft = false; bMoveMMarkerRight = false; bMoveMMarkerTop = false; bMoveMMarkerBottom = false; sSrcID = null;
Next: How to show and hide the margin dashed lines
Produced by Yehuda Shiran and Tomer Shiran
All Rights Reserved. Legal Notices.
Created: November 22, 2001
Revised: November 22, 2001
URL: https://www.webreference.com/js/column95/6.html