Advertisement
Guest User

absoluteFudge

a guest
Jul 14th, 2011
572
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*****************************************************************
  2.  
  3.   AbsoluteFudge module
  4.   ====================
  5.  
  6.   Usage:
  7.   ------
  8.  
  9.   absolutefudge.js is only applicable where the browser is IE6. So
  10.   the file should be loaded from within a conditional comment. Add this to the
  11.   head section of the HTML:
  12.  
  13.   <!--[if lt IE 7]>
  14.   <script type="text/javascript" src="absolutefudge.js"> </script>
  15.   <script type="text/javascript">
  16.  
  17.     function onLoad() {
  18.       if (AbsoluteFudge != undefined) {
  19.         AbsoluteFudge.apply(document.getElementsByTagName('body')[0], true, true);
  20.       }
  21.       // other IE6 loading stuff...
  22.     }
  23.  
  24.   </script>
  25.   <![endif]-->
  26.  
  27.   and insert this bit below the body element:
  28.  
  29. <!--[if lt IE 7]>
  30. <script type="text/javascript">document.body.onload = onLoad;</script>
  31. <![endif]-->
  32.  
  33.  
  34.   The apply() method walks the entire document. If you set the second and
  35.   third parameters to true. The second parameter instructs apply() to walk the
  36.   entire document looking for absolutely positioned elements. The third
  37.   tells it to carry on through non absolutely positioned elements. If both
  38.   are true, the entire document is traversed. If both are false it will just
  39.   apply the fudge to that single element. If true,false then recursion
  40.   is limited to absolutely positioned elements. searching stops once
  41.   non-absolute elements are found.
  42.  
  43.   If you are generating html elements dynamically (e.g. Javascript/Ajax
  44.   programming) then you may have to explicitly call apply() for the
  45.   new element(s).
  46.  
  47.  
  48. ******************************************************************/
  49.  
  50. var AbsoluteFudge = new Object();
  51.  
  52.   AbsoluteFudge.isAbsolute = function (element) {
  53.     return (element.currentStyle.position == 'absolute');
  54.   }
  55.  
  56.   AbsoluteFudge.set = function(element) {
  57.     if (element) {
  58.       element.style.setExpression("height", "AbsoluteFudge.fudgeHeight(this)");
  59.       element.style.setExpression("width", "AbsoluteFudge.fudgeWidth(this)");
  60.     }
  61.   }
  62.  
  63.   AbsoluteFudge.apply = function(element, recurse, full) {
  64.     for (var i = 0; i < element.childNodes.length; i++) {
  65.       var child = element.childNodes[i];
  66.       if (child.nodeType == 1) {
  67.         if (this.isAbsolute(child)) {
  68.           this.set(child);
  69.           if (recurse) {
  70.             this.apply(child, recurse, full);
  71.           }
  72.         }
  73.         else {
  74.           if (full && recurse) {
  75.             this.apply(child, recurse, full);
  76.           }
  77.         }
  78.       }
  79.     }
  80.   }
  81.  
  82.   AbsoluteFudge.fudgeWidth = function(el) {
  83.   if (el.currentStyle.right != 'auto') {
  84.     try {
  85.       var parent = el;
  86.       var w = 0;
  87.       do {
  88.         parent = parent.parentNode;
  89.         w = parent.clientWidth;
  90.       }
  91.       while (w == 0);
  92.       if (document.documentElement.clientHeight != 0) {
  93.         // in standards mode so width that gets set is inside padding/margin
  94.         w = w - parseInt(el.currentStyle.paddingLeft)
  95.               - parseInt(el.currentStyle.paddingRight);
  96.  
  97.         if (el.currentStyle.borderLeftStyle != 'none') {
  98.           try {
  99.             w = w - parseInt(el.currentStyle.borderLeftWidth);
  100.           }
  101.           catch(e) {
  102.             w = w - 2; //estimated
  103.           }
  104.         }
  105.         if (el.currentStyle.borderRightStyle != 'none') {
  106.           try {
  107.             w = w - parseInt(el.currentStyle.borderRightWidth);
  108.           }
  109.           catch(e) {
  110.             w = w -2; //estimated
  111.           }
  112.         }
  113.       }
  114.       el.style.width = (w - parseInt(el.currentStyle.left) - parseInt(el.currentStyle.right)) + 'px';
  115.     }
  116.     catch(e) { }
  117.   }
  118. }
  119.  
  120.   AbsoluteFudge.fudgeHeight = function(el) {
  121.   if (el.currentStyle.bottom != 'auto') {
  122.     try {
  123.       var parent = el;
  124.       var h = 0;
  125.       do {
  126.         parent = parent.parentNode;
  127.         h = parent.clientHeight;
  128.       }
  129.       while (h == 0);
  130.       if (document.documentElement.clientHeight != 0) {
  131.         //standards mode
  132.         h = h - parseInt(el.currentStyle.paddingTop)
  133.               - parseInt(el.currentStyle.paddingBottom);
  134.         if (el.currentStyle.borderTopStyle != 'none') {
  135.           try {
  136.             h = h - parseInt(el.currentStyle.borderTopWidth);
  137.           }
  138.           catch(e) {
  139.             h = h - 2;
  140.           }
  141.         }
  142.         if (el.currentStyle.borderBottomStyle != 'none') {
  143.           try {
  144.             h = h - parseInt(el.currentStyle.borderBottomWidth);
  145.           }
  146.           catch(e) {
  147.             h = h - 2;
  148.           }
  149.         }
  150.       }
  151.       var x = (h - parseInt(el.currentStyle.top) - parseInt(el.currentStyle.bottom)) + 'px';
  152.       el.style.height = x;
  153.     }
  154.     catch(e) {}
  155.   }
  156. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement