Skip to content

Commit 08ad874

Browse files
authored
ENGCOM-5600: [Lib] Fix previous attempts to correct wrong behaviour of collapsible library #23862
2 parents 28bd127 + adda871 commit 08ad874

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

lib/web/mage/collapsible.js

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ define([
1515
var hideProps = {},
1616
showProps = {};
1717

18-
hideProps.height = 'hide';
19-
showProps.height = 'show';
18+
hideProps.height = 'hide';
19+
showProps.height = 'show';
2020

2121
$.widget('mage.collapsible', {
2222
options: {
@@ -66,7 +66,7 @@ define([
6666

6767
this.element.on('dimensionsChanged', function (e) {
6868
if (e.target && e.target.classList.contains('active')) {
69-
this._scrollToTopIfVisible(e.target);
69+
this._scrollToTopIfNotVisible();
7070
}
7171
}.bind(this));
7272

@@ -309,7 +309,7 @@ define([
309309

310310
if (event) {
311311
$.each(event.split(' '), function (index, eventName) {
312-
self.events[ eventName ] = '_eventHandler';
312+
self.events[eventName] = '_eventHandler';
313313
});
314314
}
315315
this._off(this.trigger);
@@ -567,24 +567,35 @@ define([
567567
},
568568

569569
/**
570-
* @param {HTMLElement} elem
571570
* @private
572571
*/
573-
_scrollToTopIfVisible: function (elem) {
574-
if (!this._isElementOutOfViewport(elem)) {
575-
elem.scrollIntoView();
572+
_scrollToTopIfNotVisible: function () {
573+
if (this._isElementOutOfViewport()) {
574+
this.header[0].scrollIntoView();
576575
}
577576
},
578577

579578
/**
580-
* @param {HTMLElement} elem
581579
* @private
582580
* @return {Boolean}
583581
*/
584-
_isElementOutOfViewport: function (elem) {
585-
var rect = elem.getBoundingClientRect();
586-
587-
return rect.bottom < 0 || rect.right < 0 || rect.left > window.innerWidth || rect.top > window.innerHeight;
582+
_isElementOutOfViewport: function () {
583+
var headerRect = this.header[0].getBoundingClientRect(),
584+
contentRect = this.content.get().length ? this.content[0].getBoundingClientRect() : false,
585+
headerOut,
586+
contentOut;
587+
588+
headerOut = headerRect.bottom - headerRect.height < 0 ||
589+
headerRect.right - headerRect.width < 0 ||
590+
headerRect.left + headerRect.width > window.innerWidth ||
591+
headerRect.top + headerRect.height > window.innerHeight;
592+
593+
contentOut = contentRect ? contentRect.bottom - contentRect.height < 0 ||
594+
contentRect.right - contentRect.width < 0 ||
595+
contentRect.left + contentRect.width > window.innerWidth ||
596+
contentRect.top + contentRect.height > window.innerHeight : false;
597+
598+
return headerOut ? headerOut : contentOut;
588599
}
589600
});
590601

0 commit comments

Comments
 (0)