Zum Inhalt springen

MediaWiki:Common.js: Unterschied zwischen den Versionen

Aus transformal GmbH
Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Zeile 1: Zeile 1:
/* Consent System JavaScript v250820r4 */
/* Unified Consent System JavaScript v250822r2
* Single file for both EN and DE versions
* Automatically detects language based on domain
*/
 
// Language detection helper
function getCurrentLanguage() {
    var hostname = window.location.hostname;
    return (hostname === 'de.transformal.com' ||
            hostname === 'de.olaflangmack.info' ||
            hostname === 'de.mediawiki.transformal.com') ? 'de' : 'en';
}
 
// Localized strings
var strings = {
    en: {
        journalingEnabled: 'Journaling enabled',
        journalingDisabled: 'Journaling disabled',
        proofOfWorkEnabled: 'Proof-of-work enabled',
        proofOfWorkDisabled: 'Proof-of-work disabled',
        preferencesSaved: 'Your preferences are being saved',
        checkboxLabel: 'Enabled'
    },
    de: {
        journalingEnabled: 'Aufzeichnungen zugelassen',
        journalingDisabled: 'Aufzeichnungen nicht zugelassen',
        proofOfWorkEnabled: 'Proof-of-work zugelassen',
        proofOfWorkDisabled: 'Proof-of-work nicht zugelassen',
        preferencesSaved: 'Ihre Einstellungen werden gespeichert',
        checkboxLabel: 'Erlaubt'
    }
};
 
// Get string in current language
function getString(key) {
    var lang = getCurrentLanguage();
    return strings[lang][key] || strings.en[key];
}


// Handle consent acquisition box
// Handle consent acquisition box
Zeile 21: Zeile 58:
         // Set session storage
         // Set session storage
         sessionStorage.setItem('consent-acquisition-dismissed', 'true');
         sessionStorage.setItem('consent-acquisition-dismissed', 'true');
       
        // Determine language based on domain
        var hostname = window.location.hostname;
        var isGerman = (hostname === 'de.transformal.com' ||
                      hostname === 'de.olaflangmack.info' ||
                      hostname === 'de.mediawiki.transformal.com');
          
          
         // Navigate to correct language version
         // Navigate to correct language version
         var targetPage = isGerman ?  
         var targetPage = getCurrentLanguage() === 'de' ?  
             '/wiki/Transformal_GmbH:Analyseeinstellungen' :  
             '/wiki/Transformal_GmbH:Analyseeinstellungen' :  
             '/wiki/Transformal_GmbH:Analyses_preferences';
             '/wiki/Transformal_GmbH:Analyses_preferences';
Zeile 67: Zeile 98:
         }
         }
          
          
         var label = $option.find('.checkbox-placeholder').attr('data-label') || 'Enabled';
         var label = $option.find('.checkbox-placeholder').attr('data-label') || getString('checkboxLabel');
         var $label = $('<label>', {
         var $label = $('<label>', {
           'for': consentId,
           'for': consentId,
Zeile 118: Zeile 149:
      
      
     var message = '';
     var message = '';
    // For English version:
    // if (feature === 'matomo-consent') {
    //    message = enabled ? 'Journaling enabled' : 'Journaling disabled';
    // } else if (feature === 'altcha-consent') {
    //    message = enabled ? 'Proof-of-work enabled' : 'Proof-of-work disabled';
    // }
    // For German version, change the messages to:
     if (feature === 'matomo-consent') {
     if (feature === 'matomo-consent') {
         message = enabled ? 'Aufzeichnungen zugelassen' : 'Aufzeichnungen nicht zugelassen';
         message = enabled ? getString('journalingEnabled') : getString('journalingDisabled');
     } else if (feature === 'altcha-consent') {
     } else if (feature === 'altcha-consent') {
         message = enabled ? 'Proof-of-work zugelassen' : 'Proof-of-work nicht zugelassen';
         message = enabled ? getString('proofOfWorkEnabled') : getString('proofOfWorkDisabled');
     }
     }
      
      
     if (message) {
     if (message) {
         // feedbackDiv.innerHTML = message + ' &ndash; Your preferences are being saved';
         feedbackDiv.innerHTML = message + ' &ndash; ' + getString('preferencesSaved');
        feedbackDiv.innerHTML = message + ' &ndash; Ihre Einstellungen werden gespeichert';
         feedbackDiv.style.display = 'block';
         feedbackDiv.style.display = 'block';
          
          

Version vom 22. August 2025, 09:35 Uhr

/* Unified Consent System JavaScript v250822r2 
 * Single file for both EN and DE versions
 * Automatically detects language based on domain
 */

// Language detection helper
function getCurrentLanguage() {
    var hostname = window.location.hostname;
    return (hostname === 'de.transformal.com' || 
            hostname === 'de.olaflangmack.info' ||
            hostname === 'de.mediawiki.transformal.com') ? 'de' : 'en';
}

// Localized strings
var strings = {
    en: {
        journalingEnabled: 'Journaling enabled',
        journalingDisabled: 'Journaling disabled',
        proofOfWorkEnabled: 'Proof-of-work enabled',
        proofOfWorkDisabled: 'Proof-of-work disabled',
        preferencesSaved: 'Your preferences are being saved',
        checkboxLabel: 'Enabled'
    },
    de: {
        journalingEnabled: 'Aufzeichnungen zugelassen',
        journalingDisabled: 'Aufzeichnungen nicht zugelassen',
        proofOfWorkEnabled: 'Proof-of-work zugelassen',
        proofOfWorkDisabled: 'Proof-of-work nicht zugelassen',
        preferencesSaved: 'Ihre Einstellungen werden gespeichert',
        checkboxLabel: 'Erlaubt'
    }
};

// Get string in current language
function getString(key) {
    var lang = getCurrentLanguage();
    return strings[lang][key] || strings.en[key];
}

// Handle consent acquisition box
$(document).ready(function() {
    var consentBox = document.getElementById('consent-acquisition-box');
    if (!consentBox) return;
    
    // Check if already dismissed in this session
    var dismissed = sessionStorage.getItem('consent-acquisition-dismissed');
    
    if (dismissed === 'true') {
        consentBox.style.display = 'none';
    } else {
        // SHOW the box if not dismissed
        consentBox.style.display = 'block';
        consentBox.classList.add('show');
    }
    
    // Add click handler to consent box
    consentBox.addEventListener('click', function() {
        // Set session storage
        sessionStorage.setItem('consent-acquisition-dismissed', 'true');
        
        // Navigate to correct language version
        var targetPage = getCurrentLanguage() === 'de' ? 
            '/wiki/Transformal_GmbH:Analyseeinstellungen' : 
            '/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') || getString('checkboxLabel');
        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
function showConsentFeedback(feature, enabled) {
    var feedbackDiv = document.getElementById('consent-feedback');
    if (!feedbackDiv) return;
    
    var message = '';
    if (feature === 'matomo-consent') {
        message = enabled ? getString('journalingEnabled') : getString('journalingDisabled');
    } else if (feature === 'altcha-consent') {
        message = enabled ? getString('proofOfWorkEnabled') : getString('proofOfWorkDisabled');
    }
    
    if (message) {
        feedbackDiv.innerHTML = message + ' &ndash; ' + getString('preferencesSaved');
        feedbackDiv.style.display = 'block';
        
        // Hide after 3 seconds
        setTimeout(function() {
            feedbackDiv.style.display = 'none';
        }, 3000);
    }
}