From ea044c8312cf717cda4fdd820884674505dd754f Mon Sep 17 00:00:00 2001 From: Scooter Wadsworth Date: Thu, 1 Aug 2013 00:15:53 -0400 Subject: [PATCH] Make container optional in L.DomUtil.getMousePosition(). Addresses #1926 --- src/dom/DomEvent.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/dom/DomEvent.js b/src/dom/DomEvent.js index 7df9e7fd..a9a9f9a3 100644 --- a/src/dom/DomEvent.js +++ b/src/dom/DomEvent.js @@ -137,8 +137,13 @@ L.DomEvent = { docEl = document.documentElement, 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(), + pos = new L.Point(x, y); + + if (!container) { + return pos; + } + + var rect = container.getBoundingClientRect(), left = rect.left - container.clientLeft, top = rect.top - container.clientTop;