spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / javascript / column95


Print Templates, Part VI: Interactive Margin Settings

Technical Lead
Thomson Reuters (Markets) LLC
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume
Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?


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


http://www.internet.com

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business


Produced by Yehuda Shiran and Tomer Shiran
All Rights Reserved. Legal Notices.
Created: November 22, 2001
Revised: November 22, 2001

URL: http://www.webreference.com/js/column95/6.html