Zum Inhalt springen

MediaWiki:Common.js

Aus transformal GmbH

Hinweis: Leere nach dem Veröffentlichen den Browser-Cache, um die Änderungen sehen zu können.

  • Firefox/Safari: Umschalttaste drücken und gleichzeitig Aktualisieren anklicken oder entweder Strg+F5 oder Strg+R (⌘+R auf dem Mac) drücken
  • Google Chrome: Umschalttaste+Strg+R (⌘+Umschalttaste+R auf dem Mac) drücken
  • Edge: Strg+F5 drücken oder Strg drücken und gleichzeitig Aktualisieren anklicken
/* Consent System JavaScript v250820r2 */

// Handle consent acquisition box
$(document).ready(function() {
    // Hide consent box if already dismissed
    var dismissed = sessionStorage.getItem('consent-acquisition-dismissed');
    var consentBox = document.getElementById('consent-acquisition-box');
    
    if (dismissed === 'true' && consentBox) {
        consentBox.style.display = 'none';
    }
    
    // Add click handler to consent box
    if (consentBox) {
        consentBox.addEventListener('click', function() {
            // Set session storage
            sessionStorage.setItem('consent-acquisition-dismissed', 'true');
            
            // Navigate to analyses preferences page
            var lang = document.documentElement.lang || 'en';
            var targetPage = '';
            
            if (lang === 'de') {
                targetPage = '/wiki/Transformal_GmbH:Analyseeinstellungen';
            } else {
                targetPage = '/wiki/Transformal_GmbH:Analyses_preferences';
            }
            
            window.location.href = targetPage;
        });
    }
});

// Convert template placeholders to actual checkboxes
console.log('Starting consent checkbox initialization');

$(function() {
    
    $('.consent-option').each(function() {
        var $option = $(this);
        
        // Skip if already processed
        if ($option.find('.consent-checkbox').length > 0) return;
        
        var consentId = $option.find('.consent-data').text().trim();
        var status = $option.find('.consent-status-data').text().trim();
        
        // Find the checkbox-row div
        var $checkboxRow = $option.find('.checkbox-row');
        if (!$checkboxRow.length) return;
        
        // Create checkbox and append directly
        var $container = $('<span class="checkbox-container"></span>');
        var $checkbox = $('<input>', {
            type: 'checkbox',
            id: consentId,
            class: 'consent-checkbox'
        });
        
        if (status === 'disabled') {
            $checkbox.prop('disabled', true);
        }
        
        var label = $option.find('.checkbox-placeholder').attr('data-label') || 'Enabled';
        var $label = $('<label>', {
          'for': consentId,
          text: ' ' + label,
          style: 'cursor: pointer;'
        });
        
        $container.append($checkbox).append($label);
        $checkboxRow.append($container);
        
        // Remove placeholder if exists
        $checkboxRow.find('.checkbox-placeholder').remove();
        
        // Load and bind
        var saved = localStorage.getItem(consentId) === 'true';
        $checkbox.prop('checked', saved);
        
        $checkbox.on('change', function() {
            localStorage.setItem(consentId, this.checked);
            if (typeof handleConsentChange === 'function') {
              handleConsentChange(consentId, this.checked);
            }
            if (typeof showConsentFeedback === 'function') {
                showConsentFeedback(consentId, this.checked);
            }
        });
    });
});

// Handle consent changes for different features
function handleConsentChange(feature, enabled) {
    if (feature === 'matomo-consent') {
        if (enabled) {
            if (window._paq) {
                _paq.push(['rememberConsentGiven']);
                _paq.push(['trackPageView']);
            }
        } else {
            if (window._paq) {
                _paq.push(['forgetConsentGiven']);
            }
        }
    }
}

// Show feedback when consent changes - FIXED to show both enabled and disabled messages
function showConsentFeedback(feature, enabled) {
    var feedbackDiv = document.getElementById('consent-feedback');
    if (!feedbackDiv) return;
    
    var message = '';
    if (feature === 'matomo-consent') {
        message = enabled ? 'Aufzeichnungen zugelassen' : 'Aufzeichnungen nicht zugelassen';
    } else if (feature === 'altcha-consent') {
        message = enabled ? 'Proof-of-work zugelassen' : 'Proof-of-work nicht zugelassen';
    }
    
    if (message) {
        feedbackDiv.innerHTML = message + ' &ndash; Ihre Einstellungen werden gespeichert';
        feedbackDiv.style.display = 'block';
        
        // Hide after 3 seconds
        setTimeout(function() {
            feedbackDiv.style.display = 'none';
        }, 3000);
    }
}