From 4b6e3e970228189d3c37c6ec172eba14abb8c000 Mon Sep 17 00:00:00 2001 From: Lukas Winkler Date: Sun, 12 May 2024 23:34:08 +0200 Subject: [PATCH] fix accept-all --- src/accept-all/README.md | 2 ++ src/accept-all/accept-all.css | 3 +++ src/accept-all/accept-all.ts | 19 +++++++++++++------ src/toggle.ts | 10 +++++----- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/accept-all/README.md b/src/accept-all/README.md index 2acfe84..3422686 100644 --- a/src/accept-all/README.md +++ b/src/accept-all/README.md @@ -6,4 +6,6 @@ But I didn't like the thought of linking an external script and wanted to slight So I took the [banner-2024.js](https://github.com/accept-all/cdn/blob/8a09bf0d978ef6feb443a28c173bbbd86230f0fd/banner-2024.js) and manually reversed the minified code, slightly tweaked the code and adapted it to TypeScript. +And just as I was finished, I realized that the [wf-onclick-banner.js](https://github.com/accept-all/cdn/blob/8a09bf0d978ef6feb443a28c173bbbd86230f0fd/wf-onclick-banner.js) contains the unminified source code... + All credit for the creation of this module goes to [kraftwerk Agentur für neue Kommunikation](https://www.kraftwerk.co.at/) and I hope they are fine with me using a variant of their code here. diff --git a/src/accept-all/accept-all.css b/src/accept-all/accept-all.css index bfd1d81..053abce 100644 --- a/src/accept-all/accept-all.css +++ b/src/accept-all/accept-all.css @@ -1,3 +1,6 @@ +/*! +Please check https://github.com/Findus23/RainbowRoad/tree/main/src/accept-all for information about the Accept All modal by https://www.kraftwerk.co.at/ + */ :root { --paddingBorderFrom: 14px; --paddingBorderTo: 10px; diff --git a/src/accept-all/accept-all.ts b/src/accept-all/accept-all.ts index f067db7..e902b38 100644 --- a/src/accept-all/accept-all.ts +++ b/src/accept-all/accept-all.ts @@ -1,5 +1,5 @@ /*! - +Please check https://github.com/Findus23/RainbowRoad/tree/main/src/accept-all for information about the Accept All modal by https://www.kraftwerk.co.at/ */ import "./accept-all.css" import MicroModal, {MicroModalConfig} from "micromodal"; @@ -13,7 +13,7 @@ interface Translation { text: string } -const colors = ["#ec1d23", "#f59121", "#fddb0f", "#029246", "#242262", "#804194", "#60cdf5", "#fff", "#f7a9b8", "#000", "#785121"] +const columnColors = ["#ec1d23", "#f59121", "#fddb0f", "#029246", "#242262", "#804194", "#60cdf5", "#fff", "#f7a9b8", "#000", "#785121"] const translations: Translation[] = [{ language: "de", buttonText: "Alle Akzeptieren", @@ -273,7 +273,7 @@ export class AcceptAll { this.cookieBackground.id = "kwAcceptAllcookieBackground"; const bgImageDiv = document.createElement("div"); bgImageDiv.id = "kwAcceptAllbgImage" - colors.forEach((color, index) => { + columnColors.forEach((color, index) => { const bgImageBar = createBgImageBar(color, index); bgImageDiv.appendChild(bgImageBar) }) @@ -376,9 +376,9 @@ export class AcceptAll { return } - const o = this.showOnlyOnce ? 24 * 60 * 60 * 1000 : 1 - const t = Date.now(); - localStorage.setItem("kwAcceptAll_popup", `${t + o}`) + const maxAge = this.showOnlyOnce ? 24 * 60 * 60 * 1000 : 1 + const now = Date.now(); + localStorage.setItem("kwAcceptAll_popup", `${now + maxAge}`) this.cookieBackground.classList.remove("kwAcceptAllTranslateIn") this.cookieBackground.classList.add("kwAcceptAllTranslateOut"); @@ -408,6 +408,13 @@ export class AcceptAll { close() { MicroModal.close(this.cookiePopupId) } + + dispose() { + if (this.cookiePopup) { + this.cookiePopup.remove(); + this.cookiePopup = undefined; + } + } } export function immediateInit() { diff --git a/src/toggle.ts b/src/toggle.ts index 33a02e9..0779731 100644 --- a/src/toggle.ts +++ b/src/toggle.ts @@ -2,7 +2,7 @@ import {Control} from "ol/control"; import {Options} from "ol/control/Control"; import {createElement} from "./domutils"; import {router} from "./router"; -import {AcceptAll} from "./accept-all/accept-all"; +import type {AcceptAll} from "./accept-all/accept-all"; interface CustomOptions extends Options { buttonLetter: string @@ -86,7 +86,7 @@ export class BasemapControl extends MapButton { } export class AcceptAllControl extends MapButton { - private acceptall: any; + private acceptall: AcceptAll | undefined; constructor() { super({ @@ -97,10 +97,10 @@ export class AcceptAllControl extends MapButton { handleToggle() { import("./accept-all/accept-all").then(module => { - if (typeof this.acceptall === "undefined") { - console.log("sfdds") - this.acceptall = new module.AcceptAll() + if (typeof this.acceptall !== "undefined") { + this.acceptall.dispose() } + this.acceptall = new module.AcceptAll() this.acceptall.show(); }) }