|
| 1 | +# Interactive Calendar App |
| 2 | + |
| 3 | +A dynamic, interactive calendar application that demonstrates date manipulation, DOM updates, and event-driven programming in JavaScript. The calendar allows users to navigate through months and years, highlights the current date, and includes event management functionality. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- **Dynamic Calendar Display**: Shows all days of the selected month and year |
| 8 | +- **Current Date Highlighting**: Today's date is visually distinguished |
| 9 | +- **Month/Year Navigation**: Intuitive buttons for browsing through time |
| 10 | +- **Quick Navigation**: Dropdown for months and input for years |
| 11 | +- **Responsive Design**: Adapts to different screen sizes |
| 12 | +- **Event Management**: Add, view, and remove events for specific dates |
| 13 | +- **Interactive Tooltips**: Hover to see event previews |
| 14 | +- **Modal Interface**: Detailed event management for selected dates |
| 15 | + |
| 16 | +## How It Works |
| 17 | + |
| 18 | +### HTML Structure (`index.html`) |
| 19 | +- **Header Section**: Navigation buttons and month/year display |
| 20 | +- **Calendar Grid**: Weekday headers and dynamic day cells |
| 21 | +- **Controls**: Today button and quick month/year selectors |
| 22 | +- **Modal**: Event management interface with form and event list |
| 23 | +- **Tooltip**: Hover preview for dates with events |
| 24 | + |
| 25 | +### CSS Styling (`style.css`) |
| 26 | +- Modern, responsive design with gradient backgrounds |
| 27 | +- Smooth animations and transitions |
| 28 | +- Mobile-first approach with media queries |
| 29 | +- Visual feedback for interactions (hover, active states) |
| 30 | +- Modal and tooltip styling with fade-in animations |
| 31 | + |
| 32 | +### JavaScript Implementation (`script.js`) |
| 33 | + |
| 34 | +#### Core Calendar Logic |
| 35 | + |
| 36 | +**Date State Management** |
| 37 | +```javascript |
| 38 | +let currentDate = new Date(); // Currently displayed month/year |
| 39 | +let selectedDate = null; // Date selected for event management |
| 40 | +let events = {}; // Event storage: {'YYYY-MM-DD': ['event1', 'event2']} |
| 41 | +``` |
| 42 | + |
| 43 | +**Calendar Rendering** |
| 44 | +The `renderCalendar()` function dynamically generates the calendar grid: |
| 45 | +1. Calculate first and last days of the month |
| 46 | +2. Determine start/end dates for full week display |
| 47 | +3. Create day elements with appropriate styling |
| 48 | +4. Add event indicators and click handlers |
| 49 | + |
| 50 | +**Date Manipulation** |
| 51 | +```javascript |
| 52 | +// Navigate months |
| 53 | +function navigateMonth(delta) { |
| 54 | + currentDate.setMonth(currentDate.getMonth() + delta); |
| 55 | + renderCalendar(); |
| 56 | +} |
| 57 | + |
| 58 | +// Get date key for event storage |
| 59 | +function getDateKey(date) { |
| 60 | + return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`; |
| 61 | +} |
| 62 | +``` |
| 63 | + |
| 64 | +#### Event Handling |
| 65 | + |
| 66 | +**Navigation Events** |
| 67 | +- Month/Year buttons: `navigateMonth()`, `navigateYear()` |
| 68 | +- Today button: `goToToday()` - resets to current date |
| 69 | +- Quick selectors: `goToSpecificMonthYear()` - direct month/year input |
| 70 | + |
| 71 | +**Day Interactions** |
| 72 | +- Click: Opens event modal for selected date |
| 73 | +- Hover: Shows tooltip with event preview (if events exist) |
| 74 | + |
| 75 | +**Modal Management** |
| 76 | +- Add events: `addEvent()` - validates input and updates storage |
| 77 | +- Remove events: `removeEvent()` - deletes specific events |
| 78 | +- Display events: `displayEvents()` - renders event list in modal |
| 79 | + |
| 80 | +#### Key Concepts Demonstrated |
| 81 | + |
| 82 | +**Date Object Manipulation** |
| 83 | +- Creating and modifying Date objects |
| 84 | +- Extracting date components (year, month, day) |
| 85 | +- Calculating date ranges and day-of-week |
| 86 | +- Formatting dates for display and storage |
| 87 | + |
| 88 | +**DOM Manipulation** |
| 89 | +- Dynamic element creation and removal |
| 90 | +- Class manipulation for styling |
| 91 | +- Event listener attachment and management |
| 92 | +- Real-time UI updates |
| 93 | + |
| 94 | +**Event-Driven Programming** |
| 95 | +- User interaction handling (clicks, hovers, form submission) |
| 96 | +- State management and updates |
| 97 | +- Callback functions and closures |
| 98 | + |
| 99 | +**Data Structures** |
| 100 | +- Object-based event storage |
| 101 | +- Array manipulation for event lists |
| 102 | +- Date string keys for efficient lookups |
| 103 | + |
| 104 | +## Usage |
| 105 | + |
| 106 | +1. **Navigation**: Use arrow buttons or dropdown/input to change months/years |
| 107 | +2. **Today Button**: Quickly return to the current date |
| 108 | +3. **Add Events**: Click any date to open the event modal and add events |
| 109 | +4. **View Events**: Hover over dates with events to see tooltips, or click to edit |
| 110 | +5. **Remove Events**: Use the × button in the modal to delete events |
| 111 | + |
| 112 | +## Sample Events |
| 113 | + |
| 114 | +The calendar includes sample events for demonstration: |
| 115 | +- Today's date: "Meeting with team" |
| 116 | +- Tomorrow: "Doctor appointment", "Project deadline" |
| 117 | +- Next week: "Conference call" |
| 118 | + |
| 119 | +## Browser Compatibility |
| 120 | + |
| 121 | +Works in all modern browsers supporting ES6 features including: |
| 122 | +- Date object methods |
| 123 | +- Template literals |
| 124 | +- Arrow functions |
| 125 | +- Array methods (forEach, splice) |
| 126 | + |
| 127 | +## Responsive Features |
| 128 | + |
| 129 | +- **Desktop**: Full navigation and layout |
| 130 | +- **Tablet**: Adjusted button sizes and spacing |
| 131 | +- **Mobile**: Stacked controls, smaller text, touch-friendly interface |
| 132 | + |
| 133 | +This implementation provides a solid foundation for calendar-based applications and demonstrates essential JavaScript concepts in an interactive, practical way. |
0 commit comments