@@ -124,6 +124,8 @@ angular.module('ui.scroll', [])
124
124
125
125
buffer .next = 1
126
126
127
+
128
+
127
129
buffer
128
130
129
131
Padding = (template ) ->
@@ -297,6 +299,15 @@ angular.module('ui.scroll', [])
297
299
setTopVisibleElement (viewportScope, item .element )
298
300
setTopVisibleScope (viewportScope, item .scope )
299
301
302
+ if $attr .isLoading
303
+ setIsLoading = $parse ($attr .isLoading ).assign
304
+ else
305
+ setIsLoading = ->
306
+
307
+ this .loading = (value ) ->
308
+ this .isLoading = value
309
+ setIsLoading viewportScope, value
310
+
300
311
return
301
312
302
313
require : [' ?^uiScrollViewport' ]
@@ -311,7 +322,7 @@ angular.module('ui.scroll', [])
311
322
itemName = match[1 ]
312
323
datasourceName = match[2 ]
313
324
314
-
325
+ bufferSize = Math . max ( 3 , + attr . bufferSize || 10 )
315
326
316
327
($scope , element , $attr , controllers , linker ) ->
317
328
@@ -325,12 +336,10 @@ angular.module('ui.scroll', [])
325
336
if ! isDatasourceValid ()
326
337
throw new Error datasourceName + ' is not a valid datasource'
327
338
328
- bufferSize = Math .max (3 , + $attr .bufferSize || 10 )
329
-
330
- # initial settings
331
-
332
339
ridActual = 0 # current data revision id
340
+
333
341
pending = []
342
+
334
343
buffer = new Buffer (itemName, $scope, linker)
335
344
336
345
viewport = new Viewport (buffer, element, controllers, $attr .padding )
@@ -347,19 +356,7 @@ angular.module('ui.scroll', [])
347
356
adapterOnScope = $parse ($attr .adapter )($scope)
348
357
angular .extend (adapterOnScope, adapter)
349
358
adapter = adapterOnScope
350
- ###
351
- setTopVisible = (item) ->
352
-
353
- viewportScope = viewport.scope() || $rootScope
354
-
355
- adapter.topVisible = item.item
356
- adapter.topVisibleElement = item.element
357
- adapter.topVisibleScope = item.scope
358
- $parse($attr.topVisible).assign(viewportScope, adapter.topVisible) if $attr.topVisible
359
- $parse($attr.topVisibleElement).assign(viewportScope, adapter.topVisibleElement) if $attr.topVisibleElement
360
- $parse($attr.topVisibleScope).assign(viewportScope, adapter.topVisibleScope) if $attr.topVisibleScope
361
- datasource.topVisible(item) if angular.isFunction(datasource.topVisible)
362
- ###
359
+
363
360
calculateProperties = ->
364
361
if (buffer .length > 0 )
365
362
buffer .elementHeight = (buffer[buffer .length - 1 ].element .offset ().top +
@@ -376,8 +373,9 @@ angular.module('ui.scroll', [])
376
373
else
377
374
adapter .setTopVisible (item) if newRow
378
375
break
376
+ console .log " min=#{ datasource .minIndex } max=#{ datasource .maxIndex } "
379
377
380
- # Padding element builder
378
+ # Build padding elements
381
379
#
382
380
# Calling linker is the only way I found to get access to the tag name of the template
383
381
# to prevent the directive scope from pollution a new scope is created and destroyed
@@ -391,11 +389,6 @@ angular.module('ui.scroll', [])
391
389
# also remove the template when the directive scope is destroyed
392
390
$scope .$on ' $destroy' , -> template .remove ()
393
391
394
- loading = (value ) ->
395
- adapter .isLoading = value
396
- $parse ($attr .isLoading ).assign ($scope, value) if $attr .isLoading
397
- datasource .loading (value) if angular .isFunction (datasource .loading )
398
-
399
392
dismissPendingRequests = () ->
400
393
ridActual++
401
394
pending = []
@@ -411,7 +404,7 @@ angular.module('ui.scroll', [])
411
404
412
405
enqueueFetch = (rid , direction )->
413
406
if ! adapter .isLoading
414
- loading (true )
407
+ adapter . loading (true )
415
408
if pending .push (direction) == 1
416
409
fetch (rid)
417
410
@@ -521,7 +514,7 @@ angular.module('ui.scroll', [])
521
514
522
515
pending .shift ()
523
516
if pending .length == 0
524
- loading (false )
517
+ adapter . loading (false )
525
518
calculateProperties ()
526
519
else
527
520
fetch (rid)
@@ -546,6 +539,10 @@ angular.module('ui.scroll', [])
546
539
++ buffer .next
547
540
buffer .insert ' append' , item
548
541
# log 'appended: requested ' + bufferSize + ' received ' + result.length + ' buffer size ' + buffer.length + ' first ' + first + ' next ' + next
542
+ if buffer .eof
543
+ datasource .maxIndex = buffer .next - 1
544
+ else
545
+ datasource .maxIndex = Math .max buffer .next - 1 , datasource .maxIndex || Number .MIN_VALUE
549
546
adjustBufferAfterFetch rid
550
547
else
551
548
if buffer .length && ! viewport .shouldLoadTop ()
@@ -565,6 +562,10 @@ angular.module('ui.scroll', [])
565
562
-- buffer .first
566
563
buffer .insert ' prepend' , result[i]
567
564
# log 'prepended: requested ' + bufferSize + ' received ' + result.length + ' buffer size ' + buffer.length + ' first ' + first + ' next ' + next
565
+ if buffer .bof
566
+ datasource .minIndex = buffer .first
567
+ else
568
+ datasource .minIndex = Math .min buffer .first , datasource .minIndex || Number .MAX_VALUE
568
569
adjustBufferAfterFetch rid
569
570
570
571
0 commit comments