@@ -15,8 +15,8 @@ define([
15
15
var hideProps = { } ,
16
16
showProps = { } ;
17
17
18
- hideProps . height = 'hide' ;
19
- showProps . height = 'show' ;
18
+ hideProps . height = 'hide' ;
19
+ showProps . height = 'show' ;
20
20
21
21
$ . widget ( 'mage.collapsible' , {
22
22
options : {
@@ -66,7 +66,7 @@ define([
66
66
67
67
this . element . on ( 'dimensionsChanged' , function ( e ) {
68
68
if ( e . target && e . target . classList . contains ( 'active' ) ) {
69
- this . _scrollToTopIfVisible ( e . target ) ;
69
+ this . _scrollToTopIfNotVisible ( ) ;
70
70
}
71
71
} . bind ( this ) ) ;
72
72
@@ -309,7 +309,7 @@ define([
309
309
310
310
if ( event ) {
311
311
$ . each ( event . split ( ' ' ) , function ( index , eventName ) {
312
- self . events [ eventName ] = '_eventHandler' ;
312
+ self . events [ eventName ] = '_eventHandler' ;
313
313
} ) ;
314
314
}
315
315
this . _off ( this . trigger ) ;
@@ -567,24 +567,35 @@ define([
567
567
} ,
568
568
569
569
/**
570
- * @param {HTMLElement } elem
571
570
* @private
572
571
*/
573
- _scrollToTopIfVisible : function ( elem ) {
574
- if ( ! this . _isElementOutOfViewport ( elem ) ) {
575
- elem . scrollIntoView ( ) ;
572
+ _scrollToTopIfNotVisible : function ( ) {
573
+ if ( this . _isElementOutOfViewport ( ) ) {
574
+ this . header [ 0 ] . scrollIntoView ( ) ;
576
575
}
577
576
} ,
578
577
579
578
/**
580
- * @param {HTMLElement } elem
581
579
* @private
582
580
* @return {Boolean }
583
581
*/
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 ;
588
599
}
589
600
} ) ;
590
601
0 commit comments