gutenberg
3 years 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
80 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 | console.log(`Initializing toggle: ${toggleId}`); |
| 10 | |
| 11 | toggle.addEventListener('click', async function(event) { |
| 12 | const isEnabled = this.checked; |
| 13 | const badgeId = toggleId === 'cookiebot-banner-enabled' ? 'cookiebot-banner-badge' : `${toggleId}-badge`; |
| 14 | const badge = document.getElementById(badgeId); |
| 15 | if (!badge) { |
| 16 | console.error(`Badge element not found: ${badgeId}`); |
| 17 | } |
| 18 | |
| 19 | console.log(`Toggle ${toggleId} clicked. New state:`, isEnabled); |
| 20 | |
| 21 | try { |
| 22 | const response = await $.ajax({ |
| 23 | url: cookiebot_account.ajax_url, |
| 24 | method: 'POST', |
| 25 | data: { |
| 26 | action: action, |
| 27 | nonce: cookiebot_account.nonce, |
| 28 | value: isEnabled ? value : '0' |
| 29 | } |
| 30 | }); |
| 31 | |
| 32 | console.log(`Toggle ${toggleId} response:`, response); |
| 33 | |
| 34 | if (!response.success) { |
| 35 | throw new Error(response.data || `Failed to update ${toggleId} status`); |
| 36 | } |
| 37 | |
| 38 | // Update badge status |
| 39 | if (badge) { |
| 40 | badge.className = `label-wrapper status-badge ${isEnabled ? 'active' : 'inactive'}`; |
| 41 | badge.querySelector('.label-2').textContent = isEnabled ? 'Active' : 'Inactive'; |
| 42 | console.log(`Updated badge for ${toggleId}. New state:`, isEnabled ? 'active' : 'inactive'); |
| 43 | } |
| 44 | |
| 45 | if (cookiebot_account.debug) { |
| 46 | console.log(`${toggleId} toggle response:`, response); |
| 47 | } |
| 48 | } catch (error) { |
| 49 | console.error(`Failed to toggle ${toggleId}:`, error); |
| 50 | this.checked = !isEnabled; |
| 51 | // Revert badge status on error |
| 52 | if (badge) { |
| 53 | badge.className = `label-wrapper status-badge ${!isEnabled ? 'active' : 'inactive'}`; |
| 54 | badge.querySelector('.label-2').textContent = !isEnabled ? 'Active' : 'Inactive'; |
| 55 | console.log(`Reverted badge for ${toggleId}. State:`, !isEnabled ? 'active' : 'inactive'); |
| 56 | } |
| 57 | } |
| 58 | }); |
| 59 | } |
| 60 | |
| 61 | // Initialize toggles |
| 62 | console.log('Initializing toggles...'); |
| 63 | handleToggle('cookiebot-banner-enabled', 'cookiebot_set_banner_enabled', '1'); |
| 64 | handleToggle('cookiebot-gcm', 'cookiebot_set_gcm_enabled', '1'); |
| 65 | |
| 66 | // Handle expand/collapse |
| 67 | const expandToggle = document.querySelector('.expand-toggle'); |
| 68 | if (expandToggle) { |
| 69 | expandToggle.addEventListener('click', function() { |
| 70 | const expanded = this.getAttribute('aria-expanded') === 'true'; |
| 71 | const targetId = this.getAttribute('aria-controls'); |
| 72 | const targetSection = document.getElementById(targetId); |
| 73 | const arrowIcon = this.querySelector('.arrow-icon'); |
| 74 | |
| 75 | this.setAttribute('aria-expanded', !expanded); |
| 76 | targetSection.style.display = expanded ? 'none' : 'block'; |
| 77 | arrowIcon.style.transform = expanded ? 'rotate(0deg)' : 'rotate(180deg)'; |
| 78 | }); |
| 79 | } |
| 80 | }); |