Skip to content

Commit

Permalink
Merge branch 'release/1.0.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
michnhokn committed Sep 16, 2020
2 parents 638e93f + 20b7119 commit 3b5f3ce
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 40 deletions.
68 changes: 32 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,48 +15,44 @@ This plugin is free but if you use it in a commercial project please consider to
- `composer require michnhokn/kirby3-cookie-banner`

## Features
- Add custom features to cookie modal
- You can fully translate the cookie banner ([Custom language variables](https://getkirby.com/docs/guide/languages/custom-language-variables))
- Intercept cookie status via JavaScript event
- PHP functions to check for allowed features
- Trigger JavaScript event to update Cookie Modal
- Add a custom cookie consent modal
- Fully [translatable](https://github.com/michnhokn/kirby3-cookie-banner/wiki/02-Translate-the-modal).
- [Intercept](https://github.com/michnhokn/kirby3-cookie-banner/wiki/01-How-to-set-it-up#-intercept-changes-to-the-cookie-settings) cookie status
- [PHP functions](https://github.com/michnhokn/kirby3-cookie-banner/wiki/03-PHP-functions) to check for allowed features

For more features check out the [wiki](https://github.com/michnhokn/kirby3-cookie-banner/wiki).

## Setup
To setup the cookie banner just put the `cookie-modal` snippet right befor your closing body tag. Thats it. 🎉
``` php
<?php snippet('cookie-modal') ?>
```
If a selection is made an event called `cookies:saved` is triggerd on `<body>`. The included data contains an array of allowed features.
You can set these up in your `config.php` file under `site/config/`.
````php
return [
'michnhokn.cookie-banner' => [
'features' => [
'analytics' => 'Analytics',
'mapbox' => 'Mapbox'
1. Put the `cookie-modal` snippet right before the closing body tag.
``` php
<?php snippet('cookie-modal', ['assets' => true]) ?>
```
2. Set up your features for the cookie modal.
````php
return [
'michnhokn.cookie-banner' => [
'features' => [
'analytics' => 'Analytics',
'mapbox' => 'Mapbox'
]
]
]
];
````
];
````
3. Listen for the `cookied:saved` event and receive an `array` of allowed features.
````javascript
u('body').on('cookies:saved', event => {
console.log('Saved cookie features:', event.detail);
})
````

The modal can be recalled and edited by triggering the event `cookies:update` on the `<bod>` tag.
Learn more in the [wiki](https://github.com/michnhokn/kirby3-cookie-banner/wiki/01-How-to-set-it-up).

## Methods
- `isFeatureAllowed(string $featureName)` Checks if a user allowed given feature
```php
<?php if (isFeatureAllowed('analytics')): ?>
<h1>Analytics allowed</h1>
<?php endif; ?>
```
- `getAllowedFeatures()` Get all allowed features or false if nothing is selected
- `clearAllowedFeatures()` Clear all allowed features

## Roadmap
- Add wiki
- Refactor code + add comments
See all available functions in the [wiki](https://github.com/michnhokn/kirby3-cookie-banner/wiki/03-PHP-functions).

---
## Misc
**Roadmap**: Have a look at this [project](https://github.com/michnhokn/kirby3-cookie-banner/projects/1).

License: `MIT`
**License**: `MIT`

Credits: [MichnHokn](https://github.com/michnhokn)
**Credits**: [MichnHokn](https://github.com/michnhokn)
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "michnhokn/kirby3-cookie-banner",
"description": "Add a cookie modal to your Kirby3 website",
"type": "kirby-plugin",
"version": "1.0.3",
"version": "1.0.4",
"license": "MIT",
"authors": [
{
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kirby3-cookie-banner",
"version": "1.0.3",
"version": "1.0.4",
"description": "",
"author": "Michael Scheurich <[email protected]>",
"scripts": {
Expand Down
10 changes: 8 additions & 2 deletions snippets/cookie-modal.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?= css('media/plugins/michnhokn/cookie-banner/cookie-modal.css') ?>
<?php $assets = isset($assets) ? $assets : false; ?>
<?php if ($assets): ?>
<?= css('media/plugins/michnhokn/cookie-banner/cookie-modal.css') ?>
<?php endif; ?>
<div class="cookie-modal cookie-modal--hidden" id="cookie-modal">
<div class="cookie-modal__content">
<p class="cookie-modal__title"><?= t('michnhokn.cookie-banner.title') ?></p>
Expand Down Expand Up @@ -34,4 +37,7 @@
</div>
</div>
</div>
<?= js('media/plugins/michnhokn/cookie-banner/cookie-modal.js') ?>
<?php if ($assets): ?>
<?= js('media/plugins/michnhokn/cookie-banner/cookie-modal.js') ?>
<?php endif; ?>

0 comments on commit 3b5f3ce

Please sign in to comment.