Guest User

Untitled

a guest
Aug 19th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. <!-- КОДЕ подрубающий магическую сортировку:-->
  2. <%= javascript_tag do %>
  3. jQuery( function($) {
  4. $('.sortable').smmNestedSortable({
  5. 'serializer':function() {
  6. var spec = $('.sortable').smmNestedSortable.jsonSerializer.buildSpec("first");
  7. $("#spec").html("<b>json output</b><br /><br />"+ spec);
  8. updateOrder(spec);
  9. }
  10. });
  11. });
  12.  
  13. jQuery( function($) {
  14. $('#test').smmNestedSortable({
  15. 'serializer':function() {
  16. var spec1 = $('#test').smmNestedSortable.jsonSerializer.buildSpec("last");
  17. $("#spec").html("<b>json output</b><br /><br />"+ spec1);
  18. updateOrder(spec1);
  19. }
  20. });
  21. });
  22.  
  23. function updateOrder(mass)
  24. {
  25. jQuery.post('<%= update_sort_path -%>', { 'mass' : mass })
  26. }
  27. <% end %>
  28.  
  29. <!-- Кодэ исходнеГ плагина -->
  30.  
  31. $.fn.smmNestedSortable.jsonSerializer = {
  32. 'buildSpec': function() {
  33. var spec = [];
  34. jQuery("ul.sortable:first").children().each(function() {
  35. spec.push($.fn.smmNestedSortable.jsonSerializer._buildSpec($(this)));
  36. });
  37. return $.toJSON(spec);
  38. },
  39. '_buildSpec': function(liList) {
  40. var spec = [];
  41. liList.each(function() {
  42. if(this.id != 'empty') {
  43. var li=this;
  44. var node = {
  45. title: li.id
  46. };
  47. node.children = $.fn.smmNestedSortable.jsonSerializer._buildSpec(jQuery(li).children("ul").children("li"));
  48. spec.push(node);
  49. }
  50. });
  51. return spec;
  52. }
  53. };
  54.  
  55. <!-- Проблема в том, что магия сортировки работает на оба списка и на .sortable и на #test, но json output приходит только по тому списку, который первым идет на HTML страничке -->
Add Comment
Please, Sign In to add comment