initial commit
This commit is contained in:
134
scripts/script.js
Normal file
134
scripts/script.js
Normal file
@@ -0,0 +1,134 @@
|
||||
// script.js
|
||||
|
||||
// ==========================================
|
||||
// 1. MENU TOGGLE LOGIC
|
||||
// ==========================================
|
||||
const menuToggle = document.getElementById('menuToggle');
|
||||
const slideMenu = document.getElementById('slideMenu');
|
||||
const overlay = document.getElementById('overlay');
|
||||
const loginBtn = document.getElementById('loginBtn');
|
||||
|
||||
if (menuToggle && slideMenu && overlay) {
|
||||
function toggleMenu() {
|
||||
menuToggle.classList.toggle('active');
|
||||
slideMenu.classList.toggle('active');
|
||||
overlay.classList.toggle('active');
|
||||
}
|
||||
|
||||
menuToggle.addEventListener('click', toggleMenu);
|
||||
overlay.addEventListener('click', toggleMenu);
|
||||
}
|
||||
|
||||
// Login button functionality
|
||||
if (loginBtn) {
|
||||
console.log('Login button found:', loginBtn);
|
||||
loginBtn.addEventListener('click', function(e) {
|
||||
e.preventDefault();
|
||||
console.log('Login button clicked!');
|
||||
console.log('Current path:', window.location.pathname);
|
||||
|
||||
// Check if we're already on the login page
|
||||
if (window.location.pathname.includes('login.html')) {
|
||||
// If on login page, go to register page
|
||||
console.log('Navigating to register page');
|
||||
window.location.href = 'register.html';
|
||||
} else if (window.location.pathname.includes('register.html')) {
|
||||
// If on register page, go to login page
|
||||
console.log('Navigating to login page from register');
|
||||
window.location.href = 'login.html';
|
||||
} else {
|
||||
// If on any other page, go to login page
|
||||
console.log('Navigating to login page from other');
|
||||
window.location.href = 'sites/login.html';
|
||||
}
|
||||
});
|
||||
} else {
|
||||
console.error('Login button not found in DOM');
|
||||
}
|
||||
|
||||
// ==========================================
|
||||
// 2. FORM SUBMISSION LOGIC
|
||||
// ==========================================
|
||||
const contactForm = document.getElementById('contactForm');
|
||||
const successMessage = document.getElementById('successMessage');
|
||||
|
||||
if (contactForm) {
|
||||
contactForm.addEventListener('submit', async function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
const nameInput = document.getElementById('name');
|
||||
const orgInput = document.getElementById('organisation');
|
||||
const contactInput = document.getElementById('contact');
|
||||
const serviceSelect = document.getElementById('service');
|
||||
const budgetInput = document.getElementById('budget');
|
||||
const descInput = document.getElementById('description');
|
||||
|
||||
const selectedServiceText = serviceSelect ? serviceSelect.options[serviceSelect.selectedIndex].text : 'Dienstleistung';
|
||||
|
||||
const formData = {
|
||||
name: nameInput ? nameInput.value : '',
|
||||
organisation: orgInput ? orgInput.value : '',
|
||||
contact: contactInput ? contactInput.value : '',
|
||||
service: serviceSelect ? serviceSelect.value : '',
|
||||
budget: budgetInput ? budgetInput.value : '',
|
||||
description: descInput ? descInput.value : '',
|
||||
timestamp: new Date().toISOString()
|
||||
};
|
||||
|
||||
// --- LOCALSTORAGE ---
|
||||
try {
|
||||
const localLead = {
|
||||
id: Date.now(),
|
||||
datum: new Date().toLocaleDateString('de-DE'),
|
||||
dienstleistung: selectedServiceText,
|
||||
status: 'open',
|
||||
statusText: 'Offen',
|
||||
description: formData.description
|
||||
};
|
||||
|
||||
let existingLeads = JSON.parse(localStorage.getItem('myLeads')) || [];
|
||||
existingLeads.unshift(localLead);
|
||||
localStorage.setItem('myLeads', JSON.stringify(existingLeads));
|
||||
} catch (err) {
|
||||
console.error('Ошибка сохранения в LocalStorage:', err);
|
||||
}
|
||||
// false if test, true if production
|
||||
const USE_PRODUCTION = true;
|
||||
const WEBHOOK_TEST = 'https://n8n.profice.de/webhook-test/d94ef798-3f43-46dd-8207-1e335e64518f';
|
||||
const WEBHOOK_PROD = 'https://n8n.profice.de/webhook/d94ef798-3f43-46dd-8207-1e335e64518f';
|
||||
const N8N_WEBHOOK_URL = USE_PRODUCTION ? WEBHOOK_PROD : WEBHOOK_TEST;
|
||||
|
||||
let iframe = document.getElementById('hidden-iframe');
|
||||
if (!iframe) {
|
||||
iframe = document.createElement('iframe');
|
||||
iframe.id = 'hidden-iframe';
|
||||
iframe.name = 'hidden-iframe';
|
||||
iframe.style.display = 'none';
|
||||
document.body.appendChild(iframe);
|
||||
}
|
||||
|
||||
const tempForm = document.createElement('form');
|
||||
tempForm.method = 'POST';
|
||||
tempForm.action = N8N_WEBHOOK_URL;
|
||||
tempForm.target = 'hidden-iframe';
|
||||
|
||||
for (const [key, value] of Object.entries(formData)) {
|
||||
const input = document.createElement('input');
|
||||
input.type = 'hidden';
|
||||
input.name = key;
|
||||
input.value = value;
|
||||
tempForm.appendChild(input);
|
||||
}
|
||||
|
||||
document.body.appendChild(tempForm);
|
||||
tempForm.submit();
|
||||
document.body.removeChild(tempForm);
|
||||
|
||||
contactForm.style.display = 'none';
|
||||
if (successMessage) {
|
||||
successMessage.classList.add('show');
|
||||
}
|
||||
|
||||
console.log('Form submitted successfully');
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user