AI update: הוסף לפני תג הסגירה </body> קטע קוד (HTML+CSS+JS וניל, ללא ספריות חיצוניות) שיוצר כפתור פעולה צף (floating action button
This commit is contained in:
@@ -116,97 +116,4 @@
|
||||
}, { passive: true });
|
||||
}
|
||||
|
||||
// Sales Popup
|
||||
const popupOverlay = document.getElementById('popup-overlay');
|
||||
const popupClose = document.getElementById('popup-close');
|
||||
const floatingCta = document.getElementById('floating-cta');
|
||||
const popup = popupOverlay ? popupOverlay.querySelector('.popup') : null;
|
||||
|
||||
function openPopup() {
|
||||
if (!popupOverlay) return;
|
||||
popupOverlay.classList.add('is-visible');
|
||||
popupOverlay.setAttribute('aria-hidden', 'false');
|
||||
document.body.classList.add('popup-open');
|
||||
// Focus the close button for accessibility
|
||||
if (popupClose) {
|
||||
setTimeout(function() {
|
||||
popupClose.focus();
|
||||
}, 100);
|
||||
}
|
||||
}
|
||||
|
||||
function closePopup() {
|
||||
if (!popupOverlay) return;
|
||||
popupOverlay.classList.remove('is-visible');
|
||||
popupOverlay.setAttribute('aria-hidden', 'true');
|
||||
document.body.classList.remove('popup-open');
|
||||
}
|
||||
|
||||
// Auto-open popup after 5 seconds
|
||||
let popupShown = false;
|
||||
setTimeout(function() {
|
||||
if (!popupShown) {
|
||||
popupShown = true;
|
||||
openPopup();
|
||||
}
|
||||
}, 5000);
|
||||
|
||||
// Floating CTA click
|
||||
if (floatingCta) {
|
||||
floatingCta.addEventListener('click', function() {
|
||||
openPopup();
|
||||
});
|
||||
}
|
||||
|
||||
// Close button click
|
||||
if (popupClose) {
|
||||
popupClose.addEventListener('click', function() {
|
||||
closePopup();
|
||||
});
|
||||
}
|
||||
|
||||
// Click outside popup to close
|
||||
if (popupOverlay) {
|
||||
popupOverlay.addEventListener('click', function(e) {
|
||||
if (e.target === popupOverlay) {
|
||||
closePopup();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Escape key to close popup
|
||||
document.addEventListener('keydown', function(e) {
|
||||
if (e.key === 'Escape' && popupOverlay && popupOverlay.classList.contains('is-visible')) {
|
||||
closePopup();
|
||||
if (floatingCta) {
|
||||
floatingCta.focus();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Trap focus inside popup when open
|
||||
if (popup) {
|
||||
popup.addEventListener('keydown', function(e) {
|
||||
if (e.key !== 'Tab') return;
|
||||
|
||||
const focusableElements = popup.querySelectorAll(
|
||||
'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'
|
||||
);
|
||||
const firstElement = focusableElements[0];
|
||||
const lastElement = focusableElements[focusableElements.length - 1];
|
||||
|
||||
if (e.shiftKey) {
|
||||
if (document.activeElement === firstElement) {
|
||||
lastElement.focus();
|
||||
e.preventDefault();
|
||||
}
|
||||
} else {
|
||||
if (document.activeElement === lastElement) {
|
||||
firstElement.focus();
|
||||
e.preventDefault();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
})();
|
||||
Reference in New Issue
Block a user