@@ -158,7 +158,20 @@ window.ionic = {
158158 return null
159159 } ,
160160
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+ }
162175 return Array . prototype . slice . call ( element . parentNode . children ) . indexOf ( element ) ;
163176 } ,
164177 swapNodes : function ( src , dest ) {
@@ -1838,6 +1851,17 @@ window.ionic = {
18381851 */
18391852 ionic . Utils = {
18401853
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+
18411865 /**
18421866 * Return a function that will be called with the given context
18431867 */
@@ -3062,6 +3086,7 @@ window.ionic = {
30623086
30633087 var ReorderDrag = function ( opts ) {
30643088 this . dragThresholdY = opts . dragThresholdY || 0 ;
3089+ this . onReorder = opts . onReorder ;
30653090 this . el = opts . el ;
30663091 } ;
30673092
@@ -3074,6 +3099,8 @@ window.ionic = {
30743099 // Grab the starting Y point for the item
30753100 var offsetY = this . el . offsetTop ; //parseFloat(this.el.style.webkitTransform.replace('translate3d(', '').split(',')[1]) || 0;
30763101
3102+ var startIndex = ionic . DomUtil . getChildIndex ( this . el , this . el . nodeName . toLowerCase ( ) ) ;
3103+
30773104 var placeholder = this . el . cloneNode ( true ) ;
30783105
30793106 placeholder . classList . add ( ITEM_PLACEHOLDER_CLASS ) ;
@@ -3082,9 +3109,9 @@ window.ionic = {
30823109
30833110 this . el . classList . add ( ITEM_REORDERING_CLASS ) ;
30843111
3085-
30863112 this . _currentDrag = {
30873113 startOffsetTop : offsetY ,
3114+ startIndex : startIndex ,
30883115 placeholder : placeholder
30893116 } ;
30903117 } ;
@@ -3150,10 +3177,12 @@ window.ionic = {
31503177 this . el . classList . remove ( ITEM_REORDERING_CLASS ) ;
31513178 this . el . style . top = 0 ;
31523179
3153- var finalPosition = ionic . DomUtil . getChildIndex ( placeholder ) ;
3180+ var finalPosition = ionic . DomUtil . getChildIndex ( placeholder , placeholder . nodeName . toLowerCase ( ) ) ;
31543181 placeholder . parentNode . insertBefore ( this . el , placeholder ) ;
31553182 placeholder . parentNode . removeChild ( placeholder ) ;
31563183
3184+ this . onReorder && this . onReorder ( this . el , this . _currentDrag . startIndex , finalPosition ) ;
3185+
31573186 this . _currentDrag = null ;
31583187 doneCallback && doneCallback ( ) ;
31593188 } ;
@@ -3169,6 +3198,7 @@ window.ionic = {
31693198 var _this = this ;
31703199
31713200 opts = ionic . extend ( {
3201+ onReorder : function ( el , oldIndex , newIndex ) { } ,
31723202 virtualRemoveThreshold : - 200 ,
31733203 virtualAddThreshold : 200
31743204 } , opts ) ;
@@ -3292,7 +3322,12 @@ window.ionic = {
32923322 var item = this . _getItem ( e . target ) ;
32933323
32943324 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+ } ) ;
32963331 this . _dragOp . start ( e ) ;
32973332 e . preventDefault ( ) ;
32983333 return ;
0 commit comments