Skip to content

Commit

Permalink
Merge pull request #1826 from scooterw/fix_mouse_position_relative
Browse files Browse the repository at this point in the history
attempt to address regressions from #1684, #1745
  • Loading branch information
mourner committed Jul 6, 2013
2 parents e787027 + 4e2a7f2 commit 8a0b9ec
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions src/dom/DomEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,30 @@ L.DomEvent = {

getMousePosition: function (e, container) {

var body = document.body,
var ie7 = L.Browser.ie7,
body = document.body,
docEl = document.documentElement,
x = e.pageX ? e.pageX : e.clientX + body.scrollLeft + docEl.scrollLeft,
y = e.pageY ? e.pageY : e.clientY + body.scrollTop + docEl.scrollTop,
pos = new L.Point(x, y);
x = e.pageX ? e.pageX - body.scrollLeft - docEl.scrollLeft: e.clientX,
y = e.pageY ? e.pageY - body.scrollTop - docEl.scrollTop: e.clientY,
pos = new L.Point(x, y),
rect = container.getBoundingClientRect(),
left = rect.left - container.clientLeft,
top = rect.top - container.clientTop;

// webkit (and ie <= 7) handles RTL scrollLeft different to everyone else
// https://code.google.com/p/closure-library/source/browse/trunk/closure/goog/style/bidi.js
if (!L.DomUtil.documentIsLtr() && (L.Browser.webkit || ie7)) {
left += container.scrollWidth - container.clientWidth;

// ie7 shows the scrollbar by default and provides clientWidth counting it, so we
// need to add it back in if it is visible; scrollbar is on the left as we are RTL
if (ie7 && L.DomUtil.getStyle(container, 'overflow-y') !== 'hidden' &&
L.DomUtil.getStyle(container, 'overflow') !== 'hidden') {
left += 17;
}
}

return (container ? pos._subtract(L.DomUtil.getViewportOffset(container)) : pos);
return pos._subtract(new L.Point(left, top));
},

getWheelDelta: function (e) {
Expand Down

0 comments on commit 8a0b9ec

Please sign in to comment.