home *** CD-ROM | disk | FTP | other *** search
/ PC World 2001 March / PCWorld_2001-03_cd.bin / KOMUNIK / progweb / progweb.exe / phpnuke / html / dhtmllib.js < prev    next >
Text File  |  2000-12-05  |  12KB  |  541 lines

  1. /******************************************************************************
  2. * dhtmllib.js                                                                 *
  3. *                                                                             *
  4. * Copyright 1999 by Mike Hall.                                                *
  5. * Web address: http://www.brainjar.com                                        *
  6. * Last update: February 26, 2000.                                             *
  7. *                                                                             *
  8. * Provides basic functions for DHTML positioned elements which will work on   *
  9. * both Netscape Communicator and Internet Explorer browsers (version 4.0 and  *
  10. * up).                                                                        *
  11. ******************************************************************************/
  12.  
  13. // Determine browser.
  14.  
  15. var isMinNS4 = (navigator.appName.indexOf("Netscape") >= 0 &&
  16.                 parseFloat(navigator.appVersion) >= 4) ? 1 : 0;
  17. var isMinIE4 = (document.all) ? 1 : 0;
  18. var isMinIE5 = (isMinIE4 && navigator.appVersion.indexOf("5.") >= 0) ? 1 : 0;
  19.  
  20. //-----------------------------------------------------------------------------
  21. // Layer visibility.
  22. //-----------------------------------------------------------------------------
  23.  
  24. function hideLayer(layer) {
  25.  
  26.   if (isMinNS4)
  27.     layer.visibility = "hide";
  28.   if (isMinIE4)
  29.     layer.style.visibility = "hidden";
  30. }
  31.  
  32. function showLayer(layer) {
  33.  
  34.   if (isMinNS4)
  35.     layer.visibility = "show";
  36.   if (isMinIE4)
  37.     layer.style.visibility = "visible";
  38. }
  39.  
  40. function inheritLayer(layer) {
  41.  
  42.   if (isMinNS4)
  43.     layer.visibility = "inherit";
  44.   if (isMinIE4)
  45.     layer.style.visibility = "inherit";
  46. }
  47.  
  48. function getVisibility(layer) {
  49.  
  50.   if (isMinNS4) {
  51.     if (layer.visibility == "show")
  52.       return "visible";
  53.     if (layer.visibility == "hide")
  54.       return "hidden";
  55.     return layer.visibility;
  56.   }
  57.   if (isMinIE4)
  58.     return layer.style.visibility;
  59.   return "";
  60. }
  61.  
  62. //-----------------------------------------------------------------------------
  63. // Layer positioning.
  64. //-----------------------------------------------------------------------------
  65.  
  66. function moveLayerTo(layer, x, y) {
  67.  
  68.   if (isMinNS4)
  69.     layer.moveTo(x, y);
  70.   if (isMinIE4) {
  71.     layer.style.left = x;
  72.     layer.style.top  = y;
  73.   }
  74. }
  75.  
  76. function moveLayerBy(layer, dx, dy) {
  77.  
  78.   if (isMinNS4)
  79.     layer.moveBy(dx, dy);
  80.   if (isMinIE4) {
  81.     layer.style.pixelLeft += dx;
  82.     layer.style.pixelTop  += dy;
  83.   }
  84. }
  85.  
  86. function getLeft(layer) {
  87.  
  88.   if (isMinNS4)
  89.     return layer.left;
  90.   if (isMinIE4)
  91.     return layer.style.pixelLeft;
  92.   return -1;
  93. }
  94.  
  95. function getTop(layer) {
  96.  
  97.   if (isMinNS4)
  98.     return layer.top;
  99.   if (isMinIE4)
  100.     return layer.style.pixelTop;
  101.   return -1;
  102. }
  103.  
  104. function getRight(layer) {
  105.  
  106.   if (isMinNS4)
  107.     return layer.left + getWidth(layer);
  108.   if (isMinIE4)
  109.     return layer.style.pixelLeft + getWidth(layer);
  110.   return -1;
  111. }
  112.  
  113. function getBottom(layer) {
  114.  
  115.   if (isMinNS4)
  116.     return layer.top + getHeight(layer);
  117.   if (isMinIE4)
  118.     return layer.style.pixelTop + getHeight(layer);
  119.   return -1;
  120. }
  121.  
  122. function getPageLeft(layer) {
  123.  
  124.   var x;
  125.  
  126.   if (isMinNS4)
  127.     return layer.pageX;
  128.   if (isMinIE4) {
  129.     x = 0;
  130.     while (layer.offsetParent != null) {
  131.       x += layer.offsetLeft;
  132.       layer = layer.offsetParent;
  133.     }
  134.     x += layer.offsetLeft;
  135.     return x;
  136.   }
  137.   return -1;
  138. }
  139.  
  140. function getPageTop(layer) {
  141.  
  142.   var y;
  143.  
  144.   if (isMinNS4)
  145.     return layer.pageY;
  146.   if (isMinIE4) {
  147.     y = 0;
  148.     while (layer.offsetParent != null) {
  149.       y += layer.offsetTop;
  150.       layer = layer.offsetParent;
  151.     }
  152.     y += layer.offsetTop;
  153.     return y;
  154.   }
  155.   return -1;
  156. }
  157.  
  158. function getWidth(layer) {
  159.  
  160.   if (isMinNS4) {
  161.     if (layer.document.width)
  162.       return layer.document.width;
  163.     else
  164.       return layer.clip.right - layer.clip.left;
  165.   }
  166.   if (isMinIE4) {
  167.     if (layer.style.pixelWidth)
  168.       return layer.style.pixelWidth;
  169.     else
  170.       return layer.clientWidth;
  171.   }
  172.   return -1;
  173. }
  174.  
  175. function getHeight(layer) {
  176.  
  177.   if (isMinNS4) {
  178.     if (layer.document.height)
  179.       return layer.document.height;
  180.     else
  181.       return layer.clip.bottom - layer.clip.top;
  182.   }
  183.   if (isMinIE4) {
  184.     if (layer.style.pixelHeight)
  185.       return layer.style.pixelHeight;
  186.     else
  187.       return layer.clientHeight;
  188.   }
  189.   return -1;
  190. }
  191.  
  192. function getzIndex(layer) {
  193.  
  194.   if (isMinNS4)
  195.     return layer.zIndex;
  196.   if (isMinIE4)
  197.     return layer.style.zIndex;
  198.  
  199.   return -1;
  200. }
  201.  
  202. function setzIndex(layer, z) {
  203.  
  204.   if (isMinNS4)
  205.     layer.zIndex = z;
  206.   if (isMinIE4)
  207.     layer.style.zIndex = z;
  208. }
  209.  
  210. //-----------------------------------------------------------------------------
  211. // Layer clipping.
  212. //-----------------------------------------------------------------------------
  213.  
  214. function clipLayer(layer, clipleft, cliptop, clipright, clipbottom) {
  215.  
  216.   if (isMinNS4) {
  217.     layer.clip.left   = clipleft;
  218.     layer.clip.top    = cliptop;
  219.     layer.clip.right  = clipright;
  220.     layer.clip.bottom = clipbottom;
  221.   }
  222.   if (isMinIE4)
  223.     layer.style.clip = 'rect(' + cliptop + ' ' +  clipright + ' ' + clipbottom + ' ' + clipleft +')';
  224. }
  225.  
  226. function getClipLeft(layer) {
  227.  
  228.   if (isMinNS4)
  229.     return layer.clip.left;
  230.   if (isMinIE4) {
  231.     var str =  layer.style.clip;
  232.     if (!str)
  233.       return 0;
  234.     var clip = getIEClipValues(layer.style.clip);
  235.     return(clip[3]);
  236.   }
  237.   return -1;
  238. }
  239.  
  240. function getClipTop(layer) {
  241.  
  242.   if (isMinNS4)
  243.     return layer.clip.top;
  244.   if (isMinIE4) {
  245.     var str =  layer.style.clip;
  246.     if (!str)
  247.       return 0;
  248.     var clip = getIEClipValues(layer.style.clip);
  249.     return clip[0];
  250.   }
  251.   return -1;
  252. }
  253.  
  254. function getClipRight(layer) {
  255.  
  256.   if (isMinNS4)
  257.     return layer.clip.right;
  258.   if (isMinIE4) {
  259.     var str =  layer.style.clip;
  260.     if (!str)
  261.       return layer.style.pixelWidth;
  262.     var clip = getIEClipValues(layer.style.clip);
  263.     return clip[1];
  264.   }
  265.   return -1;
  266. }
  267.  
  268. function getClipBottom(layer) {
  269.  
  270.   if (isMinNS4)
  271.     return layer.clip.bottom;
  272.   if (isMinIE4) {
  273.     var str =  layer.style.clip;
  274.     if (!str)
  275.       return layer.style.pixelHeight;
  276.     var clip = getIEClipValues(layer.style.clip);
  277.     return clip[2];
  278.   }
  279.   return -1;
  280. }
  281.  
  282. function getClipWidth(layer) {
  283.  
  284.   if (isMinNS4)
  285.     return layer.clip.width;
  286.   if (isMinIE4) {
  287.     var str = layer.style.clip;
  288.     if (!str)
  289.       return layer.style.pixelWidth;
  290.     var clip = getIEClipValues(layer.style.clip);
  291.     return clip[1] - clip[3];
  292.   }
  293.   return -1;
  294. }
  295.  
  296. function getClipHeight(layer) {
  297.  
  298.   if (isMinNS4)
  299.     return layer.clip.height;
  300.   if (isMinIE4) {
  301.     var str =  layer.style.clip;
  302.     if (!str)
  303.       return layer.style.pixelHeight;
  304.     var clip = getIEClipValues(layer.style.clip);
  305.     return clip[2] - clip[0];
  306.   }
  307.   return -1;
  308. }
  309.  
  310. function getIEClipValues(str) {
  311.  
  312.   var clip = new Array();
  313.   var i;
  314.  
  315.   // Parse out the clipping values for IE layers.
  316.  
  317.   i = str.indexOf("(");
  318.   clip[0] = parseInt(str.substring(i + 1, str.length), 10);
  319.   i = str.indexOf(" ", i + 1);
  320.   clip[1] = parseInt(str.substring(i + 1, str.length), 10);
  321.   i = str.indexOf(" ", i + 1);
  322.   clip[2] = parseInt(str.substring(i + 1, str.length), 10);
  323.   i = str.indexOf(" ", i + 1);
  324.   clip[3] = parseInt(str.substring(i + 1, str.length), 10);
  325.   return clip;
  326. }
  327.  
  328. //-----------------------------------------------------------------------------
  329. // Layer scrolling.
  330. //-----------------------------------------------------------------------------
  331.  
  332. function scrollLayerTo(layer, x, y, bound) {
  333.  
  334.   var dx = getClipLeft(layer) - x;
  335.   var dy = getClipTop(layer) - y;
  336.  
  337.   scrollLayerBy(layer, -dx, -dy, bound);
  338. }
  339.  
  340. function scrollLayerBy(layer, dx, dy, bound) {
  341.  
  342.   var cl = getClipLeft(layer);
  343.   var ct = getClipTop(layer);
  344.   var cr = getClipRight(layer);
  345.   var cb = getClipBottom(layer);
  346.  
  347.   if (bound) {
  348.     if (cl + dx < 0)
  349.       dx = -cl;
  350.     else if (cr + dx > getWidth(layer))
  351.       dx = getWidth(layer) - cr;
  352.     if (ct + dy < 0)
  353.       dy = -ct;
  354.     else if (cb + dy > getHeight(layer))
  355.       dy = getHeight(layer) - cb;
  356.   }
  357.   clipLayer(layer, cl + dx, ct + dy, cr + dx, cb + dy);
  358.   moveLayerBy(layer, -dx, -dy);
  359. }
  360.  
  361. //-----------------------------------------------------------------------------
  362. // Layer background.
  363. //-----------------------------------------------------------------------------
  364.  
  365. function setBgColor(layer, color) {
  366.  
  367.   if (isMinNS4)
  368.     layer.bgColor = color;
  369.   if (isMinIE4)
  370.     layer.style.backgroundColor = color;
  371. }
  372.  
  373. function setBgImage(layer, src) {
  374.  
  375.   if (isMinNS4)
  376.     layer.background.src = src;
  377.   if (isMinIE4)
  378.     layer.style.backgroundImage = "url(" + src + ")";
  379. }
  380.  
  381. //-----------------------------------------------------------------------------
  382. // Layer utilities.
  383. //-----------------------------------------------------------------------------
  384.  
  385. function getLayer(name) {
  386.  
  387.   if (isMinNS4)
  388.     return findLayer(name, document);
  389.   if (isMinIE4)
  390.     return eval('document.all.' + name);
  391.   return null;
  392. }
  393.  
  394. function findLayer(name, doc) {
  395.  
  396.   var i, layer;
  397.  
  398.   for (i = 0; i < doc.layers.length; i++) {
  399.     layer = doc.layers[i];
  400.     if (layer.name == name)
  401.       return layer;
  402.     if (layer.document.layers.length > 0)
  403.       if ((layer = findLayer(name, layer.document)) != null)
  404.         return layer;
  405.   }
  406.   return null;
  407. }
  408.  
  409. //-----------------------------------------------------------------------------
  410. // Image utilities.
  411. //-----------------------------------------------------------------------------
  412.  
  413. function getImage(name) {
  414.  
  415.   if (isMinNS4) {
  416.     return findImage(name, document);
  417.   }
  418.   if (isMinIE4)
  419.     return eval('document.all.' + name);
  420.   return null;
  421. }
  422.  
  423. function findImage(name, doc) {
  424.  
  425.   var i, img;
  426.  
  427.   for (i = 0; i < doc.images.length; i++)
  428.     if (doc.images[i].name == name)
  429.       return doc.images[i];
  430.   for (i = 0; i < doc.layers.length; i++)
  431.     if ((img = findImage(name, doc.layers[i].document)) != null) {
  432.       img.container = doc.layers[i];
  433.       return img;
  434.     }
  435.   return null;
  436. }
  437.  
  438. function getImagePageLeft(img) {
  439.  
  440.   var x, obj;
  441.  
  442.   if (isMinNS4) {
  443.     if (img.container != null)
  444.       return img.container.pageX + img.x;
  445.     else
  446.       return img.x;
  447.   }
  448.   if (isMinIE4) {
  449.     x = 0;
  450.     obj = img;
  451.     while (obj.offsetParent != null) {
  452.       x += obj.offsetLeft;
  453.       obj = obj.offsetParent;
  454.     }
  455.     x += obj.offsetLeft;
  456.     return x;
  457.   }
  458.   return -1;
  459. }
  460.  
  461. function getImagePageTop(img) {
  462.  
  463.   var y, obj;
  464.  
  465.   if (isMinNS4) {
  466.     if (img.container != null)
  467.       return img.container.pageY + img.y;
  468.     else
  469.       return img.y;
  470.   }
  471.   if (isMinIE4) {
  472.     y = 0;
  473.     obj = img;
  474.     while (obj.offsetParent != null) {
  475.       y += obj.offsetTop;
  476.       obj = obj.offsetParent;
  477.     }
  478.     y += obj.offsetTop;
  479.     return y;
  480.   }
  481.   return -1;
  482. }
  483.  
  484. //-----------------------------------------------------------------------------
  485. // Window and page properties.
  486. //-----------------------------------------------------------------------------
  487.  
  488. function getWindowWidth() {
  489.  
  490.   if (isMinNS4)
  491.     return window.innerWidth;
  492.   if (isMinIE4)
  493.     return document.body.clientWidth;
  494.   return -1;
  495. }
  496.  
  497. function getWindowHeight() {
  498.  
  499.   if (isMinNS4)
  500.     return window.innerHeight;
  501.   if (isMinIE4)
  502.     return document.body.clientHeight;
  503.   return -1;
  504. }
  505.  
  506. function getPageWidth() {
  507.  
  508.   if (isMinNS4)
  509.     return document.width;
  510.   if (isMinIE4)
  511.     return document.body.scrollWidth;
  512.   return -1;
  513. }
  514.  
  515. function getPageHeight() {
  516.  
  517.   if (isMinNS4)
  518.     return document.height;
  519.   if (isMinIE4)
  520.     return document.body.scrollHeight;
  521.   return -1;
  522. }
  523.  
  524. function getPageScrollX() {
  525.  
  526.   if (isMinNS4)
  527.     return window.pageXOffset;
  528.   if (isMinIE4)
  529.     return document.body.scrollLeft;
  530.   return -1;
  531. }
  532.  
  533. function getPageScrollY() {
  534.  
  535.   if (isMinNS4)
  536.     return window.pageYOffset;
  537.   if (isMinIE4)
  538.     return document.body.scrollTop;
  539.   return -1;
  540. }
  541.