Changed around line 1
+ document.addEventListener('DOMContentLoaded', () => {
+ loadCards();
+ setupEventListeners();
+ });
+
+ function setupEventListeners() {
+ document.querySelectorAll('.add-card').forEach(button => {
+ button.addEventListener('click', addCard);
+ });
+
+ document.querySelectorAll('.cards-container').forEach(container => {
+ container.addEventListener('dragover', dragOver);
+ container.addEventListener('drop', drop);
+ });
+ }
+
+ function addCard(e) {
+ const board = e.target.closest('.board');
+ const container = board.querySelector('.cards-container');
+ const cardText = prompt('Enter card content:');
+
+ if (cardText) {
+ const card = createCard(cardText);
+ container.appendChild(card);
+ saveCards();
+ }
+ }
+
+ function createCard(text) {
+ const template = document.getElementById('cardTemplate');
+ const card = template.content.cloneNode(true).children[0];
+
+ card.querySelector('.card-content').textContent = text;
+ card.addEventListener('dragstart', dragStart);
+ card.addEventListener('dragend', dragEnd);
+
+ card.querySelector('.edit-card').addEventListener('click', () => editCard(card));
+ card.querySelector('.delete-card').addEventListener('click', () => deleteCard(card));
+
+ return card;
+ }
+
+ function editCard(card) {
+ const content = card.querySelector('.card-content');
+ const newText = prompt('Edit card:', content.textContent);
+
+ if (newText) {
+ content.textContent = newText;
+ saveCards();
+ }
+ }
+
+ function deleteCard(card) {
+ if (confirm('Delete this card?')) {
+ card.remove();
+ saveCards();
+ }
+ }
+
+ function dragStart(e) {
+ e.target.classList.add('dragging');
+ }
+
+ function dragEnd(e) {
+ e.target.classList.remove('dragging');
+ saveCards();
+ }
+
+ function dragOver(e) {
+ e.preventDefault();
+ const container = e.target.closest('.cards-container');
+ container.classList.add('drag-over');
+ }
+
+ function drop(e) {
+ e.preventDefault();
+ const container = e.target.closest('.cards-container');
+ const card = document.querySelector('.dragging');
+
+ container.classList.remove('drag-over');
+ container.appendChild(card);
+ }
+
+ function saveCards() {
+ const boards = {};
+ document.querySelectorAll('.cards-container').forEach(container => {
+ const boardId = container.dataset.board;
+ boards[boardId] = Array.from(container.children).map(card =>
+ card.querySelector('.card-content').textContent
+ );
+ });
+ localStorage.setItem('taskflowBoards', JSON.stringify(boards));
+ }
+
+ function loadCards() {
+ const boards = JSON.parse(localStorage.getItem('taskflowBoards') || '{}');
+ Object.entries(boards).forEach(([boardId, cards]) => {
+ const container = document.querySelector(`[data-board="${boardId}"]`);
+ cards.forEach(cardText => {
+ container.appendChild(createCard(cardText));
+ });
+ });
+ }