@@ -14,8 +14,8 @@ define([
14
14
var hideProps = { } ,
15
15
showProps = { } ;
16
16
17
- hideProps . height = 'hide' ;
18
- showProps . height = 'show' ;
17
+ hideProps . height = 'hide' ;
18
+ showProps . height = 'show' ;
19
19
20
20
$ . widget ( 'mage.collapsible' , {
21
21
options : {
@@ -65,7 +65,7 @@ define([
65
65
66
66
this . element . on ( 'dimensionsChanged' , function ( e ) {
67
67
if ( e . target && e . target . classList . contains ( 'active' ) ) {
68
- this . _scrollToTopIfVisible ( e . target ) ;
68
+ this . _scrollToTopIfNotVisible ( ) ;
69
69
}
70
70
} . bind ( this ) ) ;
71
71
@@ -308,7 +308,7 @@ define([
308
308
309
309
if ( event ) {
310
310
$ . each ( event . split ( ' ' ) , function ( index , eventName ) {
311
- self . events [ eventName ] = '_eventHandler' ;
311
+ self . events [ eventName ] = '_eventHandler' ;
312
312
} ) ;
313
313
}
314
314
this . _off ( this . trigger ) ;
@@ -566,24 +566,35 @@ define([
566
566
} ,
567
567
568
568
/**
569
- * @param {HTMLElement } elem
570
569
* @private
571
570
*/
572
- _scrollToTopIfVisible : function ( elem ) {
573
- if ( ! this . _isElementOutOfViewport ( elem ) ) {
574
- elem . scrollIntoView ( ) ;
571
+ _scrollToTopIfNotVisible : function ( ) {
572
+ if ( this . _isElementOutOfViewport ( ) ) {
573
+ this . header [ 0 ] . scrollIntoView ( ) ;
575
574
}
576
575
} ,
577
576
578
577
/**
579
- * @param {HTMLElement } elem
580
578
* @private
581
579
* @return {Boolean }
582
580
*/
583
- _isElementOutOfViewport : function ( elem ) {
584
- var rect = elem . getBoundingClientRect ( ) ;
585
-
586
- return rect . bottom < 0 || rect . right < 0 || rect . left > window . innerWidth || rect . top > window . innerHeight ;
581
+ _isElementOutOfViewport : function ( ) {
582
+ var headerRect = this . header [ 0 ] . getBoundingClientRect ( ) ,
583
+ contentRect = this . content . get ( ) . length ? this . content [ 0 ] . getBoundingClientRect ( ) : false ,
584
+ headerOut ,
585
+ contentOut ;
586
+
587
+ headerOut = headerRect . bottom - headerRect . height < 0 ||
588
+ headerRect . right - headerRect . width < 0 ||
589
+ headerRect . left + headerRect . width > window . innerWidth ||
590
+ headerRect . top + headerRect . height > window . innerHeight ;
591
+
592
+ contentOut = contentRect ? contentRect . bottom - contentRect . height < 0 ||
593
+ contentRect . right - contentRect . width < 0 ||
594
+ contentRect . left + contentRect . width > window . innerWidth ||
595
+ contentRect . top + contentRect . height > window . innerHeight : false ;
596
+
597
+ return headerOut ? headerOut : contentOut ;
587
598
}
588
599
} ) ;
589
600
0 commit comments