1/*! 2 * jquery.fancytree.themeroller.js 3 * 4 * Enable jQuery UI ThemeRoller styles. 5 * (Extension module for jquery.fancytree.js: https://github.com/mar10/fancytree/) 6 * 7 * @see http://jqueryui.com/themeroller/ 8 * 9 * Copyright (c) 2008-2023, Martin Wendt (https://wwWendt.de) 10 * 11 * Released under the MIT license 12 * https://github.com/mar10/fancytree/wiki/LicenseInfo 13 * 14 * @version 2.38.3 15 * @date 2023-02-01T20:52:50Z 16 */ 17 18(function (factory) { 19 if (typeof define === "function" && define.amd) { 20 // AMD. Register as an anonymous module. 21 define(["jquery", "./jquery.fancytree"], factory); 22 } else if (typeof module === "object" && module.exports) { 23 // Node/CommonJS 24 require("./jquery.fancytree"); 25 module.exports = factory(require("jquery")); 26 } else { 27 // Browser globals 28 factory(jQuery); 29 } 30})(function ($) { 31 "use strict"; 32 33 /******************************************************************************* 34 * Extension code 35 */ 36 $.ui.fancytree.registerExtension({ 37 name: "themeroller", 38 version: "2.38.3", 39 // Default options for this extension. 40 options: { 41 activeClass: "ui-state-active", // Class added to active node 42 // activeClass: "ui-state-highlight", 43 addClass: "ui-corner-all", // Class added to all nodes 44 focusClass: "ui-state-focus", // Class added to focused node 45 hoverClass: "ui-state-hover", // Class added to hovered node 46 selectedClass: "ui-state-highlight", // Class added to selected nodes 47 // selectedClass: "ui-state-active" 48 }, 49 50 treeInit: function (ctx) { 51 var $el = ctx.widget.element, 52 opts = ctx.options.themeroller; 53 54 this._superApply(arguments); 55 56 if ($el[0].nodeName === "TABLE") { 57 $el.addClass("ui-widget ui-corner-all"); 58 $el.find(">thead tr").addClass("ui-widget-header"); 59 $el.find(">tbody").addClass("ui-widget-conent"); 60 } else { 61 $el.addClass("ui-widget ui-widget-content ui-corner-all"); 62 } 63 64 $el.on( 65 "mouseenter mouseleave", 66 ".fancytree-node", 67 function (event) { 68 var node = $.ui.fancytree.getNode(event.target), 69 flag = event.type === "mouseenter"; 70 71 $(node.tr ? node.tr : node.span).toggleClass( 72 opts.hoverClass + " " + opts.addClass, 73 flag 74 ); 75 } 76 ); 77 }, 78 treeDestroy: function (ctx) { 79 this._superApply(arguments); 80 ctx.widget.element.removeClass( 81 "ui-widget ui-widget-content ui-corner-all" 82 ); 83 }, 84 nodeRenderStatus: function (ctx) { 85 var classes = {}, 86 node = ctx.node, 87 $el = $(node.tr ? node.tr : node.span), 88 opts = ctx.options.themeroller; 89 90 this._super(ctx); 91 /* 92 .ui-state-highlight: Class to be applied to highlighted or selected elements. Applies "highlight" container styles to an element and its child text, links, and icons. 93 .ui-state-error: Class to be applied to error messaging container elements. Applies "error" container styles to an element and its child text, links, and icons. 94 .ui-state-error-text: An additional class that applies just the error text color without background. Can be used on form labels for instance. Also applies error icon color to child icons. 95 96 .ui-state-default: Class to be applied to clickable button-like elements. Applies "clickable default" container styles to an element and its child text, links, and icons. 97 .ui-state-hover: Class to be applied on mouseover to clickable button-like elements. Applies "clickable hover" container styles to an element and its child text, links, and icons. 98 .ui-state-focus: Class to be applied on keyboard focus to clickable button-like elements. Applies "clickable hover" container styles to an element and its child text, links, and icons. 99 .ui-state-active: Class to be applied on mousedown to clickable button-like elements. Applies "clickable active" container styles to an element and its child text, links, and icons. 100*/ 101 // Set ui-state-* class (handle the case that the same class is assigned 102 // to different states) 103 classes[opts.activeClass] = false; 104 classes[opts.focusClass] = false; 105 classes[opts.selectedClass] = false; 106 if (node.isActive()) { 107 classes[opts.activeClass] = true; 108 } 109 if (node.hasFocus()) { 110 classes[opts.focusClass] = true; 111 } 112 // activeClass takes precedence before selectedClass: 113 if (node.isSelected() && !node.isActive()) { 114 classes[opts.selectedClass] = true; 115 } 116 $el.toggleClass(opts.activeClass, classes[opts.activeClass]); 117 $el.toggleClass(opts.focusClass, classes[opts.focusClass]); 118 $el.toggleClass(opts.selectedClass, classes[opts.selectedClass]); 119 // Additional classes (e.g. 'ui-corner-all') 120 $el.addClass(opts.addClass); 121 }, 122 }); 123 // Value returned by `require('jquery.fancytree..')` 124 return $.ui.fancytree; 125}); // End of closure 126