From c50365b1b5c05ca6c77386bac07547c4f08d6072 Mon Sep 17 00:00:00 2001 From: Richard Leon Date: Tue, 29 Sep 2020 09:52:14 -0400 Subject: [PATCH 1/2] Calculate iframe offset using el.getBoundingClientRect() --- src/DragDropTouch.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/DragDropTouch.js b/src/DragDropTouch.js index fafa035..8a52107 100644 --- a/src/DragDropTouch.js +++ b/src/DragDropTouch.js @@ -298,18 +298,14 @@ export default () => { // if target element is an iframe, try propagating event to child element if (el && el.nodeName === 'IFRAME') { try { - var iframeDocument = el.contentWindow.document; - // get iframe absolute offset - var iframeAbsoluteOffset = { x: 0, y: 0 }; - do { - iframeAbsoluteOffset.x += el.offsetLeft || 0; - iframeAbsoluteOffset.y += el.offsetTop || 0; - el = el.offsetParent; - } while (el); + // get iframe absolute offset relative to viewport + var rect = el.getBoundingClientRect(); + var iframeAbsoluteOffset = { x: rect.x, y: rect.y }; // remove iframe absolute offset from touch position var x = pt.x - iframeAbsoluteOffset.x, y = pt.y - iframeAbsoluteOffset.y; // get element on that position from iframe document + var iframeDocument = el.contentWindow.document; el = iframeDocument.elementFromPoint(x, y); } catch (e) { // iframe origin don't allow access From 0330d3ef4a15b9f96d3bad5e511f4c1bb7be7e60 Mon Sep 17 00:00:00 2001 From: Richard Leon Date: Tue, 29 Sep 2020 09:58:28 -0400 Subject: [PATCH 2/2] Remove unnecessary variable declaration --- src/DragDropTouch.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/DragDropTouch.js b/src/DragDropTouch.js index 8a52107..a59fcbd 100644 --- a/src/DragDropTouch.js +++ b/src/DragDropTouch.js @@ -300,10 +300,9 @@ export default () => { try { // get iframe absolute offset relative to viewport var rect = el.getBoundingClientRect(); - var iframeAbsoluteOffset = { x: rect.x, y: rect.y }; // remove iframe absolute offset from touch position - var x = pt.x - iframeAbsoluteOffset.x, - y = pt.y - iframeAbsoluteOffset.y; + var x = pt.x - rect.x, + y = pt.y - rect.y; // get element on that position from iframe document var iframeDocument = el.contentWindow.document; el = iframeDocument.elementFromPoint(x, y);