Changed around line 1
+ document.addEventListener('DOMContentLoaded', () => {
+ const editor = document.querySelector('.editor');
+ const themeToggle = document.querySelector('.theme-toggle');
+ const toolbar = document.querySelector('.toolbar');
+
+ // Theme toggling
+ themeToggle.addEventListener('click', () => {
+ document.body.dataset.theme =
+ document.body.dataset.theme === 'dark' ? 'light' : 'dark';
+ localStorage.setItem('theme', document.body.dataset.theme);
+ });
+
+ // Load saved theme
+ const savedTheme = localStorage.getItem('theme');
+ if (savedTheme) {
+ document.body.dataset.theme = savedTheme;
+ }
+
+ // Clear default text on first focus
+ editor.addEventListener('focus', function(e) {
+ if (this.textContent === 'Start typing here...') {
+ this.textContent = '';
+ }
+ }, { once: true });
+
+ // Toolbar functionality
+ toolbar.addEventListener('click', (e) => {
+ const button = e.target.closest('.tool-btn');
+ if (!button) return;
+
+ const action = button.dataset.action;
+ switch(action) {
+ case 'bold':
+ document.execCommand('bold', false);
+ break;
+ case 'italic':
+ document.execCommand('italic', false);
+ break;
+ case 'save':
+ const content = editor.innerHTML;
+ localStorage.setItem('editor-content', content);
+ showSaveNotification();
+ break;
+ }
+ });
+
+ // Load saved content
+ const savedContent = localStorage.getItem('editor-content');
+ if (savedContent) {
+ editor.innerHTML = savedContent;
+ }
+
+ function showSaveNotification() {
+ const notification = document.createElement('div');
+ notification.style.cssText = `
+ position: fixed;
+ bottom: 20px;
+ right: 20px;
+ background: var(--primary);
+ color: white;
+ padding: 1rem;
+ border-radius: 0.5rem;
+ animation: fadeInOut 2s forwards;
+ `;
+ notification.textContent = 'Changes saved!';
+ document.body.appendChild(notification);
+
+ setTimeout(() => notification.remove(), 2000);
+ }
+ });