Skip to content

Commit

Permalink
Refactor theme initialization and tool listing generation
Browse files Browse the repository at this point in the history
  • Loading branch information
TMHSDigital committed Dec 24, 2024
1 parent 40309ec commit 9c66564
Show file tree
Hide file tree
Showing 9 changed files with 901 additions and 354 deletions.
89 changes: 3 additions & 86 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,91 +28,8 @@ <h2 class="hero-title">Welcome to Digital Services Hub</h2>
</header>

<main class="container">
<section class="tools-grid">
<article class="tool-card" onclick="window.location.href='pages/text-to-speech.html'">
<div class="tool-icon">
<i class="fas fa-volume-up"></i>
</div>
<h3>Text to Speech</h3>
<p>Convert text to natural-sounding speech with multiple voices and languages.</p>
<div class="tool-features">
<span>Multiple voices</span>
<span>Download audio</span>
</div>
</article>

<article class="tool-card" onclick="window.location.href='pages/image-resizer.html'">
<div class="tool-icon">
<i class="fas fa-image"></i>
</div>
<h3>Image Resizer</h3>
<p>Resize and optimize your images while maintaining quality.</p>
<div class="tool-features">
<span>Preserve ratio</span>
<span>Multiple formats</span>
</div>
</article>

<article class="tool-card" onclick="window.location.href='pages/color-palette.html'">
<div class="tool-icon">
<i class="fas fa-palette"></i>
</div>
<h3>Color Palette</h3>
<p>Generate beautiful color harmonies for your designs.</p>
<div class="tool-features">
<span>Color harmony</span>
<span>Export options</span>
</div>
</article>

<article class="tool-card" onclick="window.location.href='pages/ascii-art.html'">
<div class="tool-icon">
<i class="fas fa-font"></i>
</div>
<h3>ASCII Art</h3>
<p>Convert images into creative ASCII art with customization options.</p>
<div class="tool-features">
<span>Custom styles</span>
<span>Export text</span>
</div>
</article>

<article class="tool-card" onclick="window.location.href='pages/qr-code.html'">
<div class="tool-icon">
<i class="fas fa-qrcode"></i>
</div>
<h3>QR Code</h3>
<p>Generate customizable QR codes for your links and data.</p>
<div class="tool-features">
<span>Custom styles</span>
<span>Download PNG</span>
</div>
</article>

<article class="tool-card" onclick="window.location.href='pages/password-generator.html'">
<div class="tool-icon">
<i class="fas fa-key"></i>
</div>
<h3>Password Generator</h3>
<p>Create strong, secure passwords with advanced customization.</p>
<div class="tool-features">
<span>Custom options</span>
<span>Strength meter</span>
</div>
</article>

<article class="tool-card" onclick="window.location.href='pages/url-shortener.html'">
<div class="tool-icon">
<i class="fas fa-link"></i>
</div>
<h3>URL Shortener</h3>
<p>Create short, memorable links for easy sharing and tracking.</p>
<div class="tool-features">
<span>Click analytics</span>
<span>Custom aliases</span>
</div>
</article>
</section>
<!-- Tool categories will be dynamically generated here -->
<div id="tools-container"></div>

<section class="features">
<h2>Why Choose Digital Services Hub?</h2>
Expand Down Expand Up @@ -167,6 +84,6 @@ <h4>Legal</h4>
</div>
</footer>

<script src="js/common.js"></script>
<script src="js/common.js" type="module"></script>
</body>
</html>
81 changes: 7 additions & 74 deletions js/common.js
Original file line number Diff line number Diff line change
@@ -1,78 +1,11 @@
// Theme Management
const themeButton = document.getElementById('theme-button');
const prefersDarkScheme = window.matchMedia('(prefers-color-scheme: dark)');
import { generateToolList } from './utils/template-generator.js';
import { initializeTheme } from './utils/theme.js';

// Initialize theme
function initializeTheme() {
const savedTheme = localStorage.getItem('theme');
if (savedTheme) {
document.documentElement.setAttribute('data-theme', savedTheme);
updateThemeIcon(savedTheme);
} else {
const defaultTheme = prefersDarkScheme.matches ? 'dark' : 'light';
document.documentElement.setAttribute('data-theme', defaultTheme);
updateThemeIcon(defaultTheme);
}
}

// Update theme icon
function updateThemeIcon(theme) {
const icon = themeButton.querySelector('i');
icon.className = theme === 'dark' ? 'fas fa-sun' : 'fas fa-moon';
}
initializeTheme();

