1
- /*!
2
- * angular-ui-scroll
3
- * https://github.com/angular-ui/ui-scroll.git
4
- * Version: 1.3.3 -- 2016-03-04T12:15:03.597Z
5
- * License: MIT
6
- */
7
-
8
-
9
- ( function ( ) {
1
+ /*!
2
+ * angular-ui-scroll
3
+ * https://github.com/angular-ui/ui-scroll.git
4
+ * Version: 1.3.3 -- 2016-03-11T21:07:06.923Z
5
+ * License: MIT
6
+ */
7
+
8
+
9
+ ( function ( ) {
10
10
'use strict' ;
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 ; } ;
@@ -115,7 +115,7 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
115
115
buffer . first = origin ;
116
116
buffer . next = origin ;
117
117
buffer . minIndex = Number . MAX_VALUE ;
118
- return buffer . maxIndex = Number . MIN_VALUE ;
118
+ buffer . maxIndex = Number . MIN_VALUE ;
119
119
}
120
120
121
121
angular . extend ( buffer , {
@@ -215,28 +215,9 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
215
215
return buffer ;
216
216
}
217
217
218
- function Padding ( template ) {
219
- var result = undefined ;
220
- var tagName = template . localName ;
221
-
222
- switch ( tagName ) {
223
- case 'dl' :
224
- throw new Error ( 'ui-scroll directive does not support <' + tagName + '> as a repeating tag: ' + template . outerHTML ) ;
225
- case 'tr' :
226
- var table = angular . element ( '<table><tr><td><div></div></td></tr></table>' ) ;
227
- result = table . find ( 'tr' ) ;
228
- break ;
229
- case 'li' :
230
- result = angular . element ( '<li></li>' ) ;
231
- break ;
232
- default :
233
- result = angular . element ( '<div></div>' ) ;
234
- }
235
-
236
- return result ;
237
- }
238
-
239
218
function Viewport ( buffer , element , controllers , attrs ) {
219
+ var PADDING_MIN = 0.3 ;
220
+ var PADDING_DEFAULT = 0.5 ;
240
221
var topPadding = null ;
241
222
var bottomPadding = null ;
242
223
var averageItemHeight = 0 ;
@@ -254,7 +235,7 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
254
235
} ;
255
236
256
237
function bufferPadding ( ) {
257
- return viewport . outerHeight ( ) * Math . max ( 0.1 , + attrs . padding || 0.1 ) ; // some extra space to initiate preload
238
+ return viewport . outerHeight ( ) * Math . max ( PADDING_MIN , + attrs . padding || PADDING_DEFAULT ) ; // some extra space to initiate preload
258
239
}
259
240
260
241
angular . extend ( viewport , {
@@ -263,6 +244,27 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
263
244
bottomPadding = new Padding ( template ) ;
264
245
element . before ( topPadding ) ;
265
246
element . after ( bottomPadding ) ;
247
+
248
+ function Padding ( template ) {
249
+ var result = undefined ;
250
+ var tagName = template . localName ;
251
+
252
+ switch ( tagName ) {
253
+ case 'dl' :
254
+ throw new Error ( 'ui-scroll directive does not support <' + tagName + '> as a repeating tag: ' + template . outerHTML ) ;
255
+ case 'tr' :
256
+ var table = angular . element ( '<table><tr><td><div></div></td></tr></table>' ) ;
257
+ result = table . find ( 'tr' ) ;
258
+ break ;
259
+ case 'li' :
260
+ result = angular . element ( '<li></li>' ) ;
261
+ break ;
262
+ default :
263
+ result = angular . element ( '<div></div>' ) ;
264
+ }
265
+
266
+ return result ;
267
+ }
266
268
} ,
267
269
bottomDataPos : function bottomDataPos ( ) {
268
270
var scrollHeight = viewport [ 0 ] . scrollHeight ;
@@ -366,6 +368,12 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
366
368
topPadding . height ( 0 ) ;
367
369
viewport . scrollTop ( viewport . scrollTop ( ) - paddingHeight ) ;
368
370
}
371
+ } ,
372
+ resetTopPaddingHeight : function resetTopPaddingHeight ( ) {
373
+ topPadding . height ( 0 ) ;
374
+ } ,
375
+ resetBottomPaddingHeight : function resetBottomPaddingHeight ( ) {
376
+ bottomPadding . height ( 0 ) ;
369
377
}
370
378
} ) ;
371
379
@@ -572,10 +580,8 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
572
580
viewport . createPaddingElements ( template [ 0 ] ) ;
573
581
// Destroy template's scope to remove any watchers on it.
574
582
scope . $destroy ( ) ;
575
- // also remove the template when the directive scope is destroyed
576
- $scope . $on ( '$destroy' , function ( ) {
577
- return template . remove ( ) ;
578
- } ) ;
583
+ // We don't need template anymore.
584
+ template . remove ( ) ;
579
585
} ) ;
580
586
581
587
adapter . reload = reload ;
@@ -585,10 +591,6 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
585
591
viewport . bind ( 'scroll' , resizeAndScrollHandler ) ;
586
592
viewport . bind ( 'mousewheel' , wheelHandler ) ;
587
593
588
- $scope . $watch ( datasource . revision , function ( ) {
589
- return reload ( ) ;
590
- } ) ;
591
-
592
594
$scope . $on ( '$destroy' , function ( ) {
593
595
// clear the buffer. It is necessary to remove the elements and $destroy the scopes
594
596
buffer . clear ( ) ;
@@ -597,6 +599,31 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
597
599
viewport . unbind ( 'mousewheel' , wheelHandler ) ;
598
600
} ) ;
599
601
602
+ // update events (deprecated since v1.1.0, unsupported since 1.2.0)
603
+ ( function ( ) {
604
+ var eventListener = datasource . scope ? datasource . scope . $new ( ) : $scope . $new ( ) ;
605
+
606
+ eventListener . $on ( 'insert.item' , function ( ) {
607
+ return unsupportedMethod ( 'insert' ) ;
608
+ } ) ;
609
+
610
+ eventListener . $on ( 'update.items' , function ( ) {
611
+ return unsupportedMethod ( 'update' ) ;
612
+ } ) ;
613
+
614
+ eventListener . $on ( 'delete.items' , function ( ) {
615
+ return unsupportedMethod ( 'delete' ) ;
616
+ } ) ;
617
+
618
+ function unsupportedMethod ( token ) {
619
+ throw new Error ( token + ' event is no longer supported - use applyUpdates instead' ) ;
620
+ }
621
+ } ) ( ) ;
622
+
623
+ reload ( ) ;
624
+
625
+ /* Functions definitions */
626
+
600
627
function dismissPendingRequests ( ) {
601
628
ridActual ++ ;
602
629
pending = [ ] ;
@@ -605,6 +632,9 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
605
632
function reload ( ) {
606
633
dismissPendingRequests ( ) ;
607
634
635
+ viewport . resetTopPaddingHeight ( ) ;
636
+ viewport . resetBottomPaddingHeight ( ) ;
637
+
608
638
if ( arguments . length ) {
609
639
buffer . clear ( arguments [ 0 ] ) ;
610
640
} else {
@@ -835,27 +865,6 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
835
865
event . preventDefault ( ) ;
836
866
}
837
867
}
838
-
839
- // update events (deprecated since v1.1.0, unsupported since 1.2.0)
840
- ( function ( ) {
841
- var eventListener = datasource . scope ? datasource . scope . $new ( ) : $scope . $new ( ) ;
842
-
843
- eventListener . $on ( 'insert.item' , function ( ) {
844
- return unsupportedMethod ( 'insert' ) ;
845
- } ) ;
846
-
847
- eventListener . $on ( 'update.items' , function ( ) {
848
- return unsupportedMethod ( 'update' ) ;
849
- } ) ;
850
-
851
- eventListener . $on ( 'delete.items' , function ( ) {
852
- return unsupportedMethod ( 'delete' ) ;
853
- } ) ;
854
-
855
- function unsupportedMethod ( token ) {
856
- throw new Error ( token + ' event is no longer supported - use applyUpdates instead' ) ;
857
- }
858
- } ) ( ) ;
859
868
} ;
860
869
}
861
870
} ] ) ;
0 commit comments