@@ -219,17 +219,19 @@ angular.module('dndLists', [])
219
219
* CSS classes:
220
220
* - dndPlaceholder When an element is dragged over the list, a new placeholder child
221
221
* element will be added. This element is of type li and has the class
222
- * dndPlaceholder set.
222
+ * dndPlaceholder set. Alternatively, you can define your own placeholder
223
+ * by creating a child element with dndPlaceholder class.
223
224
* - dndDragover Will be added to the list while an element is dragged over the list.
224
225
*/
225
226
. directive ( 'dndList' , [ '$parse' , '$timeout' , 'dndDropEffectWorkaround' , 'dndDragTypeWorkaround' ,
226
227
function ( $parse , $timeout , dndDropEffectWorkaround , dndDragTypeWorkaround ) {
227
228
return function ( scope , element , attr ) {
228
229
// While an element is dragged over the list, this placeholder element is inserted
229
230
// at the location where the element would be inserted after dropping
230
- var placeholder = angular . element ( "<li class='dndPlaceholder'></li>" ) ;
231
+ var placeholder = getPlaceholderElement ( ) ;
231
232
var placeholderNode = placeholder [ 0 ] ;
232
233
var listNode = element [ 0 ] ;
234
+ placeholder . remove ( ) ;
233
235
234
236
var horizontal = attr . dndHorizontalList && scope . $eval ( attr . dndHorizontalList ) ;
235
237
var externalSources = attr . dndExternalSources && scope . $eval ( attr . dndExternalSources ) ;
@@ -396,6 +398,21 @@ angular.module('dndLists', [])
396
398
return mousePointer < targetPosition + targetSize / 2 ;
397
399
}
398
400
401
+ /**
402
+ * Tries to find a child element that has the dndPlaceholder class set. If none was found, a
403
+ * new li element is created.
404
+ */
405
+ function getPlaceholderElement ( ) {
406
+ var placeholder ;
407
+ angular . forEach ( element . children ( ) , function ( childNode ) {
408
+ var child = angular . element ( childNode ) ;
409
+ if ( child . hasClass ( 'dndPlaceholder' ) ) {
410
+ placeholder = child ;
411
+ }
412
+ } ) ;
413
+ return placeholder || angular . element ( "<li class='dndPlaceholder'></li>" ) ;
414
+ }
415
+
399
416
/**
400
417
* We use the position of the placeholder node to determine at which position of the array the
401
418
* object needs to be inserted
0 commit comments