@@ -158,7 +158,20 @@ window.ionic = {
158
158
return null
159
159
} ,
160
160
161
- getChildIndex : function ( element ) {
161
+ getChildIndex : function ( element , type ) {
162
+ if ( type ) {
163
+ var ch = element . parentNode . children ;
164
+ var c ;
165
+ for ( var i = 0 , k = 0 , j = ch . length ; i < j ; i ++ ) {
166
+ c = ch [ i ] ;
167
+ if ( c . nodeName && c . nodeName . toLowerCase ( ) == type ) {
168
+ if ( c == element ) {
169
+ return k ;
170
+ }
171
+ k ++ ;
172
+ }
173
+ }
174
+ }
162
175
return Array . prototype . slice . call ( element . parentNode . children ) . indexOf ( element ) ;
163
176
} ,
164
177
swapNodes : function ( src , dest ) {
@@ -1838,6 +1851,17 @@ window.ionic = {
1838
1851
*/
1839
1852
ionic . Utils = {
1840
1853
1854
+ arrayMove : function ( arr , old_index , new_index ) {
1855
+ if ( new_index >= arr . length ) {
1856
+ var k = new_index - arr . length ;
1857
+ while ( ( k -- ) + 1 ) {
1858
+ arr . push ( undefined ) ;
1859
+ }
1860
+ }
1861
+ arr . splice ( new_index , 0 , arr . splice ( old_index , 1 ) [ 0 ] ) ;
1862
+ return arr ;
1863
+ } ,
1864
+
1841
1865
/**
1842
1866
* Return a function that will be called with the given context
1843
1867
*/
@@ -3062,6 +3086,7 @@ window.ionic = {
3062
3086
3063
3087
var ReorderDrag = function ( opts ) {
3064
3088
this . dragThresholdY = opts . dragThresholdY || 0 ;
3089
+ this . onReorder = opts . onReorder ;
3065
3090
this . el = opts . el ;
3066
3091
} ;
3067
3092
@@ -3074,6 +3099,8 @@ window.ionic = {
3074
3099
// Grab the starting Y point for the item
3075
3100
var offsetY = this . el . offsetTop ; //parseFloat(this.el.style.webkitTransform.replace('translate3d(', '').split(',')[1]) || 0;
3076
3101
3102
+ var startIndex = ionic . DomUtil . getChildIndex ( this . el , this . el . nodeName . toLowerCase ( ) ) ;
3103
+
3077
3104
var placeholder = this . el . cloneNode ( true ) ;
3078
3105
3079
3106
placeholder . classList . add ( ITEM_PLACEHOLDER_CLASS ) ;
@@ -3082,9 +3109,9 @@ window.ionic = {
3082
3109
3083
3110
this . el . classList . add ( ITEM_REORDERING_CLASS ) ;
3084
3111
3085
-
3086
3112
this . _currentDrag = {
3087
3113
startOffsetTop : offsetY ,
3114
+ startIndex : startIndex ,
3088
3115
placeholder : placeholder
3089
3116
} ;
3090
3117
} ;
@@ -3150,10 +3177,12 @@ window.ionic = {
3150
3177
this . el . classList . remove ( ITEM_REORDERING_CLASS ) ;
3151
3178
this . el . style . top = 0 ;
3152
3179
3153
- var finalPosition = ionic . DomUtil . getChildIndex ( placeholder ) ;
3180
+ var finalPosition = ionic . DomUtil . getChildIndex ( placeholder , placeholder . nodeName . toLowerCase ( ) ) ;
3154
3181
placeholder . parentNode . insertBefore ( this . el , placeholder ) ;
3155
3182
placeholder . parentNode . removeChild ( placeholder ) ;
3156
3183
3184
+ this . onReorder && this . onReorder ( this . el , this . _currentDrag . startIndex , finalPosition ) ;
3185
+
3157
3186
this . _currentDrag = null ;
3158
3187
doneCallback && doneCallback ( ) ;
3159
3188
} ;
@@ -3169,6 +3198,7 @@ window.ionic = {
3169
3198
var _this = this ;
3170
3199
3171
3200
opts = ionic . extend ( {
3201
+ onReorder : function ( el , oldIndex , newIndex ) { } ,
3172
3202
virtualRemoveThreshold : - 200 ,
3173
3203
virtualAddThreshold : 200
3174
3204
} , opts ) ;
@@ -3292,7 +3322,12 @@ window.ionic = {
3292
3322
var item = this . _getItem ( e . target ) ;
3293
3323
3294
3324
if ( item ) {
3295
- this . _dragOp = new ReorderDrag ( { el : item } ) ;
3325
+ this . _dragOp = new ReorderDrag ( {
3326
+ el : item ,
3327
+ onReorder : function ( el , start , end ) {
3328
+ _this . onReorder && _this . onReorder ( el , start , end ) ;
3329
+ }
3330
+ } ) ;
3296
3331
this . _dragOp . start ( e ) ;
3297
3332
e . preventDefault ( ) ;
3298
3333
return ;
0 commit comments