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