assets/includes/explorer.html in jekyll-obsidian-1.0.6 vs assets/includes/explorer.html in jekyll-obsidian-1.0.7
- old
+ new
@@ -19,10 +19,11 @@
document.addEventListener('touchstart', handleTouchStart, false);
document.addEventListener('touchmove', handleTouchMove, false);
document.addEventListener('touchend', handleTouchEnd, false);
function handleTouchStart(evt) {
+ const EXPLORER = OBSIDIAN.querySelector('#explorer');
const firstTouch = evt.touches[0];
touchStartX = firstTouch.clientX; // Get initial touch pos
explorerDisplayed = isDisplayNone(EXPLORER);
activationDistance = window.innerWidth - 120;
@@ -42,10 +43,11 @@
}
function handleTouchMove(evt) {
if (!isDraggingTouch) return;
+ const EXPLORER = OBSIDIAN.querySelector('#explorer');
touchCurrentX = evt.touches[0].clientX;
if (!explorerDisplayed) {
// Dragging to adjust the explorer width from left to right
let diffX = touchCurrentX - touchStartX;
@@ -59,10 +61,11 @@
}
}
function handleTouchEnd(evt) {
if (!isDraggingTouch) return;
+ const EXPLORER = OBSIDIAN.querySelector('#explorer');
if (!explorerDisplayed) {
let diffX = touchCurrentX - touchStartX;
if (diffX > activationDistance) {
EXPLORER.style.width = 'calc(100% - 2rem)';
@@ -92,14 +95,13 @@
</script>
<!-- ------------------------- File tree generator ------------------------- -->
<script lang="text/javascript">
- const EXPLORER = OBSIDIAN.querySelector('#explorer');
- const FILE_TREE = EXPLORER.querySelector(' #file-tree');
-
function buildFileTree(rootElement, tree, expandRoot = false) {
+ const EXPLORER = OBSIDIAN.querySelector('#explorer');
+ const FILE_TREE = EXPLORER.querySelector(' #file-tree');
const old_ul = rootElement.querySelector('ul');
if (old_ul) rootElement.removeChild(old_ul);
const ul = document.createElement('ul');
rootElement.appendChild(ul);
@@ -150,10 +152,12 @@
}
});
}
function sortObsidianVaultFiles(tree) {
+ const EXPLORER = OBSIDIAN.querySelector('#explorer');
+ const FILE_TREE = EXPLORER.querySelector(' #file-tree');
tree.sort((a, b) => {
if (a.type === 'dir' && b.type === 'file') {
return -1;
} else if (a.type === 'file' && b.type === 'dir') {
return 1;
@@ -164,13 +168,16 @@
sortObsidianVaultFiles(child.children);
}
});
return tree;
}
- const VAULT_FILES =
- JSON.parse('{{ site.data.obsidian.vault_files | escape }}'.replace(/"/g, '"'));
+
let expandOrCollapseFileTree = false;
document.addEventListener('DOMContentLoaded', () => {
+ const VAULT_FILES =
+ JSON.parse('{{ site.data.obsidian.vault_files | escape }}'.replace(/"/g, '"'));
+ const EXPLORER = OBSIDIAN.querySelector('#explorer');
+ const FILE_TREE = EXPLORER.querySelector(' #file-tree');
const sortedVaultFiles = sortObsidianVaultFiles(VAULT_FILES);
buildFileTree(FILE_TREE, sortedVaultFiles);
const collapseExpand = EXPLORER.querySelector('#vault-name #collapseExpand');
collapseExpand.innerHTML = DOMPurify.sanitize(getSVGIcon(Icon.ChevronExpand));
\ No newline at end of file