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 ( ) {
1010'use strict' ;
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 ; } ;
@@ -115,7 +115,7 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
115115 buffer . first = origin ;
116116 buffer . next = origin ;
117117 buffer . minIndex = Number . MAX_VALUE ;
118- return buffer . maxIndex = Number . MIN_VALUE ;
118+ buffer . maxIndex = Number . MIN_VALUE ;
119119 }
120120
121121 angular . extend ( buffer , {
@@ -215,28 +215,9 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
215215 return buffer ;
216216 }
217217
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-
239218 function Viewport ( buffer , element , controllers , attrs ) {
219+ var PADDING_MIN = 0.3 ;
220+ var PADDING_DEFAULT = 0.5 ;
240221 var topPadding = null ;
241222 var bottomPadding = null ;
242223 var averageItemHeight = 0 ;
@@ -254,7 +235,7 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
254235 } ;
255236
256237 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
258239 }
259240
260241 angular . extend ( viewport , {
@@ -263,6 +244,27 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
263244 bottomPadding = new Padding ( template ) ;
264245 element . before ( topPadding ) ;
265246 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+ }
266268 } ,
267269 bottomDataPos : function bottomDataPos ( ) {
268270 var scrollHeight = viewport [ 0 ] . scrollHeight ;
@@ -366,6 +368,12 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
366368 topPadding . height ( 0 ) ;
367369 viewport . scrollTop ( viewport . scrollTop ( ) - paddingHeight ) ;
368370 }
371+ } ,
372+ resetTopPaddingHeight : function resetTopPaddingHeight ( ) {
373+ topPadding . height ( 0 ) ;
374+ } ,
375+ resetBottomPaddingHeight : function resetBottomPaddingHeight ( ) {
376+ bottomPadding . height ( 0 ) ;
369377 }
370378 } ) ;
371379
@@ -572,10 +580,8 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
572580 viewport . createPaddingElements ( template [ 0 ] ) ;
573581 // Destroy template's scope to remove any watchers on it.
574582 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 ( ) ;
579585 } ) ;
580586
581587 adapter . reload = reload ;
@@ -585,10 +591,6 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
585591 viewport . bind ( 'scroll' , resizeAndScrollHandler ) ;
586592 viewport . bind ( 'mousewheel' , wheelHandler ) ;
587593
588- $scope . $watch ( datasource . revision , function ( ) {
589- return reload ( ) ;
590- } ) ;
591-
592594 $scope . $on ( '$destroy' , function ( ) {
593595 // clear the buffer. It is necessary to remove the elements and $destroy the scopes
594596 buffer . clear ( ) ;
@@ -597,6 +599,31 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
597599 viewport . unbind ( 'mousewheel' , wheelHandler ) ;
598600 } ) ;
599601
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+
600627 function dismissPendingRequests ( ) {
601628 ridActual ++ ;
602629 pending = [ ] ;
@@ -605,6 +632,9 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
605632 function reload ( ) {
606633 dismissPendingRequests ( ) ;
607634
635+ viewport . resetTopPaddingHeight ( ) ;
636+ viewport . resetBottomPaddingHeight ( ) ;
637+
608638 if ( arguments . length ) {
609639 buffer . clear ( arguments [ 0 ] ) ;
610640 } else {
@@ -835,27 +865,6 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
835865 event . preventDefault ( ) ;
836866 }
837867 }
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- } ) ( ) ;
859868 } ;
860869 }
861870} ] ) ;
0 commit comments