@@ -82,6 +82,7 @@ angular.module('ui.scroll', [])
82
82
itemScope[itemName] = item
83
83
wrapper =
84
84
scope : itemScope
85
+ item : item
85
86
86
87
linker itemScope, (clone ) ->
87
88
wrapper .element = clone
@@ -287,7 +288,7 @@ angular.module('ui.scroll', [])
287
288
viewportScope = viewport .scope () || $rootScope
288
289
289
290
topVisible = (item ) ->
290
- adapter .topVisible = item .scope [itemName]
291
+ adapter .topVisible = item .item
291
292
adapter .topVisibleElement = item .element
292
293
adapter .topVisibleScope = item .scope
293
294
$parse ($attr .topVisible ).assign (viewportScope, adapter .topVisible ) if $attr .topVisible
@@ -512,52 +513,56 @@ angular.module('ui.scroll', [])
512
513
513
514
# adapter setup
514
515
515
- adapter = {}
516
- adapter .isLoading = false
517
- adapter .reload = reloadImpl
518
-
519
- applyUpdate = (wrapper , newItems ) ->
520
- if angular .isArray newItems
521
- pos = (buffer .indexOf wrapper) + 1
522
- for newItem,i in newItems .reverse ()
523
- if newItem == wrapper .scope [itemName]
524
- keepIt = true ;
525
- pos--
516
+ Adapter = (buffer , adjustBuffer ) ->
517
+ this .isLoading = false
518
+ this .reload = reloadImpl
519
+
520
+ applyUpdate = (wrapper , newItems ) ->
521
+ if angular .isArray newItems
522
+ pos = (buffer .indexOf wrapper) + 1
523
+ for newItem,i in newItems .reverse ()
524
+ if newItem == wrapper .item
525
+ keepIt = true ;
526
+ pos--
527
+ else
528
+ buffer .insert pos, newItem
529
+ unless keepIt
530
+ wrapper .op = ' remove'
531
+
532
+ this .applyUpdates = (arg1 , arg2 ) ->
533
+ if angular .isFunction arg1
534
+ # arg1 is the updater function, arg2 is ignored
535
+ bufferClone = buffer .slice (0 )
536
+ for wrapper,i in bufferClone # we need to do it on the buffer clone, because buffer content
537
+ # may change as we iterate through
538
+ applyUpdate wrapper, arg1 (wrapper .item , wrapper .scope , wrapper .element )
539
+ else
540
+ # arg1 is item index, arg2 is the newItems array
541
+ if arg1% 1 == 0 # checking if it is an integer
542
+ if 0 <= arg1- buffer .first < buffer .length
543
+ applyUpdate buffer[arg1 - buffer .first ], arg2
526
544
else
527
- buffer .insert pos, newItem
528
- unless keepIt
529
- wrapper .op = ' remove'
545
+ throw new Error ' applyUpdates - ' + arg1 + ' is not a valid index'
546
+ adjustBuffer ()
530
547
531
- adapter .applyUpdates = (arg1 , arg2 ) ->
532
- dismissPendingRequests ()
533
- if angular .isFunction arg1
534
- # arg1 is the updater function, arg2 is ignored
535
- bufferClone = buffer .slice (0 )
536
- for wrapper,i in bufferClone # we need to do it on the buffer clone, because buffer content
537
- # may change as we iterate through
538
- applyUpdate wrapper, arg1 (wrapper .scope [itemName], wrapper .scope , wrapper .element )
539
- else
540
- # arg1 is item index, arg2 is the newItems array
541
- if arg1% 1 == 0 # checking if it is an integer
542
- if 0 <= arg1- buffer .first < buffer .length
543
- applyUpdate buffer[arg1 - buffer .first ], arg2
544
- else
545
- throw new Error ' applyUpdates - ' + arg1 + ' is not a valid index'
546
- adjustBuffer ridActual
548
+ this .append = (newItems ) ->
549
+ for item in newItems
550
+ ++ buffer .next
551
+ buffer .insert ' append' , item
552
+ adjustBuffer ()
547
553
548
- adapter .append = (newItems ) ->
549
- dismissPendingRequests ()
550
- for item in newItems
551
- ++ buffer .next
552
- buffer .insert ' append' , item
553
- adjustBuffer ridActual
554
+ this .prepend = (newItems ) ->
555
+ for item in newItems .reverse ()
556
+ -- buffer .first
557
+ buffer .insert ' prepend' , item
558
+ adjustBuffer ()
554
559
555
- adapter . prepend = ( newItems ) ->
556
- dismissPendingRequests ()
557
- for item in newItems . reverse ()
558
- -- buffer . first
559
- buffer . insert ' prepend ' , item
560
- adjustBuffer ridActual
560
+ return
561
+
562
+ adapter = new Adapter buffer,
563
+ ->
564
+ dismissPendingRequests ()
565
+ adjustBuffer ridActual
561
566
562
567
if $attr .adapter # so we have an adapter on $scope
563
568
adapterOnScope = $parse ($attr .adapter )($scope)
@@ -567,7 +572,6 @@ angular.module('ui.scroll', [])
567
572
angular .extend (adapterOnScope, adapter)
568
573
adapter = adapterOnScope
569
574
570
-
571
575
# update events (deprecated since v1.1.0, unsupported since 1.2.0)
572
576
573
577
unsupportedMethod = (token ) ->
0 commit comments