@@ -61,13 +61,20 @@ angular.module('patternfly.utils').directive('pfFixedAccordion', function ($wind
61
61
groupClass : '@'
62
62
} ,
63
63
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
+
64
72
var setBodyScrollHeight = function ( parentElement , bodyHeight ) {
65
73
// Set the max-height for the fixed height components
66
74
var collapsePanels = parentElement [ 0 ] . querySelectorAll ( '.panel-collapse' ) ;
67
75
var collapsePanel ;
68
76
var scrollElement ;
69
77
var panelContents ;
70
- var nextContent ;
71
78
var innerHeight ;
72
79
var scroller ;
73
80
@@ -78,24 +85,21 @@ angular.module('patternfly.utils').directive('pfFixedAccordion', function ($wind
78
85
79
86
if ( angular . isDefined ( $scope . scrollSelector ) ) {
80
87
scroller = angular . element ( collapsePanel [ 0 ] . querySelector ( $scope . scrollSelector ) ) ;
81
- if ( scroller . length === 1 ) {
88
+ if ( scroller . length ) {
82
89
scrollElement = angular . element ( scroller [ 0 ] ) ;
90
+
83
91
panelContents = collapsePanel . children ( ) ;
84
92
angular . forEach ( panelContents , function ( contentElement ) {
85
- nextContent = angular . element ( contentElement ) ;
86
-
87
93
// 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 ) ;
92
96
}
93
97
} ) ;
94
98
}
95
99
}
96
100
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' ) ;
99
103
angular . element ( scrollElement ) . css ( 'overflow-y' , 'auto' ) ;
100
104
} ) ;
101
105
} ;
@@ -104,7 +108,6 @@ angular.module('patternfly.utils').directive('pfFixedAccordion', function ($wind
104
108
var height , openPanel , contentHeight , bodyHeight , overflowY = 'hidden' ;
105
109
var parentElement = angular . element ( $element [ 0 ] . querySelector ( '.panel-group' ) ) ;
106
110
var headings = angular . element ( parentElement ) . children ( ) ;
107
- var headingElement ;
108
111
109
112
height = parentElement [ 0 ] . clientHeight ;
110
113
@@ -118,10 +121,7 @@ angular.module('patternfly.utils').directive('pfFixedAccordion', function ($wind
118
121
contentHeight = 0 ;
119
122
120
123
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 ) ;
125
125
} ) ;
126
126
127
127
// Determine the height remaining for opened collapse panels
@@ -148,6 +148,8 @@ angular.module('patternfly.utils').directive('pfFixedAccordion', function ($wind
148
148
} ) ;
149
149
} ;
150
150
151
+ var debounceResize = _ . debounce ( setCollapseHeights , 150 , { maxWait : 250 } ) ;
152
+
151
153
if ( $scope . groupHeight ) {
152
154
angular . element ( $element [ 0 ] . querySelector ( '.panel-group' ) ) . css ( 'height' , $scope . groupHeight ) ;
153
155
}
@@ -161,10 +163,11 @@ angular.module('patternfly.utils').directive('pfFixedAccordion', function ($wind
161
163
162
164
// Update on window resizing
163
165
$element . on ( 'resize' , function ( ) {
164
- setCollapseHeights ( ) ;
166
+ debounceResize ( ) ;
165
167
} ) ;
168
+
166
169
angular . element ( $window ) . on ( 'resize' , function ( ) {
167
- setCollapseHeights ( ) ;
170
+ debounceResize ( ) ;
168
171
} ) ;
169
172
}
170
173
} ;
0 commit comments