mirror of
https://git.hexahost.dev/smueller/HexaHost-Frontend.git
synced 2026-06-02 08:08:43 +00:00
Update cookie consent functionality: Enhanced the cookie consent banner by adding options for rejecting non-essential cookies and improved the styling for better user experience. Updated related JavaScript to ensure proper functionality and compliance with privacy regulations.
This commit is contained in:
2146
public/assets/css/style.css
Normal file
2146
public/assets/css/style.css
Normal file
File diff suppressed because it is too large
Load Diff
320
public/assets/js/contact.js
Normal file
320
public/assets/js/contact.js
Normal file
@@ -0,0 +1,320 @@
|
||||
// Contact page specific JavaScript
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
// FAQ Accordion functionality
|
||||
function initFAQ() {
|
||||
const faqItems = document.querySelectorAll('.faq-item');
|
||||
|
||||
faqItems.forEach(item => {
|
||||
const question = item.querySelector('.faq-question');
|
||||
const answer = item.querySelector('.faq-answer');
|
||||
const toggle = item.querySelector('.faq-toggle');
|
||||
|
||||
question.addEventListener('click', function() {
|
||||
const isOpen = item.classList.contains('open');
|
||||
|
||||
// Close all other FAQ items
|
||||
faqItems.forEach(otherItem => {
|
||||
if (otherItem !== item) {
|
||||
otherItem.classList.remove('open');
|
||||
const otherAnswer = otherItem.querySelector('.faq-answer');
|
||||
const otherToggle = otherItem.querySelector('.faq-toggle');
|
||||
otherAnswer.style.maxHeight = null;
|
||||
otherToggle.textContent = '+';
|
||||
}
|
||||
});
|
||||
|
||||
// Toggle current item
|
||||
if (isOpen) {
|
||||
item.classList.remove('open');
|
||||
answer.style.maxHeight = null;
|
||||
toggle.textContent = '+';
|
||||
} else {
|
||||
item.classList.add('open');
|
||||
answer.style.maxHeight = answer.scrollHeight + 'px';
|
||||
toggle.textContent = '−';
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Contact form handling
|
||||
function initContactForm() {
|
||||
const form = document.getElementById('contactForm');
|
||||
|
||||
if (!form) return;
|
||||
|
||||
form.addEventListener('submit', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
// Get form data
|
||||
const formData = new FormData(form);
|
||||
|
||||
// Basic validation
|
||||
const data = {};
|
||||
for (let [key, value] of formData.entries()) {
|
||||
data[key] = value;
|
||||
}
|
||||
|
||||
if (!validateForm(data)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Show loading state
|
||||
const submitBtn = form.querySelector('button[type="submit"]');
|
||||
const originalText = submitBtn.textContent;
|
||||
submitBtn.textContent = 'Wird gesendet...';
|
||||
submitBtn.disabled = true;
|
||||
|
||||
// Send form data to PHP backend
|
||||
fetch('contact-handler.php', {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
// Reset button state
|
||||
submitBtn.textContent = originalText;
|
||||
submitBtn.disabled = false;
|
||||
|
||||
if (data.success) {
|
||||
// Reset form
|
||||
form.reset();
|
||||
|
||||
// Show success message
|
||||
showNotification(data.message, 'success');
|
||||
|
||||
// Scroll to top
|
||||
window.scrollTo({ top: 0, behavior: 'smooth' });
|
||||
} else {
|
||||
// Show error message
|
||||
showNotification(data.message, 'error');
|
||||
|
||||
// Highlight missing fields if provided
|
||||
if (data.missing_fields) {
|
||||
data.missing_fields.forEach(field => {
|
||||
const fieldElement = document.getElementById(field);
|
||||
if (fieldElement) {
|
||||
fieldElement.style.borderColor = '#ff4d6d';
|
||||
setTimeout(() => {
|
||||
fieldElement.style.borderColor = '';
|
||||
}, 3000);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error:', error);
|
||||
showNotification('Ein Fehler ist aufgetreten. Bitte versuchen Sie es später erneut.', 'error');
|
||||
submitBtn.textContent = originalText;
|
||||
submitBtn.disabled = false;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Form validation
|
||||
function validateForm(data) {
|
||||
const requiredFields = ['firstName', 'lastName', 'email', 'subject', 'message'];
|
||||
const errors = [];
|
||||
|
||||
// Check required fields
|
||||
requiredFields.forEach(field => {
|
||||
if (!data[field] || data[field].trim() === '') {
|
||||
errors.push(`Das Feld "${getFieldLabel(field)}" ist erforderlich.`);
|
||||
}
|
||||
});
|
||||
|
||||
// Email validation
|
||||
if (data.email && !isValidEmail(data.email)) {
|
||||
errors.push('Bitte geben Sie eine gültige E-Mail-Adresse ein.');
|
||||
}
|
||||
|
||||
// Privacy checkbox
|
||||
if (!data.privacy) {
|
||||
errors.push('Sie müssen der Datenschutzerklärung zustimmen.');
|
||||
}
|
||||
|
||||
if (errors.length > 0) {
|
||||
showNotification(errors.join('\n'), 'error');
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Helper function to get field labels
|
||||
function getFieldLabel(fieldName) {
|
||||
const labels = {
|
||||
firstName: 'Vorname',
|
||||
lastName: 'Nachname',
|
||||
email: 'E-Mail-Adresse',
|
||||
subject: 'Betreff',
|
||||
message: 'Nachricht'
|
||||
};
|
||||
return labels[fieldName] || fieldName;
|
||||
}
|
||||
|
||||
// Email validation
|
||||
function isValidEmail(email) {
|
||||
const re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
||||
return re.test(email);
|
||||
}
|
||||
|
||||
// Notification system (using the global one from main.js)
|
||||
function showNotification(message, type = 'info') {
|
||||
if (window.HexaHost && window.HexaHost.showNotification) {
|
||||
window.HexaHost.showNotification(message, type);
|
||||
} else {
|
||||
// Fallback
|
||||
alert(message);
|
||||
}
|
||||
}
|
||||
|
||||
// Live chat placeholder function
|
||||
window.openLiveChat = function() {
|
||||
showNotification('Live Chat wird geöffnet... (Demo-Funktion)', 'info');
|
||||
// Here you would integrate with your actual live chat service
|
||||
// For example: Tawk.to, Intercom, Zendesk Chat, etc.
|
||||
};
|
||||
|
||||
// Auto-fill form based on URL parameters
|
||||
function autofillForm() {
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const packageParam = urlParams.get('package');
|
||||
const productParam = urlParams.get('product');
|
||||
|
||||
if (packageParam || productParam) {
|
||||
const subjectSelect = document.getElementById('subject');
|
||||
const messageTextarea = document.getElementById('message');
|
||||
|
||||
if (packageParam) {
|
||||
// Set subject based on package
|
||||
const packageNames = {
|
||||
'vpc-starter': 'Virtual Private Container - Starter Paket',
|
||||
'vpc-business': 'Virtual Private Container - Business Paket',
|
||||
'vpc-professional': 'Virtual Private Container - Professional Paket',
|
||||
'vpc-enterprise': 'Virtual Private Container - Enterprise Paket',
|
||||
'vps-basic': 'Virtual Private Server - Basic Paket',
|
||||
'vps-standard': 'Virtual Private Server - Standard Paket',
|
||||
'vps-premium': 'Virtual Private Server - Premium Paket',
|
||||
'vps-enterprise': 'Virtual Private Server - Enterprise Paket',
|
||||
'mail-starter': 'Mail Gateway - Starter Paket',
|
||||
'mail-business': 'Mail Gateway - Business Paket',
|
||||
'mail-professional': 'Mail Gateway - Professional Paket',
|
||||
'mail-enterprise': 'Mail Gateway - Enterprise Paket',
|
||||
'web-starter': 'Webhosting - Starter Paket',
|
||||
'web-business': 'Webhosting - Business Paket',
|
||||
'web-professional': 'Webhosting - Professional Paket',
|
||||
'web-enterprise': 'Webhosting - Enterprise Paket'
|
||||
};
|
||||
|
||||
if (packageNames[packageParam]) {
|
||||
messageTextarea.value = `Hallo,\n\nich interessiere mich für das ${packageNames[packageParam]}.\n\nBitte senden Sie mir weitere Informationen und ein individuelles Angebot.\n\nVielen Dank!`;
|
||||
|
||||
// Set appropriate subject
|
||||
if (packageParam.startsWith('vpc-')) {
|
||||
subjectSelect.value = 'vpc-anfrage';
|
||||
} else if (packageParam.startsWith('vps-')) {
|
||||
subjectSelect.value = 'vps-anfrage';
|
||||
} else if (packageParam.startsWith('mail-')) {
|
||||
subjectSelect.value = 'mail-gateway-anfrage';
|
||||
} else if (packageParam.startsWith('web-')) {
|
||||
subjectSelect.value = 'webhosting-anfrage';
|
||||
}
|
||||
}
|
||||
} else if (productParam) {
|
||||
// Set subject based on product
|
||||
const productSubjects = {
|
||||
'vpc': 'vpc-anfrage',
|
||||
'vps': 'vps-anfrage',
|
||||
'mail-gateway': 'mail-gateway-anfrage',
|
||||
'webhosting': 'webhosting-anfrage'
|
||||
};
|
||||
|
||||
if (productSubjects[productParam]) {
|
||||
subjectSelect.value = productSubjects[productParam];
|
||||
messageTextarea.value = `Hallo,\n\nich interessiere mich für Ihre ${productParam.replace('-', ' ')} Lösungen.\n\nBitte kontaktieren Sie mich für eine persönliche Beratung.\n\nVielen Dank!`;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Form field enhancements
|
||||
function enhanceFormFields() {
|
||||
const inputs = document.querySelectorAll('input, select, textarea');
|
||||
|
||||
inputs.forEach(input => {
|
||||
// Add focus/blur effects
|
||||
input.addEventListener('focus', function() {
|
||||
this.parentElement.classList.add('focused');
|
||||
});
|
||||
|
||||
input.addEventListener('blur', function() {
|
||||
if (!this.value) {
|
||||
this.parentElement.classList.remove('focused');
|
||||
}
|
||||
});
|
||||
|
||||
// Check if field already has value (for autofilled forms)
|
||||
if (input.value) {
|
||||
input.parentElement.classList.add('focused');
|
||||
}
|
||||
});
|
||||
|
||||
// Phone number formatting
|
||||
const phoneInput = document.getElementById('phone');
|
||||
if (phoneInput) {
|
||||
phoneInput.addEventListener('input', function() {
|
||||
// Simple German phone number formatting
|
||||
let value = this.value.replace(/\D/g, '');
|
||||
if (value.startsWith('49')) {
|
||||
value = '+' + value;
|
||||
} else if (value.startsWith('0')) {
|
||||
value = '+49' + value.substring(1);
|
||||
}
|
||||
this.value = value;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Accessibility improvements
|
||||
function improveAccessibility() {
|
||||
// Add ARIA labels to form elements
|
||||
const requiredFields = document.querySelectorAll('input[required], select[required], textarea[required]');
|
||||
requiredFields.forEach(field => {
|
||||
field.setAttribute('aria-required', 'true');
|
||||
});
|
||||
|
||||
// Add keyboard navigation for FAQ
|
||||
const faqQuestions = document.querySelectorAll('.faq-question');
|
||||
faqQuestions.forEach(question => {
|
||||
question.setAttribute('tabindex', '0');
|
||||
question.setAttribute('role', 'button');
|
||||
question.setAttribute('aria-expanded', 'false');
|
||||
|
||||
question.addEventListener('keydown', function(e) {
|
||||
if (e.key === 'Enter' || e.key === ' ') {
|
||||
e.preventDefault();
|
||||
this.click();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Initialize everything when DOM is loaded
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
initFAQ();
|
||||
initContactForm();
|
||||
autofillForm();
|
||||
enhanceFormFields();
|
||||
improveAccessibility();
|
||||
|
||||
// Show a welcome message for contact page
|
||||
setTimeout(() => {
|
||||
showNotification('💬 Haben Sie Fragen? Wir helfen gerne!', 'info');
|
||||
}, 2000);
|
||||
});
|
||||
|
||||
})();
|
||||
323
public/assets/js/cookie-consent.js
Normal file
323
public/assets/js/cookie-consent.js
Normal file
@@ -0,0 +1,323 @@
|
||||
/**
|
||||
* Cookie Consent Manager für HexaHost.de
|
||||
* DSGVO-konformes Cookie-Banner mit granularen Einstellungen
|
||||
*/
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
// Cookie-Konfiguration
|
||||
const COOKIE_NAME = 'hexahost_cookie_consent';
|
||||
const COOKIE_EXPIRY_DAYS = 365;
|
||||
|
||||
// DOM-Elemente
|
||||
const banner = document.getElementById('cookieConsent');
|
||||
const settingsPanel = document.getElementById('cookieSettingsPanel');
|
||||
const acceptAllBtn = document.getElementById('cookieAcceptAll');
|
||||
const acceptEssentialBtn = document.getElementById('cookieAcceptEssential');
|
||||
const settingsBtn = document.getElementById('cookieSettings');
|
||||
const saveSettingsBtn = document.getElementById('cookieSaveSettings');
|
||||
const closeSettingsBtn = document.getElementById('cookieCloseSettings');
|
||||
const analyticsCheckbox = document.getElementById('cookieAnalytics');
|
||||
const marketingCheckbox = document.getElementById('cookieMarketing');
|
||||
|
||||
/**
|
||||
* Cookie-Hilfsfunktionen
|
||||
*/
|
||||
const CookieUtils = {
|
||||
set: function(name, value, days) {
|
||||
const date = new Date();
|
||||
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
|
||||
const expires = 'expires=' + date.toUTCString();
|
||||
document.cookie = name + '=' + JSON.stringify(value) + ';' + expires + ';path=/;SameSite=Lax;Secure';
|
||||
},
|
||||
|
||||
get: function(name) {
|
||||
const nameEQ = name + '=';
|
||||
const cookies = document.cookie.split(';');
|
||||
for (let i = 0; i < cookies.length; i++) {
|
||||
let cookie = cookies[i].trim();
|
||||
if (cookie.indexOf(nameEQ) === 0) {
|
||||
try {
|
||||
return JSON.parse(cookie.substring(nameEQ.length));
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
},
|
||||
|
||||
delete: function(name) {
|
||||
document.cookie = name + '=;expires=Thu, 01 Jan 1970 00:00:00 UTC;path=/;';
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Cookie Consent Manager
|
||||
*/
|
||||
const CookieConsent = {
|
||||
// Standardeinstellungen
|
||||
defaultConsent: {
|
||||
essential: true, // Immer aktiviert
|
||||
analytics: false,
|
||||
marketing: false,
|
||||
timestamp: null
|
||||
},
|
||||
|
||||
/**
|
||||
* Initialisierung
|
||||
*/
|
||||
init: function() {
|
||||
if (!banner) return;
|
||||
|
||||
const consent = this.getConsent();
|
||||
|
||||
if (consent && consent.timestamp) {
|
||||
// Consent bereits gegeben - Banner verstecken
|
||||
this.hideBanner();
|
||||
this.applyConsent(consent);
|
||||
} else {
|
||||
// Zeige Banner
|
||||
this.showBanner();
|
||||
}
|
||||
|
||||
this.bindEvents();
|
||||
},
|
||||
|
||||
/**
|
||||
* Event-Listener binden
|
||||
*/
|
||||
bindEvents: function() {
|
||||
if (acceptAllBtn) {
|
||||
acceptAllBtn.addEventListener('click', () => this.acceptAll());
|
||||
}
|
||||
|
||||
if (acceptEssentialBtn) {
|
||||
acceptEssentialBtn.addEventListener('click', () => this.acceptEssential());
|
||||
}
|
||||
|
||||
if (settingsBtn) {
|
||||
settingsBtn.addEventListener('click', () => this.showSettings());
|
||||
}
|
||||
|
||||
if (saveSettingsBtn) {
|
||||
saveSettingsBtn.addEventListener('click', () => this.saveSettings());
|
||||
}
|
||||
|
||||
if (closeSettingsBtn) {
|
||||
closeSettingsBtn.addEventListener('click', () => this.hideSettings());
|
||||
}
|
||||
|
||||
// ESC-Taste zum Schließen der Einstellungen
|
||||
document.addEventListener('keydown', (e) => {
|
||||
if (e.key === 'Escape' && settingsPanel && settingsPanel.style.display !== 'none') {
|
||||
this.hideSettings();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Alle Cookies akzeptieren
|
||||
*/
|
||||
acceptAll: function() {
|
||||
const consent = {
|
||||
essential: true,
|
||||
analytics: true,
|
||||
marketing: true,
|
||||
timestamp: new Date().toISOString()
|
||||
};
|
||||
this.saveConsent(consent);
|
||||
this.hideBanner();
|
||||
this.applyConsent(consent);
|
||||
this.showNotification('Alle Cookies wurden akzeptiert.', 'success');
|
||||
},
|
||||
|
||||
/**
|
||||
* Nur essenzielle Cookies akzeptieren
|
||||
*/
|
||||
acceptEssential: function() {
|
||||
const consent = {
|
||||
essential: true,
|
||||
analytics: false,
|
||||
marketing: false,
|
||||
timestamp: new Date().toISOString()
|
||||
};
|
||||
this.saveConsent(consent);
|
||||
this.hideBanner();
|
||||
this.applyConsent(consent);
|
||||
this.showNotification('Nur notwendige Cookies wurden akzeptiert.', 'info');
|
||||
},
|
||||
|
||||
/**
|
||||
* Einstellungen speichern
|
||||
*/
|
||||
saveSettings: function() {
|
||||
const consent = {
|
||||
essential: true,
|
||||
analytics: analyticsCheckbox ? analyticsCheckbox.checked : false,
|
||||
marketing: marketingCheckbox ? marketingCheckbox.checked : false,
|
||||
timestamp: new Date().toISOString()
|
||||
};
|
||||
this.saveConsent(consent);
|
||||
this.hideSettings();
|
||||
this.hideBanner();
|
||||
this.applyConsent(consent);
|
||||
this.showNotification('Cookie-Einstellungen wurden gespeichert.', 'success');
|
||||
},
|
||||
|
||||
/**
|
||||
* Consent im Cookie speichern
|
||||
*/
|
||||
saveConsent: function(consent) {
|
||||
CookieUtils.set(COOKIE_NAME, consent, COOKIE_EXPIRY_DAYS);
|
||||
},
|
||||
|
||||
/**
|
||||
* Consent aus Cookie lesen
|
||||
*/
|
||||
getConsent: function() {
|
||||
return CookieUtils.get(COOKIE_NAME);
|
||||
},
|
||||
|
||||
/**
|
||||
* Consent anwenden (z.B. Analytics laden)
|
||||
*/
|
||||
applyConsent: function(consent) {
|
||||
// Dispatch Custom Event für andere Scripts
|
||||
window.dispatchEvent(new CustomEvent('cookieConsentUpdated', {
|
||||
detail: consent
|
||||
}));
|
||||
|
||||
// Analytics aktivieren/deaktivieren
|
||||
if (consent.analytics) {
|
||||
this.enableAnalytics();
|
||||
} else {
|
||||
this.disableAnalytics();
|
||||
}
|
||||
|
||||
// Marketing aktivieren/deaktivieren
|
||||
if (consent.marketing) {
|
||||
this.enableMarketing();
|
||||
} else {
|
||||
this.disableMarketing();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Analytics aktivieren (Placeholder für z.B. Google Analytics)
|
||||
*/
|
||||
enableAnalytics: function() {
|
||||
// Hier können Analytics-Scripts geladen werden
|
||||
// Beispiel für Google Analytics:
|
||||
// if (typeof gtag === 'undefined') {
|
||||
// const script = document.createElement('script');
|
||||
// script.src = 'https://www.googletagmanager.com/gtag/js?id=GA_MEASUREMENT_ID';
|
||||
// script.async = true;
|
||||
// document.head.appendChild(script);
|
||||
// }
|
||||
console.log('Analytics enabled');
|
||||
},
|
||||
|
||||
/**
|
||||
* Analytics deaktivieren
|
||||
*/
|
||||
disableAnalytics: function() {
|
||||
// Analytics-Cookies entfernen falls vorhanden
|
||||
console.log('Analytics disabled');
|
||||
},
|
||||
|
||||
/**
|
||||
* Marketing aktivieren (Placeholder für Marketing-Tools)
|
||||
*/
|
||||
enableMarketing: function() {
|
||||
console.log('Marketing enabled');
|
||||
},
|
||||
|
||||
/**
|
||||
* Marketing deaktivieren
|
||||
*/
|
||||
disableMarketing: function() {
|
||||
console.log('Marketing disabled');
|
||||
},
|
||||
|
||||
/**
|
||||
* Banner anzeigen
|
||||
*/
|
||||
showBanner: function() {
|
||||
if (banner) {
|
||||
banner.classList.remove('hide');
|
||||
banner.classList.add('show');
|
||||
banner.setAttribute('aria-hidden', 'false');
|
||||
// Fokus auf ersten Button setzen für Accessibility
|
||||
setTimeout(() => {
|
||||
if (acceptAllBtn) acceptAllBtn.focus();
|
||||
}, 100);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Banner verstecken
|
||||
*/
|
||||
hideBanner: function() {
|
||||
if (banner) {
|
||||
banner.classList.remove('show');
|
||||
banner.classList.add('hide');
|
||||
banner.setAttribute('aria-hidden', 'true');
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Einstellungen-Panel anzeigen
|
||||
*/
|
||||
showSettings: function() {
|
||||
if (settingsPanel) {
|
||||
// Aktuelle Einstellungen in Checkboxen laden
|
||||
const consent = this.getConsent() || this.defaultConsent;
|
||||
if (analyticsCheckbox) analyticsCheckbox.checked = consent.analytics;
|
||||
if (marketingCheckbox) marketingCheckbox.checked = consent.marketing;
|
||||
|
||||
settingsPanel.style.display = 'block';
|
||||
settingsPanel.setAttribute('aria-hidden', 'false');
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Einstellungen-Panel verstecken
|
||||
*/
|
||||
hideSettings: function() {
|
||||
if (settingsPanel) {
|
||||
settingsPanel.style.display = 'none';
|
||||
settingsPanel.setAttribute('aria-hidden', 'true');
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Notification anzeigen (nutzt HexaHost-Notification-System falls verfügbar)
|
||||
*/
|
||||
showNotification: function(message, type) {
|
||||
if (window.HexaHost && typeof window.HexaHost.showNotification === 'function') {
|
||||
window.HexaHost.showNotification(message, type);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Consent zurücksetzen (für Datenschutz-Link)
|
||||
*/
|
||||
resetConsent: function() {
|
||||
CookieUtils.delete(COOKIE_NAME);
|
||||
this.showBanner();
|
||||
if (settingsPanel) settingsPanel.style.display = 'none';
|
||||
}
|
||||
};
|
||||
|
||||
// Initialisierung wenn DOM geladen
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', () => CookieConsent.init());
|
||||
} else {
|
||||
CookieConsent.init();
|
||||
}
|
||||
|
||||
// Globaler Zugriff für manuelle Steuerung
|
||||
window.CookieConsent = CookieConsent;
|
||||
|
||||
})();
|
||||
310
public/assets/js/main.js
Normal file
310
public/assets/js/main.js
Normal file
@@ -0,0 +1,310 @@
|
||||
// Main JavaScript for HexaHost.de
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
// DOM Elements
|
||||
const navToggle = document.querySelector('.nav-toggle');
|
||||
const navMenu = document.querySelector('.nav-menu');
|
||||
const navLinks = document.querySelectorAll('.nav-link');
|
||||
const glassCards = document.querySelectorAll('.glass-card');
|
||||
const productCards = document.querySelectorAll('.product-card');
|
||||
|
||||
// Mobile Navigation Toggle
|
||||
if (navToggle && navMenu) {
|
||||
navToggle.addEventListener('click', function() {
|
||||
navMenu.classList.toggle('active');
|
||||
navToggle.classList.toggle('active');
|
||||
});
|
||||
|
||||
// Close mobile menu when clicking on a link
|
||||
navLinks.forEach(link => {
|
||||
link.addEventListener('click', function() {
|
||||
navMenu.classList.remove('active');
|
||||
navToggle.classList.remove('active');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// 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'
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Enhanced glass card hover effects
|
||||
glassCards.forEach(card => {
|
||||
card.addEventListener('mouseenter', function() {
|
||||
this.style.transform = 'translateY(-8px) scale(1.02)';
|
||||
});
|
||||
|
||||
card.addEventListener('mouseleave', function() {
|
||||
this.style.transform = 'translateY(0) scale(1)';
|
||||
});
|
||||
});
|
||||
|
||||
// Product card interactive effects
|
||||
productCards.forEach(card => {
|
||||
card.addEventListener('mouseenter', function() {
|
||||
if (!this.classList.contains('featured')) {
|
||||
this.style.transform = 'translateY(-10px) scale(1.03)';
|
||||
}
|
||||
});
|
||||
|
||||
card.addEventListener('mouseleave', function() {
|
||||
if (!this.classList.contains('featured')) {
|
||||
this.style.transform = 'translateY(0) scale(1)';
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Intersection Observer for animations
|
||||
const observerOptions = {
|
||||
threshold: 0.1,
|
||||
rootMargin: '0px 0px -50px 0px'
|
||||
};
|
||||
|
||||
const observer = new IntersectionObserver(function(entries) {
|
||||
entries.forEach(entry => {
|
||||
if (entry.isIntersecting) {
|
||||
entry.target.classList.add('animate-in');
|
||||
}
|
||||
});
|
||||
}, observerOptions);
|
||||
|
||||
// Observe elements for animation
|
||||
const animateElements = document.querySelectorAll('.glass-card, .feature-item, .product-card');
|
||||
animateElements.forEach(el => {
|
||||
observer.observe(el);
|
||||
});
|
||||
|
||||
// Header scroll effect - always visible with transparency change
|
||||
const header = document.querySelector('.header');
|
||||
const hero = document.querySelector('.hero');
|
||||
|
||||
// Kombinierter, optimierter Scroll-Handler mit requestAnimationFrame
|
||||
let ticking = false;
|
||||
|
||||
function handleScroll() {
|
||||
const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
|
||||
|
||||
// Header-Effekt
|
||||
if (header) {
|
||||
if (scrollTop > 50) {
|
||||
header.classList.add('scrolled');
|
||||
} else {
|
||||
header.classList.remove('scrolled');
|
||||
}
|
||||
}
|
||||
|
||||
// Parallax-Effekt für Hero
|
||||
if (hero) {
|
||||
const rate = scrollTop * -0.5;
|
||||
hero.style.transform = `translateY(${rate}px)`;
|
||||
}
|
||||
|
||||
ticking = false;
|
||||
}
|
||||
|
||||
window.addEventListener('scroll', function() {
|
||||
if (!ticking) {
|
||||
requestAnimationFrame(handleScroll);
|
||||
ticking = true;
|
||||
}
|
||||
}, { passive: true });
|
||||
|
||||
// Form validation (for contact forms)
|
||||
const forms = document.querySelectorAll('form');
|
||||
forms.forEach(form => {
|
||||
form.addEventListener('submit', function(e) {
|
||||
const requiredFields = form.querySelectorAll('[required]');
|
||||
let isValid = true;
|
||||
|
||||
requiredFields.forEach(field => {
|
||||
if (!field.value.trim()) {
|
||||
isValid = false;
|
||||
field.classList.add('error');
|
||||
|
||||
// Remove error class on focus
|
||||
field.addEventListener('focus', function() {
|
||||
this.classList.remove('error');
|
||||
}, { once: true });
|
||||
}
|
||||
});
|
||||
|
||||
if (!isValid) {
|
||||
e.preventDefault();
|
||||
showNotification('Bitte füllen Sie alle Pflichtfelder aus.', 'error');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Notification system
|
||||
function showNotification(message, type = 'info') {
|
||||
const notification = document.createElement('div');
|
||||
notification.className = `notification notification-${type}`;
|
||||
notification.textContent = message;
|
||||
|
||||
notification.style.position = 'fixed';
|
||||
notification.style.top = '20px';
|
||||
notification.style.right = '20px';
|
||||
notification.style.padding = '15px 20px';
|
||||
notification.style.borderRadius = '8px';
|
||||
notification.style.color = 'white';
|
||||
notification.style.fontWeight = '500';
|
||||
notification.style.zIndex = '9999';
|
||||
notification.style.transform = 'translateX(400px)';
|
||||
notification.style.transition = 'transform 0.3s ease-in-out';
|
||||
|
||||
if (type === 'error') {
|
||||
notification.style.background = 'linear-gradient(135deg, #ef4444, #dc2626)';
|
||||
} else if (type === 'success') {
|
||||
notification.style.background = 'linear-gradient(135deg, #10b981, #059669)';
|
||||
} else {
|
||||
notification.style.background = 'linear-gradient(135deg, #3b82f6, #2563eb)';
|
||||
}
|
||||
|
||||
document.body.appendChild(notification);
|
||||
|
||||
// Animate in
|
||||
setTimeout(() => {
|
||||
notification.style.transform = 'translateX(0)';
|
||||
}, 100);
|
||||
|
||||
// Remove after 5 seconds
|
||||
setTimeout(() => {
|
||||
notification.style.transform = 'translateX(400px)';
|
||||
setTimeout(() => {
|
||||
if (notification.parentNode) {
|
||||
notification.parentNode.removeChild(notification);
|
||||
}
|
||||
}, 300);
|
||||
}, 5000);
|
||||
}
|
||||
|
||||
// Lazy loading for images
|
||||
const images = document.querySelectorAll('img[data-src]');
|
||||
const imageObserver = new IntersectionObserver((entries, observer) => {
|
||||
entries.forEach(entry => {
|
||||
if (entry.isIntersecting) {
|
||||
const img = entry.target;
|
||||
img.src = img.dataset.src;
|
||||
img.classList.remove('lazy');
|
||||
imageObserver.unobserve(img);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
images.forEach(img => imageObserver.observe(img));
|
||||
|
||||
// Performance optimization: Debounce scroll events
|
||||
function debounce(func, wait) {
|
||||
let timeout;
|
||||
return function executedFunction(...args) {
|
||||
const later = () => {
|
||||
clearTimeout(timeout);
|
||||
func(...args);
|
||||
};
|
||||
clearTimeout(timeout);
|
||||
timeout = setTimeout(later, wait);
|
||||
};
|
||||
}
|
||||
|
||||
// Apply debounce to scroll events
|
||||
const debouncedScrollHandler = debounce(function() {
|
||||
// Any scroll-based animations or calculations
|
||||
updateScrollProgress();
|
||||
}, 16); // ~60fps
|
||||
|
||||
window.addEventListener('scroll', debouncedScrollHandler);
|
||||
|
||||
// Scroll progress indicator
|
||||
function updateScrollProgress() {
|
||||
const scrollTop = window.pageYOffset;
|
||||
const docHeight = document.body.scrollHeight - window.innerHeight;
|
||||
const scrollPercent = (scrollTop / docHeight) * 100;
|
||||
|
||||
// You can use this to show a progress bar
|
||||
document.documentElement.style.setProperty('--scroll-progress', scrollPercent + '%');
|
||||
}
|
||||
|
||||
// Dark mode toggle (future feature)
|
||||
function initDarkMode() {
|
||||
const darkModeToggle = document.querySelector('.dark-mode-toggle');
|
||||
if (darkModeToggle) {
|
||||
darkModeToggle.addEventListener('click', function() {
|
||||
document.body.classList.toggle('dark-mode');
|
||||
localStorage.setItem('darkMode', document.body.classList.contains('dark-mode'));
|
||||
});
|
||||
|
||||
// Check for saved dark mode preference
|
||||
if (localStorage.getItem('darkMode') === 'true') {
|
||||
document.body.classList.add('dark-mode');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// FAQ Accordion functionality
|
||||
function initFAQ() {
|
||||
const faqItems = document.querySelectorAll('.faq-item');
|
||||
|
||||
faqItems.forEach(item => {
|
||||
const question = item.querySelector('.faq-question');
|
||||
const answer = item.querySelector('.faq-answer');
|
||||
|
||||
if (question && answer) {
|
||||
question.addEventListener('click', function() {
|
||||
// Close all other FAQ items
|
||||
faqItems.forEach(otherItem => {
|
||||
if (otherItem !== item && otherItem.classList.contains('open')) {
|
||||
otherItem.classList.remove('open');
|
||||
const otherAnswer = otherItem.querySelector('.faq-answer');
|
||||
if (otherAnswer) {
|
||||
otherAnswer.style.maxHeight = null;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Toggle current item
|
||||
item.classList.toggle('open');
|
||||
|
||||
if (item.classList.contains('open')) {
|
||||
answer.style.maxHeight = answer.scrollHeight + 'px';
|
||||
} else {
|
||||
answer.style.maxHeight = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Initialize all features when DOM is loaded
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
initDarkMode();
|
||||
initFAQ();
|
||||
|
||||
// Add loading animation complete class
|
||||
document.body.classList.add('loaded');
|
||||
|
||||
// Show welcome message on first visit
|
||||
if (!localStorage.getItem('hasVisited')) {
|
||||
setTimeout(() => {
|
||||
showNotification('Willkommen bei HexaHost.de! 🚀', 'success');
|
||||
localStorage.setItem('hasVisited', 'true');
|
||||
}, 1000);
|
||||
}
|
||||
});
|
||||
|
||||
// Export functions for global access if needed
|
||||
window.HexaHost = {
|
||||
showNotification: showNotification
|
||||
};
|
||||
|
||||
})();
|
||||
Reference in New Issue
Block a user