Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 22nd, 2012  |  syntax: None  |  size: 0.87 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. returning a draggable li to its original index
  2. $item.data('originalParent', $(this).prev());
  3.        
  4. .insertAfter( $item.data('originalParent') )
  5.        
  6. <ul list="1">
  7.     <li list="1" item="1"></li>
  8.     <li list="1" item="2"></li>
  9. </ul>
  10. <ul list="2">
  11.     <li list="2" item="1"></li>
  12.     <li list="2" item="2"></li>
  13. </ul>
  14.        
  15. list =  $(this).attr('list');
  16. item =  $(this).attr('item');
  17. // store this list and item variable data with the div or parent of where ever the list item was dropped
  18.        
  19. if (item == 1)
  20. {
  21.     // the list item being restored is the first so prepend it to the beginning of the list it came from
  22.     element.prependTo( $('ul[list=' + list + ']') );
  23. }
  24. else
  25. {
  26.     // 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
  27.     element.insertAfter( $('ul[list=' + list + '] li[item=' + (item - 1) + ']') );
  28. }