DHTML Lab: Dynamic Page Segments; The Complete Code 2/2 | WebReference

DHTML Lab: Dynamic Page Segments; The Complete Code 2/2


Logo

  Dynamic Page Segments
  SPECIAL EDITION; the director's cut 2/2

The Dynamic Page Segment Routines (segments.js)

This file may be download in ZIP format

/* segments.js (Cross-browser)
* Copyright (c) 1999-2000 internet.com Corp.  To receive the right to license
* this code to use on your site the original code must be copied from
* Webreference.com. License is granted if and only if this entire copyright 
* notice is included, and you link from the page on which the code is used 
* to Webreference at https://webreference.com/dhtml/ for the latest version.
* By Peter Belesis. v1.0 980311 - column 16.
*/

semi = ";";
styStr = "<STYLE TYPE='text/css'>"
styStr += ".segment{";
styStr += "position:absolute;";
styStr += "visibility:hidden;";
if (NS4) styStr += "width:" + (innerWidth-leftPos-margRight) + semi;
if (borWid > 0) {
  styStr += "border-width:" + borWid + semi;
  styStr += "border-color:" + borCol + semi;
  styStr += "border-style:" + borSty + semi;
}
if (NS4) {
  if (borWid > 0 && padding <= 3) styStr += "padding: 0;";
  if (borWid > 0 && padding > 3) styStr += "padding:" + (padding-3) + semi;
  if (borWid == 0) styStr += "padding:" + padding + semi;
}
else {
  styStr += "padding:" + padding + semi;
}
if (backCol != null) {
  if (NS4) {
    if (borWid > 0 && padding <= 3) {
       styStr += "layer-background-color:" + backCol + semi;
    }
  
    if (borWid > 0 && padding > 3) {
      styStr += "background-color:" + backCol + semi;
    }
  
    if (borWid == 0) {
      styStr += "layer-background-color:" + backCol + semi;
    }
  }
  else {
    styStr += "background-color:" + backCol + semi;
  }
}
styStr += "}";
styStr += ".last{position:absolute;visibility:hidden}";
styStr += "</STYLE>";
document.write(styStr);
maxHeight = 0;
hasFooter = (footerEl != null);
arSegments = new Array();
function initIt(){
  if (NS4) {
    
    for (i=0; i<document.layers.length; i++) {
      tempEl = document.layers[i];
	  
      eval(tempEl.id + "= tempEl");
      tempEl.showIt = showIt;
	      
      if (tempEl.id.indexOf(prefix)!=-1)
        arSegments[arSegments.length] = tempEl;
    }
  
    for (i=0; i<arSegments.length; i++) {
      tempSeg = arSegments[i];
      
      if (topPos != null) tempSeg.top = topPos;  
      if (leftPos != null) tempSeg.left = leftPos;  
  
      tempSeg.arrangeIt = arrangeIt;
	  
      if (maxHeight < tempSeg.document.height) {
        maxHeight = tempSeg.document.height;
        longest = tempSeg;
      }
    }  
  
    if (hasFooter)
      eval(footerEl + ".pageY = topPos + maxHeight + footerElSpace");
    
  }
  else {
  
    allDIVs = document.all.tags("DIV");
	
    for (i=0; i<allDIVs.length; i++) {
      if (allDIVs(i).className=="segment")
        arSegments[arSegments.length] = allDIVs[i];
      allDIVs(i).showIt = showIt;
    }
	
    for (i=0; i<arSegments.length; i++) {
      tempSeg = arSegments[i];
	  
      if (leftPos!=null) tempSeg.style.pixelLeft = leftPos;
      if (topPos!=null) tempSeg.style.pixelTop = topPos;
      tempSeg.arrangeIt = arrangeIt;
      tempSeg.style.width = document.body.clientWidth - leftPos - margRight;
    }
  }
  
  if (hasFooter) footerEl = eval(footerEl);
  fullHash = location.hash;
  if (fullHash.length > 0)
    firstSeg = fullHash.substr(1);
  currentSeg = eval(prefix + firstSeg)
  showSegment(firstSeg);
}
function showSegment(el){
  whichSeg = eval(prefix+el);
  currentSeg.showIt(false);
  if (hasFooter) footerEl.showIt(false);
  whichSeg.showIt(true);
  currentSeg = whichSeg;
  if (hasFooter) setTimeout("whichSeg.arrangeIt();",50)
}
function arrangeIt() {
  if (NS4) {
    footerEl.top = this.pageY + this.document.height + footerElSpace;
  }
  else {
    footerEl.style.pixelTop = this.style.pixelTop + this.offsetHeight + footerElSpace;
  }
  footerEl.showIt(true);
}
function showIt(on) {
  if (NS4) {this.visibility = (on) ? "show" : "hide"}
  else {this.style.visibility = (on) ? "visible" : "hidden"}
}

Till next time.


Produced by Peter Belesis and

All Rights Reserved. Legal Notices.
Created: Mar. 11, 1998
Revised: Mar. 17, 1998

URL: https://www.webreference.com/dhtml/column16/allCode2.html