treeview.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. (function (global, factory) {
  2. if (typeof define === "function" && define.amd) {
  3. define("/advanced/treeview", ["jquery", "Site"], factory);
  4. } else if (typeof exports !== "undefined") {
  5. factory(require("jquery"), require("Site"));
  6. } else {
  7. var mod = {
  8. exports: {}
  9. };
  10. factory(global.jQuery, global.Site);
  11. global.advancedTreeview = mod.exports;
  12. }
  13. })(this, function (_jquery, _Site) {
  14. "use strict";
  15. _jquery = babelHelpers.interopRequireDefault(_jquery);
  16. (0, _jquery.default)(document).ready(function ($$$1) {
  17. (0, _Site.run)();
  18. });
  19. window.getExampleTreeview = function () {
  20. return [{
  21. text: 'Parent 1',
  22. href: '#parent1',
  23. tags: ['4'],
  24. nodes: [{
  25. text: 'Child 1',
  26. href: '#child1',
  27. tags: ['2'],
  28. nodes: [{
  29. text: 'Grandchild 1',
  30. href: '#grandchild1',
  31. tags: ['0']
  32. }, {
  33. text: 'Grandchild 2',
  34. href: '#grandchild2',
  35. tags: ['0']
  36. }]
  37. }, {
  38. text: 'Child 2',
  39. href: '#child2',
  40. tags: ['0']
  41. }]
  42. }, {
  43. text: 'Parent 2',
  44. href: '#parent2',
  45. tags: ['0']
  46. }, {
  47. text: 'Parent 3',
  48. href: '#parent3',
  49. tags: ['0']
  50. }, {
  51. text: 'Parent 4',
  52. href: '#parent4',
  53. tags: ['0']
  54. }, {
  55. text: 'Parent 5',
  56. href: '#parent5',
  57. tags: ['0']
  58. }];
  59. };
  60. var defaults = Plugin.getDefaults("treeview"); // Example TreeView Json Data
  61. // --------------------------
  62. (function () {
  63. var json = '[' + '{' + '"text": "Parent 1",' + '"nodes": [' + '{' + '"text": "Child 1",' + '"nodes": [' + '{' + '"text": "Grandchild 1"' + '},' + '{' + '"text": "Grandchild 2"' + '}' + ']' + '},' + '{' + '"text": "Child 2"' + '}' + ']' + '},' + '{' + '"text": "Parent 2"' + '},' + '{' + '"text": "Parent 3"' + '},' + '{' + '"text": "Parent 4"' + '},' + '{' + '"text": "Parent 5"' + '}' + ']';
  64. var json_options = _jquery.default.extend({}, defaults, {
  65. data: json
  66. });
  67. (0, _jquery.default)('#exampleJsonData').treeview(json_options);
  68. })(); // Example TreeView Searchable
  69. // ---------------------------
  70. (function () {
  71. var options = _jquery.default.extend({}, defaults, {
  72. data: getExampleTreeview()
  73. });
  74. var $searchableTree = (0, _jquery.default)('#exampleSearchableTree').treeview(options);
  75. (0, _jquery.default)('#inputSearchable').on('keyup', function (e) {
  76. var pattern = (0, _jquery.default)(e.target).val();
  77. var results = $searchableTree.treeview('search', [pattern, {
  78. 'ignoreCase': true,
  79. 'exactMatch': false
  80. }]);
  81. });
  82. })(); // Example TreeView Expandible
  83. // ---------------------------
  84. (function () {
  85. var options = _jquery.default.extend({}, defaults, {
  86. data: getExampleTreeview()
  87. }); // Expandible
  88. var $expandibleTree = (0, _jquery.default)('#exampleExpandibleTree').treeview(options); // Expand/collapse all
  89. (0, _jquery.default)('#exampleExpandAll').on('click', function (e) {
  90. $expandibleTree.treeview('expandAll', {
  91. levels: '99'
  92. });
  93. });
  94. (0, _jquery.default)('#exampleCollapseAll').on('click', function (e) {
  95. $expandibleTree.treeview('collapseAll');
  96. });
  97. })(); // Example TreeView Events
  98. // -----------------------
  99. (function () {
  100. // Events
  101. var events_toastr = function events_toastr(msg) {
  102. toastr.info(msg, '', {
  103. iconClass: 'toast-just-text toast-info',
  104. positionClass: 'toast-bottom-right',
  105. containertId: 'toast-bottom-right'
  106. });
  107. };
  108. var options = _jquery.default.extend({}, defaults, {
  109. data: getExampleTreeview(),
  110. onNodeCollapsed: function onNodeCollapsed(event, node) {
  111. events_toastr(node.text + ' was collapsed');
  112. },
  113. onNodeExpanded: function onNodeExpanded(event, node) {
  114. events_toastr(node.text + ' was expanded');
  115. },
  116. onNodeSelected: function onNodeSelected(event, node) {
  117. events_toastr(node.text + ' was selected');
  118. },
  119. onNodeUnselected: function onNodeUnselected(event, node) {
  120. events_toastr(node.text + ' was unselected');
  121. }
  122. });
  123. (0, _jquery.default)('#exampleEvents').treeview(options);
  124. })(); // Example jstree use JSON format
  125. // ------------------------
  126. (function () {
  127. (0, _jquery.default)('#jstreeExample_3').jstree({
  128. 'core': {
  129. 'data': [{
  130. 'text': 'Simple root node',
  131. "icon": "wb-folder"
  132. }, {
  133. 'text': 'Root node 2',
  134. "icon": "wb-folder",
  135. 'state': {
  136. 'opened': false,
  137. 'selected': true
  138. },
  139. 'children': [{
  140. 'text': 'Child 1',
  141. "icon": "wb-folder"
  142. }, {
  143. 'text': 'Child 2',
  144. "icon": "wb-folder"
  145. }]
  146. }]
  147. }
  148. });
  149. })(); // Example jstree use AJAX
  150. // ------------------------
  151. (function () {
  152. (0, _jquery.default)('#jstreeExample_4').jstree({
  153. 'core': {
  154. 'data': {
  155. "url": "../../assets/data/treeview_jstree.json",
  156. "dataType": "json"
  157. }
  158. }
  159. });
  160. })(); // Example jstree use checkbox Plugin
  161. // ------------------------------------
  162. (function () {
  163. (0, _jquery.default)('#jstreeExample_5').jstree({
  164. 'core': {
  165. 'data': [{
  166. 'text': 'Simple root node',
  167. "icon": "wb-folder"
  168. }, {
  169. 'text': 'Root node 2',
  170. "icon": "wb-folder",
  171. 'state': {
  172. 'opened': true,
  173. 'selected': true
  174. },
  175. 'children': [{
  176. 'text': 'Child 1',
  177. "icon": "wb-folder"
  178. }, {
  179. 'text': 'Child 2',
  180. "icon": "wb-folder"
  181. }]
  182. }]
  183. },
  184. 'plugins': ['checkbox']
  185. });
  186. })(); // Example jstree use Contextmenu Plugin
  187. // ------------------------------------
  188. (function () {
  189. (0, _jquery.default)('#jstreeExample_6').jstree({
  190. 'core': {
  191. "check_callback": true,
  192. 'data': [{
  193. 'text': 'Simple root node',
  194. "icon": "wb-folder"
  195. }, {
  196. 'text': 'Root node 2',
  197. "icon": "wb-folder",
  198. 'state': {
  199. 'opened': true,
  200. 'selected': true
  201. },
  202. 'children': [{
  203. 'text': 'Child 1',
  204. "icon": "wb-folder"
  205. }, {
  206. 'text': 'Child 2',
  207. "icon": "wb-folder"
  208. }]
  209. }]
  210. },
  211. 'plugins': ['contextmenu']
  212. });
  213. })(); // Example jstree use Search Plugin
  214. // --------------------------------
  215. (function () {
  216. (0, _jquery.default)('#jstreeExample_7').jstree({
  217. 'core': {
  218. 'data': [{
  219. 'text': 'Simple root node',
  220. "icon": "wb-folder"
  221. }, {
  222. 'text': 'Root node 2',
  223. "icon": "wb-folder",
  224. 'state': {
  225. 'opened': true,
  226. 'selected': true
  227. },
  228. 'children': [{
  229. 'text': 'Child 1',
  230. "icon": "wb-folder"
  231. }, {
  232. 'text': 'Child 2',
  233. "icon": "wb-folder"
  234. }]
  235. }]
  236. },
  237. 'plugins': ['search']
  238. });
  239. var to = false;
  240. (0, _jquery.default)('#jstreeSearch').keyup(function () {
  241. if (to) {
  242. clearTimeout(to);
  243. }
  244. to = setTimeout(function () {
  245. var v = (0, _jquery.default)('#jstreeSearch').val();
  246. (0, _jquery.default)('#jstreeExample_7').jstree(true).search(v);
  247. }, 250);
  248. });
  249. })(); // Example jstree use Drag & drop Plugin
  250. // -------------------------------------
  251. (function () {
  252. (0, _jquery.default)('#jstreeExample_8').jstree({
  253. 'core': {
  254. "check_callback": true,
  255. 'data': [{
  256. 'text': 'Simple root node',
  257. "icon": "wb-folder"
  258. }, {
  259. 'text': 'Root node 2',
  260. "icon": "wb-folder",
  261. 'state': {
  262. 'opened': true,
  263. 'selected': true
  264. },
  265. 'children': [{
  266. 'text': 'Child 1',
  267. "icon": "wb-folder"
  268. }, {
  269. 'text': 'Child 2',
  270. "icon": "wb-folder"
  271. }]
  272. }]
  273. },
  274. 'plugins': ['dnd']
  275. });
  276. })();
  277. });