Print Templates, Part VI: Interactive Margin Settings: The Margin Dashed Line - Doc JavaScript | WebReference

Print Templates, Part VI: Interactive Margin Settings: The Margin Dashed Line - Doc JavaScript


Print Templates, Part VI: Interactive Margin Settings

The Margin Dashed Line

An important part of the margin manipulations is the dashed line that shows across the page where the margin is. The function ShowHideMargins() switches between showing and hiding the margins. We show the margins by coloring the dashed line black, and we hide them by coloring the lines white. This function is the event handler for the Show Margins/Hide Margins button in the GUI. Here is the button definition:

<INPUT ID="marginbutton" TYPE="BUTTON" VALUE="Hide Margins"
  ONMOUSEUP="ShowHideMargins()">

And here is the event handler:

function ShowHideMargins() {
  if (marginbutton.value == "Show Margins") {
    oMMarkerClass.style.display = "block";
    oContentStyleClass.style.border = "dashed 1 black";
    marginbutton.value = "Hide Margins";
  } else {
      oMMarkerClass.style.display = "none";
      oContentStyleClass.style.border = "dashed 1 white";
      marginbutton.value = "Show Margins";
    }
}

The margin lines pose a difficulty for the printing routine, as we don't want to see the lines in the final printing. For this reason, we hide the lines before printing, and bring them back after. We hide them in the PrintPrep() function:

function PrintPrep() {
  if (oContentStyleClass.style.border = "dashed 1 black")
    reset = true;
  oContentStyleClass.style.border = "dashed 1 white";
  if (layoutrect1.contentDocument.readyState == "complete") {
    PrintNow();
  } else {
      layoutrect1.contentDocument.onreadystatechange =
        PrintWhenContentDocComplete;
    }
  if (reset) oContentStyleClass.style.border = "dashed 1 black";
}

Next: Code Listing


http://www.internet.com


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/7.html