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