-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
@todo * add translations * handle focus with care
- Loading branch information
1 parent
4802c9a
commit 918915e
Showing
21 changed files
with
389 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<!DOCTYPE html> | ||
|
||
<html class="ExamplePage" lang="en"> | ||
<head> | ||
<title>Orejime</title> | ||
|
||
<link | ||
rel="stylesheet" | ||
href="https://boscop.fr/wp-content/themes/boscop/dist/app.css" | ||
/> | ||
|
||
<link rel="stylesheet" href="../assets/style.css" /> | ||
<link rel="stylesheet" href="../orejime-standard.css" /> | ||
</head> | ||
|
||
<body> | ||
<main class="ExampleMain" role="main"> | ||
<template data-purpose="youtube" data-contextual> | ||
<figure role="group"> | ||
<iframe | ||
title="YouTube video player" | ||
src="https://www.youtube-nocookie.com/embed/pghz5vpi5q4?si=npJInLIEM7XiD0MB" | ||
allowfullscreen | ||
></iframe> | ||
|
||
<figcaption class="fr-content-media__caption"> | ||
Cooking cookies with Philippe Etchebest | ||
</figcaption> | ||
</figure> | ||
</template> | ||
|
||
<button class="ExampleReset Button"> | ||
Reset consent | ||
</button> | ||
</main> | ||
|
||
<script> | ||
window.orejimeConfig = { | ||
purposes: [ | ||
{ | ||
id: 'youtube', | ||
title: 'YouTube' | ||
} | ||
], | ||
privacyPolicyUrl: '#' | ||
}; | ||
</script> | ||
|
||
<script src="../orejime-standard-en.js"></script> | ||
|
||
<script> | ||
document | ||
.querySelector('.ExampleReset') | ||
.addEventListener('click', function () { | ||
window.orejime.manager.clearConsents(); | ||
}); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import {purposesOnly} from '../utils/config'; | ||
import {useConfig, useManager, useTheme} from '../utils/hooks'; | ||
|
||
interface ContextualNoticeContainerProps { | ||
data: Record<string, string>; | ||
} | ||
|
||
const ContextualNoticeContainer = ({data}: ContextualNoticeContainerProps) => { | ||
const config = useConfig(); | ||
const manager = useManager(); | ||
const {ContextualNotice} = useTheme(); | ||
|
||
if (!data?.purpose) { | ||
return null; | ||
} | ||
|
||
const purpose = purposesOnly(config.purposes).find( | ||
({id}) => id === data.purpose | ||
); | ||
|
||
if (!purpose) { | ||
return null; | ||
} | ||
|
||
const handleAccept = () => { | ||
manager.setConsent(purpose.id, true); | ||
}; | ||
|
||
return ( | ||
<div className="orejime-Env"> | ||
<ContextualNotice | ||
purpose={purpose} | ||
data={data} | ||
onAccept={handleAccept} | ||
></ContextualNotice> | ||
</div> | ||
); | ||
}; | ||
|
||
export default ContextualNoticeContainer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import {FunctionComponent} from 'preact'; | ||
import {Purpose} from '../../types'; | ||
|
||
export type ContextualNoticeOptions = Record<string, string>; | ||
|
||
export interface ContextualNoticeProps<Data extends ContextualNoticeOptions> { | ||
purpose: Purpose; | ||
data: Data; | ||
onAccept: () => void; | ||
} | ||
|
||
export type ContextualNoticeComponent< | ||
Data extends ContextualNoticeOptions | ||
> = FunctionComponent<ContextualNoticeProps<Data>>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import {render} from 'preact'; | ||
import {ConsentsMap, Manager} from '../core'; | ||
import {Config} from './types'; | ||
import Context from './components/Context'; | ||
import ContextualNoticeContainer from './components/ContextualNoticeContainer'; | ||
|
||
export const contextualConsentsEffect = (config: Config, manager: Manager) => { | ||
const templates = new WeakMap(); | ||
|
||
return (consents: ConsentsMap) => { | ||
Object.entries(consents).forEach(([id, state]) => { | ||
document | ||
.querySelectorAll(`template[data-contextual][data-purpose="${id}"]`) | ||
.forEach((template: HTMLTemplateElement) => { | ||
if (!templates.has(template)) { | ||
const container = document.createElement('div'); | ||
container.style.display = 'contents'; | ||
template.insertAdjacentElement('afterend', container); | ||
templates.set(template, container); | ||
} | ||
|
||
render( | ||
state ? null : ( | ||
<Context.Provider | ||
value={{ | ||
config, | ||
manager | ||
}} | ||
> | ||
<ContextualNoticeContainer data={{...template.dataset}} /> | ||
</Context.Provider> | ||
), | ||
templates.get(template) | ||
); | ||
}); | ||
}); | ||
}; | ||
}; |
Oops, something went wrong.