trilium/public/javascripts/tree_utils.js

50 lines
1.1 KiB
JavaScript
Raw Normal View History

"use strict";
2017-11-05 10:18:36 +08:00
const treeUtils = (function() {
const treeEl = $("#tree");
2017-11-05 07:28:49 +08:00
2017-11-15 12:01:23 +08:00
function getParentProtectedStatus(node) {
return isTopLevelNode(node) ? 0 : node.getParent().data.is_protected;
2017-11-05 10:18:36 +08:00
}
function getNodeByKey(key) {
return treeEl.fancytree('getNodeByKey', key);
}
2017-11-20 01:06:48 +08:00
function getNoteIdFromNotePath(notePath) {
const path = notePath.split("/");
2017-11-20 01:06:48 +08:00
return path[path.length - 1];
}
2017-11-19 21:47:22 +08:00
function getNotePath(node) {
const path = [];
while (node && !isRootNode(node)) {
if (node.data.note_id) {
path.push(node.data.note_id);
2017-11-19 21:47:22 +08:00
}
node = node.getParent();
}
return path.reverse().join("/");
}
2017-11-28 23:17:30 +08:00
function setNodeTitleWithPrefix(node) {
const noteTitle = noteTree.getNoteTitle(node.data.note_id);
const prefix = node.data.prefix;
const title = (prefix ? (prefix + " - ") : "") + noteTitle;
node.setTitle(title);
}
2017-11-05 10:18:36 +08:00
return {
2017-11-15 12:01:23 +08:00
getParentProtectedStatus,
2017-11-05 10:18:36 +08:00
getNodeByKey,
2017-11-20 01:06:48 +08:00
getNotePath,
2017-11-28 23:17:30 +08:00
getNoteIdFromNotePath,
setNodeTitleWithPrefix
2017-11-05 10:18:36 +08:00
};
})();