@@ -58,8 +58,12 @@ define([
58
58
recordsCache : [ ] ,
59
59
draggableElement : { } ,
60
60
draggableElementClass : '_dragged' ,
61
+ elemPositions : [ ] ,
61
62
listens : {
62
63
'${ $.recordsProvider }:elems' : 'setCacheRecords'
64
+ } ,
65
+ modules : {
66
+ parentComponent : '${ $.recordsProvider }'
63
67
}
64
68
} ,
65
69
@@ -189,7 +193,9 @@ define([
189
193
pageY = isTouchDevice ? event . originalEvent . touches [ 0 ] . pageY : event . pageY ,
190
194
positionY = pageY - drEl . eventMousedownY ;
191
195
192
- drEl . depElement = this . getDepElement ( drEl . instance , positionY ) ;
196
+ drEl . depElement = this . getDepElement ( drEl . instance , positionY , this . draggableElement . originRow ) ;
197
+
198
+ drEl . instance . remove ( ) ;
193
199
194
200
if ( drEl . depElement ) {
195
201
depElementCtx = this . getRecord ( drEl . depElement . elem [ 0 ] ) ;
@@ -210,7 +216,6 @@ define([
210
216
this . body . unbind ( 'mouseup' , this . mouseupHandler ) ;
211
217
}
212
218
213
- drEl . instance . remove ( ) ;
214
219
this . draggableElement = { } ;
215
220
} ,
216
221
@@ -224,11 +229,34 @@ define([
224
229
setPosition : function ( depElem , depElementCtx , dragData ) {
225
230
var depElemPosition = ~ ~ depElementCtx . position ;
226
231
232
+ this . cacheElementsPosition ( ) ;
233
+
227
234
if ( dragData . depElement . insert === 'after' ) {
228
235
dragData . instanceCtx . position = depElemPosition + 1 ;
229
236
} else if ( dragData . depElement . insert === 'before' ) {
230
237
dragData . instanceCtx . position = depElemPosition ;
231
238
}
239
+
240
+ this . normalizePositions ( ) ;
241
+ } ,
242
+
243
+ /**
244
+ * Saves elements position from current elements
245
+ */
246
+ cacheElementsPosition : function ( ) {
247
+ this . elemPositions = [ ] ;
248
+ this . parentComponent ( ) . elems . each ( function ( elem ) {
249
+ this . elemPositions . push ( elem . position ) ;
250
+ } , this ) ;
251
+ } ,
252
+
253
+ /**
254
+ * Normalize position, uses start elements position
255
+ */
256
+ normalizePositions : function ( ) {
257
+ this . parentComponent ( ) . elems . each ( function ( item , index ) {
258
+ item . position = this . elemPositions [ index ] ;
259
+ } , this ) ;
232
260
} ,
233
261
234
262
/**
0 commit comments