@@ -61,13 +61,20 @@ angular.module('patternfly.utils').directive('pfFixedAccordion', function ($wind
6161 groupClass : '@'
6262 } ,
6363 link : function ( $scope , $element , $attrs ) {
64+ var contentElementHeight = function ( contentElement ) {
65+ var contentHeight = contentElement . offsetHeight ;
66+ contentHeight += parseInt ( getComputedStyle ( contentElement ) . marginTop ) ;
67+ contentHeight += parseInt ( getComputedStyle ( contentElement ) . marginBottom ) ;
68+
69+ return contentHeight ;
70+ } ;
71+
6472 var setBodyScrollHeight = function ( parentElement , bodyHeight ) {
6573 // Set the max-height for the fixed height components
6674 var collapsePanels = parentElement [ 0 ] . querySelectorAll ( '.panel-collapse' ) ;
6775 var collapsePanel ;
6876 var scrollElement ;
6977 var panelContents ;
70- var nextContent ;
7178 var innerHeight ;
7279 var scroller ;
7380
@@ -78,24 +85,21 @@ angular.module('patternfly.utils').directive('pfFixedAccordion', function ($wind
7885
7986 if ( angular . isDefined ( $scope . scrollSelector ) ) {
8087 scroller = angular . element ( collapsePanel [ 0 ] . querySelector ( $scope . scrollSelector ) ) ;
81- if ( scroller . length === 1 ) {
88+ if ( scroller . length ) {
8289 scrollElement = angular . element ( scroller [ 0 ] ) ;
90+
8391 panelContents = collapsePanel . children ( ) ;
8492 angular . forEach ( panelContents , function ( contentElement ) {
85- nextContent = angular . element ( contentElement ) ;
86-
8793 // Get the height of all the non-scroll element contents
88- if ( nextContent [ 0 ] !== scrollElement [ 0 ] ) {
89- innerHeight += nextContent [ 0 ] . offsetHeight ;
90- innerHeight += parseInt ( getComputedStyle ( nextContent [ 0 ] ) . marginTop ) ;
91- innerHeight += parseInt ( getComputedStyle ( nextContent [ 0 ] ) . marginBottom ) ;
94+ if ( contentElement !== scrollElement [ 0 ] ) {
95+ innerHeight += contentElementHeight ( contentElement ) ;
9296 }
9397 } ) ;
9498 }
9599 }
96100
97- // set the max- height
98- angular . element ( scrollElement ) . css ( 'max-height' , ( bodyHeight - innerHeight ) + 'px' ) ;
101+ // Make sure we have enough height to be able to scroll the contents if necessary
102+ angular . element ( scrollElement ) . css ( 'max-height' , Math . max ( ( bodyHeight - innerHeight ) , 25 ) + 'px' ) ;
99103 angular . element ( scrollElement ) . css ( 'overflow-y' , 'auto' ) ;
100104 } ) ;
101105 } ;
@@ -104,7 +108,6 @@ angular.module('patternfly.utils').directive('pfFixedAccordion', function ($wind
104108 var height , openPanel , contentHeight , bodyHeight , overflowY = 'hidden' ;
105109 var parentElement = angular . element ( $element [ 0 ] . querySelector ( '.panel-group' ) ) ;
106110 var headings = angular . element ( parentElement ) . children ( ) ;
107- var headingElement ;
108111
109112 height = parentElement [ 0 ] . clientHeight ;
110113
@@ -118,10 +121,7 @@ angular.module('patternfly.utils').directive('pfFixedAccordion', function ($wind
118121 contentHeight = 0 ;
119122
120123 angular . forEach ( headings , function ( heading ) {
121- headingElement = angular . element ( heading ) ;
122- contentHeight += headingElement . prop ( 'offsetHeight' ) ;
123- contentHeight += parseInt ( getComputedStyle ( headingElement [ 0 ] ) . marginTop ) ;
124- contentHeight += parseInt ( getComputedStyle ( headingElement [ 0 ] ) . marginBottom ) ;
124+ contentHeight += contentElementHeight ( heading ) ;
125125 } ) ;
126126
127127 // Determine the height remaining for opened collapse panels
@@ -148,6 +148,8 @@ angular.module('patternfly.utils').directive('pfFixedAccordion', function ($wind
148148 } ) ;
149149 } ;
150150
151+ var debounceResize = _ . debounce ( setCollapseHeights , 150 , { maxWait : 250 } ) ;
152+
151153 if ( $scope . groupHeight ) {
152154 angular . element ( $element [ 0 ] . querySelector ( '.panel-group' ) ) . css ( 'height' , $scope . groupHeight ) ;
153155 }
@@ -161,10 +163,11 @@ angular.module('patternfly.utils').directive('pfFixedAccordion', function ($wind
161163
162164 // Update on window resizing
163165 $element . on ( 'resize' , function ( ) {
164- setCollapseHeights ( ) ;
166+ debounceResize ( ) ;
165167 } ) ;
168+
166169 angular . element ( $window ) . on ( 'resize' , function ( ) {
167- setCollapseHeights ( ) ;
170+ debounceResize ( ) ;
168171 } ) ;
169172 }
170173 } ;
0 commit comments