123 lines
4.4 KiB
JavaScript
123 lines
4.4 KiB
JavaScript
// Sparkle effect on mouse move
|
|
document.addEventListener('mousemove', function (e) {
|
|
const emojis = ['✨', '💖', '🌟', '💅', '🦄', '🎉', '🌈'];
|
|
const sparkle = document.createElement('div');
|
|
sparkle.className = 'emoji-footprint';
|
|
sparkle.textContent = emojis[Math.floor(Math.random() * emojis.length)];
|
|
sparkle.style.left = e.pageX + 'px';
|
|
sparkle.style.top = e.pageY + 'px';
|
|
document.body.appendChild(sparkle);
|
|
|
|
setTimeout(() => {
|
|
sparkle.remove();
|
|
}, 1000);
|
|
});
|
|
|
|
// Function to initialize number input buttons
|
|
function initNumberInputs(container = document) {
|
|
container.querySelectorAll('.number-input-wrapper').forEach(function(wrapper) {
|
|
const input = wrapper.querySelector('input[type="number"]');
|
|
const decreaseBtn = wrapper.querySelector('[data-action="decrease"]');
|
|
const increaseBtn = wrapper.querySelector('[data-action="increase"]');
|
|
|
|
if (!input || !decreaseBtn || !increaseBtn) return;
|
|
|
|
// Skip if already initialized
|
|
if (decreaseBtn.hasAttribute('data-initialized')) return;
|
|
|
|
const step = parseFloat(input.getAttribute('step')) || 1;
|
|
const min = 0;
|
|
const max = input.getAttribute('max') ? parseFloat(input.getAttribute('max')) : null;
|
|
|
|
decreaseBtn.addEventListener('click', function() {
|
|
const currentValue = parseFloat(input.value) || 0;
|
|
const newValue = currentValue - step;
|
|
|
|
if (min === null || newValue >= min) {
|
|
input.value = newValue;
|
|
input.dispatchEvent(new Event('change', { bubbles: true }));
|
|
}
|
|
});
|
|
|
|
increaseBtn.addEventListener('click', function() {
|
|
const currentValue = parseFloat(input.value) || 0;
|
|
const newValue = currentValue + step;
|
|
|
|
if (max === null || newValue <= max) {
|
|
input.value = newValue;
|
|
input.dispatchEvent(new Event('change', { bubbles: true }));
|
|
}
|
|
});
|
|
|
|
// Validate input on change
|
|
input.addEventListener('input', function() {
|
|
const value = parseFloat(this.value);
|
|
|
|
if (min !== null && value < min) {
|
|
this.value = min;
|
|
}
|
|
if (max !== null && value > max) {
|
|
this.value = max;
|
|
}
|
|
});
|
|
|
|
// Mark as initialized
|
|
decreaseBtn.setAttribute('data-initialized', 'true');
|
|
increaseBtn.setAttribute('data-initialized', 'true');
|
|
});
|
|
}
|
|
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
// Store and retrieve radio button state
|
|
const radioButtons = document.querySelectorAll('input[name="mode"]');
|
|
|
|
// Load saved state on page load
|
|
const savedMode = localStorage.getItem('selectedMode');
|
|
if (savedMode) {
|
|
const radioToCheck = document.getElementById(savedMode);
|
|
if (radioToCheck) {
|
|
radioToCheck.checked = true;
|
|
}
|
|
}
|
|
|
|
// Save state when radio button changes
|
|
radioButtons.forEach(radio => {
|
|
radio.addEventListener('change', function() {
|
|
if (this.checked) {
|
|
localStorage.setItem('selectedMode', this.id);
|
|
}
|
|
});
|
|
});
|
|
|
|
// Bootstrap Modal handling
|
|
const htmxModal = document.getElementById('htmxModal');
|
|
if (htmxModal) {
|
|
htmxModal.addEventListener('show.bs.modal', function(event) {
|
|
// Get the button that triggered the modal
|
|
const button = event.relatedTarget;
|
|
// Extract the drink name from data-* attributes
|
|
const drinkName = button.getAttribute('data-drink-name');
|
|
// Update the modal title
|
|
if (drinkName) {
|
|
const modalTitle = htmxModal.querySelector('.modal-title');
|
|
if (modalTitle) {
|
|
modalTitle.textContent = 'Update Stock for ' + drinkName;
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
// HTMX Modal handling
|
|
document.body.addEventListener('htmx:afterSwap', function(event) {
|
|
// If the target is the modal body, initialize any form elements inside it
|
|
if (event.detail.target.id === 'htmxModalBody') {
|
|
// The modal content has been loaded
|
|
console.log('Modal content loaded');
|
|
// Initialize number inputs in the modal
|
|
initNumberInputs(event.detail.target);
|
|
}
|
|
});
|
|
|
|
// Initialize number inputs on page load
|
|
initNumberInputs();
|
|
});
|