From a8a19eb43964b935dd365d8b887dc7f017f1078c Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Fri, 18 May 2007 01:21:41 +0000 Subject: [PATCH] prototype: Minor cleanup of the position methods --- CHANGELOG | 2 ++ src/dom.js | 18 +++++++++--------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 9256dce..da7662b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Minor cleanup of the position methods [sam] + * Fix Element#clonePosition to call viewportOffset. Closes #8372. [graemenelson, Christophe Porteneuve] * Prevent an error being thrown by $$ when #id does not exist in $$("div #id"). Closes #8325. [Tobie Langel, ecke] diff --git a/src/dom.js b/src/dom.js index 479e985..8ce66e4 100644 --- a/src/dom.js +++ b/src/dom.js @@ -550,14 +550,14 @@ Element.Methods = { valueL += element.offsetLeft || 0; // Safari fix - if (element.offsetParent == document.body) - if (Element.getStyle(element,'position')=='absolute') break; + if (element.offsetParent == document.body && + Element.getStyle(element, 'position') == 'absolute') break; } while (element = element.offsetParent); element = forElement; do { - if (!window.opera || element.tagName=='BODY') { + if (!Prototype.Browser.Opera || element.tagName == 'BODY') { valueT -= element.scrollTop || 0; valueL -= element.scrollLeft || 0; } @@ -574,7 +574,7 @@ Element.Methods = { setHeight: true, offsetTop: 0, offsetLeft: 0 - }, arguments[2] || {}) + }, arguments[2] || {}); // find page position of source source = $(source); @@ -586,7 +586,7 @@ Element.Methods = { var parent = null; // delta [0,0] will do fine with position: fixed elements, // position:absolute needs offsetParent deltas - if (Element.getStyle(element,'position') == 'absolute') { + if (Element.getStyle(element, 'position') == 'absolute') { parent = element.getOffsetParent(); delta = parent.viewportOffset(); } @@ -598,10 +598,10 @@ Element.Methods = { } // set position - if(options.setLeft) element.style.left = (p[0] - delta[0] + options.offsetLeft) + 'px'; - if(options.setTop) element.style.top = (p[1] - delta[1] + options.offsetTop) + 'px'; - if(options.setWidth) element.style.width = source.offsetWidth + 'px'; - if(options.setHeight) element.style.height = source.offsetHeight + 'px'; + if (options.setLeft) element.style.left = (p[0] - delta[0] + options.offsetLeft) + 'px'; + if (options.setTop) element.style.top = (p[1] - delta[1] + options.offsetTop) + 'px'; + if (options.setWidth) element.style.width = source.offsetWidth + 'px'; + if (options.setHeight) element.style.height = source.offsetHeight + 'px'; return element; } };