/** * HVAC Welcome Popup System * * Handles the welcome popup modal for new users with carousel functionality */ (function($) { 'use strict'; var HVACWelcomePopup = { init: function() { this.currentCard = 0; this.totalCards = 4; this.bindEvents(); this.checkAndShowPopup(); }, bindEvents: function() { var self = this; // Close popup handlers $(document).on('click', '.hvac-welcome-close', function(e) { e.preventDefault(); self.closePopup(); }); $(document).on('click', '.hvac-welcome-overlay', function(e) { if (e.target === this) { self.closePopup(); } }); // Navigation handlers $(document).on('click', '.hvac-welcome-nav-prev', function(e) { e.preventDefault(); self.previousCard(); }); $(document).on('click', '.hvac-welcome-nav-next', function(e) { e.preventDefault(); self.nextCard(); }); // Dot navigation $(document).on('click', '.hvac-welcome-dot', function(e) { e.preventDefault(); var cardIndex = $(this).data('card'); self.goToCard(cardIndex); }); // Dismiss permanently $(document).on('click', '.hvac-welcome-dismiss', function(e) { e.preventDefault(); self.dismissPermanently(); }); // Keyboard navigation $(document).on('keydown', function(e) { if ($('.hvac-welcome-popup').is(':visible')) { switch(e.which) { case 27: // ESC self.closePopup(); break; case 37: // Left arrow self.previousCard(); break; case 39: // Right arrow self.nextCard(); break; } } }); }, checkAndShowPopup: function() { var self = this; // Check if user has dismissed the popup $.ajax({ url: hvac_welcome.ajax_url, type: 'POST', data: { action: 'hvac_check_welcome_dismissed', nonce: hvac_welcome.nonce }, success: function(response) { if (response.success && !response.data.dismissed) { self.showPopup(); } } }); }, showPopup: function() { if ($('.hvac-welcome-popup').length === 0) { this.createPopup(); } $('body').addClass('hvac-welcome-open'); $('.hvac-welcome-popup').fadeIn(300); this.updateCardDisplay(); }, closePopup: function() { $('.hvac-welcome-popup').fadeOut(300); $('body').removeClass('hvac-welcome-open'); }, dismissPermanently: function() { var self = this; var shouldDismiss = $('#hvac-welcome-dont-show').is(':checked'); if (shouldDismiss) { $.ajax({ url: hvac_welcome.ajax_url, type: 'POST', data: { action: 'hvac_dismiss_welcome_popup', nonce: hvac_welcome.nonce }, success: function(response) { if (response.success) { self.closePopup(); } } }); } else { // Just close without permanently dismissing self.closePopup(); } }, previousCard: function() { this.currentCard = (this.currentCard - 1 + this.totalCards) % this.totalCards; this.updateCardDisplay(); }, nextCard: function() { this.currentCard = (this.currentCard + 1) % this.totalCards; this.updateCardDisplay(); }, goToCard: function(cardIndex) { this.currentCard = cardIndex; this.updateCardDisplay(); }, updateCardDisplay: function() { var self = this; var $cards = $('.hvac-welcome-card'); var $dots = $('.hvac-welcome-dot'); // Hide all cards $cards.removeClass('active'); $dots.removeClass('active'); // Show current card with animation setTimeout(function() { $cards.eq(self.currentCard).addClass('active'); $dots.eq(self.currentCard).addClass('active'); }, 150); // Update navigation button states $('.hvac-welcome-nav-prev').toggleClass('disabled', this.currentCard === 0); $('.hvac-welcome-nav-next').toggleClass('disabled', this.currentCard === this.totalCards - 1); }, createPopup: function() { var popupHTML = this.getPopupHTML(); $('body').append(popupHTML); }, getPopupHTML: function() { return `
`; } }; // Initialize when document is ready $(document).ready(function() { // Only initialize on dashboard page if ($('.hvac-trainer-dashboard-page').length > 0) { HVACWelcomePopup.init(); } }); })(jQuery);