1:- module(jquery_tree, [load_jquery_tree/1]). 2 3load_jquery_tree('<script\n src="https://code.jquery.com/jquery-1.11.2.min.js"\n integrity="sha256-Ls0pXSlb7AYs7evhd+VLnWsZ/AqEHcXBeMZUycz/CcA="\n crossorigin="anonymous"></script>\n\n<script type="text/javascript">\n (function($){\n $.fn.depth = function(options,depth) {\n options = options || {};\n options.delay = options.delay || 0;\n \n this.find("> li").each(function() {\n e = $(this)\n var subtree = e.find(\'> ul\');\n\n if (subtree.length > 0) {\n if (depth > 0) {\n e.addClass(\'tree-opened\');\n e.removeClass(\'tree-closed\');\n\n subtree.slideDown(options.delay);\n subtree.show(options.delay);\n\n subtree.depth(options,depth-1);\n } else {\n e.removeClass(\'tree-opened\');\n e.addClass(\'tree-closed\');\n\n subtree.slideUp(options.delay);\n subtree.hide(options.delay);\n\n subtree.collapse(options);\n }\n }\n });\n return true;\n }\n \n $.fn.expand = function(options,depth) {\n options = options || {};\n options.delay = options.delay || 0;\n \n this.find("> li").each(function() {\n e = $(this)\n var subtree = e.find(\'> ul\');\n\n if (subtree.length > 0) {\n e.addClass(\'tree-opened\');\n e.removeClass(\'tree-closed\');\n\n subtree.slideDown(options.delay);\n subtree.show(options.delay);\n\n subtree.expand(options,depth+1);\n }\n g_depth=Math.max(g_depth,depth);\n });\n return true;\n }\n\n $.fn.collapse = function(options) {\n options = options || {};\n options.delay = options.delay || 0;\n \n this.find("> li").each(function() {\n e = $(this)\n var subtree = e.find(\'> ul\');\n\n if (subtree.length > 0) {\n e.removeClass(\'tree-opened\');\n e.addClass(\'tree-closed\');\n\n subtree.slideUp(options.delay);\n subtree.hide(options.delay);\n\n subtree.collapse(options);\n } \n });\n return true;\n }\n \n $.fn.treemenu = function(options) {\n options = options || {};\n options.delay = options.delay || 0;\n options.openActive = options.openActive || false;\n options.closeOther = options.closeOther || false;\n options.activeSelector = options.activeSelector || ".active";\n\n this.addClass("treemenu");\n\n if (!options.nonroot) {\n this.addClass("treemenu-root");\n }\n\n options.nonroot = true;\n\n this.find("> li").each(function() {\n e = $(this);\n var subtree = e.find(\'> ul\');\n var button = e.find(\'.toggler\').eq(0);\n\n if(button.length == 0) {\n // create toggler\n var button = $(\'<span>\');\n button.addClass(\'toggler\');\n e.prepend(button);\n }\n\n if(subtree.length > 0) {\n subtree.hide();\n\n e.addClass(\'tree-closed\');\n\n e.find(button).click(function() {\n var li = $(this).parent(\'li\');\n\n if (options.closeOther && li.hasClass(\'tree-closed\')) {\n var siblings = li.parent(\'ul\').find("li:not(.tree-empty)");\n siblings.removeClass("tree-opened");\n siblings.addClass("tree-closed");\n siblings.removeClass(options.activeSelector);\n siblings.find(\'> ul\').slideUp(options.delay);\n }\n\n li.find(\'> ul\').slideToggle(options.delay);\n li.toggleClass(\'tree-opened\');\n li.toggleClass(\'tree-closed\');\n li.toggleClass(options.activeSelector);\n });\n\n $(this).find(\'> ul\').treemenu(options);\n } else {\n $(this).addClass(\'tree-empty\');\n }\n });\n\n if (options.openActive) {\n var cls = this.attr("class");\n\n this.find(options.activeSelector).each(function(){\n var el = $(this).parent();\n\n while (el.attr("class") !== cls) {\n el.find(\'> ul\').show();\n if(el.prop("tagName") === \'UL\') {\n el.show();\n } else if (el.prop("tagName") === \'LI\') {\n el.removeClass(\'tree-closed\');\n el.addClass("tree-opened");\n el.show();\n }\n\n el = el.parent();\n }\n });\n }\n\n expand({delay:0},0);\n max_depth = g_depth;\n this.collapse({delay:0});\n g_depth = 0;\n\n return this;\n }\n })(jQuery);\n\nvar g_depth = 0;\nvar max_depth = 4\n\nfunction depth(step){\n g_depth = g_depth + step;\n g_depth = g_depth < 0 ? 0 : g_depth;\n g_depth = g_depth > max_depth ? max_depth : g_depth;\n $(".tree").depth({delay:500},g_depth);\n}\n\nfunction expand(){\n g_depth = 0 \n $(".tree").expand({delay:0},0);\n}\n\nfunction collapse(){\n $(".tree").collapse({delay:0});\n g_depth = 0; \n}\n\n$(function(){\n $(".tree").treemenu({delay:0}).openActive();\n});\n\n</script>\n')