-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
87 lines (77 loc) · 2.55 KB
/
script.js
File metadata and controls
87 lines (77 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Promo popup close
function closePromo() {
var overlay = document.getElementById('promoOverlay');
if (overlay) overlay.classList.remove('show');
}
// Azure Static Web Apps Authentication
async function getUser() {
try {
var response = await fetch('/.auth/me');
if (!response.ok) return null;
var data = await response.json();
return (data && data.clientPrincipal) ? data.clientPrincipal : null;
} catch (e) {
return null;
}
}
function renderAuth(user) {
var authArea = document.getElementById('authArea');
if (!authArea) return;
if (user) {
var displayName = user.userDetails || user.userId || 'משתמש';
authArea.innerHTML =
'<span class="auth-user-info">' +
'<span class="user-name">שלום, ' + displayName + '</span>' +
'</span>' +
'<a href="/.auth/logout" class="btn-auth btn-logout">התנתק</a>';
} else {
authArea.innerHTML =
'<span class="auth-user-info">לא מחובר</span>' +
'<a href="/.auth/login/google" class="btn-auth btn-login">התחבר עם Google</a>';
}
}
// Mobile menu toggle
document.addEventListener('DOMContentLoaded', function () {
// Load auth state, then load cart
getUser().then(function (user) {
renderAuth(user);
initCart();
});
// Show promo popup once per session (not on reloads)
if (!sessionStorage.getItem('promo_shown')) {
var overlay = document.getElementById('promoOverlay');
if (overlay) {
setTimeout(function () { overlay.classList.add('show'); }, 500);
sessionStorage.setItem('promo_shown', '1');
}
}
var menuToggle = document.querySelector('.menu-toggle');
var nav = document.querySelector('.nav');
menuToggle.addEventListener('click', function () {
nav.classList.toggle('active');
});
// Close menu when clicking a nav link
document.querySelectorAll('.nav a').forEach(function (link) {
link.addEventListener('click', function () {
nav.classList.remove('active');
});
});
// Contact form handler
var form = document.getElementById('contactForm');
if (form) {
form.addEventListener('submit', function (e) {
e.preventDefault();
alert('ההודעה נשלחה בהצלחה! נחזור אליך בהקדם.');
form.reset();
});
}
// Header shadow on scroll
var header = document.querySelector('.header');
window.addEventListener('scroll', function () {
if (window.scrollY > 50) {
header.style.boxShadow = '0 2px 30px rgba(0, 0, 0, 0.12)';
} else {
header.style.boxShadow = '0 2px 20px rgba(0, 0, 0, 0.08)';
}
});
});