### ES6 Quickstart for Fancytree Source: https://github.com/mar10/fancytree/blob/master/README.md This snippet demonstrates how to initialize Fancytree using ES6 imports. Ensure you have jQuery and the Fancytree library installed. Loading and initialization might be asynchronous. ```javascript import $ from "jquery"; import 'jquery.fancytree/dist/skin-lion/ui.fancytree.less'; // CSS or LESS import {createTree} from 'jquery.fancytree'; import 'jquery.fancytree/dist/modules/jquery.fancytree.edit'; import 'jquery.fancytree/dist/modules/jquery.fancytree.filter'; const tree = createTree('#tree', { extensions: ['edit', 'filter'], source: {...}, ... }); // Note: Loading and initialization may be asynchronous, so the nodes may not be accessible yet. ``` -------------------------------- ### Install Fancytree Source and Tools Source: https://github.com/mar10/fancytree/wiki/HowtoContribute Commands to install Node.js, grunt-cli, and project dependencies. Run `grunt test` to check code quality and run unit tests, or `grunt dev` for development tasks. ```bash $ npm install -g grunt-cli $ cd fancytree $ npm install $ grunt test $ grunt dev ``` -------------------------------- ### Install Fancytree with npm Source: https://github.com/mar10/fancytree/wiki/Home Install Fancytree using npm for use with module bundlers like webpack. ```bash $ npm install --save jquery.fancytree ``` -------------------------------- ### Angular 8 Setup: npm Install Source: https://github.com/mar10/fancytree/wiki/tutorial/TutorialIntegration Install jQuery and Fancytree packages using npm for an Angular project. Also install the necessary type definitions. ```bash npm install jquery jquery.fancytree ``` ```bash npm install --save @types/jquery @types/jquery.fancytree ``` -------------------------------- ### Initial Data Structure Source: https://github.com/mar10/fancytree/wiki/tutorial/TutorialNodeTypes An example of a data structure where icon and tooltip information is repeated for each node. ```json [ {"title": "Books", "folder": true, "children": [ {"title": "Little Prince", "icon": "ft-ico-book", "iconTooltip": "This is a book.", "price": 1.23}, {"title": "The Hobbit", "icon": "ft-ico-book", "iconTooltip": "This is a book.", "price": 2.34} ]}, {"title": "Computers", "folder": true, "children": [ {"title": "PC", "icon": "ft-ico-computer", "iconTooltip": "This is a computer.", "price": 549.85}, {"title": "Mac", "icon": "ft-ico-computer", "iconTooltip": "This is a computer.", "price": 789.00} ]} ] ``` -------------------------------- ### Initialize Fancytree on a Web Page Source: https://github.com/mar10/fancytree/wiki/Home Demonstrates the standard setup including jQuery, the Fancytree CSS skin, the library bundle, and the initialization script. ```html [...] [...]
[...] ``` ```html ``` -------------------------------- ### Run Grunt Development Server Source: https://github.com/mar10/fancytree/blob/master/dist/skin-custom-1/README.md Execute this command in the Fancytree directory to start the development server for skin customization. Requires NPM and Grunt. ```bash grunt dev ``` -------------------------------- ### Fancytree Widget Initialization Source: https://github.com/mar10/fancytree/blob/master/demo/sample-ext-grid.html JavaScript setup for the Fancytree widget, including extension configuration and event handlers. ```javascript $(function(){ // --- Demo GUI: --------------------------------------------------- $( "#optionsForm [name=cellFocus]" ).change( function( e ) { var value = $( this ).find( ":selected" ).val(); window.sessionStorage.setItem( "cellFocus", value ); $.ui.fancytree.getTree( "#treegrid" ).setOption("ariagrid.cellFocus", value); }).val( window.sessionStorage.getItem( "cellFocus" ) || "allow" ); var modelCount = 0; // --- Fancytree widget -------------------------------------------- // var sourceUrl = getUrlParam("source"); // if( sourceUrl ){ // sourceUrl = "https://cdn.jsdelivr.net/gh/mar10/assets@master/fancytree/" + sourceUrl; // } else { // sourceUrl = "ajax-tree-products.json"; // } // var sourceUrl = getUrlParam("source"); // var sourceUrl = "../test/ajax10k_nodes.json"; // var sourceUrl = "ajax10k_nodes.json"; var sourceUrl = "https://cdn.jsdelivr.net/gh/mar10/assets@master/fancytree/ajax_101k.json"; $("#treetable").fancytree({ extensions: ["clones", "dnd5", "edit", "filter", "grid", "ariagrid"], checkbox: true, quicksearch: true, autoScroll: true, debugLevel: 5, ariagrid: { // Internal behavior flags activateCellOnDoubelclick: true, cellFocus: $( "#optionsForm [name=cellFocus]" ).find( ":selected" ).val(), // TODO: use a global tree option `name` or `title` instead?: label: "Tree Grid", // Added as `aria-label` attribute }, dnd5: { autoExpandMS: 1500, dragStart: function(node, data) { return true; }, dragEnter: function(node, data) { return true; }, dragDrop: function(node, data) { var transfer = data.dataTransfer; if( data.otherNode ) { data.otherNode.moveTo(node, data.hitMode); } else { node.addNode({ title: transfer.getData("text") }, data.hitMode); } // Expand target node when a child was created: if (data.hitMode === "over") { node.setExpanded(); } }, }, edit: { // triggerStart: ["f2", "mac+enter", "shift+click"], }, filter: { autoExpand: true, }, table: { indentation: 20, // indent 20px per node level nodeColumnIdx: 2, // render the node title into the 2nd column checkboxColumnIdx: 0, // render the checkboxes into the 1st column }, viewport: { enabled: true, count: 15, }, source: { url: sourceUrl, cache: true, }, // postProcess: function(event, data) { // // Triage: Force ext-clones to create new keys and see if we get dupes // function _walk(n) { // if( n ) { // n.refKey = n.key; // delete n.key; // if (n.children) { // for (var i=0; i < n.c ``` -------------------------------- ### Basic Variable Declaration Source: https://github.com/mar10/fancytree/wiki/specs/SpecFocus A simple JavaScript example demonstrating variable declaration and assignment. ```javascript var s = "a", i = 42; ``` -------------------------------- ### Fancytree Initialization with Viewport Options Source: https://github.com/mar10/fancytree/blob/master/demo/sample-ext-grid.html Initializes a Fancytree with viewport-related options and event handlers for various tree interactions. Includes setup for lazy loading, cell activation, default grid actions, column rendering, and viewport updates. This snippet also handles window resize events to adjust the viewport and sets up event listeners for input fields controlling viewport start and count, as well as search functionality. ```javascript init: function(event, data) { modelCount = data.tree.count(); $("#treetable caption").text("Loaded " + modelCount + " nodes."); data.tree.getNodeByKey("1.1.88").setActive(); // data.tree.getNodeByKey("10_2_1").setActive(); // Recalc the viewport's row count from the flexed size of the container: data.tree.adjustViewportSize(); // data.tree.addPagingNode(); }, lazyLoad: function(event, data) { data.result = { url: "ajax-sub2.json" } }, activateCell: function(event, data) { data.node.debug(event.type, data); }, defaultGridAction: function( event, data ) { // Called when ENTER is pressed in cell-mode. data.node.debug(event.type, data); }, renderColumns: function(event, data) { var node = data.node, $tdList = $(node.tr).find(">td"); // (index #0 is rendered by fancytree by adding the checkbox) $tdList.eq(1).text(node.getIndexHier()); //.addClass("alignRight"); // (index #2 is rendered by fancytree) $tdList.eq(3).text(node._rowIdx); // $tdList.eq(3).text(node.data.qty); $tdList.eq(4).html(""); }, updateViewport: function(event, data) { var tree = data.tree, topNode = tree.visibleNodeList[tree.viewport.start], path = (topNode && !topNode.isTopLevel()) ? topNode.getPath(false) + "/...": ""; tree.debug(event.type, data); // Display breadcrumb/parent-path in header tree.$container.find("thead th.parent-path").text(path); // Update edit controls if (!tree.isVpUpdating ) { $("input#vpStart").val(tree.viewport.start); $("input#vpCount").val(tree.viewport.count); $("span.statistics").text(", rows: " + (tree.visibleNodeList ? tree.visibleNodeList.length : "-") + "/" + modelCount ); } } }); $(window).on("resize", function(e){ // console.log(e.type, e); var tree = $.ui.fancytree.getTree(); // Resize scroll wrapper to window height: // $wrapper.height(window.innerHeight - $wrapper[0].offsetTop - BOTTOM_OFS); // Re-calculate viewport.count from current wrapper height: tree.adjustViewportSize(); }).resize(); /* Handle inputs */ $(document).on("change", "#vpStart,#vpCount", function(e){ var tree = $.ui.fancytree.getTree(), opts = { start: $("#vpStart").val(), count: $("#vpCount").val(), }; tree.setViewport(opts); }); $("input[name=search]").on("change search", function(e){ if (e.type === "change" && e.target.onsearch !== undefined ) { // We fall back to handling the change event only if the search event is not supported. return; } var n, tree = $.ui.fancytree.getTree(), match = $.trim($(this).val()); // Pass a string to perform case insensitive matching n = tree.filterNodes(match, {mode: "hide"}); // This will adjust the start value in case the filtered row set // is not inside the current viewport // tree.setViewport(); $("span.matches").text(n ? "(" + n + " matches)" : ""); }); $("#expandAll").on("click", function(e){ $.ui.fancytree.getTree().expandAll(); }); $("#collapseAll").on("click", function(e){ $.ui.fancytree.getTree().expandAll(false); }); $("#redraw").on("click", function(e){ $.ui.fancytree.getTree().redrawViewport(true); }); ``` -------------------------------- ### Fancytree Initialization and Event Handling Source: https://github.com/mar10/fancytree/blob/master/test/test-ext-grid.html JavaScript setup for the Fancytree widget including extension configuration, data loading, and event callbacks for rendering and viewport updates. ```javascript $(function(){ // --- Demo GUI: --------------------------------------------------- $( "#optionsForm [name=cellFocus]" ).change( function( e ) { var value = $( this ).find( ":selected" ).val(); window.sessionStorage.setItem( "cellFocus", value ); $.ui.fancytree.getTree( "#treegrid" ).setOption("ariagrid.cellFocus", value); }).val( window.sessionStorage.getItem( "cellFocus" ) || "allow" ); // --- Fancytree widget -------------------------------------------- // var sourceUrl = getUrlParam("source"); // if( sourceUrl ){ // sourceUrl = "https://cdn.jsdelivr.net/gh/mar10/assets@master/fancytree/" + sourceUrl; // } else { // sourceUrl = "ajax-tree-products.json"; // } // var sourceUrl = getUrlParam("source"); var sourceUrl = "ajax10k_nodes.json"; // var sourceUrl = "https://cdn.jsdelivr.net/gh/mar10/assets@master/fancytree/ajax_101k.json"; $("#treetable").fancytree({ extensions: ["dnd5", "edit", "filter", "grid", "ariagrid"], checkbox: true, quicksearch: true, autoScroll: true, debugLevel: 5, ariagrid: { // Internal behavior flags activateCellOnDoubelclick: true, cellFocus: $( "#optionsForm [name=cellFocus]" ).find( ":selected" ).val(), // TODO: use a global tree option `name` or `title` instead?: label: "Tree Grid", // Added as `aria-label` attribute }, dnd5: { autoExpandMS: 1500, dragStart: function(node, data) { return true; }, dragEnter: function(node, data) { return true; }, dragDrop: function(node, data) { var transfer = data.dataTransfer; if( data.otherNode ) { data.otherNode.moveTo(node, data.hitMode); } else { node.addNode({ title: transfer.getData("text") }, data.hitMode); } // Expand target node when a child was created: if (data.hitMode === "over") { node.setExpanded(); } }, }, edit: { // triggerStart: ["f2", "mac+enter", "shift+click"], }, filter: { autoExpand: true, }, table: { indentation: 20, // indent 20px per node level nodeColumnIdx: 2, // render the node title into the 2nd column checkboxColumnIdx: 0, // render the checkboxes into the 1st column }, viewport: { enabled: true, count: 15, }, source: { url: sourceUrl, cache: true, }, // tooltip: function(event, data){ // return data.node.data.author; // }, init: function(event, data) { $("#treetable caption").text("Loaded " + data.tree.count() + " nodes."); data.tree.getNodeByKey("10_2_1").setActive(); data.tree.adjustViewportSize(); }, lazyLoad: function(event, data) { data.result = {url: "ajax-sub2.json"} }, activateCell: function(event, data) { data.node.debug(event.type, data); }, defaultGridAction: function( event, data ) { // Called when ENTER is pressed in cell-mode. data.node.debug(event.type, data); }, renderColumns: function(event, data) { var node = data.node, $tdList = $(node.tr).find(">td"); // (index #0 is rendered by fancytree by adding the checkbox) $tdList.eq(1).text(node.getIndexHier()); //.addClass("alignRight"); // (index #2 is rendered by fancytree) $tdList.eq(3).text(node._rowIdx); // $tdList.eq(3).text(node.data.qty); $tdList.eq(4).html(""); }, updateViewport: function(event, data) { var tree = data.tree, topNode = tree.visibleNodeList[tree.viewport.start], path = (topNode && !topNode.isTopLevel()) ? topNode.getPath(false) + "/..." : ""; tree.debug(event.type, data); // Display breadcrumb/parent-path in header tree.$container.find("thead th.parent-path").text(path); // Update edit controls if (!tree.isVpUpdating ) { $("input#vpStart").val(tree.viewport.start); $("input#vpCount").val(tree.viewport.count); } }, }); $(window).on("resize", function(e){ console.log(e.type, e); var BOTTOM_OFS = 20, $wrapper = $("div.fancytree-grid-container"), tree = $.ui.fancytree.getTree(); // Resize scroll wrapper to window height: $wrapper.hei ``` -------------------------------- ### Initialize Fancytree with Persistence Options Source: https://github.com/mar10/fancytree/wiki/extensions/ExtPersist Initialize the Fancytree with the 'persist' extension enabled and configure its options. This example shows default persistence settings. ```javascript $("#tree").fancytree({ extensions: ["persist"], checkbox: true, persist: { // Available options with their default: cookieDelimiter: "~", // character used to join key strings cookiePrefix: undefined, // 'fancytree--' by default cookie: { // settings passed to jquery.cookie plugin raw: false, expires: "", path: "", domain: "", secure: false }, expandLazy: false, // true: recursively expand and load lazy nodes expandOpts: undefined, // optional `opts` argument passed to setExpanded() overrideSource: true, // true: cookie takes precedence over `source` data attributes. store: "auto", // 'cookie': use cookie, 'local': use localStore, 'session': use sessionStore types: "active expanded focus selected" // which status types to store }, [...] }); ``` -------------------------------- ### Fancytree Event Logging Setup Source: https://github.com/mar10/fancytree/blob/master/demo/sample-events.html Sets up Fancytree debug level and a helper function to log all triggered events. This is useful for understanding the event flow. ```javascript $.ui.fancytree.debugLevel = 3; // silence debug output function logEvent(event, data, msg){ // var args = Array.isArray(args) ? args.join(", ") : msg = msg ? ": " + msg : ""; $.ui.fancytree.info("Event('" + event.type + "', node=" + data.node + ")" + msg); } ``` -------------------------------- ### Fancytree Initialization with Source Array and Extensions Source: https://github.com/mar10/fancytree/wiki/tutorial/WhatsNew This example demonstrates initializing Fancytree with a source array containing nested node data and enabling extensions like 'clones' and 'edit'. ```javascript $"#tree".fancytree({ extensions: ["clones", "edit"], autoCollapse: true, // Pass an array of nodes (and child nodes) source: [ {title: "Node 1", folder: true, lazy: true, treeMode: "variant", keyType:"root", key: "_famtree_", refKey: "_famtree_", ``` -------------------------------- ### Configure Font Awesome 3.2 Glyph Mapping Source: https://github.com/mar10/fancytree/wiki/extensions/ExtGlyph Setup for Font Awesome 3.2 using the skin-awesome theme and the awesome3 preset. ```html ``` ```js map: { _addClass: "", checkbox: "icon-check-empty", checkboxSelected: "icon-check", checkboxUnknown: "icon-check icon-muted", dragHelper: "icon-caret-right", dropMarker: "icon-caret-right", error: "icon-exclamation-sign", expanderClosed: "icon-caret-right", expanderLazy: "icon-angle-right", expanderOpen: "icon-caret-down", loading: "icon-refresh icon-spin", nodata: "icon-meh", noExpander: "", radio: "icon-circle-blank", radioSelected: "icon-circle", // Default node icons. // (Use tree.options.icon callback to define custom icons based on node data) doc: "icon-file-alt", docOpen: "icon-file-alt", folder: "icon-folder-close-alt", folderOpen: "icon-folder-open-alt" } ``` -------------------------------- ### Server-Side Persistence Logic (Python/CherryPy Pseudo-code) Source: https://github.com/mar10/fancytree/wiki/extensions/ExtPersist Example Python code demonstrating how a server can evaluate expanded node keys from a cookie and include nested children in the response to handle persistence for lazy-loaded trees. ```python def get_child_data_list(node_key, expanded_key_list): """Return an array of child definitions for a given parent key.""" # Read `node` objects from our database child_node_list = get_child_nodes(node_key) # Convert nodes to an array of Fancytree data dicts result_list = [] for node in child_node_list: data = {"title": node.name, "key": node.guid, "lazy": True} # If a node is listed in the cookie as expanded, also load its children # recursively if node.guid in expanded_key_list: data["expanded"] = True data["children"] = get_child_data_list(node.guid, expanded_key_list) result_list.append(data) return result_list @cherrypy.exposed def getTreeNodes(rootKey): """This is the web service handler, called by Fancytree's `lazyLoad`.""" if rootKey == "root": # Client requests initial top level nodes: also deliver expanded children expanded_key_list = get_cookie_value("fancytree-1-expanded").split("~") else: # Client requests children of a lazy node expanded_key_list = [] # Get the (potentially nested) array of child node definitions result_list = get_child_data_list(rootKey, expanded_key_list) # and return the result as JSON return to_json(result_list) ``` -------------------------------- ### Fancytree Node Structure Example Source: https://github.com/mar10/fancytree/wiki/specs/SpecMarkup Illustrates the standard HTML output for a Fancytree node with a sub-node, including classes for styling and structure. Note the `tabindex="0"` for keyboard navigation. ```html
``` -------------------------------- ### Custom Session Storage Provider for Fancytree Persistence Source: https://github.com/mar10/fancytree/wiki/extensions/ExtPersist Example of implementing a custom storage provider for Fancytree persistence using window.sessionStorage. This custom provider must implement 'get', 'set', and 'remove' methods. ```javascript store: { get: function(key){ return window.sessionStorage.getItem(key); }, set: function(key, value){ window.sessionStorage.setItem(key, value); }, remove: function(key){ window.sessionStorage.removeItem(key); } } ``` -------------------------------- ### Initialize Fancytree with Context Menu Source: https://github.com/mar10/fancytree/blob/master/demo/sample-3rd-contextmenu-abs.html Configures the tree with extensions and event handlers for activation, clicking, keyboard navigation, and node creation. ```javascript // --- Init fancytree during startup ---------------------------------------- $(function(){ $("#tree").fancytree({ extensions: ["dnd"], activate: function(event, data) { var node = data.node; $("#echoActivated").text(node.title + ", key=" + node.key); }, click: function(event, data) { // Close menu on click if( $(".contextMenu:visible").length > 0 ){ $(".contextMenu").hide(); // return false; } }, keydown: function(event, data) { var node = data.node; // Eat keyboard events, when a menu is open if( $(".contextMenu:visible").length > 0 ) return false; switch( event.which ) { // Open context menu on [Space] key (simulate right click) case 32: // [Space] $(node.span).trigger("mousedown", { preventDefault: true, button: 2 }) .trigger("mouseup", { preventDefault: true, pageX: node.span.offsetLeft, pageY: node.span.offsetTop, button: 2 }); return false; // Handle Ctrl-C, -X and -V case 67: if( event.ctrlKey ) { // Ctrl-C copyPaste("copy", node); return false; } break; case 86: if( event.ctrlKey ) { // Ctrl-V copyPaste("paste", node); return false; } break; case 88: if( event.ctrlKey ) { // Ctrl-X copyPaste("cut", node); return false; } break; } }, /*Bind context menu for every node when its DOM element is created. We do it here, so we can also bind to lazy nodes, which do not exist at load-time. (abeautifulsite.net menu control does not support event delegation)*/ createNode: function(event, data){ bindContextMenu(data.node.span); }, /*Load lazy content (to show that context menu will work for new items too)*/ lazyLoad: function(event, data){ data.result = {url: "sample-data2.json"}; }, /* D'n'd, just to show it's compatible with a context menu. See http://code.google.com/p/dynatree/issues/detail?id=174 */ dnd: { preventVoidMoves: true, // Prevent dropping nodes 'before self', etc. preventRecursiveMoves: true, // Prevent dropping nodes on own descendants autoExpandMS: 400, dragStart: function(node, data) { return true; }, dragEnter: function(node, data) { // return true; if(node.parent !== data.otherNode.parent) return false; return ["before", "after"]; }, dragDrop: function(node, data) { data.otherNode.moveTo(node, data.hitMode); } } }); }); ``` -------------------------------- ### Initialize Fancytree with Glyph Extension Source: https://github.com/mar10/fancytree/wiki/extensions/ExtGlyph Include the necessary CSS and JS files, then configure the tree with the glyph extension and a preset. ```html ``` ```js $("#tree").fancytree({ extensions: ["glyph"], icon: function(event, data){ // (Optional dynamic icon definition...) }, glyph: { // The preset defines defaults for all supported icon types. preset: "awesome5", map: { // Override distinct default icons here folder: "fas fa-folder", folderOpen: "fas fa-folder-open", ... } }, ... }); ``` -------------------------------- ### Create Fancytree Nodes Programmatically Source: https://github.com/mar10/fancytree/blob/master/demo/sample-api.html Demonstrates adding nodes to the Fancytree. The first example adds a single hierarchical branch using `node.addChildren()`. The second example appends a sibling node using `node.appendSibling()`. ```javascript addSampleButton({ header: "Create nodes", tooltip: "Use node.addChildren() with single objects", label: "Add single nodes", newline: false, code: function(){ // Sample: add an hierarchic branch using code. // This is how we would add tree nodes programatically var rootNode = $.ui.fancytree.getTree("#tree").getRootNode(); var childNode = rootNode.addChildren({ title: "Programatically addded nodes", tooltip: "This folder and all child nodes were added programmatically.", folder: true }); childNode.addChildren({ title: "Document using a custom icon", icon: "customdoc1.gif" }); } }); ``` ```javascript addSampleButton({ tooltip: "Use node.appendSibling()", label: "Apppend a sibling node", newline: false, code: function(){ var tree = $.ui.fancytree.getTree("#tree"), node = tree.getActiveNode(), newData = {title: "New Node"}, newSibling = node.appendSibling(newData); } }); ``` -------------------------------- ### Inspect node markup with extraClasses Source: https://github.com/mar10/fancytree/wiki/tutorial/TutorialTheming Example of how extraClasses adds a class to the node span element. ```html Node 1 ``` -------------------------------- ### Initialize Fancytree with table and filter extensions Source: https://github.com/mar10/fancytree/wiki/tutorial/TutorialExtensions Demonstrates loading extension scripts and configuring the tree with 'table' and 'filter' extensions, including specific options and event handlers. ```html Fancytree - Example
[...] ``` -------------------------------- ### Initialize Theme Switcher and UI Widgets Source: https://github.com/mar10/fancytree/blob/master/lib/Super-Theme-Switcher/sample.htm Initializes the theme switcher plugin and standard jQuery UI widgets on document ready. ```javascript $(document).ready(function(){ $("#switcher").themeswitcher({ imgpath: "images/", loadTheme: "dot-luv" }); // Sample UI widgets $( "#progressbar" ).progressbar({ value: 37 }); $( "#slider" ).slider(); }); ``` -------------------------------- ### Initialize Fancytree with Clones Extension Source: https://github.com/mar10/fancytree/wiki/extensions/ExtClones Enable the 'clones' extension in the Fancytree configuration object. ```javascript $("#tree").fancytree({ extensions: ["clones"], clones: { }, ... }); ``` -------------------------------- ### Embedded JSON Data Structure Source: https://github.com/mar10/fancytree/blob/master/demo/sample-source.html Example of a JSON object used to define tree nodes and custom data. ```json {"foo": "bazbaz", "children": [ {"title": "node 1"}, {"title": "node 2", "folder": true } ]} ``` -------------------------------- ### AJAX Response JSON Structure Source: https://github.com/mar10/fancytree/wiki/Home Example of the JSON data structure expected from an AJAX request for tree data. ```json [ {"title": "Node 1", "key": "1"}, {"title": "Folder 2", "key": "2", "folder": true, "children": [ {"title": "Node 2.1", "key": "3"}, {"title": "Node 2.2", "key": "4"} ]} ] ``` -------------------------------- ### Accessing Tree Meta Data Source: https://github.com/mar10/fancytree/wiki/tutorial/TutorialLoadData Example of how to access the additional tree meta-data that was passed along with the children array during initialization. ```javascript alert(tree.data.foo); // -> 'bar' ``` -------------------------------- ### Initialize Super Theme Switcher Source: https://github.com/mar10/fancytree/blob/master/lib/Super-Theme-Switcher/README.md Configures the theme switcher with specific image paths and a default theme, or initializes it with default settings. ```javascript $('#switcher').themeswitcher({ imgpath: "images/", loadTheme: "dot-luv" }); ``` ```javascript $('#switcher').themeswitcher(); ``` -------------------------------- ### HTML Structure for UL/LI Data Source Source: https://github.com/mar10/fancytree/wiki/Home Example HTML structure using UL/LI elements to define the tree data. ```html
... ``` -------------------------------- ### Angular 8 Setup: HTML Component Source: https://github.com/mar10/fancytree/wiki/tutorial/TutorialIntegration Add the basic HTML structure for the Fancytree to your Angular component's template. ```html
``` -------------------------------- ### Fancytree ARIA HTML Structure Source: https://github.com/mar10/fancytree/wiki/specs/SpecAria Example of the required HTML structure for a Fancytree component, including ARIA roles and labels for accessibility. ```html
``` -------------------------------- ### Angular 8 Setup: tsconfig.app.json Types Source: https://github.com/mar10/fancytree/wiki/tutorial/TutorialIntegration Add jQuery and Fancytree to the 'types' array in tsconfig.app.json to enable TypeScript support for these libraries. ```json "compilerOptions": { ... "types": ["jquery","jquery.fancytree"] } ``` -------------------------------- ### Configure Fancytree with Context Menu Extension Source: https://github.com/mar10/fancytree/blob/master/3rd-party/extensions/contextmenu/contextmenu.html Initialize Fancytree with the 'contextMenu' extension. Configure the menu structure, including item names, icons, disabled states, and nested submenus. The 'actions' callback handles user selections. ```javascript $(function() { $("#tree").fancytree({ extensions: ["contextMenu"], source: { url: "../../../demo/ajax-tree-local.json" }, contextMenu: { menu: { "edit": {"name": "Edit", "icon": "edit"}, "cut": {"name": "Cut", "icon": "cut"}, "copy": {"name": "Copy", "icon": "copy"}, "paste": {"name": "Paste", "icon": "paste"}, "delete": {"name": "Delete", "icon": "delete", "disabled": true}, "sep1": "---------", "quit": {"name": "Quit", "icon": "quit"}, "sep2": "---------", "fold1": { "name": "Sub group", "items": { "fold1-key1": {"name": "Foo bar"}, "fold2": { "name": "Sub group 2", "items": { "fold2-key1": {"name": "alpha"}, "fold2-key2": {"name": "bravo"}, "fold2-key3": {"name": "charlie"} } }, "fold1-key3": {"name": "delta"} } }, "fold1a": { "name": "Other group", "items": { "fold1a-key1": {"name": "echo"}, "fold1a-key2": {"name": "foxtrot"}, "fold1a-key3": {"name": "golf"} } } }, actions: function(node, action, options) { $("#selected-action") .text("Selected action '" + action + "' on node " + node + "."); } }, lazyLoad: function(event, data) { data.result = { url: "../../ajax-sub2.json" } } }); }); ``` -------------------------------- ### Enable dnd extension and options Source: https://github.com/mar10/fancytree/wiki/extensions/ExtDnd Initialize the Fancytree instance with the dnd extension enabled and configure its options. ```js $("#tree").fancytree({ extensions: ["dnd"], dnd: { // Available options with their default: autoExpandMS: 1000, // Expand nodes after n milliseconds of hovering draggable: null, // Additional options passed to jQuery UI draggable droppable: null, // Additional options passed to jQuery UI droppable dropMarkerOffsetX: -24, // absolute position offset for .fancytree-drop-marker // relatively to ..fancytree-title (icon/img near a node accepting drop) dropMarkerInsertOffsetX: -16, // additional offset for drop-marker with hitMode = "before"/"after" focusOnClick: false, // Focus, although draggable cancels mousedown event (#270) preventRecursiveMoves: true, // Prevent dropping nodes on own descendants preventVoidMoves: true, // Prevent dropping nodes 'before self', etc. smartRevert: true, // set draggable.revert = true if drop was rejected // Events that make tree nodes draggable dragStart: null, // Callback(sourceNode, data), return true to enable dnd dragStop: null, // Callback(sourceNode, data) initHelper: null, // Callback(sourceNode, data) updateHelper: null, // Callback(sourceNode, data) // Events that make tree nodes accept draggables dragEnter: null, // Callback(targetNode, data) dragExpand: null, // Callback(targetNode, data), return false to prevent autoExpand dragOver: null, // Callback(targetNode, data) dragDrop: null, // Callback(targetNode, data) dragLeave: null // Callback(targetNode, data) }, [...] }); ``` -------------------------------- ### ES6 Modules with Webpack (CommonJS) Source: https://github.com/mar10/fancytree/wiki/tutorial/TutorialIntegration Integrate Fancytree using ES6 modules with webpack. This example shows importing CSS and initializing the tree. ```javascript import('jquery.fancytree/dist/skin-lion/ui.fancytree.css'); // CSS or LESS const $ = require('jquery'); const fancytree = require('jquery.fancytree'); $(function(){ $('#tree').fancytree({ ... }); const tree = fancytree.getTree('#tree'); }) ``` -------------------------------- ### Configure Fancytree for Server-Side Persistence Source: https://github.com/mar10/fancytree/wiki/extensions/ExtPersist Set up Fancytree to rely on the server for persistence by disabling `expandLazy` and `overrideSource`. This example forces cookie storage. ```javascript $("#tree").fancytree({ extensions: ["persist"], persist: { expandLazy: false, overrideSource: false, store: "cookie", // force using cookies! ... }, source: { url: "getTreeNodes", data: {rootKey: "root"} }, lazyLoad: { url: "getTreeNodes", data: {rootKey: data.node.key} }, [...] }); ``` -------------------------------- ### Configure Dynamic Node Options Source: https://github.com/mar10/fancytree/wiki/Home Demonstrates setting global options and overriding them per node using JSON data or callback functions. ```javascript $("#tree").fancytree({ checkbox: true, source: {url: "/mySource"}, ... ``` ```json [{"title": "Node 1"}, {"title": "Node 2", "checkbox": false}, {"title": "Node 3", "checkbox": "radio"} ] ``` ```javascript $("#tree").fancytree({ checkbox: function(event, data) { // Hide checkboxes for folders return data.node.isFolder() ? false : true; }, tooltip: function(event, data) { // Create dynamic tooltips return data.node.title + " (" + data.node.key + ")"; }, icon: function(event, data) { var node = data.node; // Create custom icons if( node.data.refType === "foo" ) { return "foo-icon-class"; } // Exit without returning a value: continue with default processing. }, ... ```