From 62d0430f3b98153af49b01f7972e75cf2264ce13 Mon Sep 17 00:00:00 2001 From: Andrew Dupont Date: Fri, 6 Nov 2009 10:56:01 -0600 Subject: [PATCH] Fix Element.viewportOffset on nested elements in Opera < 9.5 and remove browser sniff. (cherry picked from commit 0d2d18fb7297fb945ca6983b843c5bcf367c721c) --- src/dom/layout.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/dom/layout.js b/src/dom/layout.js index 3152ed6..d0d4dca 100644 --- a/src/dom/layout.js +++ b/src/dom/layout.js @@ -707,21 +707,23 @@ * Returns the X/Y coordinates of element relative to the viewport. **/ function viewportOffset(forElement) { - var valueT = 0, valueL = 0; + var valueT = 0, valueL = 0, docBody = document.body; var element = forElement; do { valueT += element.offsetTop || 0; valueL += element.offsetLeft || 0; // Safari fix - if (element.offsetParent == document.body && + if (element.offsetParent == docBody && Element.getStyle(element, 'position') == 'absolute') break; } while (element = element.offsetParent); - element = forElement; - var tagName = element.tagName, O = Prototype.Browser.Opera; + element = forElement; do { - if (!O || tagName && tagName.toUpperCase() === 'BODY') { + // Opera < 9.5 sets scrollTop/Left on both HTML and BODY elements. + // Other browsers set it only on the HTML element. The BODY element + // can be skipped since its scrollTop/Left should always be 0. + if (element != docBody) { valueT -= element.scrollTop || 0; valueL -= element.scrollLeft || 0; }