Changed around line 1
+ document.addEventListener('DOMContentLoaded', () => {
+ // Theme toggle
+ const themeToggle = document.getElementById('theme-toggle');
+ themeToggle.addEventListener('change', () => {
+ document.body.dataset.theme = themeToggle.checked ? 'dark' : 'light';
+ });
+
+ // Board and task management
+ const boardsContainer = document.querySelector('.boards-container');
+ const boardTemplate = document.getElementById('board-template');
+
+ document.getElementById('add-board').addEventListener('click', () => {
+ const boardClone = boardTemplate.content.cloneNode(true);
+ boardsContainer.appendChild(boardClone);
+ });
+
+ // Drag and drop functionality
+ let draggedTask;
+ document.addEventListener('dragstart', (e) => {
+ if (e.target.classList.contains('task')) {
+ draggedTask = e.target;
+ }
+ });
+
+ document.addEventListener('dragover', (e) => {
+ e.preventDefault();
+ const afterElement = getDragAfterElement(e.target.closest('.tasks'), e.clientY);
+ const tasksContainer = e.target.closest('.tasks');
+ if (tasksContainer && draggedTask) {
+ if (afterElement == null) {
+ tasksContainer.appendChild(draggedTask);
+ } else {
+ tasksContainer.insertBefore(draggedTask, afterElement);
+ }
+ }
+ });
+
+ function getDragAfterElement(container, y) {
+ const draggableElements = [...container.querySelectorAll('.task:not(.dragging)')];
+ return draggableElements.reduce((closest, child) => {
+ const box = child.getBoundingClientRect();
+ const offset = y - box.top - box.height / 2;
+ if (offset < 0 && offset > closest.offset) {
+ return { offset: offset, element: child };
+ } else {
+ return closest;
+ }
+ }, { offset: Number.NEGATIVE_INFINITY }).element;
+ }
+
+ // Task completion
+ document.addEventListener('change', (e) => {
+ if (e.target.classList.contains('task-check') && e.target.checked) {
+ const completedList = document.querySelector('.completed-list');
+ const task = e.target.closest('.task');
+ task.remove();
+ completedList.appendChild(task);
+ }
+ });
+ });