@@ -80,15 +80,6 @@ function virtualRepeatContainerTemplate($element) {
8080 '</div></div>' ;
8181}
8282
83- /**
84- * Maximum size, in pixels, that can be explicitly set to an element. The actual value varies
85- * between browsers, but IE11 has the very lowest size at a mere 1,533,917px. Ideally we could
86- * *compute* this value, but Firefox always reports an element to have a size of zero if it
87- * goes over the max, meaning that we'd have to binary search for the value.
88- * @const {number}
89- */
90- var MAX_ELEMENT_SIZE = 1533917 ;
91-
9283/**
9384 * Number of additional elements to render above and below the visible area inside
9485 * of the virtual repeat container. A higher number results in less flicker when scrolling
@@ -98,8 +89,8 @@ var MAX_ELEMENT_SIZE = 1533917;
9889var NUM_EXTRA = 3 ;
9990
10091/** @ngInject */
101- function VirtualRepeatContainerController (
102- $$rAF , $mdUtil , $parse , $rootScope , $window , $scope , $element , $attrs ) {
92+ function VirtualRepeatContainerController ( $$rAF , $mdUtil , $mdConstant , $parse , $rootScope , $window , $scope ,
93+ $element , $attrs ) {
10394 this . $rootScope = $rootScope ;
10495 this . $scope = $scope ;
10596 this . $element = $element ;
@@ -125,6 +116,8 @@ function VirtualRepeatContainerController(
125116 this . offsetSize = parseInt ( this . $attrs . mdOffsetSize , 10 ) || 0 ;
126117 /** @type {?string } height or width element style on the container prior to auto-shrinking. */
127118 this . oldElementSize = null ;
119+ /** @type {!number } Maximum amount of pixels allowed for a single DOM element */
120+ this . maxElementPixels = $mdConstant . ELEMENT_MAX_PIXELS ;
128121
129122 if ( this . $attrs . mdTopIndex ) {
130123 /** @type {function(angular.Scope): number } Binds to topIndex on Angular scope */
@@ -262,26 +255,26 @@ VirtualRepeatContainerController.prototype.sizeScroller_ = function(size) {
262255 // If the size falls within the browser's maximum explicit size for a single element, we can
263256 // set the size and be done. Otherwise, we have to create children that add up the the desired
264257 // size.
265- if ( size < MAX_ELEMENT_SIZE ) {
258+ if ( size < this . maxElementPixels ) {
266259 this . sizer . style [ dimension ] = size + 'px' ;
267260 } else {
268261 this . sizer . style [ dimension ] = 'auto' ;
269262 this . sizer . style [ crossDimension ] = 'auto' ;
270263
271264 // Divide the total size we have to render into N max-size pieces.
272- var numChildren = Math . floor ( size / MAX_ELEMENT_SIZE ) ;
265+ var numChildren = Math . floor ( size / this . maxElementPixels ) ;
273266
274267 // Element template to clone for each max-size piece.
275268 var sizerChild = document . createElement ( 'div' ) ;
276- sizerChild . style [ dimension ] = MAX_ELEMENT_SIZE + 'px' ;
269+ sizerChild . style [ dimension ] = this . maxElementPixels + 'px' ;
277270 sizerChild . style [ crossDimension ] = '1px' ;
278271
279272 for ( var i = 0 ; i < numChildren ; i ++ ) {
280273 this . sizer . appendChild ( sizerChild . cloneNode ( false ) ) ;
281274 }
282275
283276 // Re-use the element template for the remainder.
284- sizerChild . style [ dimension ] = ( size - ( numChildren * MAX_ELEMENT_SIZE ) ) + 'px' ;
277+ sizerChild . style [ dimension ] = ( size - ( numChildren * this . maxElementPixels ) ) + 'px' ;
285278 this . sizer . appendChild ( sizerChild ) ;
286279 }
287280} ;
0 commit comments