| 1 |
/** |
| 2 |
* MxChat Pro & Extensions Page JavaScript |
| 3 |
* Handles navigation, license management, and mobile interactions |
| 4 |
*/ |
| 5 |
(function($) { |
| 6 |
'use strict'; |
| 7 |
|
| 8 |
// ========================================================================== |
| 9 |
// Mobile Detection |
| 10 |
// ========================================================================== |
| 11 |
function isMobile() { |
| 12 |
return window.innerWidth <= 782; |
| 13 |
} |
| 14 |
|
| 15 |
// ========================================================================== |
| 16 |
// Section Navigation |
| 17 |
// ========================================================================== |
| 18 |
function showSection(targetId) { |
| 19 |
// Hide all sections |
| 20 |
$('.mxch-section').removeClass('active'); |
| 21 |
|
| 22 |
// Show target section |
| 23 |
$('#' + targetId).addClass('active'); |
| 24 |
|
| 25 |
// Update sidebar nav active states |
| 26 |
$('.mxch-nav-link, .mxch-addon-nav-link').removeClass('active'); |
| 27 |
$('[data-target="' + targetId + '"]').addClass('active'); |
| 28 |
|
| 29 |
// Update mobile nav active states |
| 30 |
$('.mxch-mobile-nav-link').removeClass('active'); |
| 31 |
$('.mxch-mobile-nav-link[data-target="' + targetId + '"]').addClass('active'); |
| 32 |
|
| 33 |
// Close mobile menu if open |
| 34 |
closeMobileMenu(); |
| 35 |
|
| 36 |
// Handle mobile detail panel |
| 37 |
if (isMobile() && targetId.startsWith('addon-')) { |
| 38 |
showMobileDetailPanel(targetId); |
| 39 |
} |
| 40 |
|
| 41 |
// Scroll to top of content |
| 42 |
$('.mxch-content').scrollTop(0); |
| 43 |
} |
| 44 |
|
| 45 |
// ========================================================================== |
| 46 |
// Mobile Menu |
| 47 |
// ========================================================================== |
| 48 |
function openMobileMenu() { |
| 49 |
$('.mxch-mobile-menu').addClass('open'); |
| 50 |
$('.mxch-mobile-overlay').addClass('open'); |
| 51 |
$('body').addClass('mxch-mobile-menu-open'); |
| 52 |
} |
| 53 |
|
| 54 |
function closeMobileMenu() { |
| 55 |
$('.mxch-mobile-menu').removeClass('open'); |
| 56 |
$('.mxch-mobile-overlay').removeClass('open'); |
| 57 |
$('body').removeClass('mxch-mobile-menu-open'); |
| 58 |
} |
| 59 |
|
| 60 |
// ========================================================================== |
| 61 |
// Mobile Detail Panel |
| 62 |
// ========================================================================== |
| 63 |
function showMobileDetailPanel(targetId) { |
| 64 |
if (isMobile()) { |
| 65 |
$('#' + targetId).addClass('mobile-active'); |
| 66 |
$('body').addClass('mxch-mobile-panel-open'); |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
function hideMobileDetailPanel() { |
| 71 |
$('.mxch-addon-detail').removeClass('mobile-active'); |
| 72 |
$('body').removeClass('mxch-mobile-panel-open'); |
| 73 |
} |
| 74 |
|
| 75 |
// ========================================================================== |
| 76 |
// License Activation - HANDLED BY activation-script.js |
| 77 |
// ========================================================================== |
| 78 |
// License activation is handled by activation-script.js which provides |
| 79 |
// better status feedback and error recovery with domain linking. |
| 80 |
// Do not add duplicate handlers here. |
| 81 |
|
| 82 |
// ========================================================================== |
| 83 |
// License Deactivation - HANDLED BY activation-script.js |
| 84 |
// ========================================================================== |
| 85 |
// License deactivation is handled by activation-script.js. |
| 86 |
// Do not add duplicate handlers here. |
| 87 |
|
| 88 |
// ========================================================================== |
| 89 |
// Domain Linking - HANDLED BY activation-script.js |
| 90 |
// ========================================================================== |
| 91 |
// Domain linking is handled by activation-script.js. |
| 92 |
// Do not add duplicate handlers here. |
| 93 |
|
| 94 |
// ========================================================================== |
| 95 |
// Initialize |
| 96 |
// ========================================================================== |
| 97 |
$(document).ready(function() { |
| 98 |
// Sidebar navigation clicks |
| 99 |
$(document).on('click', '.mxch-nav-link[data-target], .mxch-addon-nav-link[data-target]', function(e) { |
| 100 |
e.preventDefault(); |
| 101 |
var target = $(this).data('target'); |
| 102 |
if (target) { |
| 103 |
showSection(target); |
| 104 |
} |
| 105 |
}); |
| 106 |
|
| 107 |
// Extension card clicks (overview grid) |
| 108 |
$(document).on('click', '.mxch-extension-card', function(e) { |
| 109 |
// Don't trigger if clicking on a button inside |
| 110 |
if ($(e.target).closest('button, a').length) { |
| 111 |
return; |
| 112 |
} |
| 113 |
var addon = $(this).data('addon'); |
| 114 |
if (addon) { |
| 115 |
showSection('addon-' + addon); |
| 116 |
} |
| 117 |
}); |
| 118 |
|
| 119 |
// View addon button clicks |
| 120 |
$(document).on('click', '.mxch-view-addon-btn', function(e) { |
| 121 |
e.preventDefault(); |
| 122 |
e.stopPropagation(); |
| 123 |
var target = $(this).data('target'); |
| 124 |
if (target) { |
| 125 |
showSection(target); |
| 126 |
} |
| 127 |
}); |
| 128 |
|
| 129 |
// Back button clicks (supports both .mxch-back-btn and .mxch-back-link) |
| 130 |
$(document).on('click', '.mxch-back-btn, .mxch-back-link', function(e) { |
| 131 |
e.preventDefault(); |
| 132 |
var target = $(this).data('target') || 'overview'; |
| 133 |
hideMobileDetailPanel(); |
| 134 |
showSection(target); |
| 135 |
}); |
| 136 |
|
| 137 |
// Mobile menu toggle |
| 138 |
$(document).on('click', '.mxch-mobile-menu-btn', function(e) { |
| 139 |
e.preventDefault(); |
| 140 |
openMobileMenu(); |
| 141 |
}); |
| 142 |
|
| 143 |
// Mobile menu close |
| 144 |
$(document).on('click', '.mxch-mobile-menu-close, .mxch-mobile-overlay', function(e) { |
| 145 |
e.preventDefault(); |
| 146 |
closeMobileMenu(); |
| 147 |
}); |
| 148 |
|
| 149 |
// Mobile nav link clicks |
| 150 |
$(document).on('click', '.mxch-mobile-nav-link', function(e) { |
| 151 |
e.preventDefault(); |
| 152 |
var target = $(this).data('target'); |
| 153 |
if (target) { |
| 154 |
showSection(target); |
| 155 |
} |
| 156 |
}); |
| 157 |
|
| 158 |
// License activation, deactivation, and domain linking are handled by |
| 159 |
// activation-script.js - do not add duplicate handlers here. |
| 160 |
|
| 161 |
// Activate license button in sidebar (when inactive) |
| 162 |
$(document).on('click', '.mxch-activate-license-btn', function(e) { |
| 163 |
e.preventDefault(); |
| 164 |
showSection('overview'); |
| 165 |
// Focus on email field after section loads |
| 166 |
setTimeout(function() { |
| 167 |
$('#mxchat_pro_email').focus(); |
| 168 |
}, 300); |
| 169 |
}); |
| 170 |
|
| 171 |
// Handle window resize |
| 172 |
$(window).on('resize', function() { |
| 173 |
if (!isMobile()) { |
| 174 |
hideMobileDetailPanel(); |
| 175 |
closeMobileMenu(); |
| 176 |
} |
| 177 |
}); |
| 178 |
|
| 179 |
// Handle escape key |
| 180 |
$(document).on('keydown', function(e) { |
| 181 |
if (e.key === 'Escape') { |
| 182 |
closeMobileMenu(); |
| 183 |
if (isMobile()) { |
| 184 |
hideMobileDetailPanel(); |
| 185 |
showSection('overview'); |
| 186 |
} |
| 187 |
} |
| 188 |
}); |
| 189 |
}); |
| 190 |
|
| 191 |
})(jQuery); |
| 192 |
|