gutenberg
2 weeks ago
account-static.js
10 months ago
account.js
10 months ago
amplitude.js
1 year ago
consent-mapping.js
1 year ago
cookiebot-admin-script.js
6 months ago
dashboard.js
1 year ago
jquery.tipTip.js
3 years ago
multiple-page.js
3 years ago
network-settings-page.js
4 months ago
ppg-page.js
4 months ago
prior-consent-settings.js
3 years ago
settings-page.js
4 months ago
support-page.js
1 year ago
dashboard.js
76 lines
| 1 | jQuery(document).ready(function($) { |
| 2 | // Handle toggle functionality |
| 3 | const userData = cookiebot_dashboard.user_data; |
| 4 | function handleToggle(toggleId, action, value) { |
| 5 | const toggle = document.getElementById(toggleId); |
| 6 | if (!toggle) { |
| 7 | return; |
| 8 | } |
| 9 | |
| 10 | toggle.addEventListener('click', async function() { |
| 11 | const isEnabled = this.checked; |
| 12 | const badgeId = toggleId === 'cookiebot-banner-enabled' ? 'cookiebot-banner-badge' : `${toggleId}-badge`; |
| 13 | const badge = document.getElementById(badgeId); |
| 14 | |
| 15 | window.amplitude.track('Banner toggle', { |
| 16 | Enabled: isEnabled, |
| 17 | settingsId: userData.settingsId, |
| 18 | subscription: userData.subscriptions['active'].subscription_status |
| 19 | }); |
| 20 | |
| 21 | if (!badge) { |
| 22 | console.error(`Badge element not found: ${badgeId}`); |
| 23 | } |
| 24 | |
| 25 | try { |
| 26 | const response = await $.ajax({ |
| 27 | url: cookiebot_account.ajax_url, |
| 28 | method: 'POST', |
| 29 | data: { |
| 30 | action: action, |
| 31 | nonce: cookiebot_account.nonce, |
| 32 | value: isEnabled ? value : '0' |
| 33 | } |
| 34 | }); |
| 35 | |
| 36 | if (!response.success) { |
| 37 | throw new Error(response.data || `Failed to update ${toggleId} status`); |
| 38 | } |
| 39 | |
| 40 | // Update badge status |
| 41 | if (badge) { |
| 42 | badge.className = `label-wrapper status-badge ${isEnabled ? 'active' : 'inactive'}`; |
| 43 | badge.querySelector('.label-2').textContent = isEnabled ? 'Active' : 'Inactive'; |
| 44 | } |
| 45 | |
| 46 | } catch (error) { |
| 47 | console.error(`Failed to toggle ${toggleId}:`, error); |
| 48 | this.checked = !isEnabled; |
| 49 | // Revert badge status on error |
| 50 | if (badge) { |
| 51 | badge.className = `label-wrapper status-badge ${!isEnabled ? 'active' : 'inactive'}`; |
| 52 | badge.querySelector('.label-2').textContent = !isEnabled ? 'Active' : 'Inactive'; |
| 53 | } |
| 54 | } |
| 55 | }); |
| 56 | } |
| 57 | |
| 58 | handleToggle('cookiebot-banner-enabled', 'cookiebot_set_banner_enabled', '1'); |
| 59 | handleToggle('cookiebot-uc-auto-blocking-mode', 'cookiebot_set_auto_blocking_mode', '1'); |
| 60 | handleToggle('cookiebot-gcm', 'cookiebot_set_gcm_enabled', '1'); |
| 61 | |
| 62 | // Handle expand/collapse |
| 63 | const expandToggle = document.querySelector('.expand-toggle'); |
| 64 | if (expandToggle) { |
| 65 | expandToggle.addEventListener('click', function() { |
| 66 | const expanded = this.getAttribute('aria-expanded') === 'true'; |
| 67 | const targetId = this.getAttribute('aria-controls'); |
| 68 | const targetSection = document.getElementById(targetId); |
| 69 | const arrowIcon = this.querySelector('.arrow-icon'); |
| 70 | |
| 71 | this.setAttribute('aria-expanded', !expanded); |
| 72 | targetSection.style.display = expanded ? 'none' : 'block'; |
| 73 | arrowIcon.style.transform = expanded ? 'rotate(0deg)' : 'rotate(180deg)'; |
| 74 | }); |
| 75 | } |
| 76 | }); |