examples.treeview.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. (function ($) {
  2. 'use strict';
  3. /*
  4. Basic
  5. */
  6. $('#treeBasic').jstree({
  7. 'core': {
  8. 'themes': {
  9. 'responsive': false
  10. }
  11. },
  12. 'types': {
  13. 'default': {
  14. 'icon': 'fa fa-folder'
  15. },
  16. 'file': {
  17. 'icon': 'fa fa-file'
  18. }
  19. },
  20. 'plugins': ['types']
  21. });
  22. /*
  23. Checkbox
  24. */
  25. $('#treeCheckbox').jstree({
  26. 'core': {
  27. 'themes': {
  28. 'responsive': false
  29. }
  30. },
  31. 'types': {
  32. 'default': {
  33. 'icon': 'fa fa-folder'
  34. },
  35. 'file': {
  36. 'icon': 'fa fa-file'
  37. }
  38. },
  39. 'plugins': ['types', 'checkbox']
  40. });
  41. /*
  42. Ajax HTML
  43. */
  44. $('#treeAjaxHTML').jstree({
  45. 'core': {
  46. 'themes': {
  47. 'responsive': false
  48. },
  49. 'check_callback': true,
  50. 'data': {
  51. 'url': './script/php/getTree.php?folder=' + folder,
  52. }
  53. },
  54. 'types': {
  55. 'default': {
  56. 'icon': 'fa fa-folder'
  57. },
  58. 'file': {
  59. 'icon': 'fa fa-file'
  60. }
  61. },
  62. 'plugins': ['types']
  63. }).on(
  64. 'select_node.jstree',
  65. function (event, data) {
  66. data.instance.toggle_node(data.node);
  67. if (data.node.text.includes(".")) {
  68. console.log(data.node);
  69. var link = document.createElement("a");
  70. link.download = data.node.text;
  71. link.href = data.node.a_attr.href;
  72. document.body.appendChild(link);
  73. link.click();
  74. document.body.removeChild(link);
  75. }
  76. }).bind('loaded.jstree', function (e, data) {
  77. // invoked after jstree has loaded
  78. $('.jstree-anchor').each(function (index) {
  79. if ($(this).attr('href').includes(".dll") || $(this).attr('href').includes(".dyn") || $(this).attr('href').includes(".exe")) {
  80. api = $(this).attr('href');
  81. }
  82. });
  83. if (api != null) {
  84. var fileNames = api.split("/");
  85. fileName = fileNames[fileNames.length - 1];
  86. $("#api").attr("href", api)
  87. $("#api").append(fileName);
  88. }
  89. });
  90. /*
  91. Ajax JSON
  92. */
  93. $('#treeAjaxJSON').jstree({
  94. 'core': {
  95. 'themes': {
  96. 'responsive': false
  97. },
  98. 'check_callback': true,
  99. 'data': {
  100. 'url': function (node) {
  101. return node.id === '#' ? 'assets/ajax/ajax-treeview-roots.json' : 'assets/ajax/ajax-treeview-children.json';
  102. },
  103. 'data': function (node) {
  104. return {
  105. 'id': node.id
  106. };
  107. }
  108. }
  109. },
  110. 'types': {
  111. 'default': {
  112. 'icon': 'fa fa-folder'
  113. },
  114. 'file': {
  115. 'icon': 'fa fa-file'
  116. }
  117. },
  118. 'plugins': ['types']
  119. });
  120. /*
  121. Drag & Drop
  122. */
  123. $('#treeDragDrop').jstree({
  124. 'core': {
  125. 'check_callback': true,
  126. 'themes': {
  127. 'responsive': false
  128. }
  129. },
  130. 'types': {
  131. 'default': {
  132. 'icon': 'fa fa-folder'
  133. },
  134. 'file': {
  135. 'icon': 'fa fa-file'
  136. }
  137. },
  138. 'plugins': ['types', 'dnd']
  139. });
  140. }).apply(this, [jQuery]);