1
1
/*!
2
2
* angular-ui-scroll
3
3
* https://github.com/angular-ui/ui-scroll.git
4
- * Version: 1.5.0 -- 2016-06-19T00:30:40.294Z
4
+ * Version: 1.5.0 -- 2016-06-27T00:06:28.439Z
5
5
* License: MIT
6
6
*/
7
7
@@ -386,20 +386,16 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
386
386
topPadding . height ( topPaddingHeight + topPaddingHeightAdd ) ;
387
387
bottomPadding . height ( bottomPaddingHeight + bottomPaddingHeightAdd ) ;
388
388
} ,
389
- adjustPaddingUnbound : function adjustPaddingUnbound ( updates ) {
390
- if ( updates . prepended && updates . prepended . length ) topPadding . height ( topPadding . height ( ) + updates . estimatedPaddingIncrement ) ; else viewport . adjustPadding ( ) ;
391
- } ,
392
- adjustPaddingBound : function adjustPaddingBound ( updates ) {
393
- if ( updates . prepended && updates . prepended . length ) topPadding . height ( topPadding . height ( ) - updates . estimatedPaddingIncrement ) ;
394
- } ,
395
389
adjustScrollTopAfterMinIndexSet : function adjustScrollTopAfterMinIndexSet ( topPaddingHeightOld ) {
396
390
// additional scrollTop adjustment in case of datasource.minIndex external set
397
391
if ( buffer . minIndexUser !== null && buffer . minIndex > buffer . minIndexUser ) {
398
392
var diff = topPadding . height ( ) - topPaddingHeightOld ;
399
393
viewport . scrollTop ( viewport . scrollTop ( ) + diff ) ;
400
394
}
401
395
} ,
402
- adjustScrollTopAfterPrepend : function adjustScrollTopAfterPrepend ( height ) {
396
+ adjustScrollTopAfterPrepend : function adjustScrollTopAfterPrepend ( updates ) {
397
+ if ( ! updates . prepended . length ) return ;
398
+ var height = buffer . effectiveHeight ( updates . prepended ) ;
403
399
var paddingHeight = topPadding . height ( ) - height ;
404
400
if ( paddingHeight >= 0 ) {
405
401
topPadding . height ( paddingHeight ) ;
@@ -432,7 +428,7 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
432
428
var topVisibleScopeInjector = createValueInjector ( 'topVisibleScope' ) ;
433
429
var isLoadingInjector = createValueInjector ( 'isLoading' ) ;
434
430
435
- // Adapter API definition
431
+ // Adapter API definition
436
432
437
433
Object . defineProperty ( this , 'disabled' , {
438
434
get : function get ( ) {
@@ -720,14 +716,13 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
720
716
}
721
717
722
718
function insertWrapperContent ( wrapper , insertAfter ) {
723
-
724
719
createElement ( wrapper , insertAfter , viewport . insertElement ) ;
725
-
726
- if ( isElementVisible ( wrapper ) ) return true ;
727
- wrapper . unregisterVisibilityWatcher = wrapper . scope . $watch ( function ( ) {
728
- return visibilityWatcher ( wrapper ) ;
729
- } ) ;
730
- return false ;
720
+ if ( ! isElementVisible ( wrapper ) ) {
721
+ wrapper . unregisterVisibilityWatcher = wrapper . scope . $watch ( function ( ) {
722
+ return visibilityWatcher ( wrapper ) ;
723
+ } ) ;
724
+ }
725
+ wrapper . element . addClass ( 'ng-hide' ) ; // hide inserted elements before data binding
731
726
}
732
727
733
728
function createElement ( wrapper , insertAfter , insertElement ) {
@@ -783,12 +778,7 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
783
778
return item . scope . $index = buffer . first + i ;
784
779
} ) ;
785
780
786
- var estimatedPaddingIncrement = buffer . effectiveHeight ( toBePrepended ) ;
787
-
788
- viewport . adjustScrollTopAfterPrepend ( estimatedPaddingIncrement ) ;
789
-
790
781
return {
791
- estimatedPaddingIncrement : estimatedPaddingIncrement ,
792
782
prepended : toBePrepended ,
793
783
removed : toBeRemoved ,
794
784
inserted : inserted ,
@@ -797,11 +787,6 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
797
787
}
798
788
799
789
function updatePaddings ( rid , updates ) {
800
-
801
- var adjustedPaddingHeight = buffer . effectiveHeight ( updates . prepended ) - updates . estimatedPaddingIncrement ;
802
-
803
- viewport . adjustScrollTopAfterPrepend ( adjustedPaddingHeight ) ;
804
-
805
790
// schedule another adjustBuffer after animation completion
806
791
if ( updates . animated . length ) {
807
792
$q . all ( updates . animated ) . then ( function ( ) {
@@ -811,24 +796,26 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
811
796
} else {
812
797
viewport . adjustPadding ( ) ;
813
798
}
814
-
815
- // return true if inserted elements have height > 0
816
- return adjustedPaddingHeight + updates . estimatedPaddingIncrement > 0 || buffer . effectiveHeight ( updates . inserted ) > 0 ;
817
799
}
818
800
819
- function enqueueFetch ( rid , keepFetching ) {
820
- if ( viewport . shouldLoadBottom ( ) && keepFetching ) {
821
- // keepFetching = true means that at least one item app/prepended in the last batch had height > 0
822
- if ( pending . push ( true ) === 1 ) {
823
- fetch ( rid ) ;
824
- adapter . loading ( true ) ;
801
+ function enqueueFetch ( rid , updates ) {
802
+ if ( viewport . shouldLoadBottom ( ) ) {
803
+ if ( ! updates || buffer . effectiveHeight ( updates . inserted ) > 0 ) {
804
+ // this means that at least one item appended in the last batch has height > 0
805
+ if ( pending . push ( true ) === 1 ) {
806
+ fetch ( rid ) ;
807
+ adapter . loading ( true ) ;
808
+ }
825
809
}
826
- } else if ( viewport . shouldLoadTop ( ) && ( keepFetching || pending [ 0 ] ) ) {
827
- // pending[0] = true means that previous fetch was appending. We need to force at least one prepend
828
- // BTW there will always be at least 1 element in the pending array because bottom is fetched first
829
- if ( pending . push ( false ) === 1 ) {
830
- fetch ( rid ) ;
831
- adapter . loading ( true ) ;
810
+ } else if ( viewport . shouldLoadTop ( ) ) {
811
+ if ( ! updates || buffer . effectiveHeight ( updates . prepended ) > 0 || pending [ 0 ] ) {
812
+ // this means that at least one item appended in the last batch has height > 0
813
+ // pending[0] = true means that previous fetch was appending. We need to force at least one prepend
814
+ // BTW there will always be at least 1 element in the pending array because bottom is fetched first
815
+ if ( pending . push ( false ) === 1 ) {
816
+ fetch ( rid ) ;
817
+ adapter . loading ( true ) ;
818
+ }
832
819
}
833
820
}
834
821
}
@@ -844,12 +831,21 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
844
831
845
832
// We need the item bindings to be processed before we can do adjustment
846
833
$timeout ( function ( ) {
834
+
835
+ // show elements after data binging has been done
836
+ updates . inserted . forEach ( function ( w ) {
837
+ return w . element . removeClass ( 'ng-hide' ) ;
838
+ } ) ;
839
+ updates . prepended . forEach ( function ( w ) {
840
+ return w . element . removeClass ( 'ng-hide' ) ;
841
+ } ) ;
842
+
847
843
if ( isInvalid ( rid ) ) {
848
844
return ;
849
845
}
850
846
851
847
updatePaddings ( rid , updates ) ;
852
- enqueueFetch ( rid , true ) ;
848
+ enqueueFetch ( rid ) ;
853
849
854
850
if ( ! pending . length ) {
855
851
adapter . calculateProperties ( ) ;
@@ -860,18 +856,25 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
860
856
function adjustBufferAfterFetch ( rid ) {
861
857
var updates = updateDOM ( ) ;
862
858
863
- viewport . adjustPaddingUnbound ( updates ) ;
864
-
865
859
// We need the item bindings to be processed before we can do adjustment
866
860
$timeout ( function ( ) {
867
861
868
- viewport . adjustPaddingBound ( updates ) ;
862
+ // show elements after data binging has been done
863
+ updates . inserted . forEach ( function ( w ) {
864
+ return w . element . removeClass ( 'ng-hide' ) ;
865
+ } ) ;
866
+ updates . prepended . forEach ( function ( w ) {
867
+ return w . element . removeClass ( 'ng-hide' ) ;
868
+ } ) ;
869
+
870
+ viewport . adjustScrollTopAfterPrepend ( updates ) ;
869
871
870
872
if ( isInvalid ( rid ) ) {
871
873
return ;
872
874
}
873
875
874
- enqueueFetch ( rid , updatePaddings ( rid , updates ) ) ;
876
+ updatePaddings ( rid , updates ) ;
877
+ enqueueFetch ( rid , updates ) ;
875
878
pending . shift ( ) ;
876
879
877
880
if ( pending . length ) fetch ( rid ) ; else {
@@ -936,7 +939,7 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
936
939
function resizeAndScrollHandler ( ) {
937
940
if ( ! $rootScope . $$phase && ! adapter . isLoading && ! adapter . disabled ) {
938
941
939
- enqueueFetch ( ridActual , true ) ;
942
+ enqueueFetch ( ridActual ) ;
940
943
941
944
if ( pending . length ) {
942
945
unbindEvents ( ) ;
0 commit comments