I have a jQuery mobile list which has a swipe to delete function and stores preferences locally. I am trying to implement a functionality to re-order the list items and store this within the same array, please help! Here is my fiddle: http://jsfiddle.net/f18nfz/nUSUB/2/
So the function could be something like (http://jsfiddle.net/maziar/P2XDc/):
function moveUp(item) {
var prev = item.prev();
if (prev.length == 0)
return;
prev.css('z-index', 999).css('position','relative').animate({ top: item.height() }, 250);
item.css('z-index', 1000).css('position', 'relative').animate({ top: '-' + prev.height() }, 300, function () {
prev.css('z-index', '').css('top', '').css('position', '');
item.css('z-index', '').css('top', '').css('position', '');
item.insertBefore(prev);
});
}
function moveDown(item) {
var next = item.next();
if (next.length == 0)
return;
next.css('z-index', 999).css('position', 'relative').animate({ top: '-' + item.height() }, 250);
item.css('z-index', 1000).css('position', 'relative').animate({ top: next.height() }, 300, function () {
next.css('z-index', '').css('top', '').css('position', '');
item.css('z-index', '').css('top', '').css('position', '');
item.insertAfter(next);
});
}
$(".FieldContainer").sortable({ items: ".OrderingField", distance: 10 });
$('button').click(function() {
var btn = $(this);
var val = btn.val();
if (val == 'up')
moveUp(btn.parents('.OrderingField'));
else
moveDown(btn.parents('.OrderingField'));
});
Here is a nice example of a sortable drag&drop list with jQuery Mobile: http://jsfiddle.net/sidonaldson/pes2d/