1
1
/*!
2
2
* angular-ui-scroll
3
3
* 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
5
5
* License: MIT
6
6
*/
7
7
11
11
12
12
var _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 ; } ;
13
13
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)
25
25
*/
26
26
angular . module ( 'ui.scroll' , [ ] ) . directive ( 'uiScrollViewport' , function ( ) {
27
27
return {
@@ -137,11 +137,11 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
137
137
} ,
138
138
139
139
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'
145
145
*/
146
146
insert : function insert ( operation , item ) {
147
147
var itemScope = $scope . $new ( ) ;
@@ -221,12 +221,6 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
221
221
'display' : 'block'
222
222
} ) ;
223
223
224
- var viewportOffset = viewport . offset ( ) ? function ( ) {
225
- return viewport . offset ( ) ;
226
- } : function ( ) {
227
- return { top : 0 } ;
228
- } ;
229
-
230
224
function Cache ( ) {
231
225
var cache = Object . create ( Array . prototype ) ;
232
226
@@ -310,12 +304,17 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
310
304
clipBottom : function clipBottom ( ) {
311
305
// clip the invisible items off the bottom
312
306
var overage = 0 ;
307
+ var overageHeight = 0 ;
308
+ var itemHeight = 0 ;
309
+ var emptySpaceHeight = viewport . bottomDataPos ( ) - viewport . bottomVisiblePos ( ) - bufferPadding ( ) ;
313
310
314
311
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 ) {
316
314
break ;
317
315
}
318
316
bottomPadding . cache . add ( buffer [ i ] ) ;
317
+ overageHeight += itemHeight ;
319
318
overage ++ ;
320
319
}
321
320
@@ -333,13 +332,16 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
333
332
// clip the invisible items off the top
334
333
var overage = 0 ;
335
334
var overageHeight = 0 ;
335
+ var itemHeight = 0 ;
336
+ var emptySpaceHeight = viewport . topVisiblePos ( ) - viewport . topDataPos ( ) - bufferPadding ( ) ;
336
337
337
338
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 ) {
339
341
break ;
340
342
}
341
343
topPadding . cache . add ( buffer [ i ] ) ;
342
- overageHeight += buffer [ i ] . element . outerHeight ( true ) ;
344
+ overageHeight += itemHeight ;
343
345
overage ++ ;
344
346
}
345
347
@@ -539,6 +541,7 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
539
541
var itemName = match [ 1 ] ;
540
542
var datasourceName = match [ 2 ] ;
541
543
var bufferSize = Math . max ( 3 , + attr . bufferSize || 10 ) ;
544
+ var startIndex = + attr . startIndex || 1 ;
542
545
543
546
return function link ( $scope , element , $attr , controllers , linker ) {
544
547
// starting from angular 1.2 compileLinker usage is deprecated
@@ -650,12 +653,12 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
650
653
adapter = angular . extend ( adapterOnScope , adapter ) ;
651
654
}
652
655
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
659
662
*/
660
663
linker ( $scope . $new ( ) , function ( template , scope ) {
661
664
viewport . createPaddingElements ( template [ 0 ] ) ;
@@ -667,50 +670,29 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
667
670
668
671
adapter . reload = reload ;
669
672
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
-
682
673
$scope . $on ( '$destroy' , function ( ) {
683
674
// clear the buffer. It is necessary to remove the elements and $destroy the scopes
684
675
buffer . clear ( ) ;
685
676
unbindEvents ( ) ;
686
677
viewport . unbind ( 'mousewheel' , wheelHandler ) ;
687
678
} ) ;
688
679
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 ) ;
709
681
710
682
reload ( ) ;
711
683
712
684
/* Functions definitions */
713
685
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
+
714
696
function dismissPendingRequests ( ) {
715
697
ridActual ++ ;
716
698
pending = [ ] ;
@@ -722,15 +704,9 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
722
704
viewport . resetTopPadding ( ) ;
723
705
viewport . resetBottomPadding ( ) ;
724
706
725
- adapter . abCount = 0 ;
726
- adapter . abfCount = 0 ;
727
- adapter . sCount = 0 ;
707
+ if ( arguments . length ) startIndex = arguments [ 0 ] ;
728
708
729
- if ( arguments . length ) {
730
- buffer . clear ( arguments [ 0 ] ) ;
731
- } else {
732
- buffer . clear ( ) ;
733
- }
709
+ buffer . clear ( startIndex ) ;
734
710
735
711
return adjustBuffer ( ridActual ) ;
736
712
}
@@ -844,7 +820,6 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
844
820
function adjustBuffer ( rid ) {
845
821
// We need the item bindings to be processed before we can do adjustment
846
822
return $timeout ( function ( ) {
847
- adapter . abCount ++ ;
848
823
processBufferedItems ( rid ) ;
849
824
850
825
if ( viewport . shouldLoadBottom ( ) ) {
@@ -862,7 +837,6 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
862
837
function adjustBufferAfterFetch ( rid ) {
863
838
// We need the item bindings to be processed before we can do adjustment
864
839
return $timeout ( function ( ) {
865
- adapter . abfCount ++ ;
866
840
var keepFetching = processBufferedItems ( rid ) ;
867
841
868
842
if ( viewport . shouldLoadBottom ( ) && keepFetching ) {
@@ -944,7 +918,6 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
944
918
945
919
function resizeAndScrollHandler ( ) {
946
920
if ( ! $rootScope . $$phase && ! adapter . isLoading ) {
947
- adapter . sCount ++ ;
948
921
if ( viewport . shouldLoadBottom ( ) ) {
949
922
enqueueFetch ( ridActual , true ) ;
950
923
} else if ( viewport . shouldLoadTop ( ) ) {
0 commit comments