1/*!
2 * jquery.fancytree.multi.js
3 *
4 * Allow multiple selection of nodes  by mouse or keyboard.
5 * (Extension module for jquery.fancytree.js: https://github.com/mar10/fancytree/)
6 *
7 * Copyright (c) 2008-2023, Martin Wendt (https://wwWendt.de)
8 *
9 * Released under the MIT license
10 * https://github.com/mar10/fancytree/wiki/LicenseInfo
11 *
12 * @version 2.38.3
13 * @date 2023-02-01T20:52:50Z
14 */
15
16(function (factory) {
17	if (typeof define === "function" && define.amd) {
18		// AMD. Register as an anonymous module.
19		define(["jquery", "./jquery.fancytree"], factory);
20	} else if (typeof module === "object" && module.exports) {
21		// Node/CommonJS
22		require("./jquery.fancytree");
23		module.exports = factory(require("jquery"));
24	} else {
25		// Browser globals
26		factory(jQuery);
27	}
28})(function ($) {
29	"use strict";
30
31	/*******************************************************************************
32	 * Private functions and variables
33	 */
34
35	// var isMac = /Mac/.test(navigator.platform);
36
37	/*******************************************************************************
38	 * Extension code
39	 */
40	$.ui.fancytree.registerExtension({
41		name: "multi",
42		version: "2.38.3",
43		// Default options for this extension.
44		options: {
45			allowNoSelect: false, //
46			mode: "sameParent", //
47			// Events:
48			// beforeSelect: $.noop  // Return false to prevent cancel/save (data.input is available)
49		},
50
51		treeInit: function (ctx) {
52			this._superApply(arguments);
53			this.$container.addClass("fancytree-ext-multi");
54			if (ctx.options.selectMode === 1) {
55				$.error(
56					"Fancytree ext-multi: selectMode: 1 (single) is not compatible."
57				);
58			}
59		},
60		nodeClick: function (ctx) {
61			var //pluginOpts = ctx.options.multi,
62				tree = ctx.tree,
63				node = ctx.node,
64				activeNode = tree.getActiveNode() || tree.getFirstChild(),
65				isCbClick = ctx.targetType === "checkbox",
66				isExpanderClick = ctx.targetType === "expander",
67				eventStr = $.ui.fancytree.eventToString(ctx.originalEvent);
68
69			switch (eventStr) {
70				case "click":
71					if (isExpanderClick) {
72						break;
73					} // Default handler will expand/collapse
74					if (!isCbClick) {
75						tree.selectAll(false);
76						// Select clicked node (radio-button  mode)
77						node.setSelected();
78					}
79					// Default handler will toggle checkbox clicks and activate
80					break;
81				case "shift+click":
82					// node.debug("click")
83					tree.visitRows(
84						function (n) {
85							// n.debug("click2", n===node, node)
86							n.setSelected();
87							if (n === node) {
88								return false;
89							}
90						},
91						{
92							start: activeNode,
93							reverse: activeNode.isBelowOf(node),
94						}
95					);
96					break;
97				case "ctrl+click":
98				case "meta+click": // Mac: [Command]
99					node.toggleSelected();
100					return;
101			}
102			return this._superApply(arguments);
103		},
104		nodeKeydown: function (ctx) {
105			var tree = ctx.tree,
106				node = ctx.node,
107				event = ctx.originalEvent,
108				eventStr = $.ui.fancytree.eventToString(event);
109
110			switch (eventStr) {
111				case "up":
112				case "down":
113					tree.selectAll(false);
114					node.navigate(event.which, true);
115					tree.getActiveNode().setSelected();
116					break;
117				case "shift+up":
118				case "shift+down":
119					node.navigate(event.which, true);
120					tree.getActiveNode().setSelected();
121					break;
122			}
123			return this._superApply(arguments);
124		},
125	});
126	// Value returned by `require('jquery.fancytree..')`
127	return $.ui.fancytree;
128}); // End of closure
129