pvdung / ourlibrary

Automatically exported from code.google.com/p/ourlibrary
0 stars 0 forks source link

getViewportSrollSize reports the viewport size on Firefox 3.6 on Mac OS #33

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
document.documentElement.scrollHeight always reports the viewport height 
instead of the root element's height. I've added a check on my local file that 
sets the display style of the body element to "none" and then check if  
scrollElement.scrollHeight is greater than zero. According to my local tests 
this fixes the problem and doesn't impact on other browsers.

Here's the modified version of the said function:

      getViewportScrollSize = (function() {
        var cm, addMargin, bd, sh, scrollHeightUnreliable, body;

        if (typeof getElementMarginsOrigin == 'function') {
          cm = getElementMarginsOrigin(containerElement);
          // IE quirk with scrollWidth/Height + HTML element margin
          addMargin = (scrollElement.offsetWidth == cm[0] + scrollElement.scrollWidth);
        }

        if (typeof scrollElement.scrollWidth != 'undefined') {
          // Firefox 3.6 reports the viewport height on documentElement.scrollHeight
          body = getBodyElement();
          bd = body.style.display;
          body.style.display = 'none';
          sh = scrollElement.scrollHeight;
          body.style.display = bd;
          scrollHeightUnreliable = (sh !== 0);
          if(!scrollHeightUnreliable)
          {
            return function(docNode) {
              var se = getTopRenderedElement(docNode);
              return [se.scrollHeight + ((addMargin)?cm[0]:0), se.scrollWidth + ((addMargin)?cm[1]:0)];
            };
          }
        }
        if (typeof global.document.width != 'undefined') {
          return function(docNode) {
            docNode = docNode || global.document;
            return [docNode.height, docNode.width];
          };
        }
        if (typeof scrollElement.offsetWidth != 'undefined') {
          return function(docNode) {
            var ce = getTopRenderedElement(docNode);
            return [ce.offsetHeight, ce.offsetWidth];
          };
        }
      })();

I have also attached my modified build.

Original issue reported on code.google.com by gabrielg...@gmail.com on 2 Aug 2010 at 10:55

Attachments:

GoogleCodeExporter commented 9 years ago
Interesting bug in FF3.6.  Don't have that problem on the Windows version.

I don't have a Mac handy at the moment.  Can you confirm that this is an issue 
in 3.6 only.  I will report the bug to the FF developers.

Setting the body to display:none isn't quite right for a workaround though.  
The body could have margins (as it does on all of the pages on my site).

A workaround would have to use logic similar to that found in this primer:-

http://www.cinsoft.net/viewport.asp

You add an element to the body and see if the scroll height changes.

If you can put together such a workaround and confirm that all is well in Mac 
land, I'll patch the builder and the 1.0 release candidate.

BTW, did you try the modal alert example on the Examples page without the 
patch.  That would be the acid test as the "curtain" would cover only the 
viewport?  That uses the coverDocument function, which would be the only one 
affected in that browser as getScrollPositionMax uses window.scrollMaxX/Y when 
available.

Thanks Gabe!

Original comment by dmark.ci...@gmail.com on 3 Aug 2010 at 1:28

GoogleCodeExporter commented 9 years ago
I'll change the test and run those tests tomorrow :)

Original comment by gabrielg...@gmail.com on 3 Aug 2010 at 2:25