Certainly! Enhancing your task management app with a skeuomorphic design can make it more engaging and visually appealing by mimicking real-world textures and objects. Below is an improved version of your app with skeuomorphic touches, including textures, shadows, and 3D effects to create a more satisfying and interactive user experience.
Below is the complete HTML, CSS, and JavaScript code with the skeuomorphic enhancements. You can replace your existing code with the following or integrate the changes accordingly.
html Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Task Management Notebook</title>
<style>
/* Importing Google Fonts for a more realistic feel */
@import url('https://fonts.googleapis.com/css2?family=Architects+Daughter&family=Roboto:wght@400;700&display=swap');
/* Keyframes for animations */
@keyframes fadeIn {
from { opacity: 0; transform: translateY(20px); }
to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeOut {
from { opacity: 1; transform: translateY(0); }
to { opacity: 0; transform: translateY(20px); }
}
@keyframes slideIn {
from { transform: translateX(-100%); }
to { transform: translateX(0); }
}
@keyframes pulse {
0% { transform: scale(1); }
50% { transform: scale(1.05); }
100% { transform: scale(1); }
}
@keyframes rotate {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}
/* Global Styles */
body {
font-family: 'Roboto', sans-serif;
background-color: #f4f1ee;
margin: 0;
padding: 0;
display: flex;
flex-direction: column;
min-height: 100vh;
background-image:
url('https://www.toptal.com/designers/subtlepatterns/patterns/paper_texture.png');
background-size: cover;
transition: background-color 0.3s ease;
}
/* Top Bar Styling */
.top-bar {
position: fixed;
top: 0;
left: 0;
right: 0;
background: linear-gradient(to bottom, #6b4f31, #3e2c1f);
color: #fffaf0;
padding: 15px 0;
box-shadow: 0 4px 6px rgba(0,0,0,0.3);
z-index: 1000;
animation: slideIn 0.5s ease-out;
display: flex;
flex-direction: column;
}
/* Tabs Styling */
.tabs {
display: flex;
justify-content: flex-start;
padding: 0 30px;
background-color: transparent;
border-bottom: 2px solid #5e2c0b;
overflow-x: auto;
white-space: nowrap;
}
.tab {
position: relative;
padding: 10px 25px;
background: linear-gradient(to bottom, #d2b48c, #a0522d);
color: #fffaf0;
border: none;
cursor: pointer;
transition: all 0.3s ease;
margin-right: 10px;
border-top-left-radius: 10px;
border-top-right-radius: 10px;
box-shadow: inset 0 -4px 6px rgba(0,0,0,0.2),
0 4px 6px rgba(0,0,0,0.1);
font-weight: bold;
font-size: 16px;
}
.tab.active {
background: linear-gradient(to bottom, #f0e6d2, #d2b48c);
color: #3e2c1f;
box-shadow: inset 0 -2px 4px rgba(0,0,0,0.1);
transform: translateY(2px);
}
.tab:hover {
filter: brightness(110%);
box-shadow: inset 0 -3px 5px rgba(0,0,0,0.15),
0 6px 8px rgba(0,0,0,0.15);
}
/* Add Category Tab Styling */
#addCategoryTab {
background: linear-gradient(to bottom, #8B4513, #5e2c0b);
color: #fffaf0;
font-size: 20px;
display: flex;
align-items: center;
justify-content: center;
width: 40px;
height: 40px;
border-radius: 50%;
text-align: center;
}
/* Sort Tasks Button Styling */
#sortTasks {
margin-left: auto;
padding: 8px 16px;
background: linear-gradient(to bottom, #8B4513, #5e2c0b);
color: #fffaf0;
border: none;
border-radius: 20px;
cursor: pointer;
font-size: 14px;
transition: all 0.3s ease;
box-shadow: 0 4px 6px rgba(0,0,0,0.2);
display: flex;
align-items: center;
}
#sortTasks:hover {
filter: brightness(110%);
box-shadow: 0 6px 8px rgba(0,0,0,0.25);
transform: translateY(-2px);
}
/* Input Container Styling */
.input-container {
background: url('https://www.toptal.com/designers/subtlepatterns/patterns/black_linen.png');
background-size: cover;
border: 2px solid #5e2c0b;
border-radius: 10px;
box-shadow: 0 4px 6px rgba(0,0,0,0.2);
padding: 20px 30px;
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 15px;
margin: 20px auto 0;
max-width: 1000px;
width: 95%;
background-color: #fffaf0;
transition: all 0.3s ease;
}
/* Input Fields Styling */
#taskInput, #taskDate, #taskTime, #taskImportance {
height: 35px;
padding: 8px 12px;
border: 2px solid #8B4513;
border-radius: 8px;
font-size: 16px;
background-color: #fff8dc;
color: #5e2c0b;
box-shadow: inset 0 2px 4px rgba(0,0,0,0.1);
transition: all 0.3s ease;
font-family: 'Roboto', sans-serif;
}
#taskInput:focus, #taskDate:focus, #taskTime:focus, #taskImportance:focus {
box-shadow: 0 0 8px rgba(139, 69, 19, 0.5);
transform: translateY(-2px);
}
#taskInput {
width: 300px;
}
#taskDate, #taskTime {
width: 150px;
}
#taskImportance {
width: 140px;
}
/* Add Task Button Styling */
#addTask {
height: 45px;
padding: 0 25px;
background: linear-gradient(to bottom, #5e2c0b, #3d1c07);
color: #fffaf0;
border: none;
border-radius: 25px;
cursor: pointer;
font-size: 16px;
transition: all 0.3s ease;
box-shadow: 0 4px 6px rgba(0,0,0,0.3);
display: flex;
align-items: center;
}
#addTask:hover {
filter: brightness(110%);
box-shadow: 0 6px 10px rgba(0,0,0,0.35);
transform: translateY(-3px);
}
/* Task List Styling */
.task-list {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
gap: 25px;
padding: 30px;
margin-top: 150px;
max-width: 1200px;
width: 95%;
margin-left: auto;
margin-right: auto;
}
/* Task Item Styling */
.task-item {
background: #fffaf0;
border: 2px solid #d2b48c;
border-radius: 15px;
padding: 20px;
box-shadow: 0 4px 8px rgba(0,0,0,0.15);
transition: all 0.3s ease;
display: flex;
flex-direction: column;
justify-content: space-between;
position: relative;
animation: fadeIn 0.5s ease-out;
background-image: url('https://www.toptal.com/designers/subtlepatterns/patterns/paperplanes.png');
background-size: cover;
}
.task-item:hover {
transform: translateY(-5px) scale(1.02);
box-shadow: 0 8px 15px rgba(0,0,0,0.2);
}
/* Task Text Styling */
.task-text {
color: #5e2c0b;
font-size: 1.2em;
margin-bottom: 15px;
cursor: pointer;
transition: color 0.3s ease;
font-family: 'Architects Daughter', cursive;
text-shadow: 1px 1px 2px rgba(0,0,0,0.1);
}
.task-text:hover {
color: #3e2c1f;
filter: brightness(120%);
}
/* Task DateTime and Category Styling */
.task-datetime, .task-category {
font-size: 0.95em;
color: #8B4513;
margin-top: 5px;
cursor: pointer;
transition: all 0.3s ease;
font-family: 'Roboto', sans-serif;
}
.task-datetime:hover, .task-category:hover {
filter: brightness(120%);
transform: translateX(5px);
}
/* Task Importance Styling */
.task-importance {
font-size: 0.95em;
font-weight: bold;
padding: 5px 10px;
border-radius: 12px;
margin-top: 10px;
align-self: flex-start;
cursor: pointer;
transition: all 0.3s ease;
font-family: 'Roboto', sans-serif;
}
.task-importance:hover {
transform: scale(1.1);
box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}
.importance-None { background-color: #e0e0e0; color: #333; }
.importance-Low { background-color: #81c784; color: #1b5e20; }
.importance-Medium { background-color: #fff176; color: #f57f17; }
.importance-High { background-color: #ef5350; color: #ffffff; }
/* Task Category Styling */
.task-category {
padding: 5px 10px;
border-radius: 12px;
align-self: flex-start;
background-color: #d2b48c;
color: #fffaf0;
box-shadow: inset 0 -2px 4px rgba(0,0,0,0.1);
}
.task-category:hover {
filter: brightness(110%);
}
/* Delete Task Button Styling */
.delete-task {
position: absolute;
top: 15px;
right: 15px;
background: linear-gradient(to bottom, #ef5350, #c62828);
color: #fffaf0;
border: none;
border-radius: 50%;
width: 30px;
height: 30px;
font-size: 18px;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
transition: all 0.3s ease;
box-shadow: 0 3px 5px rgba(0,0,0,0.2);
}
.delete-task:hover {
filter: brightness(110%);
box-shadow: 0 5px 8px rgba(0,0,0,0.25);
animation: rotate 0.3s linear;
}
/* Complete Task Button Styling */
.complete-task {
position: absolute;
bottom: 15px;
right: 15px;
background: linear-gradient(to bottom, #81c784, #4caf50);
color: #fffaf0;
border: none;
border-radius: 50%;
width: 30px;
height: 30px;
font-size: 16px;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
transition: all 0.3s ease;
box-shadow: 0 3px 5px rgba(0,0,0,0.2);
}
.complete-task:hover {
filter: brightness(110%);
box-shadow: 0 5px 8px rgba(0,0,0,0.25);
transform: scale(1.1);
}
/* Modal Styling */
.modal {
display: none;
position: fixed;
z-index: 1001;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgba(0,0,0,0.4);
animation: fadeIn 0.3s ease-out;
display: flex;
align-items: center;
justify-content: center;
}
.modal-content {
background-color: #fffaf0;
margin: auto;
padding: 30px;
border: 3px solid #8B4513;
width: 350px;
border-radius: 15px;
box-shadow: 0 6px 12px rgba(0,0,0,0.3);
animation: fadeIn 0.5s ease-out;
background-image: url('https://www.toptal.com/designers/subtlepatterns/patterns/vintage-paper.png');
background-size: cover;
}
.close {
color: #8B4513;
float: right;
font-size: 30px;
font-weight: bold;
cursor: pointer;
transition: all 0.3s ease;
}
.close:hover,
.close:focus {
color: #000;
text-decoration: none;
transform: scale(1.1);
}
/* New Category Inputs */
#newCategoryInput, #categoryColorInput {
width: 100%;
padding: 12px;
margin: 12px 0;
border: 2px solid #8B4513;
border-radius: 8px;
font-size: 16px;
transition: all 0.3s ease;
font-family: 'Roboto', sans-serif;
}
#newCategoryInput:focus, #categoryColorInput:focus {
box-shadow: 0 0 8px rgba(139, 69, 19, 0.5);
transform: translateY(-2px);
}
#addNewCategory {
width: 100%;
padding: 12px;
background: linear-gradient(to bottom, #8B4513, #5e2c0b);
color: #fffaf0;
border: none;
border-radius: 20px;
cursor: pointer;
font-size: 16px;
transition: all 0.3s ease;
box-shadow: 0 4px 6px rgba(0,0,0,0.3);
font-family: 'Roboto', sans-serif;
}
#addNewCategory:hover {
filter: brightness(110%);
box-shadow: 0 6px 10px rgba(0,0,0,0.35);
transform: translateY(-2px);
}
/* Confirm Delete Modal Styling */
.confirm-delete-modal .modal-content {
text-align: center;
background-image: url('https://www.toptal.com/designers/subtlepatterns/patterns/vintage-paper.png');
}
.confirm-delete-modal button {
margin: 15px;
padding: 12px 25px;
border: none;
border-radius: 20px;
cursor: pointer;
font-size: 16px;
transition: all 0.3s ease;
font-family: 'Roboto', sans-serif;
}
.confirm-delete-modal .confirm {
background: linear-gradient(to bottom, #ef5350, #c62828);
color: #fffaf0;
box-shadow: 0 4px 6px rgba(0,0,0,0.25);
}
.confirm-delete-modal .confirm:hover {
filter: brightness(110%);
box-shadow: 0 6px 8px rgba(0,0,0,0.3);
transform: translateY(-2px);
}
.confirm-delete-modal .cancel {
background: linear-gradient(to bottom, #81c784, #4caf50);
color: #fffaf0;
box-shadow: 0 4px 6px rgba(0,0,0,0.25);
}
.confirm-delete-modal .cancel:hover {
filter: brightness(110%);
box-shadow: 0 6px 8px rgba(0,0,0,0.3);
transform: translateY(-2px);
}
/* Editable Fields Styling */
.editable {
cursor: pointer;
transition: all 0.3s ease;
font-family: 'Roboto', sans-serif;
}
.editable:hover {
background-color: rgba(255, 255, 255, 0.5);
transform: scale(1.03);
border-radius: 5px;
}
.edit-input {
width: 100%;
padding: 8px;
border: 2px solid #8B4513;
border-radius: 8px;
font-size: 16px;
background-color: #fffaf0;
color: #8B4513;
transition: all 0.3s ease;
font-family: 'Roboto', sans-serif;
}
.edit-input:focus {
box-shadow: 0 0 8px rgba(139, 69, 19, 0.5);
transform: translateY(-2px);
}
.category-select {
width: 100%;
padding: 8px;
border: 2px solid #8B4513;
border-radius: 8px;
font-size: 16px;
background-color: #fffaf0;
color: #8B4513;
transition: all 0.3s ease;
font-family: 'Roboto', sans-serif;
}
.category-select:focus {
box-shadow: 0 0 8px rgba(139, 69, 19, 0.5);
transform: translateY(-2px);
}
/* Completed Task Styling */
.task-completed {
text-decoration: line-through;
opacity: 0.6;
background-color: #f0f0f0;
border-color: #b0b0b0;
}
/* Footer Styling */
.footer {
text-align: center;
padding: 25px;
background: linear-gradient(to bottom, #6b4f31, #3e2c1f);
color: #fffaf0;
margin-top: auto;
font-family: 'Roboto', sans-serif;
box-shadow: 0 -2px 5px rgba(0,0,0,0.2);
}
</style>
</head>
<body>
<!-- Top Bar with Tabs and Add/Sort Buttons -->
<div class="top-bar">
<div class="tabs" id="categoryTabs">
<button class="tab active" data-category="General" data-color="#6b4f31">General</button>
<button class="tab" id="addCategoryTab">+</button>
<button id="sortTasks">Sort Tasks</button>
</div>
<!-- Input Fields for Adding New Tasks -->
<div class="input-container">
<input type="text" id="taskInput" placeholder="Enter a new task">
<input type="date" id="taskDate">
<input type="time" id="taskTime">
<select id="taskImportance">
<option value="None">None</option>
<option value="Low">Low</option>
<option value="Medium">Medium</option>
<option value="High">High</option>
</select>
<button id="addTask">Add Task</button>
</div>
</div>
<!-- Task List -->
<div class="task-list" id="taskList"></div>
<!-- New Category Modal -->
<div id="newCategoryModal" class="modal">
<div class="modal-content">
<span class="close">×</span>
<h2>Add New Category</h2>
<input type="text" id="newCategoryInput" placeholder="Enter category name">
<input type="color" id="categoryColorInput" value="#6b4f31">
<button id="addNewCategory">Add Category</button>
</div>
</div>
<!-- Confirm Delete Modal -->
<div id="confirmDeleteModal" class="modal confirm-delete-modal">
<div class="modal-content">
<h2>Confirm Delete</h2>
<p>Are you sure you want to delete this task?</p>
<button class="confirm">Yes, Delete</button>
<button class="cancel">Cancel</button>
</div>
</div>
<!-- Footer -->
<footer class="footer">
<p>© 2023 Task Management Notebook. All rights reserved.</p>
</footer>
<!-- JavaScript for Interactivity -->
<script>
document.addEventListener('DOMContentLoaded', function() {
const taskInput = document.getElementById('taskInput');
const taskDate = document.getElementById('taskDate');
const taskTime = document.getElementById('taskTime');
const taskImportance = document.getElementById('taskImportance');
const addTaskButton = document.getElementById('addTask');
const taskList = document.getElementById('taskList');
const categoryTabs = document.getElementById('categoryTabs');
const addCategoryTab = document.getElementById('addCategoryTab');
const modal = document.getElementById('newCategoryModal');
const newCategoryInput = document.getElementById('newCategoryInput');
const categoryColorInput = document.getElementById('categoryColorInput');
const addNewCategoryButton = document.getElementById('addNewCategory');
const closeModal = document.getElementsByClassName('close')[0];
const confirmDeleteModal = document.getElementById('confirmDeleteModal');
const confirmDeleteButton = confirmDeleteModal.querySelector('.confirm');
const cancelDeleteButton = confirmDeleteModal.querySelector('.cancel');
const sortTasksButton = document.getElementById('sortTasks');
let currentCategory = 'General';
let taskToDelete = null;
let categoryColors = {
'General': '#6b4f31'
};
// Set default date and time to now
const now = new Date();
taskDate.valueAsDate = now;
taskTime.value = now.getHours().toString().padStart(2, '0') + ':' +
now.getMinutes().toString().padStart(2, '0');
// Event Listeners
addTaskButton.addEventListener('click', addTask);
taskInput.addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
addTask();
}
});
addCategoryTab.addEventListener('click', function() {
openNewCategoryModal();
});
closeModal.addEventListener('click', function() {
modal.style.display = 'none';
});
window.addEventListener('click', function(event) {
if (event.target == modal) {
modal.style.display = 'none';
}
if (event.target == confirmDeleteModal) {
confirmDeleteModal.style.display = 'none';
}
});
addNewCategoryButton.addEventListener('click', function() {
const categoryName = newCategoryInput.value.trim();
const categoryColor = categoryColorInput.value;
if (categoryName) {
addNewCategory(categoryName, categoryColor);
modal.style.display = 'none';
newCategoryInput.value = '';
}
});
categoryTabs.addEventListener('click', function(e) {
if (e.target.classList.contains('tab') && e.target.id !== 'addCategoryTab') {
setActiveCategory(e.target.dataset.category);
}
});
confirmDeleteButton.addEventListener('click', function() {
if (taskToDelete) {
taskToDelete.style.animation = 'fadeOut 0.5s ease-out';
taskToDelete.addEventListener('animationend', function() {
taskToDelete.remove();
taskToDelete = null;
confirmDeleteModal.style.display = 'none';
saveTasks();
});
}
});
cancelDeleteButton.addEventListener('click', function() {
confirmDeleteModal.style.display = 'none';
taskToDelete = null;
});
sortTasksButton.addEventListener('click', sortTasks);
// Functions
function openNewCategoryModal(taskItem = null) {
modal.style.display = 'flex';
addNewCategoryButton.onclick = function() {
const categoryName = newCategoryInput.value.trim();
const categoryColor = categoryColorInput.value;
if (categoryName) {
addNewCategory(categoryName, categoryColor);
modal.style.display = 'none';
newCategoryInput.value = '';
if (taskItem) {
updateTaskCategory(taskItem, categoryName);
}
}
};
}
function addNewCategory(categoryName, categoryColor) {
if (!document.querySelector(`.tab[data-category="${categoryName}"]`)) {
const newTab = document.createElement('button');
newTab.className = 'tab';
newTab.textContent = categoryName;
newTab.dataset.category = categoryName;
newTab.dataset.color = categoryColor;
newTab.style.animation = 'fadeIn 0.5s ease-out';
categoryTabs.insertBefore(newTab, addCategoryTab);
categoryColors[categoryName] = categoryColor;
updateCategoryStyles(categoryName, categoryColor);
}
setActiveCategory(categoryName);
}
function setActiveCategory(category) {
currentCategory = category;
document.querySelectorAll('.tab').forEach(tab => {
tab.classList.remove('active');
if (tab.dataset.category === category) {
tab.classList.add('active');
}
});
updateCategoryStyles(category, categoryColors[category]);
filterTasks();
}
function updateCategoryStyles(category, color) {
const style = document.createElement('style');
const darkerColor = darkenColor(color, 20);
const lighterColor = lightenColor(color, 20);
const veryLightColor = lightenColor(color, 80);
const contrastColor = getContrastColor(color);
const darkColor = ensureDarkColor(color);
style.textContent = `
.tab[data-category="${category}"] {
background: linear-gradient(to bottom, ${color}, ${darkerColor});
color: #fffaf0;
}
.tab[data-category="${category}"]:hover {
background: linear-gradient(to bottom, ${lighterColor}, ${color});
}
.tab[data-category="${category}"].active {
background: linear-gradient(to bottom, ${veryLightColor}, ${color});
color: ${darkColor};
}
.task-item[data-category="${category}"] {
border-color: ${darkerColor};
}
.task-item[data-category="${category}"] .task-importance {
background-color: ${lightenColor(color, 15)};
color: ${getContrastColor(lightenColor(color, 15))};
}
`;
document.head.appendChild(style);
// Update top bar and input container styles
const topBar = document.querySelector('.top-bar');
topBar.style.background = `linear-gradient(to bottom, ${darkColor}, ${darkenColor(darkColor, 20)})`;
const inputContainer = document.querySelector('.input-container');
inputContainer.style.borderColor = darkenColor(darkColor, 30);
const inputs = inputContainer.querySelectorAll('input, select');
inputs.forEach(input => {
input.style.borderColor = darkenColor(darkColor, 30);
input.style.backgroundColor = lightenColor(darkColor, 60);
input.style.color = darkColor;
});
const addTaskBtn = inputContainer.querySelector('#addTask');
addTaskBtn.style.background = `linear-gradient(to bottom, ${darkColor}, ${darkenColor(darkColor, 20)})`;
addTaskBtn.style.color = getContrastColor(darkColor);
}
function addTask() {
const taskText = taskInput.value.trim();
const dateValue = taskDate.value;
const timeValue = taskTime.value;
const importanceValue = taskImportance.value;
if (taskText) {
const taskItem = document.createElement('div');
taskItem.className = 'task-item';
taskItem.dataset.category = currentCategory;
taskItem.style.animation = 'fadeIn 0.5s ease-out';
const taskTextSpan = document.createElement('span');
taskTextSpan.className = 'task-text editable';
taskTextSpan.textContent = taskText;
taskTextSpan.addEventListener('click', makeEditable);
const taskDateTimeSpan = document.createElement('span');
taskDateTimeSpan.className = 'task-datetime editable';
if (dateValue && timeValue) {
const dateTime = new Date(dateValue + 'T' + timeValue);
taskDateTimeSpan.textContent = dateTime.toLocaleString();
} else if (dateValue) {
taskDateTimeSpan.textContent = new Date(dateValue).toLocaleDateString();
} else if (timeValue) {
taskDateTimeSpan.textContent = timeValue;
}
taskDateTimeSpan.addEventListener('click', makeEditable);
const taskImportanceSpan = document.createElement('span');
taskImportanceSpan.className = `task-importance importance-${importanceValue} editable`;
taskImportanceSpan.textContent = importanceValue;
taskImportanceSpan.addEventListener('click', makeEditable);
const taskCategorySpan = document.createElement('span');
taskCategorySpan.className = 'task-category editable';
taskCategorySpan.textContent = currentCategory;
taskCategorySpan.style.backgroundColor = categoryColors[currentCategory];
taskCategorySpan.addEventListener('click', function() {
makeCategoryEditable(taskItem);
});
const deleteButton = document.createElement('button');
deleteButton.className = 'delete-task';
deleteButton.innerHTML = '×';
deleteButton.addEventListener('click', function(e) {
e.stopPropagation();
taskToDelete = taskItem;
confirmDeleteModal.style.display = 'flex';
});
const completeButton = document.createElement('button');
completeButton.className = 'complete-task';
completeButton.innerHTML = '✔';
completeButton.addEventListener('click', function(e) {
e.stopPropagation();
toggleTaskCompletion(taskItem);
});
taskItem.appendChild(taskTextSpan);
taskItem.appendChild(taskDateTimeSpan);
taskItem.appendChild(taskImportanceSpan);
taskItem.appendChild(taskCategorySpan);
taskItem.appendChild(deleteButton);
taskItem.appendChild(completeButton);
taskList.appendChild(taskItem);
taskInput.value = '';
saveTasks();
filterTasks();
}
}
function filterTasks() {
const tasks = taskList.getElementsByClassName('task-item');
for (let task of tasks) {
if (task.dataset.category === currentCategory) {
task.style.display = 'flex';
task.style.animation = 'fadeIn 0.5s ease-out';
} else {
task.style.display = 'none';
}
}
}
function makeEditable(event) {
const element = event.target;
const originalText = element.textContent;
const originalClass = element.className;
let input;
if (element.classList.contains('task-importance')) {
input = document.createElement('select');
const options = ['None', 'Low', 'Medium', 'High'];
options.forEach(option => {
const optionElement = document.createElement('option');
optionElement.value = option;
optionElement.textContent = option;
if (option === originalText) {
optionElement.selected = true;
}
input.appendChild(optionElement);
});
} else if (element.classList.contains('task-datetime')) {
input = document.createElement('input');
input.type = 'datetime-local';
const date = new Date(originalText);
input.value = date.toISOString().slice(0, 16);
} else {
input = document.createElement('input');
input.type = 'text';
input.value = originalText;
}
input.className = 'edit-input';
element.textContent = '';
element.appendChild(input);
input.focus();
input.addEventListener('blur', function() {
let newValue = input.value;
if (element.classList.contains('task-datetime')) {
newValue = new Date(input.value).toLocaleString();
}
element.textContent = newValue;
element.className = originalClass;
if (element.classList.contains('task-importance')) {
element.classList.remove(...element.classList);
element.classList.add(`task-importance`, `importance-${newValue}`, `editable`);
}
element.style.animation = 'pulse 0.3s ease-out';
saveTasks();
});
input.addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
input.blur();
}
});
}
function makeCategoryEditable(taskItem) {
const categorySpan = taskItem.querySelector('.task-category');
const currentCategory = categorySpan.textContent;
const select = document.createElement('select');
select.className = 'category-select';
// Add existing categories
Object.keys(categoryColors).forEach(category => {
const option = document.createElement('option');
option.value = category;
option.textContent = category;
if (category === currentCategory) {
option.selected = true;
}
select.appendChild(option);
});
// Add "New Category" option
const newCategoryOption = document.createElement('option');
newCategoryOption.value = 'new';
newCategoryOption.textContent = '+ New Category';
select.appendChild(newCategoryOption);
categorySpan.textContent = '';
categorySpan.appendChild(select);
select.focus();
select.addEventListener('change', function() {
if (select.value === 'new') {
openNewCategoryModal(taskItem);
} else {
updateTaskCategory(taskItem, select.value);
}
});
select.addEventListener('blur', function() {
if (select.value !== 'new') {
categorySpan.textContent = select.value;
categorySpan.style.backgroundColor = categoryColors[select.value];
taskItem.dataset.category = select.value;
filterTasks();
saveTasks();
}
});
}
function updateTaskCategory(taskItem, newCategory) {
taskItem.dataset.category = newCategory;
const categorySpan = taskItem.querySelector('.task-category');
categorySpan.textContent = newCategory;
categorySpan.style.backgroundColor = categoryColors[newCategory];
filterTasks();
saveTasks();
}
function getRandomColor() {
return '#' + Math.floor(Math.random()*16777215).toString(16);
}
function lightenColor(color, percent) {
const num = parseInt(color.replace('#',''),16),
amt = Math.round(2.55 * percent),
R = (num >> 16) + amt,
B = (num >> 8 & 0x00FF) + amt,
G = (num & 0x0000FF) + amt;
return '#' + (0x1000000 + (R<255?R<1?0:R:255)*0x10000 +
(B<255?B<1?0:B:255)*0x100 +
(G<255?G<1?0:G:255)).toString(16).slice(1);
}
function darkenColor(color, percent) {
const num = parseInt(color.replace('#',''),16),
amt = Math.round(2.55 * percent),
R = (num >> 16) - amt,
B = (num >> 8 & 0x00FF) - amt,
G = (num & 0x0000FF) - amt;
return '#' + (0x1000000 +
(R>0?R:0)*0x10000 +
(B>0?B:0)*0x100 +
(G>0?G:0)).toString(16).slice(1);
}
function getContrastColor(hexcolor) {
hexcolor = hexcolor.replace("#", "");
const r = parseInt(hexcolor.substr(0,2),16);
const g = parseInt(hexcolor.substr(2,2),16);
const b = parseInt(hexcolor.substr(4,2),16);
const yiq = ((r*299)+(g*587)+(b*114))/1000;
return (yiq >= 128) ? 'black' : 'white';
}
function ensureDarkColor(color) {
const hexcolor = color.replace("#", "");
const r = parseInt(hexcolor.substr(0,2),16);
const g = parseInt(hexcolor.substr(2,2),16);
const b = parseInt(hexcolor.substr(4,2),16);
const yiq = ((r*299)+(g*587)+(b*114))/1000;
if (yiq < 128) {
return color;
} else {
return darkenColor(color, 40);
}
}
function toggleTaskCompletion(taskItem) {
taskItem.classList.toggle('task-completed');
const completeButton = taskItem.querySelector('.complete-task');
if (taskItem.classList.contains('task-completed')) {
completeButton.innerHTML = '↻'; // Undo symbol
} else {
completeButton.innerHTML = '✔'; // Checkmark
}
saveTasks();
}
function sortTasks() {
const tasks = Array.from(taskList.getElementsByClassName('task-item'));
tasks.sort((a, b) => {
const aImportance = a.querySelector('.task-importance').textContent;
const bImportance = b.querySelector('.task-importance').textContent;
const importanceOrder = ['High', 'Medium', 'Low', 'None'];
return importanceOrder.indexOf(aImportance) - importanceOrder.indexOf(bImportance);
});
tasks.forEach(task => taskList.appendChild(task));
saveTasks();
}
// Initialize styles for the default category
updateCategoryStyles('General', categoryColors['General']);
// Load tasks from localStorage
loadTasks();
// Save tasks to localStorage when adding or updating
function saveTasks() {
const tasks = Array.from(taskList.getElementsByClassName('task-item')).map(task => ({
text: task.querySelector('.task-text').textContent,
datetime: task.querySelector('.task-datetime').textContent,
importance: task.querySelector('.task-importance').textContent,
category: task.dataset.category,
completed: task.classList.contains('task-completed')
}));
localStorage.setItem('tasks', JSON.stringify(tasks));
}
function loadTasks() {
const savedTasks = JSON.parse(localStorage.getItem('tasks')) || [];
savedTasks.forEach(task => {
const taskItem = createTaskElement(task);
taskList.appendChild(taskItem);
});
filterTasks();
}
function createTaskElement(task) {
const taskItem = document.createElement('div');
taskItem.className = 'task-item';
taskItem.dataset.category = task.category;
if (task.completed) {
taskItem.classList.add('task-completed');
}
taskItem.style.animation = 'fadeIn 0.5s ease-out';
const taskTextSpan = document.createElement('span');
taskTextSpan.className = 'task-text editable';
taskTextSpan.textContent = task.text;
taskTextSpan.addEventListener('click', makeEditable);
const taskDateTimeSpan = document.createElement('span');
taskDateTimeSpan.className = 'task-datetime editable';
taskDateTimeSpan.textContent = task.datetime;
taskDateTimeSpan.addEventListener('click', makeEditable);
const taskImportanceSpan = document.createElement('span');
taskImportanceSpan.className = `task-importance importance-${task.importance} editable`;
taskImportanceSpan.textContent = task.importance;
taskImportanceSpan.addEventListener('click', makeEditable);
const taskCategorySpan = document.createElement('span');
taskCategorySpan.className = 'task-category editable';
taskCategorySpan.textContent = task.category;
taskCategorySpan.style.backgroundColor = categoryColors[task.category];
taskCategorySpan.addEventListener('click', function() {
makeCategoryEditable(taskItem);
});
const deleteButton = document.createElement('button');
deleteButton.className = 'delete-task';
deleteButton.innerHTML = '×';
deleteButton.addEventListener('click', function(e) {
e.stopPropagation();
taskToDelete = taskItem;
confirmDeleteModal.style.display = 'flex';
});
const completeButton = document.createElement('button');
completeButton.className = 'complete-task';
completeButton.innerHTML = task.completed ? '↻' : '✔';
completeButton.addEventListener('click', function(e) {
e.stopPropagation();
toggleTaskCompletion(taskItem);
});
taskItem.appendChild(taskTextSpan);
taskItem.appendChild(taskDateTimeSpan);
taskItem.appendChild(taskImportanceSpan);
taskItem.appendChild(taskCategorySpan);
taskItem.appendChild(deleteButton);
taskItem.appendChild(completeButton);
return taskItem;
}
// Modify existing functions to save tasks after changes
function addTask() {
const taskText = taskInput.value.trim();
const dateValue = taskDate.value;
const timeValue = taskTime.value;
const importanceValue = taskImportance.value;
if (taskText) {
const taskItem = document.createElement('div');
taskItem.className = 'task-item';
taskItem.dataset.category = currentCategory;
taskItem.style.animation = 'fadeIn 0.5s ease-out';
const taskTextSpan = document.createElement('span');
taskTextSpan.className = 'task-text editable';
taskTextSpan.textContent = taskText;
taskTextSpan.addEventListener('click', makeEditable);
const taskDateTimeSpan = document.createElement('span');
taskDateTimeSpan.className = 'task-datetime editable';
if (dateValue && timeValue) {
const dateTime = new Date(dateValue + 'T' + timeValue);
taskDateTimeSpan.textContent = dateTime.toLocaleString();
} else if (dateValue) {
taskDateTimeSpan.textContent = new Date(dateValue).toLocaleDateString();
} else if (timeValue) {
taskDateTimeSpan.textContent = timeValue;
}
taskDateTimeSpan.addEventListener('click', makeEditable);
const taskImportanceSpan = document.createElement('span');
taskImportanceSpan.className = `task-importance importance-${importanceValue} editable`;
taskImportanceSpan.textContent = importanceValue;
taskImportanceSpan.addEventListener('click', makeEditable);
const taskCategorySpan = document.createElement('span');
taskCategorySpan.className = 'task-category editable';
taskCategorySpan.textContent = currentCategory;
taskCategorySpan.style.backgroundColor = categoryColors[currentCategory];
taskCategorySpan.addEventListener('click', function() {
makeCategoryEditable(taskItem);
});
const deleteButton = document.createElement('button');
deleteButton.className = 'delete-task';
deleteButton.innerHTML = '×';
deleteButton.addEventListener('click', function(e) {
e.stopPropagation();
taskToDelete = taskItem;
confirmDeleteModal.style.display = 'flex';
});
const completeButton = document.createElement('button');
completeButton.className = 'complete-task';
completeButton.innerHTML = '✔';
completeButton.addEventListener('click', function(e) {
e.stopPropagation();
toggleTaskCompletion(taskItem);
});
taskItem.appendChild(taskTextSpan);
taskItem.appendChild(taskDateTimeSpan);
taskItem.appendChild(taskImportanceSpan);
taskItem.appendChild(taskCategorySpan);
taskItem.appendChild(deleteButton);
taskItem.appendChild(completeButton);
taskList.appendChild(taskItem);
taskInput.value = '';
saveTasks();
filterTasks();
}
}
function makeEditable(event) {
const element = event.target;
const originalText = element.textContent;
const originalClass = element.className;
let input;
if (element.classList.contains('task-importance')) {
input = document.createElement('select');
const options = ['None', 'Low', 'Medium', 'High'];
options.forEach(option => {
const optionElement = document.createElement('option');
optionElement.value = option;
optionElement.textContent = option;
if (option === originalText) {
optionElement.selected = true;
}
input.appendChild(optionElement);
});
} else if (element.classList.contains('task-datetime')) {
input = document.createElement('input');
input.type = 'datetime-local';
const date = new Date(originalText);
input.value = date.toISOString().slice(0, 16);
} else {
input = document.createElement('input');
input.type = 'text';
input.value = originalText;
}
input.className = 'edit-input';
element.textContent = '';
element.appendChild(input);
input.focus();
input.addEventListener('blur', function() {
let newValue = input.value;
if (element.classList.contains('task-datetime')) {
newValue = new Date(input.value).toLocaleString();
}
element.textContent = newValue;
element.className = originalClass;
if (element.classList.contains('task-importance')) {
element.classList.remove(...element.classList);
element.classList.add(`task-importance`, `importance-${newValue}`, `editable`);
}
element.style.animation = 'pulse 0.3s ease-out';
saveTasks();
});
input.addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
input.blur();
}
});
}
function makeCategoryEditable(taskItem) {
const categorySpan = taskItem.querySelector('.task-category');
const currentCategory = categorySpan.textContent;
const select = document.createElement('select');
select.className = 'category-select';
// Add existing categories
Object.keys(categoryColors).forEach(category => {
const option = document.createElement('option');
option.value = category;
option.textContent = category;
if (category === currentCategory) {
option.selected = true;
}
select.appendChild(option);
});
// Add "New Category" option
const newCategoryOption = document.createElement('option');
newCategoryOption.value = 'new';
newCategoryOption.textContent = '+ New Category';
select.appendChild(newCategoryOption);
categorySpan.textContent = '';
categorySpan.appendChild(select);
select.focus();
select.addEventListener('change', function() {
if (select.value === 'new') {
openNewCategoryModal(taskItem);
} else {
updateTaskCategory(taskItem, select.value);
}
});
select.addEventListener('blur', function() {
if (select.value !== 'new') {
categorySpan.textContent = select.value;
categorySpan.style.backgroundColor = categoryColors[select.value];
taskItem.dataset.category = select.value;
filterTasks();
saveTasks();
}
});
}
function updateTaskCategory(taskItem, newCategory) {
taskItem.dataset.category = newCategory;
const categorySpan = taskItem.querySelector('.task-category');
categorySpan.textContent = newCategory;
categorySpan.style.backgroundColor = categoryColors[newCategory];
filterTasks();
saveTasks();
}
function getRandomColor() {
return '#' + Math.floor(Math.random()*16777215).toString(16);
}
function lightenColor(color, percent) {
const num = parseInt(color.replace('#',''),16),
amt = Math.round(2.55 * percent),
R = (num >> 16) + amt,
B = (num >> 8 & 0x00FF) + amt,
G = (num & 0x0000FF) + amt;
return '#' + (0x1000000 + (R<255?R<1?0:R:255)*0x10000 +
(B<255?B<1?0:B:255)*0x100 +
(G<255?G<1?0:G:255)).toString(16).slice(1);
}
function darkenColor(color, percent) {
const num = parseInt(color.replace('#',''),16),
amt = Math.round(2.55 * percent),
R = (num >> 16) - amt,
B = (num >> 8 & 0x00FF) - amt,
G = (num & 0x0000FF) - amt;
return '#' + (0x1000000 +
(R>0?R:0)*0x10000 +
(B>0?B:0)*0x100 +
(G>0?G:0)).toString(16).slice(1);
}
function getContrastColor(hexcolor) {
hexcolor = hexcolor.replace("#", "");
const r = parseInt(hexcolor.substr(0,2),16);
const g = parseInt(hexcolor.substr(2,2),16);
const b = parseInt(hexcolor.substr(4,2),16);
const yiq = ((r*299)+(g*587)+(b*114))/1000;
return (yiq >= 128) ? 'black' : 'white';
}
function ensureDarkColor(color) {
const hexcolor = color.replace("#", "");
const r = parseInt(hexcolor.substr(0,2),16);
const g = parseInt(hexcolor.substr(2,2),16);
const b = parseInt(hexcolor.substr(4,2),16);
const yiq = ((r*299)+(g*587)+(b*114))/1000;
if (yiq < 128) {
return color;
} else {
return darkenColor(color, 40);
}
}
function toggleTaskCompletion(taskItem) {
taskItem.classList.toggle('task-completed');
const completeButton = taskItem.querySelector('.complete-task');
if (taskItem.classList.contains('task-completed')) {
completeButton.innerHTML = '↻'; // Undo symbol
} else {
completeButton.innerHTML = '✔'; // Checkmark
}
saveTasks();
}
function sortTasks() {
const tasks = Array.from(taskList.getElementsByClassName('task-item'));
tasks.sort((a, b) => {
const aImportance = a.querySelector('.task-importance').textContent;
const bImportance = b.querySelector('.task-importance').textContent;
const importanceOrder = ['High', 'Medium', 'Low', 'None'];
return importanceOrder.indexOf(aImportance) - importanceOrder.indexOf(bImportance);
});
tasks.forEach(task => taskList.appendChild(task));
saveTasks();
}
// Initialize styles for the default category
updateCategoryStyles('General', categoryColors['General']);
// Load tasks from localStorage
loadTasks();
function saveTasks() {
const tasks = Array.from(taskList.getElementsByClassName('task-item')).map(task => ({
text: task.querySelector('.task-text').textContent,
datetime: task.querySelector('.task-datetime').textContent,
importance: task.querySelector('.task-importance').textContent,
category: task.dataset.category,
completed: task.classList.contains('task-completed')
}));
localStorage.setItem('tasks', JSON.stringify(tasks));
}
function loadTasks() {
const savedTasks = JSON.parse(localStorage.getItem('tasks')) || [];
savedTasks.forEach(task => {
const taskItem = createTaskElement(task);
taskList.appendChild(taskItem);
});
filterTasks();
}
function createTaskElement(task) {
const taskItem = document.createElement('div');
taskItem.className = 'task-item';
taskItem.dataset.category = task.category;
if (task.completed) {
taskItem.classList.add('task-completed');
}
taskItem.style.animation = 'fadeIn 0.5s ease-out';
const taskTextSpan = document.createElement('span');
taskTextSpan.className = 'task-text editable';
taskTextSpan.textContent = task.text;
taskTextSpan.addEventListener('click', makeEditable);
const taskDateTimeSpan = document.createElement('span');
taskDateTimeSpan.className = 'task-datetime editable';
taskDateTimeSpan.textContent = task.datetime;
taskDateTimeSpan.addEventListener('click', makeEditable);
const taskImportanceSpan = document.createElement('span');
taskImportanceSpan.className = `task-importance importance-${task.importance} editable`;
taskImportanceSpan.textContent = task.importance;
taskImportanceSpan.addEventListener('click', makeEditable);
const taskCategorySpan = document.createElement('span');
taskCategorySpan.className = 'task-category editable';
taskCategorySpan.textContent = task.category;
taskCategorySpan.style.backgroundColor = categoryColors[task.category];
taskCategorySpan.addEventListener('click', function() {
makeCategoryEditable(taskItem);
});
const deleteButton = document.createElement('button');
deleteButton.className = 'delete-task';
deleteButton.innerHTML = '×';
deleteButton.addEventListener('click', function(e) {
e.stopPropagation();
taskToDelete = taskItem;
confirmDeleteModal.style.display = 'flex';
});
const completeButton = document.createElement('button');
completeButton.className = 'complete-task';
completeButton.innerHTML = task.completed ? '↻' : '✔';
completeButton.addEventListener('click', function(e) {
e.stopPropagation();
toggleTaskCompletion(taskItem);
});
taskItem.appendChild(taskTextSpan);
taskItem.appendChild(taskDateTimeSpan);
taskItem.appendChild(taskImportanceSpan);
taskItem.appendChild(taskCategorySpan);
taskItem.appendChild(deleteButton);
taskItem.appendChild(completeButton);
return taskItem;
}
// Modify existing functions to save tasks after changes
function addTask() {
const taskText = taskInput.value.trim();
const dateValue = taskDate.value;
const timeValue = taskTime.value;
const importanceValue = taskImportance.value;
if (taskText) {
const taskItem = document.createElement('div');
taskItem.className = 'task-item';
taskItem.dataset.category = currentCategory;
taskItem.style.animation = 'fadeIn 0.5s ease-out';
const taskTextSpan = document.createElement('span');
taskTextSpan.className = 'task-text editable';
taskTextSpan.textContent = taskText;
taskTextSpan.addEventListener('click', makeEditable);
const taskDateTimeSpan = document.createElement('span');
taskDateTimeSpan.className = 'task-datetime editable';
if (dateValue && timeValue) {
const dateTime = new Date(dateValue + 'T' + timeValue);
taskDateTimeSpan.textContent = dateTime.toLocaleString();
} else if (dateValue) {
taskDateTimeSpan.textContent = new Date(dateValue).toLocaleDateString();
} else if (timeValue) {
taskDateTimeSpan.textContent = timeValue;
}
taskDateTimeSpan.addEventListener('click', makeEditable);
const taskImportanceSpan = document.createElement('span');
taskImportanceSpan.className = `task-importance importance-${importanceValue} editable`;
taskImportanceSpan.textContent = importanceValue;
taskImportanceSpan.addEventListener('click', makeEditable);
const taskCategorySpan = document.createElement('span');
taskCategorySpan.className = 'task-category editable';
taskCategorySpan.textContent = currentCategory;
taskCategorySpan.style.backgroundColor = categoryColors[currentCategory];
taskCategorySpan.addEventListener('click', function() {
makeCategoryEditable(taskItem);
});
const deleteButton = document.createElement('button');
deleteButton.className = 'delete-task';
deleteButton.innerHTML = '×';
deleteButton.addEventListener('click', function(e) {
e.stopPropagation();
taskToDelete = taskItem;
confirmDeleteModal.style.display = 'flex';
});
const completeButton = document.createElement('button');
completeButton.className = 'complete-task';
completeButton.innerHTML = '✔';
completeButton.addEventListener('click', function(e) {
e.stopPropagation();
toggleTaskCompletion(taskItem);
});
taskItem.appendChild(taskTextSpan);
taskItem.appendChild(taskDateTimeSpan);
taskItem.appendChild(taskImportanceSpan);
taskItem.appendChild(taskCategorySpan);
taskItem.appendChild(deleteButton);
taskItem.appendChild(completeButton);
taskList.appendChild(taskItem);
taskInput.value = '';
saveTasks();
filterTasks();
}
}
function makeEditable(event) {
const element = event.target;
const originalText = element.textContent;
const originalClass = element.className;
let input;
if (element.classList.contains('task-importance')) {
input = document.createElement('select');
const options = ['None', 'Low', 'Medium', 'High'];
options.forEach(option => {
const optionElement = document.createElement('option');
optionElement.value = option;
optionElement.textContent = option;
if (option === originalText) {
optionElement.selected = true;
}
input.appendChild(optionElement);
});
} else if (element.classList.contains('task-datetime')) {
input = document.createElement('input');
input.type = 'datetime-local';
const date = new Date(originalText);
input.value = date.toISOString().slice(0, 16);
} else {
input = document.createElement('input');
input.type = 'text';
input.value = originalText;
}
input.className = 'edit-input';
element.textContent = '';
element.appendChild(input);
input.focus();
input.addEventListener('blur', function() {
let newValue = input.value;
if (element.classList.contains('task-datetime')) {
newValue = new Date(input.value).toLocaleString();
}
element.textContent = newValue;
element.className = originalClass;
if (element.classList.contains('task-importance')) {
element.className = `task-importance importance-${newValue} editable`;
}
element.style.animation = 'pulse 0.3s ease-out';
saveTasks();
});
input.addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
input.blur();
}
});
}
function makeCategoryEditable(taskItem) {
const categorySpan = taskItem.querySelector('.task-category');
const currentCategory = categorySpan.textContent;
const select = document.createElement('select');
select.className = 'category-select';
// Add existing categories
Object.keys(categoryColors).forEach(category => {
const option = document.createElement('option');
option.value = category;
option.textContent = category;
if (category === currentCategory) {
option.selected = true;
}
select.appendChild(option);
});
// Add "New Category" option
const newCategoryOption = document.createElement('option');
newCategoryOption.value = 'new';
newCategoryOption.textContent = '+ New Category';
select.appendChild(newCategoryOption);
categorySpan.textContent = '';
categorySpan.appendChild(select);
select.focus();
select.addEventListener('change', function() {
if (select.value === 'new') {
openNewCategoryModal(taskItem);
} else {
updateTaskCategory(taskItem, select.value);
}
});
select.addEventListener('blur', function() {
if (select.value !== 'new') {
categorySpan.textContent = select.value;
categorySpan.style.backgroundColor = categoryColors[select.value];
taskItem.dataset.category = select.value;
filterTasks();
saveTasks();
}
});
}
function toggleTaskCompletion(taskItem) {
taskItem.classList.toggle('task-completed');
const completeButton = taskItem.querySelector('.complete-task');
if (taskItem.classList.contains('task-completed')) {
completeButton.innerHTML = '↻'; // Undo symbol
} else {
completeButton.innerHTML = '✔'; // Checkmark
}
saveTasks();
}
function sortTasks() {
const tasks = Array.from(taskList.getElementsByClassName('task-item'));
tasks.sort((a, b) => {
const aImportance = a.querySelector('.task-importance').textContent;
const bImportance = b.querySelector('.task-importance').textContent;
const importanceOrder = ['High', 'Medium', 'Low', 'None'];
return importanceOrder.indexOf(aImportance) - importanceOrder.indexOf(bImportance);
});
tasks.forEach(task => taskList.appendChild(task));
saveTasks();
}
// Initialize styles for the default category
updateCategoryStyles('General', categoryColors['General']);
// Load tasks from localStorage
loadTasks();
function saveTasks() {
const tasks = Array.from(taskList.getElementsByClassName('task-item')).map(task => ({
text: task.querySelector('.task-text').textContent,
datetime: task.querySelector('.task-datetime').textContent,
importance: task.querySelector('.task-importance').textContent,
category: task.dataset.category,
completed: task.classList.contains('task-completed')
}));
localStorage.setItem('tasks', JSON.stringify(tasks));
}
function loadTasks() {
const savedTasks = JSON.parse(localStorage.getItem('tasks')) || [];
savedTasks.forEach(task => {
const taskItem = createTaskElement(task);
taskList.appendChild(taskItem);
});
filterTasks();
}
function createTaskElement(task) {
const taskItem = document.createElement('div');
taskItem.className = 'task-item';
taskItem.dataset.category = task.category;
if (task.completed) {
taskItem.classList.add('task-completed');
}
taskItem.style.animation = 'fadeIn 0.5s ease-out';
const taskTextSpan = document.createElement('span');
taskTextSpan.className = 'task-text editable';
taskTextSpan.textContent = task.text;
taskTextSpan.addEventListener('click', makeEditable);
const taskDateTimeSpan = document.createElement('span');
taskDateTimeSpan.className = 'task-datetime editable';
taskDateTimeSpan.textContent = task.datetime;
taskDateTimeSpan.addEventListener('click', makeEditable);
const taskImportanceSpan = document.createElement('span');
taskImportanceSpan.className = `task-importance importance-${task.importance} editable`;
taskImportanceSpan.textContent = task.importance;
taskImportanceSpan.addEventListener('click', makeEditable);
const taskCategorySpan = document.createElement('span');
taskCategorySpan.className = 'task-category editable';
taskCategorySpan.textContent = task.category;
taskCategorySpan.style.backgroundColor = categoryColors[task.category];
taskCategorySpan.addEventListener('click', function() {
makeCategoryEditable(taskItem);
});
const deleteButton = document.createElement('button');
deleteButton.className = 'delete-task';
deleteButton.innerHTML = '×';
deleteButton.addEventListener('click', function(e) {
e.stopPropagation();
taskToDelete = taskItem;
confirmDeleteModal.style.display = 'flex';
});
const completeButton = document.createElement('button');
completeButton.className = 'complete-task';
completeButton.innerHTML = task.completed ? '↻' : '✔';
completeButton.addEventListener('click', function(e) {
e.stopPropagation();
toggleTaskCompletion(taskItem);
});
taskItem.appendChild(taskTextSpan);
taskItem.appendChild(taskDateTimeSpan);
taskItem.appendChild(taskImportanceSpan);
taskItem.appendChild(taskCategorySpan);
taskItem.appendChild(deleteButton);
taskItem.appendChild(completeButton);
return taskItem;
}
});
</script>
</body>
</html>
By implementing the above enhancements, your task management app will have a more inviting and intuitive skeuomorphic design, making it both functional and aesthetically pleasing.