@@ -61,24 +61,67 @@ angular.module('patternfly.utils').directive('pfFixedAccordion', function ($wind
6161 groupClass : '@'
6262 } ,
6363 link : function ( $scope , $element , $attrs ) {
64+ var setBodyScrollHeight = function ( parentElement , bodyHeight ) {
65+ // Set the max-height for the fixed height components
66+ var collapsePanels = parentElement [ 0 ] . querySelectorAll ( '.panel-collapse' ) ;
67+ var collapsePanel ;
68+ var scrollElement ;
69+ var panelContents ;
70+ var nextContent ;
71+ var innerHeight ;
72+ var scroller ;
73+
74+ angular . forEach ( collapsePanels , function ( collapseElement ) {
75+ collapsePanel = angular . element ( collapseElement ) ;
76+ scrollElement = collapsePanel ;
77+ innerHeight = 0 ;
78+
79+ if ( angular . isDefined ( $scope . scrollSelector ) ) {
80+ scroller = angular . element ( collapsePanel [ 0 ] . querySelector ( $scope . scrollSelector ) ) ;
81+ if ( scroller . length === 1 ) {
82+ scrollElement = angular . element ( scroller [ 0 ] ) ;
83+ panelContents = collapsePanel . children ( ) ;
84+ angular . forEach ( panelContents , function ( contentElement ) {
85+ nextContent = angular . element ( contentElement ) ;
86+
87+ // 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 ) ;
92+ }
93+ } ) ;
94+ }
95+ }
96+
97+ // set the max-height
98+ angular . element ( scrollElement ) . css ( 'max-height' , ( bodyHeight - innerHeight ) + 'px' ) ;
99+ angular . element ( scrollElement ) . css ( 'overflow-y' , 'auto' ) ;
100+ } ) ;
101+ } ;
102+
64103 var setCollapseHeights = function ( ) {
65- var componentSelector , height , openPanel , contentHeight , bodyHeight , overflowY = 'hidden' , parentElement = $element . find ( '.panel-group' ) ;
104+ var height , openPanel , contentHeight , bodyHeight , overflowY = 'hidden' ;
105+ var parentElement = angular . element ( $element [ 0 ] . querySelector ( '.panel-group' ) ) ;
106+ var headings = angular . element ( parentElement ) . children ( ) ;
107+ var headingElement ;
66108
67- height = parentElement . height ( ) ;
109+ height = parentElement [ 0 ] . clientHeight ;
68110
69111 // Close any open panel
70- openPanel = parentElement . find ( '.collapse.in' ) ;
112+ openPanel = parentElement [ 0 ] . querySelectorAll ( '.collapse.in' ) ;
71113 if ( openPanel && openPanel . length > 0 ) {
72- openPanel . removeClass ( 'in' ) ;
114+ angular . element ( openPanel ) . removeClass ( 'in' ) ;
73115 }
74116
75117 // Determine the necessary height for the closed content
76118 contentHeight = 0 ;
77- parentElement . children ( ) . each ( function ( index , groupHeading ) {
78- var headingElement = angular . element ( groupHeading ) ;
119+
120+ angular . forEach ( headings , function ( heading ) {
121+ headingElement = angular . element ( heading ) ;
79122 contentHeight += headingElement . prop ( 'offsetHeight' ) ;
80- contentHeight += parseInt ( headingElement . css ( 'margin-top' ) ) ;
81- contentHeight += parseInt ( headingElement . css ( 'margin-bottom' ) ) ;
123+ contentHeight += parseInt ( getComputedStyle ( headingElement [ 0 ] ) . marginTop ) ;
124+ contentHeight += parseInt ( getComputedStyle ( headingElement [ 0 ] ) . marginBottom ) ;
82125 } ) ;
83126
84127 // Determine the height remaining for opened collapse panels
@@ -94,54 +137,32 @@ angular.module('patternfly.utils').directive('pfFixedAccordion', function ($wind
94137
95138 // Reopen the initially opened panel
96139 if ( openPanel && openPanel . length > 0 ) {
97- openPanel . addClass ( "in" ) ;
140+ angular . element ( openPanel ) . addClass ( "in" ) ;
98141 }
99142
100- $timeout ( function ( ) {
101- // Set the max-height for the fixed height components
102- parentElement . find ( '.panel-collapse' ) . each ( function ( index , collapsePanel ) {
103- var $panel = angular . element ( collapsePanel ) ;
104- var scrollElement = $panel ;
105- var innerHeight = 0 ;
106- var selected ;
107- var $sibling ;
108-
109- if ( angular . isDefined ( $scope . scrollSelector ) ) {
110- selected = angular . element ( $panel . find ( $scope . scrollSelector ) ) ;
111- if ( selected . length === 1 ) {
112- scrollElement = angular . element ( selected [ 0 ] ) ;
113- $panel . children ( ) . each ( function ( j , sibling ) {
114- if ( sibling !== scrollElement [ 0 ] ) {
115- $sibling = angular . element ( sibling ) ;
116- innerHeight += $sibling . prop ( 'offsetHeight' ) ;
117- innerHeight += parseInt ( $sibling . css ( 'margin-top' ) ) ;
118- innerHeight += parseInt ( $sibling . css ( 'margin-bottom' ) ) ;
119- }
120- } ) ;
121- }
122- }
143+ angular . element ( parentElement ) . css ( 'overflow-y' , overflowY ) ;
123144
124- // set the max-height
125- angular . element ( scrollElement ) . css ( 'max-height' , ( bodyHeight - innerHeight ) + 'px' ) ;
126- angular . element ( scrollElement ) . css ( 'overflow-y' , 'auto' ) ;
127- } ) ;
145+ // Update body scroll element's height after allowing these changes to set in
146+ $timeout ( function ( ) {
147+ setBodyScrollHeight ( parentElement , bodyHeight ) ;
128148 } ) ;
129-
130- angular . element ( parentElement ) . css ( 'overflow-y' , overflowY ) ;
131149 } ;
132150
133151 if ( $scope . groupHeight ) {
134- $element . find ( '.panel-group' ) . css ( " height" , $scope . groupHeight ) ;
152+ angular . element ( $element [ 0 ] . querySelector ( '.panel-group' ) ) . css ( ' height' , $scope . groupHeight ) ;
135153 }
136154 if ( $scope . groupClass ) {
137- $element . find ( ' .panel-group' ) . addClass ( $scope . groupClass ) ;
155+ angular . element ( $element [ 0 ] . querySelector ( " .panel-group" ) ) . addClass ( $scope . groupClass ) ;
138156 }
139157
140158 $timeout ( function ( ) {
141159 setCollapseHeights ( ) ;
142160 } , 100 ) ;
143161
144162 // Update on window resizing
163+ $element . bind ( 'resize' , function ( ) {
164+ setCollapseHeights ( ) ;
165+ } ) ;
145166 angular . element ( $window ) . bind ( 'resize' , function ( ) {
146167 setCollapseHeights ( ) ;
147168 } ) ;
0 commit comments