-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
265 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,169 @@ | ||
document.addEventListener("DOMContentLoaded", function () { | ||
const TreeView = (() => { | ||
const treeview = document.querySelector('.treeview'); | ||
|
||
function toggleNode(event) { | ||
const toggleNode = (event) => { | ||
const li = event.target.closest('li'); | ||
const ul = li.querySelector('ul'); | ||
if (ul) { | ||
ul.classList.toggle('hidden'); | ||
const isOpen = !ul.classList.contains('hidden'); | ||
const icon = li.querySelector('.tree-view-icon'); | ||
const block = li.querySelector('div'); | ||
if (isOpen) { | ||
icon.style.transform = 'rotate(-90deg)'; | ||
block.classList.add('active'); | ||
} | ||
else { | ||
icon.style.transform = ''; | ||
block.classList.remove('active'); | ||
} | ||
|
||
const nodeId = li.getAttribute('data-id'); | ||
sessionStorage.setItem(nodeId, isOpen); | ||
const isOpen = toggleElementVisibility(ul); | ||
updateNodeAppearance(li, isOpen); | ||
saveNodeState(li, isOpen); | ||
} | ||
} | ||
}; | ||
|
||
function hideNode(toggle) { | ||
const hideNode = (toggle, isOpen) => { | ||
const li = toggle.closest('li'); | ||
const ul = li.querySelector('ul'); | ||
if (ul) { | ||
ul.classList.add('hidden'); | ||
const icon = li.querySelector('.tree-view-icon'); | ||
const block = li.querySelector('div'); | ||
icon.style.transform = ''; | ||
block.classList.remove('active'); | ||
const nodeId = li.getAttribute('data-id'); | ||
sessionStorage.setItem(nodeId, false); | ||
toggleElementVisibility(ul, isOpen); | ||
updateNodeAppearance(li, isOpen); | ||
saveNodeState(li, isOpen); | ||
} | ||
} | ||
}; | ||
|
||
const togglers = treeview.querySelectorAll('.toggle'); | ||
togglers.forEach(toggle => { | ||
toggle.addEventListener('click', toggleNode); | ||
}); | ||
const toggleElementVisibility = (element, isOpen = null) => { | ||
if (isOpen !== null) { | ||
element.classList.toggle('hidden', !isOpen); | ||
} else { | ||
element.classList.toggle('hidden'); | ||
} | ||
return !element.classList.contains('hidden'); | ||
}; | ||
|
||
const updateNodeAppearance = (li, isOpen) => { | ||
const icon = li.querySelector('.tree-view-icon'); | ||
const block = li.querySelector('div'); | ||
icon.style.transform = isOpen ? 'rotate(-90deg)' : ''; | ||
block.classList.toggle('active', isOpen); | ||
}; | ||
|
||
const saveNodeState = (li, isOpen) => { | ||
const nodeId = li.getAttribute('data-id'); | ||
sessionStorage.setItem(nodeId, isOpen); | ||
}; | ||
|
||
document.getElementById('collapse-concepts').addEventListener('click', () => { | ||
const initialize = () => { | ||
const togglers = treeview.querySelectorAll('.toggler'); | ||
togglers.forEach(toggle => { | ||
hideNode(toggle); | ||
toggle.addEventListener('click', toggleNode); | ||
}); | ||
}); | ||
|
||
treeview.querySelectorAll('li[data-id]').forEach(li => { | ||
const nodeId = li.getAttribute('data-id'); | ||
const isOpen = sessionStorage.getItem(nodeId) === 'true'; | ||
const ul = li.querySelector('ul'); | ||
if (ul && isOpen) { | ||
ul.classList.remove('hidden'); | ||
console.log(nodeId); | ||
li.querySelector('.tree-view-icon').style.transform = 'rotate(-90deg)'; | ||
li.querySelector('div').classList.add('active'); | ||
} | ||
}); | ||
let isOpenG = true; | ||
document.getElementById('collapse-concepts').addEventListener('click', () => { | ||
isOpenG = !isOpenG; | ||
togglers.forEach(toggle => { | ||
hideNode(toggle, isOpenG); | ||
}); | ||
}); | ||
|
||
}); | ||
treeview.querySelectorAll('li[data-id]').forEach(li => { | ||
const nodeId = li.getAttribute('data-id'); | ||
const isOpen = sessionStorage.getItem(nodeId) === 'true'; | ||
const ul = li.querySelector('ul'); | ||
if (ul && isOpen) { | ||
ul.classList.remove('hidden'); | ||
li.querySelector('.tree-view-icon').style.transform = 'rotate(-90deg)'; | ||
li.querySelector('div').classList.add('active'); | ||
} | ||
}); | ||
}; | ||
|
||
window.addEventListener("load", function () { | ||
return { | ||
initialize | ||
}; | ||
})(); | ||
|
||
const ContextMenu = (() => { | ||
const contextmenu = document.getElementById('contextmenu'); | ||
const treeview = document.querySelector('.treeview'); | ||
treeview.querySelectorAll('div.open-concept').forEach(div => { | ||
div.addEventListener('dblclick', (e) => { | ||
const route = e.currentTarget.dataset.openConceptRoute; | ||
console.log('click', e.currentTarget.dataset); | ||
window.location.href = route; | ||
let opened = false; | ||
const handleContextMenu = (event, concept) => { | ||
if (opened) { | ||
contextmenu.classList.add('hidden'); | ||
opened = false; | ||
} | ||
|
||
event.preventDefault(); | ||
event.stopPropagation(); | ||
|
||
const title = contextmenu.querySelector('#conctextmenu-title'); | ||
const createParent = contextmenu.querySelector('#conctextmenu-create-parent'); | ||
const createBrother = contextmenu.querySelector('#conctextmenu-create-brother'); | ||
const editConcept = contextmenu.querySelector('#conctextmenu-edit'); | ||
const deleteConcept = contextmenu.querySelector('#conctextmenu-delete'); | ||
const openConcept = contextmenu.querySelector('#conctextmenu-open'); | ||
|
||
title.textContent = concept.name; | ||
createParent.href = concept.parent; | ||
createBrother.href = concept.brother; | ||
editConcept.href = concept.edit; | ||
deleteConcept.action = concept.delete; | ||
openConcept.action = concept.open; | ||
|
||
const x = event.pageX; | ||
const y = event.pageY; | ||
const menuWidth = contextmenu.offsetWidth; | ||
|
||
contextmenu.style.left = x + menuWidth + 'px'; | ||
contextmenu.style.top = y + 'px'; | ||
contextmenu.style.right = 'auto'; | ||
contextmenu.classList.toggle('hidden'); | ||
opened = true; | ||
}; | ||
|
||
const initialize = () => { | ||
treeview.querySelectorAll('div.open-concept').forEach(div => { | ||
div.addEventListener('click', (e) => { | ||
const route = e.currentTarget.dataset.openConceptRoute; | ||
window.location.href = route; | ||
}); | ||
}); | ||
}) | ||
|
||
treeview.querySelectorAll('li[data-el="concept"]').forEach(li => { | ||
const concept = { | ||
name: li.dataset.name, | ||
parent: li.dataset.createParent, | ||
brother: li.dataset.createBrother, | ||
edit: li.dataset.edit, | ||
delete: li.dataset.delete, | ||
open: li.dataset.open | ||
}; | ||
const div = li.querySelector('.lidiv'); | ||
div.addEventListener('contextmenu', (event) => handleContextMenu(event, concept)); | ||
}); | ||
|
||
document.addEventListener('click', (event) => { | ||
if (!contextmenu.contains(event.target)) | ||
contextmenu.classList.add('hidden'); | ||
}); | ||
document.addEventListener('contextmenu', (event) => { | ||
if (!contextmenu.contains(event.target)) | ||
contextmenu.classList.add('hidden'); | ||
}); | ||
}; | ||
|
||
const getConceptFromTarget = (target) => { | ||
const li = target.closest('li[data-el="concept"]'); | ||
if (li) { | ||
return { | ||
name: li.dataset.name, | ||
parent: li.dataset.createParent, | ||
brother: li.dataset.createBrother, | ||
edit: li.dataset.edit, | ||
delete: li.dataset.delete, | ||
open: li.dataset.open | ||
}; | ||
} | ||
return null; | ||
}; | ||
|
||
return { | ||
initialize | ||
}; | ||
})(); | ||
|
||
// Инициализация модулей | ||
document.addEventListener("DOMContentLoaded", () => { | ||
TreeView.initialize(); | ||
ContextMenu.initialize(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<svg class="w-4 h-4 transition-transform delay-50 shrink-0 tree-view-icon dark:text-white" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="3" stroke="currentColor" class="size-6"> | ||
<svg {{ $attributes->merge(['class' => 'w-4 h-4 transition-transform delay-50 shrink-0 tree-view-icon']) }} xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="3" stroke="currentColor" class="size-6"> | ||
<path stroke-linecap="round" stroke-linejoin="round" d="M15.75 19.5 8.25 12l7.5-7.5" /> | ||
</svg> |
Oops, something went wrong.