11/*!
22 * angular-ui-scroll
33 * https://github.com/angular-ui/ui-scroll.git
4- * Version: 1.4.0 -- 2016-04-04T13:14:46.276Z
4+ * Version: 1.4.0 -- 2016-04-08T01:17:59.374Z
55 * License: MIT
66 */
77
1111
1212var _typeof = typeof Symbol === 'function' && typeof Symbol . iterator === 'symbol' ? function ( obj ) { return typeof obj ; } : function ( obj ) { return obj && typeof Symbol === 'function' && obj . constructor === Symbol ? 'symbol' : typeof obj ; } ;
1313
14- /*!
15- globals: angular, window
16-
17- List of used element methods available in JQuery but not in JQuery Lite
18-
19- element.before(elem)
20- element.height()
21- element.outerHeight(true)
22- element.height(value) = only for Top/Bottom padding elements
23- element.scrollTop()
24- element.scrollTop(value)
14+ /*!
15+ globals: angular, window
16+
17+ List of used element methods available in JQuery but not in JQuery Lite
18+
19+ element.before(elem)
20+ element.height()
21+ element.outerHeight(true)
22+ element.height(value) = only for Top/Bottom padding elements
23+ element.scrollTop()
24+ element.scrollTop(value)
2525 */
2626angular . module ( 'ui.scroll' , [ ] ) . directive ( 'uiScrollViewport' , function ( ) {
2727 return {
@@ -137,11 +137,11 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
137137 } ,
138138
139139
140- /**
141- * inserts wrapped element in the buffer
142- * the first argument is either operation keyword (see below) or a number for operation 'insert'
143- * for insert the number is the index for the buffer element the new one have to be inserted after
144- * operations: 'append', 'prepend', 'insert', 'remove', 'update', 'none'
140+ /**
141+ * inserts wrapped element in the buffer
142+ * the first argument is either operation keyword (see below) or a number for operation 'insert'
143+ * for insert the number is the index for the buffer element the new one have to be inserted after
144+ * operations: 'append', 'prepend', 'insert', 'remove', 'update', 'none'
145145 */
146146 insert : function insert ( operation , item ) {
147147 var itemScope = $scope . $new ( ) ;
@@ -221,12 +221,6 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
221221 'display' : 'block'
222222 } ) ;
223223
224- var viewportOffset = viewport . offset ( ) ? function ( ) {
225- return viewport . offset ( ) ;
226- } : function ( ) {
227- return { top : 0 } ;
228- } ;
229-
230224 function Cache ( ) {
231225 var cache = Object . create ( Array . prototype ) ;
232226
@@ -310,12 +304,17 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
310304 clipBottom : function clipBottom ( ) {
311305 // clip the invisible items off the bottom
312306 var overage = 0 ;
307+ var overageHeight = 0 ;
308+ var itemHeight = 0 ;
309+ var emptySpaceHeight = viewport . bottomDataPos ( ) - viewport . bottomVisiblePos ( ) - bufferPadding ( ) ;
313310
314311 for ( var i = buffer . length - 1 ; i >= 0 ; i -- ) {
315- if ( buffer [ i ] . element . offset ( ) . top - viewportOffset ( ) . top <= viewport . outerHeight ( ) + bufferPadding ( ) ) {
312+ itemHeight = buffer [ i ] . element . outerHeight ( true ) ;
313+ if ( overageHeight + itemHeight > emptySpaceHeight ) {
316314 break ;
317315 }
318316 bottomPadding . cache . add ( buffer [ i ] ) ;
317+ overageHeight += itemHeight ;
319318 overage ++ ;
320319 }
321320
@@ -333,13 +332,16 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
333332 // clip the invisible items off the top
334333 var overage = 0 ;
335334 var overageHeight = 0 ;
335+ var itemHeight = 0 ;
336+ var emptySpaceHeight = viewport . topVisiblePos ( ) - viewport . topDataPos ( ) - bufferPadding ( ) ;
336337
337338 for ( var i = 0 ; i < buffer . length ; i ++ ) {
338- if ( buffer [ i ] . element . offset ( ) . top - viewportOffset ( ) . top + buffer [ i ] . element . outerHeight ( true ) >= - 1 * bufferPadding ( ) ) {
339+ itemHeight = buffer [ i ] . element . outerHeight ( true ) ;
340+ if ( overageHeight + itemHeight > emptySpaceHeight ) {
339341 break ;
340342 }
341343 topPadding . cache . add ( buffer [ i ] ) ;
342- overageHeight += buffer [ i ] . element . outerHeight ( true ) ;
344+ overageHeight += itemHeight ;
343345 overage ++ ;
344346 }
345347
@@ -539,6 +541,7 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
539541 var itemName = match [ 1 ] ;
540542 var datasourceName = match [ 2 ] ;
541543 var bufferSize = Math . max ( 3 , + attr . bufferSize || 10 ) ;
544+ var startIndex = + attr . startIndex || 1 ;
542545
543546 return function link ( $scope , element , $attr , controllers , linker ) {
544547 // starting from angular 1.2 compileLinker usage is deprecated
@@ -650,12 +653,12 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
650653 adapter = angular . extend ( adapterOnScope , adapter ) ;
651654 }
652655
653- /**
654- * Build padding elements
655- *
656- * Calling linker is the only way I found to get access to the tag name of the template
657- * to prevent the directive scope from pollution a new scope is created and destroyed
658- * right after the builder creation is completed
656+ /**
657+ * Build padding elements
658+ *
659+ * Calling linker is the only way I found to get access to the tag name of the template
660+ * to prevent the directive scope from pollution a new scope is created and destroyed
661+ * right after the builder creation is completed
659662 */
660663 linker ( $scope . $new ( ) , function ( template , scope ) {
661664 viewport . createPaddingElements ( template [ 0 ] ) ;
@@ -667,50 +670,29 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
667670
668671 adapter . reload = reload ;
669672
670- // events and bindings
671- function bindEvents ( ) {
672- viewport . bind ( 'resize' , resizeAndScrollHandler ) ;
673- viewport . bind ( 'scroll' , resizeAndScrollHandler ) ;
674- }
675- viewport . bind ( 'mousewheel' , wheelHandler ) ;
676-
677- function unbindEvents ( ) {
678- viewport . unbind ( 'resize' , resizeAndScrollHandler ) ;
679- viewport . unbind ( 'scroll' , resizeAndScrollHandler ) ;
680- }
681-
682673 $scope . $on ( '$destroy' , function ( ) {
683674 // clear the buffer. It is necessary to remove the elements and $destroy the scopes
684675 buffer . clear ( ) ;
685676 unbindEvents ( ) ;
686677 viewport . unbind ( 'mousewheel' , wheelHandler ) ;
687678 } ) ;
688679
689- // update events (deprecated since v1.1.0, unsupported since 1.2.0)
690- ( function ( ) {
691- var eventListener = datasource . scope ? datasource . scope . $new ( ) : $scope . $new ( ) ;
692-
693- eventListener . $on ( 'insert.item' , function ( ) {
694- return unsupportedMethod ( 'insert' ) ;
695- } ) ;
696-
697- eventListener . $on ( 'update.items' , function ( ) {
698- return unsupportedMethod ( 'update' ) ;
699- } ) ;
700-
701- eventListener . $on ( 'delete.items' , function ( ) {
702- return unsupportedMethod ( 'delete' ) ;
703- } ) ;
704-
705- function unsupportedMethod ( token ) {
706- throw new Error ( token + ' event is no longer supported - use applyUpdates instead' ) ;
707- }
708- } ) ( ) ;
680+ viewport . bind ( 'mousewheel' , wheelHandler ) ;
709681
710682 reload ( ) ;
711683
712684 /* Functions definitions */
713685
686+ function bindEvents ( ) {
687+ viewport . bind ( 'resize' , resizeAndScrollHandler ) ;
688+ viewport . bind ( 'scroll' , resizeAndScrollHandler ) ;
689+ }
690+
691+ function unbindEvents ( ) {
692+ viewport . unbind ( 'resize' , resizeAndScrollHandler ) ;
693+ viewport . unbind ( 'scroll' , resizeAndScrollHandler ) ;
694+ }
695+
714696 function dismissPendingRequests ( ) {
715697 ridActual ++ ;
716698 pending = [ ] ;
@@ -722,15 +704,9 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
722704 viewport . resetTopPadding ( ) ;
723705 viewport . resetBottomPadding ( ) ;
724706
725- adapter . abCount = 0 ;
726- adapter . abfCount = 0 ;
727- adapter . sCount = 0 ;
707+ if ( arguments . length ) startIndex = arguments [ 0 ] ;
728708
729- if ( arguments . length ) {
730- buffer . clear ( arguments [ 0 ] ) ;
731- } else {
732- buffer . clear ( ) ;
733- }
709+ buffer . clear ( startIndex ) ;
734710
735711 return adjustBuffer ( ridActual ) ;
736712 }
@@ -844,7 +820,6 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
844820 function adjustBuffer ( rid ) {
845821 // We need the item bindings to be processed before we can do adjustment
846822 return $timeout ( function ( ) {
847- adapter . abCount ++ ;
848823 processBufferedItems ( rid ) ;
849824
850825 if ( viewport . shouldLoadBottom ( ) ) {
@@ -862,7 +837,6 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
862837 function adjustBufferAfterFetch ( rid ) {
863838 // We need the item bindings to be processed before we can do adjustment
864839 return $timeout ( function ( ) {
865- adapter . abfCount ++ ;
866840 var keepFetching = processBufferedItems ( rid ) ;
867841
868842 if ( viewport . shouldLoadBottom ( ) && keepFetching ) {
@@ -944,7 +918,6 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
944918
945919 function resizeAndScrollHandler ( ) {
946920 if ( ! $rootScope . $$phase && ! adapter . isLoading ) {
947- adapter . sCount ++ ;
948921 if ( viewport . shouldLoadBottom ( ) ) {
949922 enqueueFetch ( ridActual , true ) ;
950923 } else if ( viewport . shouldLoadTop ( ) ) {
0 commit comments