DOCJSLIB Version 4.0: The DOCJSLIB 4.0's Code - www.docjavascript.com | WebReference

DOCJSLIB Version 4.0: The DOCJSLIB 4.0's Code - www.docjavascript.com


The DOCJSLIB 4.0's Code

// Copyright (c) 2000 internet.com Corp.
// http://www.webreference.com/js/
// License is granted if and only if this entire
// copyright notice is included. By Yehuda Shiran.
// Begin DOCJSLIB version 4.0. Released January 4, 1999.
// This is DOCJSLIB library. It is a cross-browser library.
// You should not worry about the browser in your code.
// This version includes the following functions (numbers
// to the left designate version of DOCJSLIB where first
//      introduced:
//   4.0 docjslib_getRealLeft (computes the left coordinate
//     of an element)
//   4.0 docjslib_getRealTop (gets the top coordinate of an
//      element)
//   4.0 docjslib_getImageXfromLeft (gets the left coordinate
//      of an image)
//   4.0 docjslib_getImageYfromTop (gets the top coordinate
//      of an image)
//   4.0 docjslib_moveVertically (moves the element in the
//      vertical direction)
//   4.0 docjslib_getElementTop (gets the element's top coordinate)
//   4.0 docjslib_setElementTop (sets the elements' top coordinate)
//   4.0 docjslib_setElementLeft (sets the element's left coordinate)
//   4.0 docjslib_setElementBgColor (sets the element's
//      background color)
//   4.0 docjslib_createClipRegionAt00 (creates a clipping
//      region at 0,0)
//   4.0 docjslib_getElementHeight (gets the element's height)
//   4.0 docjslib_getImageWidth (gets the image's width)
//   4.0 docjslib_getImageHeight (gets the image's height)
//   4.0 docjslib_setElementVisibility (sets the element's
//      visibility)
//   4.0 docjslib_setElementWidth (sets the element's width)
//   4.0 docjslib_setElementHeight (sets the element's height)
//   4.0 docjslib_setElementLeft (sets the element's left
//      coordinate)
//   4.0 docjslib_setElementTop (sets the element's top
//      coordinate)
//   3.1 fix a bug in findHighestZ (change () to [] for
//      documentDivs)
//   3.0 docjslib_doThisCommandEveryIntervalMS (executes a
//      command every inteval)
//   3.0 docjslib_getWindowWidth (gets the width of the
//      browser's window, in pixels)
//   3.0 docjslib_getWindowHeight (gets the height of the
//      window, in pixels)
//   3.0 docjslib_getPageScrollLeft (gets the width of the
//      scrolled area, pixels)
//   3.0 docjslib_getPageScrollTop (get the height of the
//      scrolled area, pixels)
//   1.0 docjslib_getSrc (gets the image's URL of a DHTML
//      element, url)
//   1.0 docjslib_setSrc (sets the image's URL of a DHTML
//      element)
//   2.0 docjslib_getWidth (gets the DHTML element's width,
//      pixels)
//   2.0 docjslib_getVisibility (gets the DHTML element's
//      visibility, true or false)
//   2.0 docjslib_setVisibility (sets the DHTML element's
//      visibility, true or false)
//   2.0 docjslib_setPosFromLeft (sets the DHTML element's
//      horiz. position, pixels from left)
//   3.0 docjslib_setPosFromTop (sets the DHTML element's
//      vertical position, pixels from TOP)
//   2.0 docjslib_setZposition (set the Z position of the
//      DHTML element, integer)
//   3.0 docjslib_findHighestZ (find the highest Z of all
//      pages's DHTML elements)
//   1.0 docjslib_makeClickedImage (creates an image-based
//      DHTML element with event handling capability)
//   3.0 docjslib_makeLinkedImage (creates an image-based
//      DHTML element with a built-in link to a
//      developer-specified location)
//   2.0 docjslib_makeBox (creates a DHTML container)
//
var IE4 = (document.all) ? true : false;
var NS4 = (document.layers) ? true : false;
function docjslib_getRealLeft(imgElem) {
	xPos = eval(imgElem).offsetLeft;
	tempEl = eval(imgElem).offsetParent;
  	while (tempEl != null) {
  		xPos += tempEl.offsetLeft;
  		tempEl = tempEl.offsetParent;
  	}
	return xPos;
}
function docjslib_getRealTop(imgElem) {
	yPos = eval(imgElem).offsetTop;
	tempEl = eval(imgElem).offsetParent;
	while (tempEl != null) {
  		yPos += tempEl.offsetTop;
  		tempEl = tempEl.offsetParent;
  	}
	return yPos;
}
function docjslib_getImageXfromLeft(imgID) {
  if (NS4) return eval(imgID).x
  else return docjslib_getRealLeft(imgID);
}
function docjslib_getImageYfromTop(imgID) {
  if (NS4) return eval(imgID).y;
  else return docjslib_getRealTop(imgID);
}
function docjslib_moveVertically(id, increment) {
  if (NS4) eval(id).top += increment
  else eval(id).style.pixelTop += increment;
}
function docjslib_getElementTop(id) {
  if (NS4) return eval(id).top
  else return eval(id).style.pixelTop;
}
function docjslib_setElementTop(id, elementTop) {
  if (NS4) eval(id).top = elementTop
  else eval(id).style.top = elementTop;
}
function docjslib_setElementLeft(id, elementLeft) {
  if (NS4) eval(id).left = elementLeft
  else eval(id).style.left = elementLeft;
}
function docjslib_setElementBgColor(id, elementColor) {
  if (NS4) eval(id).bgColor = elementColor
  else eval(id).style.backgroundColor = elementColor;
}
function docjslib_createClipRegionAt00(id, clipWidth, clipHeight) {
  if (NS4) {
    eval(id).clip.width = clipWidth;
    eval(id).clip.height = clipHeight;
  } else eval(id).style.clip = "rect(0 " + eval(clipWidth) + " "
    + eval(clipHeight) + " 0)";
  // (The above two lines should be joined as one line.
  // They have been split for formatting purposes.)
}
function docjslib_getElementHeight(id) {
  if (NS4) return eval(id).clip.height
  else return eval(id).clientHeight;
}
function docjslib_getImageWidth(imgID) {
  return eval(imgID).width;
}
function docjslib_getImageHeight(imgID) {
  return eval(imgID).height;
}
function docjslib_doThisCommandEveryIntervalMS(command, interval) {
  setInterval(eval('"' + command + '"'), interval);
}
function docjslib_getWindowWidth() {
  if (NS4) {return window.innerWidth}
  else {return document.body.clientWidth}
}
function docjslib_getWindowHeight() {
  if (NS4) {return window.innerHeight}
  else {return document.body.clientHeight}
}
function docjslib_getPageScrollLeft() {
  if (NS4) {return window.pageXOffset}
  else {return document.body.scrollLeft}
}
function docjslib_getPageScrollTop() {
  if (NS4) {return window.pageYOffset}
  else {return document.body.scrollTop}
}
function docjslib_getSrc(id) {
  if (NS4) {return eval("document." + id + ".document."
    + id + "img.src")}
  // (The above two lines should be joined as one line.
  // They have been split for formatting purposes.)
  else {return eval("document.all." + id + "img.src")}
}
function docjslib_setSrc(id, url) {
  if (NS4) {eval("document." + id + ".document."
    + id + "img").src = url}
  // (The above two lines should be joined as one line.
  // They have been split for formatting purposes.)
  else {eval("document.all." + id + "img").src = url}
}
function docjslib_getWidth(id) {
  if (NS4) {return eval("document." + id + ".clip.width")}
  else {return eval("document.all." + id + ".style.pixelWidth")}
}
function docjslib_getVisibility(id) {
  if (NS4) {
    if (eval("document." + id).visibility == "show") return true
    else return false;
  }
  else {
   if (eval("document.all." + id).style.visibility == "visible")
     return true
  // (The above two lines should be joined as one line.
  // They have been split for formatting purposes.)
    else return false;
  }
}
function docjslib_setVisibility(id, flag) {
  if (NS4) {
    var str = (flag) ? 'show' : 'hide';
    eval("document." + id).visibility = str;
  }
  else {
    var str = (flag) ? 'visible' : 'hidden';
    eval("document.all." + id).style.visibility = str;
  }
}
function docjslib_setElementVisibility(id, flag) {
  if (NS4) {
    var str = (flag) ? 'show' : 'hide';
    eval(id).visibility = str;
  }
  else {
    var str = (flag) ? 'visible' : 'hidden';
    eval(id).style.visibility = str;
  }
}
function docjslib_setPosFromLeft(id, xCoord) {
  if (NS4) {eval("document." + id).left = xCoord}
  else {eval("document.all." + id).style.left = xCoord}
}
function docjslib_setElementLeft(id, elementLeft) {
  if (NS4) eval(id).left = elementLeft
  else eval(id).style.left = elementLeft;
}
function docjslib_setElementWidth(id, elementWidth) {
  if (NS4) eval(id).width = elementWidth
  else eval(id).style.width = elementWidth;
}
function docjslib_setElementHeight(id, elementHeight) {
  if (NS4) eval(id).height = elementHeight
  else eval(id).style.height = elementHeight;
}
function docjslib_setPosFromTop(id, yCoord) {
  if (NS4) {eval("document." + id).top = yCoord}
  else {eval("document.all." + id).style.top = yCoord}
}
function docjslib_setElementTop(id, elementTop) {
  if (NS4) eval(id).top = elementTop
  else eval(id).style.top = elementTop;
}
function docjslib_setZposition(id, z) {
  if (NS4) {eval("document." + id).zIndex = z}
  else {eval("document.all." + id).style.zIndex = z}
}
function docjslib_findHighestZ() {
  var documentDivs = new Array();
  if (NS4) {documentDivs = document.layers}
  else {documentDivs = document.all.tags("DIV")};
  var highestZ = 0;
  for (var i = 0; i < documentDivs.length; i++) {
     var zIndex = (NS4) ? documentDivs[i].zIndex :
       documentDivs[i].style.zIndex;
  // (The above two lines should be joined as one line.
  // They have been split for formatting purposes.)
     highestZ = (zIndex > highestZ) ? zIndex : highestZ;
  }
  return highestZ;
}
function docjslib_makeClickedImage(imgID,          // given id
         imgURL,         // image URL
         imgHeight,      // image height
         imgWidth,       // image width
         imgAlt,         // alternative image
         posFromLeft,    // absolute position from left of window
         posFromTop,     // absolute position from top of window
         clickParam1,    // parameter passed to "onclick" handler
         clickParam2)    // parameter passed to "onclick" handler
  {
  document.write(
    '<STYLE TYPE="text/css">',
    '#', imgID, ' {',
      'position: absolute;',
      'left: ', posFromLeft, ';',
      'top: ', posFromTop, ';',
      'width: ', imgWidth, ';',
      'z-index: 1',
    '}',
    '</STYLE>',
    '<DIV ID="', imgID, '">',
    '<A HREF="javascript:', "handleImageClick('", imgID, "'",
      ',', clickParam1, ',',
  // (The above two lines should be joined as one line.
  // They have been split for formatting purposes.)
    clickParam2, ')">',
    '<IMG NAME="', imgID, 'img" ID="', imgID, 'img" SRC="', imgURL,
      '" ALT="', imgAlt,
  // (The above two lines should be joined as one line.
  // They have been split for formatting purposes.)
    '" BORDER="0" ', 'HEIGHT="', imgHeight, '" WIDTH="', imgWidth, '">',
    '</A></DIV>'
  );
}
function docjslib_makeLinkedImage(imgID,    // given id
           imgURL,         // image URL
           linkURL,        // link URL
           imgHeight,      // image height
           imgWidth,       // image width
           imgAlt,         // alternative image
           posFromLeft,    // absolute position from left of window
           posFromTop,     // absolute position from top of window
           imgVisibility,  // image visibility  (true of false)
           imgZindex)      // image Z index
  {
  var visibility = (imgVisibility) ? 'visible' : 'hidden';
  document.write(
    '<STYLE TYPE="text/css">',
    '#', imgID, ' {',
      'position: absolute;',
      'visibility: ', visibility, ';',
      'left: ', posFromLeft, ';',
      'top: ', posFromTop, ';',
      'width: ', imgWidth, ';',
      'z-index:', imgZindex,
    '}',
    '</STYLE>',
    '<DIV ID="', imgID, '">',
    '<A HREF="', linkURL, '">',
    '<IMG NAME="', imgID, 'img" ID="', imgID, 'img" SRC="',
      imgURL, '" ALT="', imgAlt,
  // (The above two lines should be joined as one line.
  // They have been split for formatting purposes.)
    '" BORDER="0" ', 'HEIGHT="', imgHeight, '" WIDTH="',
      imgWidth, '">',
  // (The above two lines should be joined as one line.
  // They have been split for formatting purposes.)
    '</A></DIV>'
  );
}
function docjslib_makeBox(boxID,       // given id
       htmlFiller,           // HTML filler
       boxWidth,             // box width
       posFromLeft,          // absolute position from left of window
       posFromTop,           // absolute position from top of window
       boxBg,                // box background color
       boxColor,             // html filler text color
       boxVisibility)        // visibility
 {
  var padding = (NS4) ? '' : 'padding: 3 0 3 3;';
  var visibility = (boxVisibility) ? 'visible' : 'hidden';
  document.write(
    '<STYLE TYPE="text/css">',
    '#', boxID, ' {',
      'position: absolute;',
      'left: ', posFromLeft, '; top: ', posFromTop, ';',
      'width: ', boxWidth, ';',
      'layer-background-color: ', boxBg, ';',
      'background-color: ', boxBg, ';',
      'visibility: ', visibility, ';',
      'border-width: 2;',
      'border-style: solid;',
      'border-color: ', boxColor, ';',
      padding,
      'z-index: 1',
    '}',
    '</STYLE>',
    '<DIV ID="', boxID, '">',
    htmlFiller,
    '</DIV>'
  );
}
//
// End DOCJSLIB Version 4.0

http://www.internet.com

Produced by Yehuda Shiran and Tomer Shiran

Created: January 4, 1999
Revised: January 4, 1999

URL: http://www.webreference.com/js/column33/docjslib4.html