65 lines
1.9 KiB
JavaScript
65 lines
1.9 KiB
JavaScript
/**
|
|
* Reward System Module
|
|
*/
|
|
(function() {
|
|
function initReward() {
|
|
const btn = document.getElementById('reward-btn');
|
|
const modal = document.getElementById('reward-modal');
|
|
const close = document.getElementById('reward-close');
|
|
|
|
if (!btn || !modal) return;
|
|
|
|
// Helper to show modal
|
|
const showModal = (e) => {
|
|
if(e) {
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
}
|
|
modal.classList.add('show');
|
|
document.body.style.overflow = 'hidden'; // Prevent scrolling
|
|
};
|
|
|
|
// Helper to hide modal
|
|
const hideModal = () => {
|
|
modal.classList.remove('show');
|
|
document.body.style.overflow = '';
|
|
};
|
|
|
|
// Button click
|
|
btn.addEventListener('click', showModal);
|
|
|
|
// Close button click
|
|
if (close) {
|
|
close.addEventListener('click', hideModal);
|
|
}
|
|
|
|
// Click outside modal content
|
|
modal.addEventListener('click', (e) => {
|
|
if (e.target === modal) {
|
|
hideModal();
|
|
}
|
|
});
|
|
|
|
// Escape key to close
|
|
if (!window.rewardKeyHandlerAttached) {
|
|
document.addEventListener('keydown', function(e) {
|
|
const activeModal = document.getElementById('reward-modal');
|
|
if (e.key === 'Escape' && activeModal && activeModal.classList.contains('show')) {
|
|
activeModal.classList.remove('show');
|
|
document.body.style.overflow = '';
|
|
}
|
|
});
|
|
window.rewardKeyHandlerAttached = true;
|
|
}
|
|
}
|
|
|
|
// Initialize on load
|
|
document.addEventListener('DOMContentLoaded', initReward);
|
|
|
|
// Initialize on Pjax complete
|
|
document.addEventListener('pjax:complete', initReward);
|
|
|
|
// Export
|
|
window.initReward = initReward;
|
|
})();
|