ui-nestable.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. var UINestable = function () {
  2. var updateOutput = function (e) {
  3. var list = e.length ? e : $(e.target),
  4. output = list.data('output');
  5. if (window.JSON) {
  6. output.val(window.JSON.stringify(list.nestable('serialize'))); //, null, 2));
  7. } else {
  8. output.val('JSON browser support required for this demo.');
  9. }
  10. };
  11. return {
  12. //main function to initiate the module
  13. init: function () {
  14. // activate Nestable for list 1
  15. $('#nestable_list_1').nestable({
  16. group: 1
  17. })
  18. .on('change', updateOutput);
  19. // activate Nestable for list 2
  20. $('#nestable_list_2').nestable({
  21. group: 1
  22. })
  23. .on('change', updateOutput);
  24. // output initial serialised data
  25. updateOutput($('#nestable_list_1').data('output', $('#nestable_list_1_output')));
  26. updateOutput($('#nestable_list_2').data('output', $('#nestable_list_2_output')));
  27. $('#nestable_list_menu').on('click', function (e) {
  28. var target = $(e.target),
  29. action = target.data('action');
  30. if (action === 'expand-all') {
  31. $('.dd').nestable('expandAll');
  32. }
  33. if (action === 'collapse-all') {
  34. $('.dd').nestable('collapseAll');
  35. }
  36. });
  37. $('#nestable_list_3').nestable();
  38. }
  39. };
  40. }();