1
1
/*!
2
2
* angular-ui-scroll
3
3
* https://github.com/angular-ui/ui-scroll.git
4
- * Version: 1.3.2 -- 2015-10-09T10:33:17.514Z
4
+ * Version: 1.3.2 -- 2015-10-27T14:48:21.672Z
5
5
* License: MIT
6
6
*/
7
7
@@ -41,9 +41,10 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function() {
41
41
transclude : 'element' ,
42
42
priority : 1000 ,
43
43
terminal : true ,
44
- compile : function ( elementTemplate , attr , linker ) {
45
- return function ( $scope , element , $attr , controllers ) {
46
- var adapter , adapterOnScope , adjustBuffer , adjustBufferAfterFetch , applyUpdate , bof , bottomVisiblePos , buffer , bufferPadding , bufferSize , builder , calculateTopProperties , clipBottom , clipTop , datasource , datasourceName , dismissPendingRequests , enqueueFetch , eof , eventListener , fetch , first , insertElement , insertElementAnimated , insertItem , insertWrapperContent , isAngularVersionLessThen1_3 , isDatasourceValid , isElementVisible , itemName , loading , log , match , next , pending , processBufferedItems , reload , removeFromBuffer , removeItem , resizeAndScrollHandler , ridActual , scrollHeight , shouldLoadBottom , shouldLoadTop , topVisible , topVisiblePos , unsupportedMethod , viewport , viewportScope , visibilityWatcher , wheelHandler ;
44
+ compile : function ( elementTemplate , attr , compileLinker ) {
45
+ return function ( $scope , element , $attr , controllers , linker ) {
46
+ var Buffer , adapter , adapterOnScope , adjustBuffer , adjustBufferAfterFetch , applyUpdate , bof , bottomVisiblePos , buffer , bufferPadding , bufferSize , builder , calculateTopProperties , clipBottom , clipTop , datasource , datasourceName , dismissPendingRequests , enqueueFetch , eof , eventListener , fetch , first , insertElement , insertElementAnimated , insertItem , insertWrapperContent , isAngularVersionLessThen1_3 , isDatasourceValid , isElementVisible , itemName , loading , log , match , next , pending , processBufferedItems , reload , resizeAndScrollHandler , ridActual , scrollHeight , shouldLoadBottom , shouldLoadTop , topVisible , topVisiblePos , unsupportedMethod , viewport , viewportScope , visibilityWatcher , wheelHandler ;
47
+ linker = linker || compileLinker ;
47
48
log = console . debug || console . log ;
48
49
if ( ! ( match = $attr . uiScroll . match ( / ^ \s * ( \w + ) \s + i n \s + ( [ \w \. ] + ) \s * $ / ) ) ) {
49
50
throw new Error ( 'Expected uiScroll in form of \'_item_ in _datasource_\' but got \'' + $attr . uiScroll + '\'' ) ;
@@ -68,37 +69,7 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function() {
68
69
var ref ;
69
70
return ( ref = elem [ 0 ] . scrollHeight ) != null ? ref : elem [ 0 ] . document . documentElement . scrollHeight ;
70
71
} ;
71
- builder = null ;
72
- ridActual = 0 ;
73
- first = 1 ;
74
- next = 1 ;
75
- buffer = [ ] ;
76
- pending = [ ] ;
77
- eof = false ;
78
- bof = false ;
79
72
isAngularVersionLessThen1_3 = angular . version . major === 1 && angular . version . minor < 3 ;
80
- removeItem = $animate ? isAngularVersionLessThen1_3 ? function ( wrapper ) {
81
- var deferred ;
82
- buffer . splice ( buffer . indexOf ( wrapper ) , 1 ) ;
83
- deferred = $q . defer ( ) ;
84
- $animate . leave ( wrapper . element , function ( ) {
85
- wrapper . scope . $destroy ( ) ;
86
- return deferred . resolve ( ) ;
87
- } ) ;
88
- return [ deferred . promise ] ;
89
- } : function ( wrapper ) {
90
- buffer . splice ( buffer . indexOf ( wrapper ) , 1 ) ;
91
- return [
92
- ( $animate . leave ( wrapper . element ) ) . then ( function ( ) {
93
- return wrapper . scope . $destroy ( ) ;
94
- } )
95
- ] ;
96
- } : function ( wrapper ) {
97
- buffer . splice ( buffer . indexOf ( wrapper ) , 1 ) ;
98
- wrapper . element . remove ( ) ;
99
- wrapper . scope . $destroy ( ) ;
100
- return [ ] ;
101
- } ;
102
73
insertElement = function ( newElement , previousElement ) {
103
74
element . after . apply ( previousElement , [ newElement ] ) ;
104
75
return [ ] ;
@@ -113,6 +84,64 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function() {
113
84
} : function ( newElement , previousElement ) {
114
85
return [ $animate . enter ( newElement , element , previousElement ) ] ;
115
86
} : insertElement ;
87
+ Buffer = function ( ) {
88
+ var buffer , remove ;
89
+ buffer = Object . create ( Array . prototype ) ;
90
+ if ( $animate ) {
91
+ if ( isAngularVersionLessThen1_3 ) {
92
+ remove = function ( wrapper ) {
93
+ var deferred ;
94
+ buffer . splice ( buffer . indexOf ( wrapper ) , 1 ) ;
95
+ deferred = $q . defer ( ) ;
96
+ $animate . leave ( wrapper . element , function ( ) {
97
+ wrapper . scope . $destroy ( ) ;
98
+ return deferred . resolve ( ) ;
99
+ } ) ;
100
+ return [ deferred . promise ] ;
101
+ } ;
102
+ } else {
103
+ remove = function ( wrapper ) {
104
+ buffer . splice ( buffer . indexOf ( wrapper ) , 1 ) ;
105
+ return [
106
+ ( $animate . leave ( wrapper . element ) ) . then ( function ( ) {
107
+ return wrapper . scope . $destroy ( ) ;
108
+ } )
109
+ ] ;
110
+ } ;
111
+ }
112
+ } else {
113
+ remove = function ( wrapper ) {
114
+ buffer . splice ( buffer . indexOf ( wrapper ) , 1 ) ;
115
+ wrapper . element . remove ( ) ;
116
+ wrapper . scope . $destroy ( ) ;
117
+ return [ ] ;
118
+ } ;
119
+ }
120
+ buffer . remove = function ( arg1 , arg2 ) {
121
+ var i , j , ref , ref1 ;
122
+ if ( angular . isNumber ( arg1 ) ) {
123
+ for ( i = j = ref = arg1 , ref1 = arg2 ; ref <= ref1 ? j < ref1 : j > ref1 ; i = ref <= ref1 ? ++ j : -- j ) {
124
+ buffer [ i ] . scope . $destroy ( ) ;
125
+ buffer [ i ] . element . remove ( ) ;
126
+ }
127
+ return buffer . splice ( arg1 , arg2 - arg1 ) ;
128
+ } else {
129
+ return remove ( arg1 ) ;
130
+ }
131
+ } ;
132
+ buffer . clear = function ( ) {
133
+ return buffer . remove ( 0 , buffer . length ) ;
134
+ } ;
135
+ return buffer ;
136
+ } ;
137
+ builder = null ;
138
+ ridActual = 0 ;
139
+ first = 1 ;
140
+ next = 1 ;
141
+ buffer = new Buffer ( ) ;
142
+ pending = [ ] ;
143
+ eof = false ;
144
+ bof = false ;
116
145
linker ( $scope . $new ( ) , function ( template , scope ) {
117
146
var bottomPadding , padding , repeaterType , topPadding , viewport ;
118
147
scope . $destroy ( ) ;
@@ -202,14 +231,6 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function() {
202
231
return datasource . loading ( value ) ;
203
232
}
204
233
} ;
205
- removeFromBuffer = function ( start , stop ) {
206
- var i , j , ref , ref1 ;
207
- for ( i = j = ref = start , ref1 = stop ; ref <= ref1 ? j < ref1 : j > ref1 ; i = ref <= ref1 ? ++ j : -- j ) {
208
- buffer [ i ] . scope . $destroy ( ) ;
209
- buffer [ i ] . element . remove ( ) ;
210
- }
211
- return buffer . splice ( start , stop - start ) ;
212
- } ;
213
234
dismissPendingRequests = function ( ) {
214
235
ridActual ++ ;
215
236
return pending = [ ] ;
@@ -218,7 +239,7 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function() {
218
239
dismissPendingRequests ( ) ;
219
240
first = 1 ;
220
241
next = 1 ;
221
- removeFromBuffer ( 0 , buffer . length ) ;
242
+ buffer . clear ( ) ;
222
243
builder . topPadding ( 0 ) ;
223
244
builder . bottomPadding ( 0 ) ;
224
245
eof = false ;
@@ -261,7 +282,7 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function() {
261
282
}
262
283
if ( overage > 0 ) {
263
284
builder . bottomPadding ( builder . bottomPadding ( ) + bottomHeight ) ;
264
- removeFromBuffer ( buffer . length - overage , buffer . length ) ;
285
+ buffer . remove ( buffer . length - overage , buffer . length ) ;
265
286
return next -= overage ;
266
287
}
267
288
} ;
@@ -295,7 +316,7 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function() {
295
316
}
296
317
if ( overage > 0 ) {
297
318
builder . topPadding ( builder . topPadding ( ) + topHeight ) ;
298
- removeFromBuffer ( 0 , overage ) ;
319
+ buffer . remove ( 0 , overage ) ;
299
320
return first += overage ;
300
321
}
301
322
} ;
@@ -390,7 +411,7 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function() {
390
411
}
391
412
for ( k = 0 , len1 = toBeRemoved . length ; k < len1 ; k ++ ) {
392
413
wrapper = toBeRemoved [ k ] ;
393
- promises = promises . concat ( removeItem ( wrapper ) ) ;
414
+ promises = promises . concat ( buffer . remove ( wrapper ) ) ;
394
415
}
395
416
builder . bottomPadding ( Math . max ( 0 , builder . bottomPadding ( ) - ( builder . bottomDataPos ( ) - bottomPos ) ) ) ;
396
417
if ( toBePrepended . length ) {
@@ -551,12 +572,7 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function() {
551
572
viewport . bind ( 'mousewheel' , wheelHandler ) ;
552
573
$scope . $watch ( datasource . revision , reload ) ;
553
574
$scope . $on ( '$destroy' , function ( ) {
554
- var item , j , len ;
555
- for ( j = 0 , len = buffer . length ; j < len ; j ++ ) {
556
- item = buffer [ j ] ;
557
- item . scope . $destroy ( ) ;
558
- item . element . remove ( ) ;
559
- }
575
+ buffer . clear ( ) ;
560
576
viewport . unbind ( 'resize' , resizeAndScrollHandler ) ;
561
577
viewport . unbind ( 'scroll' , resizeAndScrollHandler ) ;
562
578
return viewport . unbind ( 'mousewheel' , wheelHandler ) ;
@@ -626,7 +642,7 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function() {
626
642
} ;
627
643
if ( $attr . adapter ) {
628
644
adapterOnScope = $parse ( $attr . adapter ) ( $scope ) ;
629
- if ( ! adapterOnScope ) {
645
+ if ( ! angular . isObject ( adapterOnScope ) ) {
630
646
$parse ( $attr . adapter ) . assign ( $scope , { } ) ;
631
647
adapterOnScope = $parse ( $attr . adapter ) ( $scope ) ;
632
648
}
0 commit comments