Skip to content

Commit

Permalink
Merge pull request #27 from sandstorm/task/callback-methods
Browse files Browse the repository at this point in the history
[TASK] Allow configuration of callback methods for onInit, onAccept a…
  • Loading branch information
mberhorst authored Dec 11, 2024
2 parents 01268ab + e6e254d commit f3ba00b
Show file tree
Hide file tree
Showing 23 changed files with 4,411 additions and 2,304 deletions.
3 changes: 3 additions & 0 deletions Configuration/Settings.Translations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ Sandstorm:
title: Sandstorm.CookiePunch:Klaro:consentModal.title
consentNotice:
changeDescription: Sandstorm.CookiePunch:Klaro:consentNotice.changeDescription
title: Sandstorm.CookiePunch:Klaro:consentNotice.title
description: Sandstorm.CookiePunch:Klaro:consentNotice.description
learnMore: Sandstorm.CookiePunch:Klaro:consentNotice.learnMore
testing: Sandstorm.CookiePunch:Klaro:consentNotice.testing
contextualConsent:
acceptAlways: Sandstorm.CookiePunch:Klaro:contextualConsent.acceptAlways
acceptOnce: Sandstorm.CookiePunch:Klaro:contextualConsent.acceptOnce
description: Sandstorm.CookiePunch:Klaro:contextualConsent.description
descriptionEmptyStore: Sandstorm.CookiePunch:Klaro:contextualConsent.descriptionEmptyStore
modalLinkText: Sandstorm.CookiePunch:Klaro:contextualConsent.modalLinkText
decline: Sandstorm.CookiePunch:Klaro:decline
ok: Sandstorm.CookiePunch:Klaro:ok
poweredBy: Sandstorm.CookiePunch:Klaro:poweredBy
Expand Down
6 changes: 6 additions & 0 deletions Examples/Settings.CookiePunch.FullServiceConfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,9 @@ Sandstorm:
# If "onlyOnce" is set to true, the service will only be executed
# once regardless how often the user toggles it on and off.
onlyOnce: true
# JavaScript code to execute when the service is initialized.
onInit: "console.log('init');"
# JavaScript code to execute when the user gives consent.
onAccept: "console.log('accept');"
# JavaScript code to execute when the user declines consent.
onDecline: "console.log('decline');"
3 changes: 3 additions & 0 deletions Resources/Private/Fusion/Config.Translations.fusion
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ prototype(Sandstorm.CookiePunch:Config.Translations) < prototype(Neos.Fusion:Dat
consentModal.description = ${CookiePunchConfig.translate("Sandstorm.CookiePunch.translations.consentModal.description")}
consentModal.title = ${CookiePunchConfig.translate("Sandstorm.CookiePunch.translations.consentModal.title")}
consentNotice.changeDescription = ${CookiePunchConfig.translate("Sandstorm.CookiePunch.translations.consentNotice.changeDescription")}
consentNotice.title = ${CookiePunchConfig.translate("Sandstorm.CookiePunch.translations.consentNotice.title")}
consentNotice.description = ${CookiePunchConfig.translate("Sandstorm.CookiePunch.translations.consentNotice.description")}
consentNotice.learnMore = ${CookiePunchConfig.translate("Sandstorm.CookiePunch.translations.consentNotice.learnMore")}
consentNotice.testing = ${CookiePunchConfig.translate("Sandstorm.CookiePunch.translations.consentNotice.testing")}
contextualConsent.acceptAlways = ${CookiePunchConfig.translate("Sandstorm.CookiePunch.translations.contextualConsent.acceptAlways")}
contextualConsent.acceptOnce = ${CookiePunchConfig.translate("Sandstorm.CookiePunch.translations.contextualConsent.acceptOnce")}
contextualConsent.description = ${CookiePunchConfig.translate("Sandstorm.CookiePunch.translations.contextualConsent.description")}
contextualConsent.descriptionEmptyStore = ${CookiePunchConfig.translate("Sandstorm.CookiePunch.translations.contextualConsent.descriptionEmptyStore")}
contextualConsent.modalLinkText = ${CookiePunchConfig.translate("Sandstorm.CookiePunch.translations.contextualConsent.modalLinkText")}
decline = ${CookiePunchConfig.translate("Sandstorm.CookiePunch.translations.decline")}
ok = ${CookiePunchConfig.translate("Sandstorm.CookiePunch.translations.ok")}
poweredBy = ${CookiePunchConfig.translate("Sandstorm.CookiePunch.translations.poweredBy")}
Expand Down
3 changes: 3 additions & 0 deletions Resources/Private/Fusion/Config.fusion
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ prototype(Sandstorm.CookiePunch:Config) < prototype(Neos.Fusion:DataStructure) {
required = ${item.required}
optOut = ${item.optOut}
onlyOnce = ${item.onlyOnce}
onInit = ${item.onInit}
onAccept = ${item.onAccept}
onDecline = ${item.onDecline}
}
}

Expand Down
12 changes: 12 additions & 0 deletions Resources/Private/JavaScript/Helper/buildKlaroConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,18 @@ function buildKlaroServicesConfig(
if (typeof cookiePunchService.onlyOnce === "boolean")
klaroService.onlyOnce = cookiePunchService.onlyOnce;

if (cookiePunchService.onInit) {
klaroService.onInit = eval("(function() { " + cookiePunchService.onInit + " })");
}

if (cookiePunchService.onAccept) {
klaroService.onAccept = eval("(function() { " + cookiePunchService.onAccept + " })");
}

if (cookiePunchService.onDecline) {
klaroService.onDecline = eval("(function() { " + cookiePunchService.onDecline + " })");
}

result.push(klaroService);
});

Expand Down
14 changes: 10 additions & 4 deletions Resources/Private/JavaScript/Types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ export type CookiePunchService = {
optOut?: boolean;
cookies?: CookiePunchServiceCookies;
onlyOnce?: boolean;
onInit?: string;
onAccept?: string;
onDecline?: string;
};

export type CookiePunchPurpose = {
title?: string;
description?: string;
}
};

export type CookiePunchServiceCookies = {
pattern: string;
Expand All @@ -44,7 +47,7 @@ export type CookiePunchConfig = {
htmlTexts: boolean;
embedded: false;
groupByPurpose: boolean;
storageMethod: 'cookie' | 'localStorage';
storageMethod: "cookie" | "localStorage";
cookieName: string;
cookieExpiresAfterDays: number;
default: boolean;
Expand All @@ -58,7 +61,7 @@ export type CookiePunchConfig = {
cookiePath?: string;
cookieDomain?: string;

purposes: CookiePunchPurposes
purposes: CookiePunchPurposes;
services: CookiePunchServices;
translations: {
[key: string]: any;
Expand Down Expand Up @@ -99,6 +102,9 @@ export type KlaroService = {
required?: boolean;
optOut?: boolean;
onlyOnce?: boolean;
onInit?: () => void;
onAccept?: () => void;
onDecline?: () => void;
};

export type KlaroServiceCookies = ((RegExp | string)[] | string | RegExp)[];
Expand All @@ -114,7 +120,7 @@ export type KlaroConfig = {
htmlTexts: boolean;
embedded: false;
groupByPurpose: boolean;
storageMethod: 'cookie' | 'localStorage';
storageMethod: "cookie" | "localStorage";
cookieName: string;
cookieExpiresAfterDays: number;
default: boolean;
Expand Down
Loading

0 comments on commit f3ba00b

Please sign in to comment.