Changed around line 1
+ document.addEventListener('DOMContentLoaded', () => {
+ const themeToggle = document.getElementById('theme-toggle');
+ const taskModal = document.getElementById('task-modal');
+ const addTaskBtn = document.getElementById('add-task-btn');
+ const closeBtn = document.querySelector('.close-btn');
+ const taskForm = document.getElementById('task-form');
+ const todoColumn = document.querySelector('#todo .tasks');
+
+ // Theme toggle
+ themeToggle.addEventListener('change', () => {
+ document.body.dataset.theme = themeToggle.checked ? 'dark' : 'light';
+ });
+
+ // Task modal
+ addTaskBtn.addEventListener('click', () => {
+ taskModal.style.display = 'block';
+ });
+
+ closeBtn.addEventListener('click', () => {
+ taskModal.style.display = 'none';
+ });
+
+ window.addEventListener('click', (e) => {
+ if (e.target === taskModal) {
+ taskModal.style.display = 'none';
+ }
+ });
+
+ // Task form submission
+ taskForm.addEventListener('submit', (e) => {
+ e.preventDefault();
+
+ const task = {
+ name: document.getElementById('task-name').value,
+ description: document.getElementById('task-description').value,
+ labels: document.getElementById('task-labels').value,
+ dueDate: document.getElementById('task-due-date').value,
+ color: document.getElementById('task-color').value
+ };
+
+ createTask(task);
+ taskModal.style.display = 'none';
+ taskForm.reset();
+ });
+
+ // Drag and drop functionality
+ let draggedTask = null;
+
+ document.querySelectorAll('.tasks').forEach(column => {
+ column.addEventListener('dragover', (e) => {
+ e.preventDefault();
+ const afterElement = getDragAfterElement(column, e.clientY);
+ const task = document.querySelector('.dragging');
+ if (afterElement == null) {
+ column.appendChild(task);
+ } else {
+ column.insertBefore(task, afterElement);
+ }
+ });
+ });
+
+ function createTask(task) {
+ const taskElement = document.createElement('div');
+ taskElement.classList.add('task');
+ taskElement.draggable = true;
+ taskElement.style.backgroundColor = task.color;
+
+ taskElement.innerHTML = `
+
${task.name} +
+ ${task.labels}
+ ${task.dueDate}
+
+
+ `;
+
+ taskElement.addEventListener('dragstart', () => {
+ taskElement.classList.add('dragging');
+ draggedTask = taskElement;
+ });
+
+ taskElement.addEventListener('dragend', () => {
+ taskElement.classList.remove('dragging');
+ draggedTask = null;
+ });
+
+ todoColumn.appendChild(taskElement);
+ }
+
+ 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;
+ }
+ });