@@ -245,8 +245,8 @@ var ngRepeatDirective = ['$parse', '$animator', function($parse, $animator) {
245
245
//watch props
246
246
$scope . $watchCollection ( rhs , function ngRepeatAction ( collection ) {
247
247
var index , length ,
248
- cursor = $element , // current position of the node
249
- nextCursor ,
248
+ previousNode = $element [ 0 ] , // current position of the node
249
+ nextNode ,
250
250
// Same as lastBlockMap but it has the current state. It will become the
251
251
// lastBlockMap on the next iteration.
252
252
nextBlockMap = { } ,
@@ -288,7 +288,7 @@ var ngRepeatDirective = ['$parse', '$animator', function($parse, $animator) {
288
288
} else if ( nextBlockMap . hasOwnProperty ( trackById ) ) {
289
289
// restore lastBlockMap
290
290
forEach ( nextBlockOrder , function ( block ) {
291
- if ( block && block . element ) lastBlockMap [ block . id ] = block ;
291
+ if ( block && block . startNode ) lastBlockMap [ block . id ] = block ;
292
292
} ) ;
293
293
// This is a duplicate and we need to throw an error
294
294
throw ngError ( 50 , "ngRepeat error! Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys. Repeater: {0}, Duplicate key: {1}" ,
@@ -304,8 +304,8 @@ var ngRepeatDirective = ['$parse', '$animator', function($parse, $animator) {
304
304
for ( key in lastBlockMap ) {
305
305
if ( lastBlockMap . hasOwnProperty ( key ) ) {
306
306
block = lastBlockMap [ key ] ;
307
- animate . leave ( block . element ) ;
308
- forEach ( block . element , function ( element ) { element [ NG_REMOVED ] = true } ) ;
307
+ animate . leave ( block . elements ) ;
308
+ forEach ( block . elements , function ( element ) { element [ NG_REMOVED ] = true } ) ;
309
309
block . scope . $destroy ( ) ;
310
310
}
311
311
}
@@ -316,24 +316,23 @@ var ngRepeatDirective = ['$parse', '$animator', function($parse, $animator) {
316
316
value = collection [ key ] ;
317
317
block = nextBlockOrder [ index ] ;
318
318
319
- if ( block . element ) {
319
+ if ( block . startNode ) {
320
320
// if we have already seen this object, then we need to reuse the
321
321
// associated scope/element
322
322
childScope = block . scope ;
323
323
324
- nextCursor = cursor [ 0 ] ;
324
+ nextNode = previousNode ;
325
325
do {
326
- nextCursor = nextCursor . nextSibling ;
327
- } while ( nextCursor && nextCursor [ NG_REMOVED ] ) ;
326
+ nextNode = nextNode . nextSibling ;
327
+ } while ( nextNode && nextNode [ NG_REMOVED ] ) ;
328
328
329
- if ( block . element [ 0 ] == nextCursor ) {
329
+ if ( block . startNode == nextNode ) {
330
330
// do nothing
331
- cursor = block . element ;
332
331
} else {
333
332
// existing item which got moved
334
- animate . move ( block . element , null , cursor ) ;
335
- cursor = block . element ;
333
+ animate . move ( block . elements , null , jqLite ( previousNode ) ) ;
336
334
}
335
+ previousNode = block . endNode ;
337
336
} else {
338
337
// new item which we don't know about
339
338
childScope = $scope . $new ( ) ;
@@ -346,12 +345,14 @@ var ngRepeatDirective = ['$parse', '$animator', function($parse, $animator) {
346
345
childScope . $last = ( index === ( arrayLength - 1 ) ) ;
347
346
childScope . $middle = ! ( childScope . $first || childScope . $last ) ;
348
347
349
- if ( ! block . element ) {
348
+ if ( ! block . startNode ) {
350
349
linker ( childScope , function ( clone ) {
351
- animate . enter ( clone , null , cursor ) ;
352
- cursor = clone ;
350
+ animate . enter ( clone , null , jqLite ( previousNode ) ) ;
351
+ previousNode = clone ;
353
352
block . scope = childScope ;
354
- block . element = clone ;
353
+ block . startNode = clone [ 0 ] ;
354
+ block . elements = clone ;
355
+ block . endNode = clone [ clone . length - 1 ] ;
355
356
nextBlockMap [ block . id ] = block ;
356
357
} ) ;
357
358
}
0 commit comments