Ticket #1151 (new defect)
popup placement is incorrect if root element is in scrolled DIV
| Reported by: | EricShulman | Owned by: | EricShulman |
|---|---|---|---|
| Priority: | undefined | Milestone: | 2.7.1 |
| Component: | core | Version: | |
| Severity: | undefined | Keywords: | |
| Cc: |
Description (last modified by EricShulman) (diff)
When a popup link is placed inside a DIV with style "overflow:scroll" or "overflow:auto" and that DIV is then scrolled, the position of the resulting popup appears further down the page that intended, because it is not adjusting for the relative scroll offset of the containing DIV. This tweak patches the Popup.place() function to calculate and subtract the current scroll offset from the computed popup position, so that it appears in the correct location on the page.
Add these functions:
window.findScrollOffsetX=function(obj) {
var x=0;
while(obj) {
if (obj.scrollLeft && obj.nodeName!='HTML')
y+=obj.scrollLeft;
obj=obj.parentNode;
}
return -x;
}
window.findScrollOffsetY=function(obj) {
var y=0;
while(obj) {
if (obj.scrollTop && obj.nodeName!='HTML')
y+=obj.scrollTop;
obj=obj.parentNode;
}
return -y;
}
and, in Popup.place, replace these lines:
var rootLeft = findPosX(root); var rootTop = findPosY(root);
with:
var rootLeft = findScrollOffsetX(root) + findPosX(root); var rootTop = findScrollOffsetY(root) + findPosY(root);
This fix has been successfully implemented at http://www.TiddlyTools.com/#CoreTweaks
