A jquery plugin that shows a GDPR compliant cookie warning according to the language set on the users device.
- Import the jQuery library
- Load the cookie-z script in your HTML after the body
<script type="text/javascript" src="jquery.cookie-z.min.js"></script>
- Create the template for the cookie warning on your page. Example:
<div class="cookie-warning">
<div class="cookie-warning-inner">
<p class="cookie-warning-text"></p>
<button class="cookie-warning-close"></button>
</div>
</div>
- Call the cookie-z plugin on the wrapper of your cookie warning
$('.cookie-warning').cookiez();
- Use JSON to change the options
- Example of disabling automated language detection, setting the default language and changing the animation to fade:
$('.cookie-warning').cookiez({ autoLang: false, defaultLang: 'en', animation: 'fade', });
- Example of disabling automated language detection, setting the default language and changing the animation to fade:
NOTE: if you set
autoLang
to false it will use the default language's text
NOTE: if you want to overwrite a language use the
customLanguages
JSON Array
Option | Description | Default value | Var type |
---|---|---|---|
autoLang |
Turning automated language detection on or off. | true |
boolean |
defaultLang |
Locale of the language to use if the detected language is not found | en |
string |
animation |
Change the animation of toggling the cookie warning (slide or fade ) |
slide |
string |
fadeTime |
Speed of the fade animation (in miliseconds) | 350 |
integer |
cookieConfName |
Name of the cookie to set when the user has confirmed | cookie-warning-confirmed |
string |
customLanguages.[locale].cookieWarning |
Cookie warning text for a custom language (v1.1.0 supports HTML) | null |
string |
customLanguages.[locale].btnClose |
Confirm button Text for a custom language (v1.1.0 supports HTML) | null |
string |
elements.selectors.wrapper |
Selector for the cookie warning wrapper | .cookie-warning |
string |
elements.selectors.text |
Selector for the element to place the warning into | .cookie-warning-text |
string |
elements.selectors.btnClose |
Selector for the element the user clicks on to confirm | .cookie-warning-close |
string |
- English
- German
- When calling the cookie-z plugin add the
customLanguages
JSON Array to the parameters as follows:
$('.cookie-warning').cookiez({
customLanguages: {
fb: {
cookieWarning: "foo",
btnClose: "bar"
}
}
});
NOTE: the locale of the language in this example is
fb
. After defining the custom language, you can use it as a default language with thedefaultLang
option.