// Toggle theme
function toggleTheme() {
const currentTheme = document.documentElement.getAttribute('data-theme');
const newTheme = currentTheme === 'dark' ? 'light' : 'dark';

document.documentElement.setAttribute('data-theme', newTheme);
localStorage.setItem('theme', newTheme);
updateThemeIcon(newTheme);
// Generate tool listings if on index page
const toolsContainer = document.getElementById('tools-container');
if (toolsContainer) {
toolsContainer.innerHTML = generateToolList();
}

// Event Listeners
if (themeButton) {
themeButton.addEventListener('click', toggleTheme);
}

// Initialize theme on load
document.addEventListener('DOMContentLoaded', initializeTheme);

// Handle system theme changes
prefersDarkScheme.addEventListener('change', (e) => {
if (!localStorage.getItem('theme')) {
const newTheme = e.matches ? 'dark' : 'light';
document.documentElement.setAttribute('data-theme', newTheme);
updateThemeIcon(newTheme);
}
});

// Navigation active state
function setActiveNavItem() {
const currentPath = window.location.pathname;
const navLinks = document.querySelectorAll('nav a');

navLinks.forEach(link => {
if (link.getAttribute('href') === currentPath) {
link.classList.add('active');
}
});
}

// Initialize navigation
document.addEventListener('DOMContentLoaded', setActiveNavItem);

// Smooth scrolling for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
target.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
});
});
110 changes: 110 additions & 0 deletions js/config/tools.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
export const TOOLS = [
{
id: 'text-to-speech',
name: 'Text to Speech',
description: 'Convert text to natural-sounding speech with multiple voices and languages.',
icon: 'fa-volume-up',
features: ['Multiple voices', 'Download audio'],
path: 'text-to-speech.html',
category: 'audio',
order: 1
},
{
id: 'image-resizer',
name: 'Image Resizer',
description: 'Resize and optimize your images while maintaining quality.',
icon: 'fa-image',
features: ['Preserve ratio', 'Multiple formats'],
path: 'image-resizer.html',
category: 'image',
order: 2
},
{
id: 'color-palette',
name: 'Color Palette',
description: 'Generate beautiful color harmonies for your designs.',
icon: 'fa-palette',
features: ['Color harmony', 'Export options'],
path: 'color-palette.html',
category: 'design',
order: 3
},
{
id: 'ascii-art',
name: 'ASCII Art',
description: 'Convert images into creative ASCII art with customization options.',
icon: 'fa-font',
features: ['Custom styles', 'Export text'],
path: 'ascii-art.html',
category: 'image',
order: 4
},
{
id: 'qr-code',
name: 'QR Code',
description: 'Generate customizable QR codes for your links and data.',
icon: 'fa-qrcode',
features: ['Custom styles', 'Download PNG'],
path: 'qr-code.html',
category: 'utility',
order: 5
},
{
id: 'password-generator',
name: 'Password Generator',
description: 'Create strong, secure passwords with advanced customization.',
icon: 'fa-key',
features: ['Custom options', 'Strength meter'],
path: 'password-generator.html',
category: 'security',
order: 6
},
{
id: 'url-shortener',
name: 'URL Shortener',
description: 'Create short, memorable links for easy sharing and tracking.',
icon: 'fa-link',
features: ['Click analytics', 'Custom aliases'],
path: 'url-shortener.html',
category: 'utility',
order: 7
}
];

export const CATEGORIES = {
audio: {
name: 'Audio Tools',
description: 'Tools for audio processing and conversion',
icon: 'fa-music'
},
image: {
name: 'Image Tools',
description: 'Tools for image manipulation and conversion',
icon: 'fa-image'
},
design: {
name: 'Design Tools',
description: 'Tools for design and color management',
icon: 'fa-palette'
},
utility: {
name: 'Utility Tools',
description: 'General purpose utility tools',
icon: 'fa-tools'
},
security: {
name: 'Security Tools',
description: 'Tools for security and privacy',
icon: 'fa-shield-alt'
}
};

export const TOOL_STATS = {
totalTools: TOOLS.length,
toolsByCategory: Object.fromEntries(
Object.keys(CATEGORIES).map(category => [
category,
TOOLS.filter(tool => tool.category === category).length
])
)
};
Loading

0 comments on commit 9c66564

Please sign in to comment.