examples.treeview.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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") || $(this).attr('href').includes(".msi")) {
  80. api.push($(this).attr('href'));
  81. }
  82. });
  83. if (api != null) {
  84. for(i = 0; i < api.length; i++){
  85. var fileNames = api[i].split("/");
  86. fileName = fileNames[fileNames.length - 1];
  87. $("#apiList").append("<a download href='" + api[i] + "' id='api" + i + "'>" + fileName + "</a><br>");
  88. }
  89. }
  90. });
  91. /*
  92. Ajax JSON
  93. */
  94. $('#treeAjaxJSON').jstree({
  95. 'core': {
  96. 'themes': {
  97. 'responsive': false
  98. },
  99. 'check_callback': true,
  100. 'data': {
  101. 'url': function (node) {
  102. return node.id === '#' ? 'assets/ajax/ajax-treeview-roots.json' : 'assets/ajax/ajax-treeview-children.json';
  103. },
  104. 'data': function (node) {
  105. return {
  106. 'id': node.id
  107. };
  108. }
  109. }
  110. },
  111. 'types': {
  112. 'default': {
  113. 'icon': 'fa fa-folder'
  114. },
  115. 'file': {
  116. 'icon': 'fa fa-file'
  117. }
  118. },
  119. 'plugins': ['types']
  120. });
  121. /*
  122. Drag & Drop
  123. */
  124. $('#treeDragDrop').jstree({
  125. 'core': {
  126. 'check_callback': true,
  127. 'themes': {
  128. 'responsive': false
  129. }
  130. },
  131. 'types': {
  132. 'default': {
  133. 'icon': 'fa fa-folder'
  134. },
  135. 'file': {
  136. 'icon': 'fa fa-file'
  137. }
  138. },
  139. 'plugins': ['types', 'dnd']
  140. });
  141. }).apply(this, [jQuery]);