@@ -91,10 +91,13 @@ declare const angular: any;
9191 console . error ( 'Template url not found: ' + templateUrl ) ;
9292 }
9393 } ) ;
94+ var sizeDimension ;
9495 scope . $watch ( 'options.alignHorizontal' , ( alignHorizontal ) => {
9596 if ( alignHorizontal ) {
97+ sizeDimension = 'width' ;
9698 elem . children ( ) . addClass ( 'horizontal' ) ;
9799 } else {
100+ sizeDimension = 'height' ;
98101 elem . children ( ) . removeClass ( 'horizontal' ) ;
99102 }
100103 placeholderStart . css ( {
@@ -133,20 +136,20 @@ declare const angular: any;
133136 }
134137
135138 const rect = elem [ 0 ] . getBoundingClientRect ( ) ;
136- const itemHeight = scope . options . tileSize . height ;
139+ const itemSize = scope . options . tileSize [ sizeDimension ] ;
137140
138- const maxScrollPosition = rowCount * itemHeight - rect . height ;
141+ const maxScrollPosition = rowCount * itemSize - rect [ sizeDimension ] ;
139142
140143 const scrollDimension = scope . options . alignHorizontal ? 'scrollLeft' : 'scrollTop' ;
141144 container [ 0 ] [ scrollDimension ] = clamp ( container [ 0 ] [ scrollDimension ] , 0 , maxScrollPosition ) ;
142145 const scrollPosition = container [ 0 ] [ scrollDimension ] ;
143146
144- const scrollEndThreshold = maxScrollPosition - scope . options . scrollEndOffset * itemHeight ;
147+ const scrollEndThreshold = maxScrollPosition - scope . options . scrollEndOffset * itemSize ;
145148 if ( scrollPosition >= scrollEndThreshold && ! ( lastScrollPosition >= scrollEndThreshold ) && scope . scrollEnd !== undefined ) {
146149 scope . scrollEnd ( ) ;
147150 }
148151
149- startRow = clamp ( Math . floor ( scrollPosition / itemHeight ) , 0 , rowCount - cachedRowCount ) ;
152+ startRow = clamp ( Math . floor ( scrollPosition / itemSize ) , 0 , rowCount - cachedRowCount ) ;
150153 endRow = startRow + cachedRowCount ;
151154 lastScrollPosition = scrollPosition ;
152155 }
@@ -167,11 +170,10 @@ declare const angular: any;
167170 }
168171
169172 function setPlaceholder ( ) {
170- heightStart = Math . max ( startRow * scope . options . tileSize . height , 0 ) ;
171- heightEnd = Math . max ( ( rowCount - endRow ) * scope . options . tileSize . height , 0 ) ;
172- const placeHolderDimension = scope . options . alignHorizontal ? 'width' : 'height' ;
173- placeholderStart . css ( placeHolderDimension , heightStart + 'px' ) ;
174- placeholderEnd . css ( placeHolderDimension , heightEnd + 'px' ) ;
173+ heightStart = Math . max ( startRow * scope . options . tileSize [ sizeDimension ] , 0 ) ;
174+ heightEnd = Math . max ( ( rowCount - endRow ) * scope . options . tileSize [ sizeDimension ] , 0 ) ;
175+ placeholderStart . css ( sizeDimension , heightStart + 'px' ) ;
176+ placeholderEnd . css ( sizeDimension , heightEnd + 'px' ) ;
175177 }
176178
177179 function createElements ( diff ) {
@@ -211,14 +213,13 @@ declare const angular: any;
211213
212214 function layout ( ) {
213215 if ( linkFunction !== undefined && scope . items !== undefined ) {
214- const itemHeight = scope . options . tileSize . height ;
215216 const itemWidth = scope . options . tileSize . width ;
216- const width = ( ( scope . options . alignHorizontal ) ? itemContainer [ 0 ] : elem [ 0 ] ) . getBoundingClientRect ( ) . width ;
217- const height = elem [ 0 ] . getBoundingClientRect ( ) . height ;
217+ const width = itemContainer [ 0 ] . getBoundingClientRect ( ) . width ;
218+ const size = elem [ 0 ] . getBoundingClientRect ( ) [ sizeDimension ] ;
218219
219220 itemsPerRow = ( scope . options . alignHorizontal ) ? 1 : Math . floor ( width / itemWidth ) ;
220221 rowCount = Math . ceil ( scope . items . length / itemsPerRow ) ;
221- cachedRowCount = Math . ceil ( height / itemHeight ) + scope . options . overflow ;
222+ cachedRowCount = Math . ceil ( size / scope . options . tileSize [ sizeDimension ] ) + scope . options . overflow ;
222223
223224 createElements ( itemsPerRow * cachedRowCount - itemElementCount ( ) ) ;
224225 setPlaceholder ( ) ;
0 commit comments