ui-tree.js 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. var UITree = function () {
  2. return {
  3. //main function to initiate the module
  4. init: function () {
  5. // handle collapse/expand for tree_1
  6. $('#tree_1_collapse').click(function () {
  7. $('.tree-toggle', $('#tree_1 > li > ul')).addClass("closed");
  8. $('.branch', $('#tree_1 > li > ul')).removeClass("in");
  9. });
  10. $('#tree_1_expand').click(function () {
  11. $('.tree-toggle', $('#tree_1 > li > ul')).removeClass("closed");
  12. $('.branch', $('#tree_1 > li > ul')).addClass("in");
  13. });
  14. // handle collapse/expand for tree_2
  15. $('#tree_2_collapse').click(function () {
  16. $('.tree-toggle', $('#tree_2 > li > ul')).addClass("closed");
  17. $('.branch', $('#tree_2 > li > ul')).removeClass("in");
  18. });
  19. $('#tree_2_expand').click(function () {
  20. //$('.tree-toggle', $('#tree_2 > li > ul')).removeClass("closed");
  21. // iterate tree nodes and exppand all nodes
  22. $('.tree-toggle', $('#tree_2 > li > ul')).each(function () {
  23. $(this).click(); //trigger tree node click
  24. });
  25. $('.branch', $('#tree_2 > li > ul')).addClass("in");
  26. });
  27. //This is a quick example of capturing the select event on tree leaves, not branches
  28. $("#tree_1").on("nodeselect.tree.data-api", "[data-role=leaf]", function (e) {
  29. var output = "";
  30. output += "Node nodeselect event fired:\n";
  31. output += "Node Type: leaf\n";
  32. output += "Value: " + ((e.node.value) ? e.node.value : e.node.el.text()) + "\n";
  33. output += "Parentage: " + e.node.parentage.join("/");
  34. alert(output);
  35. });
  36. //This is a quick example of capturing the select event on tree branches, not leaves
  37. $("#tree_1").on("nodeselect.tree.data-api", "[role=branch]", function (e) {
  38. var output = "Node nodeselect event fired:\n"; + "Node Type: branch\n" + "Value: " + ((e.node.value) ? e.node.value : e.node.el.text()) + "\n" + "Parentage: " + e.node.parentage.join("/") + "\n"
  39. alert(output);
  40. });
  41. //Listening for the 'openbranch' event. Look for e.node, which is the actual node the user opens
  42. $("#tree_1").on("openbranch.tree", "[data-toggle=branch]", function (e) {
  43. var output = "Node openbranch event fired:\n" + "Node Type: branch\n" + "Value: " + ((e.node.value) ? e.node.value : e.node.el.text()) + "\n" + "Parentage: " + e.node.parentage.join("/") + "\n"
  44. alert(output);
  45. });
  46. //Listening for the 'closebranch' event. Look for e.node, which is the actual node the user closed
  47. $("#tree_1").on("closebranch.tree", "[data-toggle=branch]", function (e) {
  48. var output = "Node closebranch event fired:\n" + "Node Type: branch\n" + "Value: " + ((e.node.value) ? e.node.value : e.node.el.text()) + "\n" + "Parentage: " + e.node.parentage.join("/") + "\n"
  49. alert(output);
  50. });
  51. }
  52. };
  53. }();