jqtree 1.9.0 → 1.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bower.json +1 -1
- package/package.json +22 -22
- package/pnpm-workspace.yaml +4 -3
- package/src/nodeElement/folderElement.ts +5 -5
- package/src/nodeElement/index.ts +6 -6
- package/src/scrollHandler/containerScrollParent.ts +8 -8
- package/src/scrollHandler/documentScrollParent.ts +8 -8
- package/src/scrollHandler/scrollParent.ts +41 -41
- package/src/tree.jquery.d.ts +3 -2
- package/src/tree.jquery.ts +224 -118
- package/src/version.ts +1 -1
- package/tree.jquery.debug.js +263 -281
- package/tree.jquery.debug.js.map +1 -1
- package/tree.jquery.js +2 -2
- package/tree.jquery.js.map +1 -1
- package/eslint.config.mjs +0 -112
- package/src/simple.widget.ts +0 -134
package/src/tree.jquery.ts
CHANGED
|
@@ -17,7 +17,6 @@ import { getOffsetTop } from "./positionUtils";
|
|
|
17
17
|
import SaveStateHandler from "./saveStateHandler";
|
|
18
18
|
import ScrollHandler from "./scrollHandler";
|
|
19
19
|
import SelectNodeHandler from "./selectNodeHandler";
|
|
20
|
-
import SimpleWidget from "./simple.widget";
|
|
21
20
|
import __version__ from "./version";
|
|
22
21
|
|
|
23
22
|
interface SelectNodeOptions {
|
|
@@ -25,48 +24,50 @@ interface SelectNodeOptions {
|
|
|
25
24
|
mustToggle?: boolean;
|
|
26
25
|
}
|
|
27
26
|
|
|
27
|
+
const defaults: JQTreeOptions = {
|
|
28
|
+
animationSpeed: "fast",
|
|
29
|
+
autoEscape: true,
|
|
30
|
+
autoOpen: false, // true / false / int (open n levels starting at 0)
|
|
31
|
+
buttonLeft: true,
|
|
32
|
+
// The symbol to use for a closed node - ► BLACK RIGHT-POINTING POINTER
|
|
33
|
+
// http://www.fileformat.info/info/unicode/char/25ba/index.htm
|
|
34
|
+
closedIcon: undefined,
|
|
35
|
+
data: undefined,
|
|
36
|
+
dataFilter: undefined,
|
|
37
|
+
dataUrl: undefined,
|
|
38
|
+
dragAndDrop: false,
|
|
39
|
+
keyboardSupport: true,
|
|
40
|
+
nodeClass: Node,
|
|
41
|
+
onCanMove: undefined, // Can this node be moved?
|
|
42
|
+
onCanMoveTo: undefined, // Can this node be moved to this position? function(moved_node, target_node, position)
|
|
43
|
+
onCanSelectNode: undefined,
|
|
44
|
+
onCreateLi: undefined,
|
|
45
|
+
onDragMove: undefined,
|
|
46
|
+
onDragStop: undefined,
|
|
47
|
+
onGetStateFromStorage: undefined,
|
|
48
|
+
onIsMoveHandle: undefined,
|
|
49
|
+
onLoadFailed: undefined,
|
|
50
|
+
onLoading: undefined,
|
|
51
|
+
onSetStateFromStorage: undefined,
|
|
52
|
+
openedIcon: "▼",
|
|
53
|
+
openFolderDelay: 500, // The delay for opening a folder during drag and drop; the value is in milliseconds
|
|
54
|
+
// The symbol to use for an open node - ▼ BLACK DOWN-POINTING TRIANGLE
|
|
55
|
+
// http://www.fileformat.info/info/unicode/char/25bc/index.htm
|
|
56
|
+
rtl: undefined, // right-to-left support; true / false (default)
|
|
57
|
+
saveState: false, // true / false / string (cookie name)
|
|
58
|
+
selectable: true,
|
|
59
|
+
showEmptyFolder: false,
|
|
60
|
+
slide: true, // must display slide animation?
|
|
61
|
+
startDndDelay: 300, // The delay for starting dnd (in milliseconds)
|
|
62
|
+
tabIndex: 0,
|
|
63
|
+
useContextMenu: true,
|
|
64
|
+
};
|
|
65
|
+
|
|
28
66
|
const NODE_PARAM_IS_EMPTY = "Node parameter is empty";
|
|
29
67
|
const PARAM_IS_EMPTY = "Parameter is empty: ";
|
|
30
68
|
|
|
31
|
-
export class JqTreeWidget
|
|
32
|
-
|
|
33
|
-
animationSpeed: "fast",
|
|
34
|
-
autoEscape: true,
|
|
35
|
-
autoOpen: false, // true / false / int (open n levels starting at 0)
|
|
36
|
-
buttonLeft: true,
|
|
37
|
-
// The symbol to use for a closed node - ► BLACK RIGHT-POINTING POINTER
|
|
38
|
-
// http://www.fileformat.info/info/unicode/char/25ba/index.htm
|
|
39
|
-
closedIcon: undefined,
|
|
40
|
-
data: undefined,
|
|
41
|
-
dataFilter: undefined,
|
|
42
|
-
dataUrl: undefined,
|
|
43
|
-
dragAndDrop: false,
|
|
44
|
-
keyboardSupport: true,
|
|
45
|
-
nodeClass: Node,
|
|
46
|
-
onCanMove: undefined, // Can this node be moved?
|
|
47
|
-
onCanMoveTo: undefined, // Can this node be moved to this position? function(moved_node, target_node, position)
|
|
48
|
-
onCanSelectNode: undefined,
|
|
49
|
-
onCreateLi: undefined,
|
|
50
|
-
onDragMove: undefined,
|
|
51
|
-
onDragStop: undefined,
|
|
52
|
-
onGetStateFromStorage: undefined,
|
|
53
|
-
onIsMoveHandle: undefined,
|
|
54
|
-
onLoadFailed: undefined,
|
|
55
|
-
onLoading: undefined,
|
|
56
|
-
onSetStateFromStorage: undefined,
|
|
57
|
-
openedIcon: "▼",
|
|
58
|
-
openFolderDelay: 500, // The delay for opening a folder during drag and drop; the value is in milliseconds
|
|
59
|
-
// The symbol to use for an open node - ▼ BLACK DOWN-POINTING TRIANGLE
|
|
60
|
-
// http://www.fileformat.info/info/unicode/char/25bc/index.htm
|
|
61
|
-
rtl: undefined, // right-to-left support; true / false (default)
|
|
62
|
-
saveState: false, // true / false / string (cookie name)
|
|
63
|
-
selectable: true,
|
|
64
|
-
showEmptyFolder: false,
|
|
65
|
-
slide: true, // must display slide animation?
|
|
66
|
-
startDndDelay: 300, // The delay for starting dnd (in milliseconds)
|
|
67
|
-
tabIndex: 0,
|
|
68
|
-
useContextMenu: true,
|
|
69
|
-
};
|
|
69
|
+
export class JqTreeWidget {
|
|
70
|
+
[key: string]: unknown;
|
|
70
71
|
|
|
71
72
|
private _dataLoader: DataLoader;
|
|
72
73
|
private _dndHandler: DragAndDropHandler;
|
|
@@ -75,12 +76,19 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
75
76
|
private _isInitialized: boolean;
|
|
76
77
|
private _keyHandler: KeyHandler;
|
|
77
78
|
private _mouseHandler: MouseHandler;
|
|
79
|
+
private _options: JQTreeOptions;
|
|
78
80
|
private _renderer: ElementsRenderer;
|
|
79
81
|
private _saveStateHandler: SaveStateHandler;
|
|
80
82
|
private _scrollHandler: ScrollHandler;
|
|
81
83
|
private _selectNodeHandler: SelectNodeHandler;
|
|
82
84
|
private _tree: Node;
|
|
83
85
|
|
|
86
|
+
constructor(el: HTMLElement, options: Partial<JQTreeOptions>) {
|
|
87
|
+
this._htmlElement = el;
|
|
88
|
+
this._element = jQuery(el);
|
|
89
|
+
this._options = { ...defaults, ...options };
|
|
90
|
+
}
|
|
91
|
+
|
|
84
92
|
public addNodeAfter(
|
|
85
93
|
newNodeInfo: NodeData,
|
|
86
94
|
existingNode: Node,
|
|
@@ -158,12 +166,12 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
158
166
|
throw Error(NODE_PARAM_IS_EMPTY);
|
|
159
167
|
}
|
|
160
168
|
|
|
161
|
-
const slide = slideParam ?? this.
|
|
169
|
+
const slide = slideParam ?? this._options.slide;
|
|
162
170
|
|
|
163
171
|
if (node.isFolder() || node.isEmptyFolder) {
|
|
164
172
|
this._createFolderElement(node).close(
|
|
165
173
|
slide,
|
|
166
|
-
this.
|
|
174
|
+
this._options.animationSpeed,
|
|
167
175
|
);
|
|
168
176
|
|
|
169
177
|
this._saveState();
|
|
@@ -180,8 +188,10 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
180
188
|
this._mouseHandler.deinit();
|
|
181
189
|
|
|
182
190
|
this._tree = new Node({}, true);
|
|
191
|
+
}
|
|
183
192
|
|
|
184
|
-
|
|
193
|
+
public destroy(): void {
|
|
194
|
+
this.deinit();
|
|
185
195
|
}
|
|
186
196
|
|
|
187
197
|
public getNodeByCallback(callback: (node: Node) => boolean): Node | null {
|
|
@@ -244,18 +254,16 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
244
254
|
}
|
|
245
255
|
|
|
246
256
|
public init(): void {
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
this._element = this.$el;
|
|
250
|
-
this._htmlElement = this._element.get(0) as HTMLElement;
|
|
257
|
+
const htmlElement = this._element.get(0) as HTMLElement;
|
|
258
|
+
this._htmlElement = htmlElement;
|
|
251
259
|
this._isInitialized = false;
|
|
252
260
|
|
|
253
|
-
this.
|
|
261
|
+
this._options.dataUrl ??= this._element.data("url");
|
|
254
262
|
|
|
255
263
|
const dataRtl = this._element.data("rtl") as unknown;
|
|
256
|
-
this.
|
|
264
|
+
this._options.rtl ??= dataRtl === '' ? true : Boolean(dataRtl);
|
|
257
265
|
|
|
258
|
-
this.
|
|
266
|
+
this._options.closedIcon ??= this._getDefaultClosedIcon();
|
|
259
267
|
|
|
260
268
|
this._connectHandlers();
|
|
261
269
|
this._initData();
|
|
@@ -378,7 +386,7 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
378
386
|
onFinished = param2 as OnFinishOpenNode;
|
|
379
387
|
}
|
|
380
388
|
|
|
381
|
-
slide ??= this.
|
|
389
|
+
slide ??= this._options.slide;
|
|
382
390
|
|
|
383
391
|
return [slide, onFinished];
|
|
384
392
|
};
|
|
@@ -467,7 +475,7 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
467
475
|
}
|
|
468
476
|
|
|
469
477
|
public setOption(option: string, value: unknown): JQuery {
|
|
470
|
-
(this.
|
|
478
|
+
(this._options as unknown as Record<string, unknown>)[option] = value;
|
|
471
479
|
return this._element;
|
|
472
480
|
}
|
|
473
481
|
|
|
@@ -485,7 +493,7 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
485
493
|
throw Error(NODE_PARAM_IS_EMPTY);
|
|
486
494
|
}
|
|
487
495
|
|
|
488
|
-
const slide = slideParam ?? this.
|
|
496
|
+
const slide = slideParam ?? this._options.slide;
|
|
489
497
|
|
|
490
498
|
if (node.is_open) {
|
|
491
499
|
this.closeNode(node, slide);
|
|
@@ -564,7 +572,7 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
564
572
|
showEmptyFolder,
|
|
565
573
|
slide,
|
|
566
574
|
tabIndex,
|
|
567
|
-
} = this.
|
|
575
|
+
} = this._options;
|
|
568
576
|
|
|
569
577
|
const closeNode = this.closeNode.bind(this);
|
|
570
578
|
const getNodeElement = this._getNodeElement.bind(this);
|
|
@@ -592,7 +600,7 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
592
600
|
selectNodeHandler.isNodeSelected.bind(selectNodeHandler);
|
|
593
601
|
const removeFromSelection =
|
|
594
602
|
selectNodeHandler.removeFromSelection.bind(selectNodeHandler);
|
|
595
|
-
const getMouseDelay = () => this.
|
|
603
|
+
const getMouseDelay = () => this._options.startDndDelay ?? 0;
|
|
596
604
|
|
|
597
605
|
const refreshHitAreas = () => {
|
|
598
606
|
dndHandler.refresh();
|
|
@@ -687,7 +695,7 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
687
695
|
onMouseStart,
|
|
688
696
|
onMouseStop,
|
|
689
697
|
triggerEvent,
|
|
690
|
-
useContextMenu: this.
|
|
698
|
+
useContextMenu: this._options.useContextMenu,
|
|
691
699
|
});
|
|
692
700
|
|
|
693
701
|
this._dataLoader = dataLoader;
|
|
@@ -700,19 +708,13 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
700
708
|
this._selectNodeHandler = selectNodeHandler;
|
|
701
709
|
}
|
|
702
710
|
|
|
703
|
-
private _containsElement(element: HTMLElement): boolean {
|
|
704
|
-
const node = this._getNode(element);
|
|
705
|
-
|
|
706
|
-
return node?.tree === this._tree;
|
|
707
|
-
}
|
|
708
|
-
|
|
709
711
|
private _createFolderElement(node: Node) {
|
|
710
712
|
const closedIconElement = this._renderer.closedIconElement;
|
|
711
713
|
const getScrollLeft = this._scrollHandler.getScrollLeft.bind(
|
|
712
714
|
this._scrollHandler,
|
|
713
715
|
);
|
|
714
716
|
const openedIconElement = this._renderer.openedIconElement;
|
|
715
|
-
const tabIndex = this.
|
|
717
|
+
const tabIndex = this._options.tabIndex;
|
|
716
718
|
const triggerEvent = this._triggerEvent.bind(this);
|
|
717
719
|
|
|
718
720
|
return new FolderElement({
|
|
@@ -730,7 +732,7 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
730
732
|
const getScrollLeft = this._scrollHandler.getScrollLeft.bind(
|
|
731
733
|
this._scrollHandler,
|
|
732
734
|
);
|
|
733
|
-
const tabIndex = this.
|
|
735
|
+
const tabIndex = this._options.tabIndex;
|
|
734
736
|
|
|
735
737
|
return new NodeElement({
|
|
736
738
|
getScrollLeft,
|
|
@@ -790,7 +792,7 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
790
792
|
optionsParam?: SelectNodeOptions,
|
|
791
793
|
): void {
|
|
792
794
|
const saveState = (): void => {
|
|
793
|
-
if (this.
|
|
795
|
+
if (this._options.saveState) {
|
|
794
796
|
this._saveStateHandler.saveState();
|
|
795
797
|
}
|
|
796
798
|
};
|
|
@@ -805,13 +807,13 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
805
807
|
const selectOptions = { ...defaultOptions, ...(optionsParam ?? {}) };
|
|
806
808
|
|
|
807
809
|
const canSelect = (): boolean => {
|
|
808
|
-
if (this.
|
|
810
|
+
if (this._options.onCanSelectNode) {
|
|
809
811
|
return (
|
|
810
|
-
this.
|
|
811
|
-
this.
|
|
812
|
+
this._options.selectable &&
|
|
813
|
+
this._options.onCanSelectNode(node)
|
|
812
814
|
);
|
|
813
815
|
} else {
|
|
814
|
-
return this.
|
|
816
|
+
return this._options.selectable;
|
|
815
817
|
}
|
|
816
818
|
};
|
|
817
819
|
|
|
@@ -843,12 +845,12 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
843
845
|
}
|
|
844
846
|
|
|
845
847
|
private _getAutoOpenMaxLevel(): number {
|
|
846
|
-
if (this.
|
|
848
|
+
if (this._options.autoOpen === true) {
|
|
847
849
|
return -1;
|
|
848
|
-
} else if (typeof this.
|
|
849
|
-
return this.
|
|
850
|
-
} else if (typeof this.
|
|
851
|
-
return parseInt(this.
|
|
850
|
+
} else if (typeof this._options.autoOpen === "number") {
|
|
851
|
+
return this._options.autoOpen;
|
|
852
|
+
} else if (typeof this._options.autoOpen === "string") {
|
|
853
|
+
return parseInt(this._options.autoOpen, 10);
|
|
852
854
|
} else {
|
|
853
855
|
return 0;
|
|
854
856
|
}
|
|
@@ -878,7 +880,7 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
878
880
|
}
|
|
879
881
|
};
|
|
880
882
|
|
|
881
|
-
const dataUrl = this.
|
|
883
|
+
const dataUrl = this._options.dataUrl;
|
|
882
884
|
if (typeof dataUrl === "function") {
|
|
883
885
|
return dataUrl(node);
|
|
884
886
|
} else if (typeof dataUrl === "string") {
|
|
@@ -892,7 +894,7 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
892
894
|
}
|
|
893
895
|
|
|
894
896
|
private _getDefaultClosedIcon(): string {
|
|
895
|
-
if (this.
|
|
897
|
+
if (this._options.rtl) {
|
|
896
898
|
// triangle to the left
|
|
897
899
|
return "◀";
|
|
898
900
|
} else {
|
|
@@ -929,7 +931,7 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
929
931
|
}
|
|
930
932
|
|
|
931
933
|
private _getNodeIdToBeSelected(): NodeId | null {
|
|
932
|
-
if (this.
|
|
934
|
+
if (this._options.saveState) {
|
|
933
935
|
return this._saveStateHandler.getNodeIdToBeSelected();
|
|
934
936
|
} else {
|
|
935
937
|
return null;
|
|
@@ -937,8 +939,8 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
937
939
|
}
|
|
938
940
|
|
|
939
941
|
private _initData(): void {
|
|
940
|
-
if (this.
|
|
941
|
-
this._doLoadData(this.
|
|
942
|
+
if (this._options.data) {
|
|
943
|
+
this._doLoadData(this._options.data, null);
|
|
942
944
|
} else {
|
|
943
945
|
const dataUrl = this._getDataUrlInfo(null);
|
|
944
946
|
|
|
@@ -958,10 +960,10 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
958
960
|
}
|
|
959
961
|
};
|
|
960
962
|
|
|
961
|
-
this._tree = new this.
|
|
963
|
+
this._tree = new this._options.nodeClass(
|
|
962
964
|
null,
|
|
963
965
|
true,
|
|
964
|
-
this.
|
|
966
|
+
this._options.nodeClass,
|
|
965
967
|
);
|
|
966
968
|
|
|
967
969
|
this._selectNodeHandler.clear();
|
|
@@ -972,18 +974,31 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
972
974
|
|
|
973
975
|
this._refreshElements(null);
|
|
974
976
|
|
|
975
|
-
if (
|
|
976
|
-
doInit();
|
|
977
|
-
} else {
|
|
977
|
+
if (mustLoadOnDemand) {
|
|
978
978
|
// Load data on demand and then init the tree
|
|
979
979
|
this._setInitialStateOnDemand(doInit);
|
|
980
|
+
} else {
|
|
981
|
+
doInit();
|
|
980
982
|
}
|
|
981
983
|
}
|
|
982
984
|
|
|
985
|
+
// Does an element in the tree have the focus?
|
|
983
986
|
private _isFocusOnTree(): boolean {
|
|
984
987
|
const activeElement = document.activeElement;
|
|
985
988
|
|
|
986
|
-
|
|
989
|
+
/* istanbul ignore if */
|
|
990
|
+
if (!activeElement) {
|
|
991
|
+
return false;
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
// The keyboard must still work for input elements.
|
|
995
|
+
const tagName = activeElement.tagName;
|
|
996
|
+
if (tagName !== "A" && tagName !== "SPAN") {
|
|
997
|
+
return false;
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
const node = this._getNode(activeElement as HTMLElement);
|
|
1001
|
+
return node?.tree === this._tree;
|
|
987
1002
|
}
|
|
988
1003
|
|
|
989
1004
|
private _isSelectedNodeInSubtree(subtree: Node): boolean {
|
|
@@ -1018,39 +1033,41 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
1018
1033
|
}
|
|
1019
1034
|
|
|
1020
1035
|
private _mouseCapture(positionInfo: PositionInfo): boolean | null {
|
|
1021
|
-
if (this.
|
|
1022
|
-
return this._dndHandler.mouseCapture(positionInfo);
|
|
1023
|
-
} else {
|
|
1036
|
+
if (!this._options.dragAndDrop) {
|
|
1024
1037
|
return false;
|
|
1025
1038
|
}
|
|
1039
|
+
|
|
1040
|
+
return this._dndHandler.mouseCapture(positionInfo);
|
|
1026
1041
|
}
|
|
1027
1042
|
|
|
1028
1043
|
private _mouseDrag(positionInfo: PositionInfo): boolean {
|
|
1029
|
-
if
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
this._scrollHandler.checkScrolling(positionInfo);
|
|
1033
|
-
return result;
|
|
1034
|
-
} else {
|
|
1044
|
+
/* istanbul ignore if */
|
|
1045
|
+
if (!this._options.dragAndDrop) {
|
|
1035
1046
|
return false;
|
|
1036
1047
|
}
|
|
1048
|
+
|
|
1049
|
+
const result = this._dndHandler.mouseDrag(positionInfo);
|
|
1050
|
+
this._scrollHandler.checkScrolling(positionInfo);
|
|
1051
|
+
return result;
|
|
1037
1052
|
}
|
|
1038
1053
|
|
|
1039
1054
|
private _mouseStart(positionInfo: PositionInfo): boolean {
|
|
1040
|
-
if
|
|
1041
|
-
|
|
1042
|
-
} else {
|
|
1055
|
+
/* istanbul ignore if */
|
|
1056
|
+
if (!this._options.dragAndDrop) {
|
|
1043
1057
|
return false;
|
|
1044
1058
|
}
|
|
1059
|
+
|
|
1060
|
+
return this._dndHandler.mouseStart(positionInfo);
|
|
1045
1061
|
}
|
|
1046
1062
|
|
|
1047
1063
|
private _mouseStop(positionInfo: PositionInfo): boolean {
|
|
1048
|
-
if
|
|
1049
|
-
|
|
1050
|
-
return this._dndHandler.mouseStop(positionInfo);
|
|
1051
|
-
} else {
|
|
1064
|
+
/* istanbul ignore if */
|
|
1065
|
+
if (!this._options.dragAndDrop) {
|
|
1052
1066
|
return false;
|
|
1053
1067
|
}
|
|
1068
|
+
|
|
1069
|
+
this._scrollHandler.stopScrolling();
|
|
1070
|
+
return this._dndHandler.mouseStop(positionInfo);
|
|
1054
1071
|
}
|
|
1055
1072
|
|
|
1056
1073
|
private _openNodeInternal(
|
|
@@ -1071,7 +1088,7 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
1071
1088
|
folderElement.open(
|
|
1072
1089
|
_onFinished,
|
|
1073
1090
|
_slide,
|
|
1074
|
-
this.
|
|
1091
|
+
this._options.animationSpeed,
|
|
1075
1092
|
);
|
|
1076
1093
|
};
|
|
1077
1094
|
|
|
@@ -1123,7 +1140,7 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
1123
1140
|
}
|
|
1124
1141
|
|
|
1125
1142
|
private _saveState(): void {
|
|
1126
|
-
if (this.
|
|
1143
|
+
if (this._options.saveState) {
|
|
1127
1144
|
this._saveStateHandler.saveState();
|
|
1128
1145
|
}
|
|
1129
1146
|
}
|
|
@@ -1141,7 +1158,7 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
1141
1158
|
private _setInitialState(): boolean {
|
|
1142
1159
|
const restoreState = (): [boolean, boolean] => {
|
|
1143
1160
|
// result: is state restored, must load on demand?
|
|
1144
|
-
if (!this.
|
|
1161
|
+
if (!this._options.saveState) {
|
|
1145
1162
|
return [false, false];
|
|
1146
1163
|
} else {
|
|
1147
1164
|
const state = this._saveStateHandler.getStateFromStorage();
|
|
@@ -1160,7 +1177,7 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
1160
1177
|
|
|
1161
1178
|
const autoOpenNodes = (): boolean => {
|
|
1162
1179
|
// result: must load on demand?
|
|
1163
|
-
if (this.
|
|
1180
|
+
if (this._options.autoOpen === false) {
|
|
1164
1181
|
return false;
|
|
1165
1182
|
}
|
|
1166
1183
|
|
|
@@ -1195,21 +1212,17 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
1195
1212
|
// Call cb_finished when done
|
|
1196
1213
|
private _setInitialStateOnDemand(cbFinished: () => void): void {
|
|
1197
1214
|
const restoreState = (): boolean => {
|
|
1198
|
-
|
|
1215
|
+
const state = this._saveStateHandler.getStateFromStorage();
|
|
1216
|
+
|
|
1217
|
+
if (!state) {
|
|
1199
1218
|
return false;
|
|
1200
1219
|
} else {
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
} else {
|
|
1206
|
-
this._saveStateHandler.setInitialStateOnDemand(
|
|
1207
|
-
state,
|
|
1208
|
-
cbFinished,
|
|
1209
|
-
);
|
|
1220
|
+
this._saveStateHandler.setInitialStateOnDemand(
|
|
1221
|
+
state,
|
|
1222
|
+
cbFinished,
|
|
1223
|
+
);
|
|
1210
1224
|
|
|
1211
|
-
|
|
1212
|
-
}
|
|
1225
|
+
return true;
|
|
1213
1226
|
}
|
|
1214
1227
|
};
|
|
1215
1228
|
|
|
@@ -1263,4 +1276,97 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
1263
1276
|
}
|
|
1264
1277
|
}
|
|
1265
1278
|
|
|
1266
|
-
|
|
1279
|
+
const register = (): void => {
|
|
1280
|
+
const getWidgetData = (
|
|
1281
|
+
el: HTMLElement,
|
|
1282
|
+
dataKey: string,
|
|
1283
|
+
): JqTreeWidget | null => {
|
|
1284
|
+
const widget = jQuery.data(el, dataKey) as unknown;
|
|
1285
|
+
|
|
1286
|
+
if (widget && widget instanceof JqTreeWidget) {
|
|
1287
|
+
return widget;
|
|
1288
|
+
} else {
|
|
1289
|
+
return null;
|
|
1290
|
+
}
|
|
1291
|
+
};
|
|
1292
|
+
|
|
1293
|
+
const createWidget = ($el: JQuery, options: null | Partial<JQTreeOptions>): JQuery => {
|
|
1294
|
+
for (const el of $el.get()) {
|
|
1295
|
+
const existingWidget = getWidgetData(el, "jqtree");
|
|
1296
|
+
|
|
1297
|
+
if (!existingWidget) {
|
|
1298
|
+
const widget = new JqTreeWidget(el, options ?? {});
|
|
1299
|
+
|
|
1300
|
+
if (!jQuery.data(el, "jqtree")) {
|
|
1301
|
+
jQuery.data(el, "jqtree", widget);
|
|
1302
|
+
}
|
|
1303
|
+
|
|
1304
|
+
// Call init after setting data, so we can call methods
|
|
1305
|
+
widget.init();
|
|
1306
|
+
}
|
|
1307
|
+
}
|
|
1308
|
+
|
|
1309
|
+
return $el;
|
|
1310
|
+
};
|
|
1311
|
+
|
|
1312
|
+
const destroyWidget = ($el: JQuery): void => {
|
|
1313
|
+
for (const el of $el.get()) {
|
|
1314
|
+
const widget = getWidgetData(el, "jqtree");
|
|
1315
|
+
|
|
1316
|
+
if (widget) {
|
|
1317
|
+
widget.destroy();
|
|
1318
|
+
}
|
|
1319
|
+
|
|
1320
|
+
jQuery.removeData(el, "jqtree");
|
|
1321
|
+
}
|
|
1322
|
+
};
|
|
1323
|
+
|
|
1324
|
+
const callFunction = (
|
|
1325
|
+
$el: JQuery,
|
|
1326
|
+
functionName: string,
|
|
1327
|
+
args: unknown[],
|
|
1328
|
+
): unknown => {
|
|
1329
|
+
let result = null;
|
|
1330
|
+
|
|
1331
|
+
for (const el of $el.get()) {
|
|
1332
|
+
const widget = jQuery.data(el, "jqtree") as unknown;
|
|
1333
|
+
|
|
1334
|
+
if (widget && widget instanceof JqTreeWidget) {
|
|
1335
|
+
const widgetFunction = widget[functionName];
|
|
1336
|
+
|
|
1337
|
+
if (widgetFunction && typeof widgetFunction === "function") {
|
|
1338
|
+
result = widgetFunction.apply(widget, args) as unknown;
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
}
|
|
1342
|
+
|
|
1343
|
+
return result;
|
|
1344
|
+
};
|
|
1345
|
+
|
|
1346
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
1347
|
+
(jQuery.fn as any).tree = function (
|
|
1348
|
+
this: JQuery,
|
|
1349
|
+
argument1: unknown,
|
|
1350
|
+
...args: unknown[]
|
|
1351
|
+
) {
|
|
1352
|
+
if (!argument1) {
|
|
1353
|
+
return createWidget(this, null);
|
|
1354
|
+
} else if (typeof argument1 === "object") {
|
|
1355
|
+
const options = argument1 as unknown;
|
|
1356
|
+
return createWidget(this, options as JQTreeOptions);
|
|
1357
|
+
} else if (typeof argument1 === "string" && argument1[0] !== "_") {
|
|
1358
|
+
const functionName = argument1;
|
|
1359
|
+
|
|
1360
|
+
if (argument1 === "destroy") {
|
|
1361
|
+
destroyWidget(this);
|
|
1362
|
+
return undefined;
|
|
1363
|
+
} else {
|
|
1364
|
+
return callFunction(this, functionName, args);
|
|
1365
|
+
}
|
|
1366
|
+
} else {
|
|
1367
|
+
return undefined;
|
|
1368
|
+
}
|
|
1369
|
+
};
|
|
1370
|
+
};
|
|
1371
|
+
|
|
1372
|
+
register();
|
package/src/version.ts
CHANGED