From c029f5a20228ae8573b18538674f2c7c91a5f570 Mon Sep 17 00:00:00 2001 From: Oskar Olaussen Date: Tue, 25 Jun 2019 08:58:04 +0300 Subject: [PATCH 1/4] Changed logic so that _scrollToTopIfVisible is called only if element is in viewport. Previously it was called only when the element was outside it. Also changed the logic of _isElementOutOfViewport to work correctly. --- lib/web/mage/collapsible.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/web/mage/collapsible.js b/lib/web/mage/collapsible.js index 3d283d102e323..0ada7102a898a 100644 --- a/lib/web/mage/collapsible.js +++ b/lib/web/mage/collapsible.js @@ -570,7 +570,7 @@ define([ * @private */ _scrollToTopIfVisible: function (elem) { - if (this._isElementOutOfViewport(elem)) { + if (!this._isElementOutOfViewport(elem)) { elem.scrollIntoView(); } }, @@ -583,7 +583,7 @@ define([ _isElementOutOfViewport: function (elem) { var rect = elem.getBoundingClientRect(); - return rect.bottom < 0 || rect.right < 0 || rect.left > window.innerWidth || rect.top > window.innerHeight; + return rect.bottom > window.innerHeight || rect.right < 0 || rect.left > window.innerWidth || rect.top < 0; } }); From b5f23575f077536abf6ac8ad3689d87517baf449 Mon Sep 17 00:00:00 2001 From: Oskar Olaussen Date: Tue, 25 Jun 2019 10:20:16 +0300 Subject: [PATCH 2/4] Changed logic so that _scrollToTopIfVisible is called only if element is in viewport. Previously it was called only when the element was outside it. Also changed the logic of _isElementOutOfViewport to work correctly. --- lib/web/mage/collapsible.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/web/mage/collapsible.js b/lib/web/mage/collapsible.js index 0ada7102a898a..cf0bd076f8d4b 100644 --- a/lib/web/mage/collapsible.js +++ b/lib/web/mage/collapsible.js @@ -582,7 +582,6 @@ define([ */ _isElementOutOfViewport: function (elem) { var rect = elem.getBoundingClientRect(); - return rect.bottom > window.innerHeight || rect.right < 0 || rect.left > window.innerWidth || rect.top < 0; } }); From f13d718d2bd52274c9afb4ad6f44ca0e202a6401 Mon Sep 17 00:00:00 2001 From: Oskar Olaussen Date: Tue, 25 Jun 2019 11:37:28 +0300 Subject: [PATCH 3/4] Revert "Changed logic so that _scrollToTopIfVisible is called only if element is in viewport. Previously it was called only when the element was outside it. Also changed the logic of _isElementOutOfViewport to work correctly." This reverts commit b5f23575f077536abf6ac8ad3689d87517baf449. --- lib/web/mage/collapsible.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/web/mage/collapsible.js b/lib/web/mage/collapsible.js index cf0bd076f8d4b..0ada7102a898a 100644 --- a/lib/web/mage/collapsible.js +++ b/lib/web/mage/collapsible.js @@ -582,6 +582,7 @@ define([ */ _isElementOutOfViewport: function (elem) { var rect = elem.getBoundingClientRect(); + return rect.bottom > window.innerHeight || rect.right < 0 || rect.left > window.innerWidth || rect.top < 0; } }); From 00b5bfeecd7eece15d2437f3149e36cf18986151 Mon Sep 17 00:00:00 2001 From: Oskar Olaussen Date: Wed, 26 Jun 2019 10:42:26 +0300 Subject: [PATCH 4/4] _isElementOutOfViewport reverted back to how it was. The original logic worked correctly --- lib/web/mage/collapsible.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/web/mage/collapsible.js b/lib/web/mage/collapsible.js index 0ada7102a898a..cae6ee01b0de5 100644 --- a/lib/web/mage/collapsible.js +++ b/lib/web/mage/collapsible.js @@ -583,7 +583,7 @@ define([ _isElementOutOfViewport: function (elem) { var rect = elem.getBoundingClientRect(); - return rect.bottom > window.innerHeight || rect.right < 0 || rect.left > window.innerWidth || rect.top < 0; + return rect.bottom < 0 || rect.right < 0 || rect.left > window.innerWidth || rect.top > window.innerHeight; } });