From: Marek Janda Date: Sun, 5 Apr 2015 13:45:40 +0000 (+0200) Subject: Fix range selection when chart is located inside fullscreen element X-Git-Tag: v2.0.0~59^2~1 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=4debe18e145f45f09788f3ba6af800536818efa8;p=dygraphs.git Fix range selection when chart is located inside fullscreen element --- diff --git a/src/dygraph-utils.js b/src/dygraph-utils.js index 4fa42d1..44ad0cf 100644 --- a/src/dygraph-utils.js +++ b/src/dygraph-utils.js @@ -166,46 +166,22 @@ Dygraph.hsvToRGB = function (hue, saturation, value) { return 'rgb(' + red + ',' + green + ',' + blue + ')'; }; -// The following functions are from quirksmode.org with a modification for Safari from -// http://blog.firetree.net/2005/07/04/javascript-find-position/ -// http://www.quirksmode.org/js/findpos.html -// ... and modifications to support scrolling divs. - /** * Find the coordinates of an object relative to the top left of the page. * - * TODO(danvk): change obj type from Node -> !Node * @param {Node} obj * @return {{x:number,y:number}} * @private */ Dygraph.findPos = function(obj) { - var curleft = 0, curtop = 0; - if (obj.offsetParent) { - var copyObj = obj; - while (1) { - var borderLeft = "0", borderTop = "0"; - var computedStyle = window.getComputedStyle(copyObj, null); - borderLeft = computedStyle.borderLeft || "0"; - borderTop = computedStyle.borderTop || "0"; - curleft += parseInt(borderLeft, 10) ; - curtop += parseInt(borderTop, 10) ; - curleft += copyObj.offsetLeft; - curtop += copyObj.offsetTop; - if (!copyObj.offsetParent) { - break; - } - copyObj = copyObj.offsetParent; - } - } + var p = obj.getBoundingClientRect(), + w = window, + d = document.documentElement; - // This handles the case where the object is inside a scrolled div. - while (obj && obj != document.body) { - curleft -= obj.scrollLeft; - curtop -= obj.scrollTop; - obj = obj.parentNode; + return { + x: p.left + (w.pageXOffset || d.scrollLeft) - (d.clientLeft || 0), + y: p.top + (w.pageYOffset || d.scrollTop) - (d.clientTop || 0) } - return {x: curleft, y: curtop}; }; /**