Skip to content

Commit

Permalink
collapse/expand dirs
Browse files Browse the repository at this point in the history
  • Loading branch information
abinthomasonline committed Sep 28, 2024
1 parent dc362fa commit 01f8e07
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
8 changes: 8 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
<meta property="og:url" content="https://repo2txt.simplebasedomain.com/">
<meta property="og:type" content="website">
<link rel="icon" href="/favicon.ico" type="image/x-icon">
<style>
.directory-checkbox + button:focus {
outline: none;
}
.directory-checkbox + button:hover {
color: #4a5568;
}
</style>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://unpkg.com/lucide@latest"></script>
<script src="https://unpkg.com/lucide@latest/dist/umd/lucide.js"></script>
Expand Down
19 changes: 19 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,13 @@ function displayDirectoryStructure(tree) {
// Directory
checkbox.classList.add('directory-checkbox');
li.appendChild(checkbox);

// Add collapse/expand button
const collapseButton = document.createElement('button');
collapseButton.innerHTML = '<i data-lucide="chevron-down" class="w-4 h-4"></i>';
collapseButton.className = 'mr-1 focus:outline-none';
li.appendChild(collapseButton);

const folderIcon = document.createElement('i');
folderIcon.setAttribute('data-lucide', 'folder');
folderIcon.className = 'inline-block w-4 h-4 mr-1';
Expand All @@ -185,6 +192,18 @@ function displayDirectoryStructure(tree) {
childBox.indeterminate = false;
});
});

// Add collapse/expand functionality
collapseButton.addEventListener('click', function() {
ul.classList.toggle('hidden');
const icon = this.querySelector('[data-lucide]');
if (ul.classList.contains('hidden')) {
icon.setAttribute('data-lucide', 'chevron-right');
} else {
icon.setAttribute('data-lucide', 'chevron-down');
}
lucide.createIcons();
});
} else {
// File
checkbox.value = JSON.stringify({ url: item.url, path: item.path });
Expand Down

0 comments on commit 01f8e07

Please sign in to comment.