+ // subroutine: Move itemContents in i2 into i1
+ function moveItemContents( vl, i1, i2 ) {
+ // TODO: Find a efficient way to replace data!
+ // Assumption: i1 and i2 has same children.
+ var NODETYPE = { ELEMENT_NODE: 1, TEXT_NODE: 3 },
+ c1, // child item 1 (old)
+ c2, // child item 2 (new)
+ newText,
+ newImg,
+ i;
+
+ $( i1 ).find( ".ui-li-text-main", ".ui-li-text-sub", ".ui-li-text-sub2", "ui-btn-text" ).each( function ( index ) {
+ c1 = $( this );
+ newText = $( i2 ).find( ".ui-li-text-main", ".ui-li-text-sub", "ui-btn-text" ).eq( index ).text();
+
+ $( c1 ).contents().filter( function () {
+ return ( this.nodeType == NODETYPE.TEXT_NODE );
+ } ).get( 0 ).data = newText;
+ } );
+
+ $( i1 ).find( "img" ).each( function ( imgIdx ) {
+ var c1 = $( this );
+ newImg = $( i2 ).find( "img" ).eq( imgIdx ).attr( "src" );
+
+ $( c1 ).attr( "src", newImg );
+ } );
+
+ $( i1 ).removeData( ); // Clear old data
+ }
+
+ // subroutine: Move item
+ function moveItem( vl, fromIdx, toIdx ) {
+ var itemData, // data from itemData()
+ item, // item element
+ newItem, // new item element
+ tmpl; // template
+
+ log( ">> move item: " + fromIdx + " --> " + toIdx );
+
+ // Find current item
+ item = $( '#' + vl.options.itemIDPrefix + fromIdx ); // TODO: refactor ID generation!
+ if ( ! item ) {
+ return false;
+ }
+
+ // Get new item
+ tmpl = $( "#" + vl.options.template );
+ newItem = tmpl.tmpl( vl._itemData( toIdx ) );
+
+ // TODO: Consider touch block while moving?
+
+ // Move item contents
+ moveItemContents( vl, item, newItem );
+
+ // clean up temporary item
+ newItem.remove();
+
+ // Move position, and set id
+ item.css( 'top', toIdx * vl._line_h )
+ .attr( 'id' , vl.options.itemIDPrefix + toIdx ); // TODO: refactor ID generation!
+
+ // TODO: Apply jqmdata? check following old code;
+ // $( oldItem ).removeData( ); // Clear old data
+ // if (key) { $( oldItem ).data( key, $( newItem ).data( key ) ); }
+
+ return true;
+ }
+
+