Skip to content

Commit

Permalink
optim choose path when move, fix hover, fix keep loading when click i…
Browse files Browse the repository at this point in the history
…con of jqtree
  • Loading branch information
suchen-sci committed Feb 2, 2024
1 parent af565cc commit 2457344
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
2 changes: 1 addition & 1 deletion assets/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ body {
padding-left: 2px;
}

.paths-table tbody tr:hover {
.paths-table tbody tr:not(.selected):hover {
background-color: transparent;
}

Expand Down
33 changes: 19 additions & 14 deletions assets/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1530,25 +1530,17 @@ function initFileTree() {
openedIcon: iconOpen,
closedIcon: iconClose,
});
$("#tree").bind("tree.click", function (event) {
const node = event.node;

// when open tree node, load children
$("#tree").on("tree.open", function (e) {
const node = e.node;
mylog("tree open node", node);
selectedPath = node.id || notChoosePath;
document.getElementById("selectedPath").textContent = `已选择路径:${selectedPath}`
// by source code, single node children is use name as label
document.getElementById("selectedPath").textContent = `已选择路径:${selectedPath.replace(getDefaultPathPrefix(), "")}`
if (node.children && node.children.length > 0 && !hasLoadingChildren(node)) {
if (node.is_open) {
$('#tree').tree('closeNode', node);
} else {
$('#tree').tree('openNode', node);
}
return;
}
if (node.name === treeNoChildren) {
if (node.is_open) {
$('#tree').tree('closeNode', node);
} else {
$('#tree').tree('openNode', node);
}
return;
}
mylog("tree click node", node)
Expand All @@ -1570,6 +1562,19 @@ function initFileTree() {
$('#tree').tree('openNode', node);
})
});

// when click tree node, open or close it.
// also set selectedPath.
$("#tree").bind("tree.click", function (event) {
const node = event.node;
selectedPath = node.id || notChoosePath;
document.getElementById("selectedPath").textContent = `已选择路径:${selectedPath.replace(getDefaultPathPrefix(), "")}`
if (node.is_open) {
$('#tree').tree('closeNode', node);
} else {
$('#tree').tree('openNode', node);
}
});
}

/**
Expand Down

0 comments on commit 2457344

Please sign in to comment.