mirror of
https://codeberg.org/kirche-im-netz/Startodon-Hub.git
synced 2025-08-28 05:53:55 +02:00
Datenschutzeinstellungen-Hinweis neu erstellt (noch funktionslos)
This commit is contained in:
parent
e85e4d9742
commit
5a76a237bf
3 changed files with 65 additions and 48 deletions
|
@ -1,4 +1,4 @@
|
||||||
export function createPopup({ title, body, footer = '', closeCallback = null, customClass = '' }) {
|
export function createPopup({ title, body, footer = '', customClass = '' }) {
|
||||||
// Popup-Container erstellen
|
// Popup-Container erstellen
|
||||||
const popup = document.createElement('div');
|
const popup = document.createElement('div');
|
||||||
popup.classList.add('popup');
|
popup.classList.add('popup');
|
||||||
|
@ -17,32 +17,41 @@ export function createPopup({ title, body, footer = '', closeCallback = null, cu
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
// Popup dem Body hinzufügen
|
||||||
document.body.appendChild(popup);
|
document.body.appendChild(popup);
|
||||||
|
|
||||||
|
// Scrollen deaktivieren
|
||||||
|
document.body.classList.add('body-no-scroll');
|
||||||
|
|
||||||
// Event-Listener für Schließen-Button
|
// Event-Listener für Schließen-Button
|
||||||
const closeButton = popup.querySelector('.close-popup');
|
const closeButton = popup.querySelector('.close-popup');
|
||||||
closeButton.addEventListener('click', () => closePopup(popup, closeCallback));
|
closeButton.addEventListener('click', () => closePopup(popup));
|
||||||
|
|
||||||
// Event-Listener für ESC-Taste
|
// Event-Listener für ESC-Taste
|
||||||
document.addEventListener('keydown', (event) => {
|
document.addEventListener('keydown', (event) => {
|
||||||
if (event.key === 'Escape') closePopup(popup, closeCallback);
|
if (event.key === 'Escape') closePopup(popup);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Event-Listener für Klick außerhalb des Popups
|
// Event-Listener für Klick außerhalb des Popups
|
||||||
popup.addEventListener('click', (event) => {
|
popup.addEventListener('click', (event) => {
|
||||||
if (event.target === popup) closePopup(popup, closeCallback);
|
if (event.target === popup) closePopup(popup);
|
||||||
});
|
});
|
||||||
|
|
||||||
return popup;
|
return popup;
|
||||||
}
|
}
|
||||||
|
|
||||||
function closePopup(popup, closeCallback) {
|
export function closePopup(popup) {
|
||||||
|
// Popup entfernen
|
||||||
popup.remove();
|
popup.remove();
|
||||||
if (typeof closeCallback === 'function') {
|
|
||||||
closeCallback();
|
// Scrollen wieder aktivieren
|
||||||
}
|
document.body.classList.remove('body-no-scroll');
|
||||||
}
|
}
|
||||||
|
|
||||||
export function destroyAllPopups() {
|
export function destroyAllPopups() {
|
||||||
|
// Alle Popups entfernen
|
||||||
document.querySelectorAll('.popup').forEach(popup => popup.remove());
|
document.querySelectorAll('.popup').forEach(popup => popup.remove());
|
||||||
|
|
||||||
|
// Scrollen wieder aktivieren
|
||||||
|
document.body.classList.remove('body-no-scroll');
|
||||||
}
|
}
|
||||||
|
|
44
src/main.js
44
src/main.js
|
@ -2,21 +2,28 @@ import { createStarterKitElement, enhanceStarterKits } from './utils/starterkit-
|
||||||
import { seededShuffleChildren } from './utils/shuffle-utils.js';
|
import { seededShuffleChildren } from './utils/shuffle-utils.js';
|
||||||
import { initializeCreateStarterKitPopup } from './utils/create-starterkit.js';
|
import { initializeCreateStarterKitPopup } from './utils/create-starterkit.js';
|
||||||
import { loadPostwall } from './components/postwall.js';
|
import { loadPostwall } from './components/postwall.js';
|
||||||
|
import { checkConsent, setUserConsent, showConsentPopup } from './utils/consent-utils.js';
|
||||||
|
|
||||||
let userConsent = null;
|
|
||||||
export { userConsent };
|
|
||||||
|
|
||||||
async function loadTemplates() {
|
|
||||||
const response = await fetch('src/template/template.html');
|
|
||||||
const templateHTML = await response.text();
|
|
||||||
|
|
||||||
const templateContainer = document.createElement('div');
|
|
||||||
templateContainer.innerHTML = templateHTML;
|
|
||||||
document.body.appendChild(templateContainer);
|
|
||||||
}
|
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', async function () {
|
document.addEventListener('DOMContentLoaded', async function () {
|
||||||
|
// Überprüfe Consent, bevor Inhalte geladen werden
|
||||||
|
const consent = checkConsent();
|
||||||
|
if (!consent) {
|
||||||
|
showConsentPopup(
|
||||||
|
() => {
|
||||||
|
setUserConsent(true);
|
||||||
|
initializeApp();
|
||||||
|
},
|
||||||
|
() => {
|
||||||
|
setUserConsent(false);
|
||||||
|
initializeApp();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
initializeApp();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
async function initializeApp() {
|
||||||
await loadTemplates();
|
await loadTemplates();
|
||||||
|
|
||||||
initializeCreateStarterKitPopup();
|
initializeCreateStarterKitPopup();
|
||||||
|
@ -50,4 +57,13 @@ document.addEventListener('DOMContentLoaded', async function () {
|
||||||
enhanceStarterKits();
|
enhanceStarterKits();
|
||||||
})
|
})
|
||||||
.catch(error => console.error('Fehler beim Laden der StarterKits:', error));
|
.catch(error => console.error('Fehler beim Laden der StarterKits:', error));
|
||||||
});
|
}
|
||||||
|
|
||||||
|
async function loadTemplates() {
|
||||||
|
const response = await fetch('src/template/template.html');
|
||||||
|
const templateHTML = await response.text();
|
||||||
|
|
||||||
|
const templateContainer = document.createElement('div');
|
||||||
|
templateContainer.innerHTML = templateHTML;
|
||||||
|
document.body.appendChild(templateContainer);
|
||||||
|
}
|
||||||
|
|
|
@ -1,16 +1,24 @@
|
||||||
import { createPopup } from '../components/popupManager.js';
|
import { createPopup, closePopup } from '../components/popupManager.js';
|
||||||
|
|
||||||
|
// Speichert die Benutzerzustimmung
|
||||||
export function setUserConsent(consent) {
|
export function setUserConsent(consent) {
|
||||||
localStorage.setItem('userConsent', JSON.stringify(consent));
|
localStorage.setItem('userConsent', JSON.stringify(consent));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ruft die Benutzerzustimmung ab
|
||||||
export function getUserConsent() {
|
export function getUserConsent() {
|
||||||
const consent = localStorage.getItem('userConsent');
|
const consent = localStorage.getItem('userConsent');
|
||||||
return consent !== null ? JSON.parse(consent) : null;
|
return consent !== null ? JSON.parse(consent) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Überprüft, ob bereits eine Zustimmung vorliegt
|
||||||
|
export function checkConsent() {
|
||||||
|
return getUserConsent() !== null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Zeigt das Consent-Banner an
|
||||||
export function showConsentPopup(onAccept, onDecline) {
|
export function showConsentPopup(onAccept, onDecline) {
|
||||||
const title = 'Zustimmung zur Datenabfrage';
|
const title = 'Datenschutzeinstellungen';
|
||||||
const body = `
|
const body = `
|
||||||
<p>
|
<p>
|
||||||
Mit dem Klicken auf "Bestätigen" erlaubst du, dass Profilinformationen von unterschiedlichen Mastodon-Instanzen
|
Mit dem Klicken auf "Bestätigen" erlaubst du, dass Profilinformationen von unterschiedlichen Mastodon-Instanzen
|
||||||
|
@ -26,38 +34,22 @@ export function showConsentPopup(onAccept, onDecline) {
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
// Erstelle das Popup
|
||||||
const popup = createPopup({
|
const popup = createPopup({
|
||||||
title,
|
title,
|
||||||
body,
|
body,
|
||||||
customClass: 'consent-popup',
|
customClass: 'consent-popup'
|
||||||
closeCallback: () => {
|
|
||||||
document.body.classList.remove('body-no-scroll');
|
|
||||||
window.removeEventListener('popstate', onPopState);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Klasse hinzufügen, um das Scrollen des Hintergrunds zu verhindern
|
|
||||||
document.body.classList.add('body-no-scroll');
|
|
||||||
|
|
||||||
// Füge einen neuen Eintrag zur Browser-Historie hinzu
|
|
||||||
history.pushState({ popupOpen: true }, null, '');
|
|
||||||
|
|
||||||
const onPopState = () => {
|
|
||||||
popup.remove();
|
|
||||||
document.body.classList.remove('body-no-scroll');
|
|
||||||
window.removeEventListener('popstate', onPopState);
|
|
||||||
history.back();
|
|
||||||
};
|
|
||||||
window.addEventListener('popstate', onPopState);
|
|
||||||
|
|
||||||
// Event-Listener für die Buttons
|
// Event-Listener für die Buttons
|
||||||
popup.querySelector('#consent-accept').addEventListener('click', () => {
|
popup.querySelector('#consent-accept').addEventListener('click', () => {
|
||||||
popup.remove();
|
closePopup(popup); // Popup korrekt schließen
|
||||||
onAccept(); // Zustimmung
|
onAccept(); // Zustimmung speichern
|
||||||
});
|
});
|
||||||
|
|
||||||
popup.querySelector('#consent-decline').addEventListener('click', () => {
|
popup.querySelector('#consent-decline').addEventListener('click', () => {
|
||||||
popup.remove();
|
closePopup(popup); // Popup korrekt schließen
|
||||||
onDecline(); // Ablehnung
|
onDecline(); // Ablehnung speichern
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue