
Untitled
By: a guest on
May 22nd, 2012 | syntax:
None | size: 0.87 KB | hits: 11 | expires: Never
returning a draggable li to its original index
$item.data('originalParent', $(this).prev());
.insertAfter( $item.data('originalParent') )
<ul list="1">
<li list="1" item="1"></li>
<li list="1" item="2"></li>
</ul>
<ul list="2">
<li list="2" item="1"></li>
<li list="2" item="2"></li>
</ul>
list = $(this).attr('list');
item = $(this).attr('item');
// store this list and item variable data with the div or parent of where ever the list item was dropped
if (item == 1)
{
// the list item being restored is the first so prepend it to the beginning of the list it came from
element.prependTo( $('ul[list=' + list + ']') );
}
else
{
// the list item is not the first so find the item before it in the list it came from and insert it after that list item
element.insertAfter( $('ul[list=' + list + '] li[item=' + (item - 1) + ']') );
}