@dargmuesli/nuxt-cookie-control 1.9.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +285 -0
- package/components/CookieControl.vue +182 -0
- package/components/CookieIframe.vue +32 -0
- package/lib/module.js +74 -0
- package/lib/plugin.js +206 -0
- package/lib/postinstall.js +1 -0
- package/lib/styles.scss +434 -0
- package/locale/de.js +15 -0
- package/locale/en.js +15 -0
- package/locale/es.js +15 -0
- package/locale/fr.js +15 -0
- package/locale/hr.js +15 -0
- package/locale/hu.js +15 -0
- package/locale/it.js +15 -0
- package/locale/ja.js +15 -0
- package/locale/no.js +16 -0
- package/locale/pt.js +15 -0
- package/locale/ru.js +15 -0
- package/locale/uk.js +15 -0
- package/package.json +42 -0
package/README.md
ADDED
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
# Nuxt Cookie Control
|
|
2
|
+

|
|
3
|
+
####
|
|
4
|
+
Try it out here:
|
|
5
|
+
[Nuxt.js Cookie Control](https://codesandbox.io/s/vkwqmm577)
|
|
6
|
+
|
|
7
|
+
## 🚀 Usage
|
|
8
|
+
```bash
|
|
9
|
+
npm i nuxt-cookie-control
|
|
10
|
+
```
|
|
11
|
+
[![npm version][npm-version-src]][npm-version-href]
|
|
12
|
+
[![npm downloads][npm-downloads-src]][npm-downloads-href]
|
|
13
|
+
[![npm downloads][kofi-src]][kofi-href]
|
|
14
|
+
|
|
15
|
+
```javascript
|
|
16
|
+
//nuxt.config.js
|
|
17
|
+
modules: [
|
|
18
|
+
'nuxt-cookie-control'
|
|
19
|
+
]
|
|
20
|
+
//or
|
|
21
|
+
modules: [
|
|
22
|
+
['nuxt-cookie-control', {
|
|
23
|
+
//your options
|
|
24
|
+
}]
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
//to open cookie modal anywhere:
|
|
28
|
+
$cookies.modal = true
|
|
29
|
+
//or
|
|
30
|
+
this.$cookies.modal = true
|
|
31
|
+
```
|
|
32
|
+
```html
|
|
33
|
+
<!--template-->
|
|
34
|
+
<!--
|
|
35
|
+
CookieControl component is registered globally,
|
|
36
|
+
you don't need to register it anywhere.
|
|
37
|
+
-->
|
|
38
|
+
<CookieControl/>
|
|
39
|
+
<!--or-->
|
|
40
|
+
<CookieControl></CookieControl>
|
|
41
|
+
```
|
|
42
|
+
## Slot
|
|
43
|
+
### Bar
|
|
44
|
+
```html
|
|
45
|
+
<CookieControl>
|
|
46
|
+
<template v-slot:bar>
|
|
47
|
+
<h3>Bar title</h3>
|
|
48
|
+
<p>Bar description (you can use $cookies.text.barDescription)</p>
|
|
49
|
+
<n-link>Go somewhere</n-link>
|
|
50
|
+
</template>
|
|
51
|
+
</CookieControl>
|
|
52
|
+
```
|
|
53
|
+
### Modal
|
|
54
|
+
```html
|
|
55
|
+
<template v-slot:modal>
|
|
56
|
+
<h3>Modal title</h3>
|
|
57
|
+
<p>Modal description</p>
|
|
58
|
+
</template>
|
|
59
|
+
```
|
|
60
|
+
### Cookie
|
|
61
|
+
```html
|
|
62
|
+
<template v-slot:cookie="{config}">
|
|
63
|
+
<span v-for="c in config" :key="c.id" v-text="c.cookies"/>
|
|
64
|
+
</template>
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Props
|
|
68
|
+
### Locale
|
|
69
|
+
```html
|
|
70
|
+
<CookieControl locale="de"/>
|
|
71
|
+
```
|
|
72
|
+
#### Default: en,
|
|
73
|
+
#### Currently available:
|
|
74
|
+
- en
|
|
75
|
+
- de
|
|
76
|
+
- it
|
|
77
|
+
- es
|
|
78
|
+
- fr
|
|
79
|
+
- pt
|
|
80
|
+
- hr
|
|
81
|
+
- no
|
|
82
|
+
- hu
|
|
83
|
+
- ja
|
|
84
|
+
- ru
|
|
85
|
+
- uk
|
|
86
|
+
|
|
87
|
+
## 🔧 Options
|
|
88
|
+
Options in nuxt.config.js
|
|
89
|
+
```javascript
|
|
90
|
+
modules: [
|
|
91
|
+
['nuxt-cookie-control', {
|
|
92
|
+
//default css (true)
|
|
93
|
+
//if css is set to false, you will still be able to access
|
|
94
|
+
//your color variables (example. background-color: var(--cookie-control-barBackground))
|
|
95
|
+
css: true,
|
|
96
|
+
|
|
97
|
+
//enable or disable css variables polyfill
|
|
98
|
+
cssPolyfill: true,
|
|
99
|
+
|
|
100
|
+
//in case you have subdomains (shop.yourdomain.com)
|
|
101
|
+
domain: 'yourdomain.com',
|
|
102
|
+
|
|
103
|
+
//if you want to tree-shake locales set locales you want to use
|
|
104
|
+
locales: ['en', 'de'],
|
|
105
|
+
|
|
106
|
+
//modal opener (cookie control)
|
|
107
|
+
controlButton: true,
|
|
108
|
+
|
|
109
|
+
//block iframes to prevent them from adding additional cookies
|
|
110
|
+
blockIframe: true,
|
|
111
|
+
|
|
112
|
+
//or if you want to set initialState to false (default value for initialState is true)
|
|
113
|
+
blockIframe: {
|
|
114
|
+
initialState: false
|
|
115
|
+
},
|
|
116
|
+
|
|
117
|
+
//position of cookie bar:
|
|
118
|
+
//'top-left', 'top-right', 'top-full',
|
|
119
|
+
//'bottom-left', 'bottom-right', 'bottom-full'
|
|
120
|
+
barPosition: 'bottom-full',
|
|
121
|
+
|
|
122
|
+
//default colors
|
|
123
|
+
//if you want to disable colors set colors property to false
|
|
124
|
+
colors: {
|
|
125
|
+
barTextColor: '#fff',
|
|
126
|
+
modalOverlay: '#000',
|
|
127
|
+
barBackground: '#000',
|
|
128
|
+
barButtonColor: '#000',
|
|
129
|
+
modalTextColor: '#000',
|
|
130
|
+
modalBackground: '#fff',
|
|
131
|
+
modalOverlayOpacity: 0.8,
|
|
132
|
+
modalButtonColor: '#fff',
|
|
133
|
+
modalUnsavedColor: '#fff',
|
|
134
|
+
barButtonHoverColor: '#fff',
|
|
135
|
+
barButtonBackground: '#fff',
|
|
136
|
+
modalButtonHoverColor: '#fff',
|
|
137
|
+
modalButtonBackground: '#000',
|
|
138
|
+
controlButtonIconColor: '#000',
|
|
139
|
+
controlButtonBackground: '#fff',
|
|
140
|
+
barButtonHoverBackground: '#333',
|
|
141
|
+
checkboxActiveBackground: '#000',
|
|
142
|
+
checkboxInactiveBackground: '#000',
|
|
143
|
+
modalButtonHoverBackground: '#333',
|
|
144
|
+
checkboxDisabledBackground: '#ddd',
|
|
145
|
+
controlButtonIconHoverColor: '#fff',
|
|
146
|
+
controlButtonHoverBackground: '#000',
|
|
147
|
+
checkboxActiveCircleBackground: '#fff',
|
|
148
|
+
checkboxInactiveCircleBackground: '#fff',
|
|
149
|
+
checkboxDisabledCircleBackground: '#fff',
|
|
150
|
+
},
|
|
151
|
+
|
|
152
|
+
//default texts
|
|
153
|
+
text: {
|
|
154
|
+
barTitle: 'Cookies',
|
|
155
|
+
barDescription: 'We use our own cookies and third-party cookies so that we can show you this website and better understand how you use it, with a view to improving the services we offer. If you continue browsing, we consider that you have accepted the cookies.',
|
|
156
|
+
acceptAll: 'Accept all',
|
|
157
|
+
declineAll: 'Delete all',
|
|
158
|
+
manageCookies: 'Manage cookies',
|
|
159
|
+
unsaved: 'You have unsaved settings',
|
|
160
|
+
close: 'Close',
|
|
161
|
+
save: 'Save',
|
|
162
|
+
necessary: 'Necessary cookies',
|
|
163
|
+
optional: 'Optional cookies',
|
|
164
|
+
functional: 'Functional cookies',
|
|
165
|
+
blockedIframe: 'To see this, please enable functional cookies',
|
|
166
|
+
here: 'here'
|
|
167
|
+
}
|
|
168
|
+
]
|
|
169
|
+
]
|
|
170
|
+
|
|
171
|
+
//for multilanguage see - Multilanguage
|
|
172
|
+
```
|
|
173
|
+
without options (Simple)
|
|
174
|
+
```javascript
|
|
175
|
+
modules: [
|
|
176
|
+
'nuxt-cookie-control'
|
|
177
|
+
]
|
|
178
|
+
```
|
|
179
|
+
### Cookies
|
|
180
|
+
```javascript
|
|
181
|
+
modules: [
|
|
182
|
+
'nuxt-cookie-control'
|
|
183
|
+
]
|
|
184
|
+
...
|
|
185
|
+
...
|
|
186
|
+
...
|
|
187
|
+
cookies: {
|
|
188
|
+
necessary: [
|
|
189
|
+
{
|
|
190
|
+
//if multilanguage
|
|
191
|
+
name: {
|
|
192
|
+
en: 'Default Cookies'
|
|
193
|
+
},
|
|
194
|
+
//else
|
|
195
|
+
name: 'Default Cookies',
|
|
196
|
+
//if multilanguage
|
|
197
|
+
description: {
|
|
198
|
+
en: 'Used for cookie control.'
|
|
199
|
+
},
|
|
200
|
+
//else
|
|
201
|
+
description: 'Used for cookie control.',
|
|
202
|
+
cookies: ['cookie_control_consent', 'cookie_control_enabled_cookies']
|
|
203
|
+
}
|
|
204
|
+
],
|
|
205
|
+
optional: [
|
|
206
|
+
{
|
|
207
|
+
name: 'Google Analitycs',
|
|
208
|
+
//if you don't set identifier, slugified name will be used
|
|
209
|
+
identifier: 'ga',
|
|
210
|
+
//if multilanguage
|
|
211
|
+
description: {
|
|
212
|
+
en: 'Google GTM is ...'
|
|
213
|
+
},
|
|
214
|
+
//else
|
|
215
|
+
description: 'Google GTM is...',
|
|
216
|
+
|
|
217
|
+
initialState: true,
|
|
218
|
+
src: 'https://www.googletagmanager.com/gtag/js?id=<API-KEY>',
|
|
219
|
+
async: true,
|
|
220
|
+
cookies: ['_ga', '_gat', '_gid'],
|
|
221
|
+
accepted: () =>{
|
|
222
|
+
window.dataLayer = window.dataLayer || [];
|
|
223
|
+
window.dataLayer.push({
|
|
224
|
+
'gtm.start': new Date().getTime(),
|
|
225
|
+
event: 'gtm.js'
|
|
226
|
+
});
|
|
227
|
+
},
|
|
228
|
+
declined: () =>{
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
]
|
|
232
|
+
}
|
|
233
|
+
```
|
|
234
|
+
### Multilanguage
|
|
235
|
+
Set **locale** prop
|
|
236
|
+
```html
|
|
237
|
+
<CookieControl locale="de"/>
|
|
238
|
+
```
|
|
239
|
+
#### Default: en,
|
|
240
|
+
#### Currently available:
|
|
241
|
+
- en
|
|
242
|
+
- de
|
|
243
|
+
- it
|
|
244
|
+
- es
|
|
245
|
+
- fr
|
|
246
|
+
- pt
|
|
247
|
+
- hr
|
|
248
|
+
- no
|
|
249
|
+
- hu
|
|
250
|
+
- ja
|
|
251
|
+
- ru
|
|
252
|
+
- uk
|
|
253
|
+
|
|
254
|
+
If you don't like the default texts you can change them in options (**nuxt.config.js**)
|
|
255
|
+
```javascript
|
|
256
|
+
text: {
|
|
257
|
+
locale: {
|
|
258
|
+
en: {
|
|
259
|
+
barTitle: 'Cookies Different',
|
|
260
|
+
barDescription: 'We use our own cookies and third-party...',
|
|
261
|
+
},
|
|
262
|
+
|
|
263
|
+
de: {
|
|
264
|
+
...
|
|
265
|
+
}
|
|
266
|
+
},
|
|
267
|
+
|
|
268
|
+
//this will override locale text
|
|
269
|
+
barTitle: 'Override Title'
|
|
270
|
+
}
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
### Buy me a coffee
|
|
274
|
+
[](https://ko-fi.com/F1F31MWWL)
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
<!-- Badges -->
|
|
278
|
+
[npm-version-src]: https://badgen.net/npm/v/nuxt-cookie-control/latest
|
|
279
|
+
[npm-version-href]: https://npmjs.com/package/nuxt-cookie-control
|
|
280
|
+
|
|
281
|
+
[kofi-src]: https://badgen.net/badge/icon/kofi?icon=kofi&label=support
|
|
282
|
+
[kofi-href]: https://ko-fi.com/darioferderber
|
|
283
|
+
|
|
284
|
+
[npm-downloads-src]: https://badgen.net/npm/dm/nuxt-cookie-control
|
|
285
|
+
[npm-downloads-href]: https://npmjs.com/package/nuxt-cookie-control
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<client-only>
|
|
3
|
+
<section class="cookieControl" v-if="cookies.text">
|
|
4
|
+
<transition :name="`cookieControl__Bar--${cookies.barPosition}`">
|
|
5
|
+
<div :class="`cookieControl__Bar cookieControl__Bar--${cookies.barPosition}`" v-if="colorsSet && !cookies.consent">
|
|
6
|
+
<div class="cookieControl__BarContainer">
|
|
7
|
+
<div>
|
|
8
|
+
<slot name="bar">
|
|
9
|
+
<h3 v-text="cookies.text.barTitle"/>
|
|
10
|
+
<p v-text="cookies.text.barDescription"/>
|
|
11
|
+
</slot>
|
|
12
|
+
</div>
|
|
13
|
+
<div class="cookieControl__BarButtons">
|
|
14
|
+
<button @click="cookies.modal = true" v-text="cookies.text.manageCookies"/>
|
|
15
|
+
<button @click="setConsent({reload: false})" v-text="cookies.text.acceptAll"/>
|
|
16
|
+
</div>
|
|
17
|
+
</div>
|
|
18
|
+
</div>
|
|
19
|
+
</transition>
|
|
20
|
+
<button class="cookieControl__ControlButton" aria-label="Cookie control" v-if="cookies.controlButton && colorsSet && cookies.consent" @click="cookies.modal = true">
|
|
21
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="M510.52 255.82c-69.97-.85-126.47-57.69-126.47-127.86-70.17 0-127-56.49-127.86-126.45-27.26-4.14-55.13.3-79.72 12.82l-69.13 35.22a132.221 132.221 0 00-57.79 57.81l-35.1 68.88a132.645 132.645 0 00-12.82 80.95l12.08 76.27a132.521 132.521 0 0037.16 72.96l54.77 54.76a132.036 132.036 0 0072.71 37.06l76.71 12.15c27.51 4.36 55.7-.11 80.53-12.76l69.13-35.21a132.273 132.273 0 0057.79-57.81l35.1-68.88c12.56-24.64 17.01-52.58 12.91-79.91zM176 368c-17.67 0-32-14.33-32-32s14.33-32 32-32 32 14.33 32 32-14.33 32-32 32zm32-160c-17.67 0-32-14.33-32-32s14.33-32 32-32 32 14.33 32 32-14.33 32-32 32zm160 128c-17.67 0-32-14.33-32-32s14.33-32 32-32 32 14.33 32 32-14.33 32-32 32z"/></svg>
|
|
22
|
+
</button>
|
|
23
|
+
<transition name="cookieControl__Modal">
|
|
24
|
+
<div class="cookieControl__Modal" v-if="cookies.modal">
|
|
25
|
+
<p v-if="!saved" class="cookieControl__ModalUnsaved" v-text="cookies.text.unsaved"/>
|
|
26
|
+
<div class="cookieControl__ModalContent">
|
|
27
|
+
<div>
|
|
28
|
+
<slot name="modal"/>
|
|
29
|
+
<button @click="cookies.modal = false" class="cookieControl__ModalClose" v-text="cookies.text.close"/>
|
|
30
|
+
<template v-for="type in ['necessary', 'optional']">
|
|
31
|
+
<h3 v-text="cookies.text[type]" :key="type.id"/>
|
|
32
|
+
<ul :key="type.id">
|
|
33
|
+
<li v-for="cookie in cookies[type]" :key="cookie.id">
|
|
34
|
+
<div class="cookieControl__ModalInputWrapper">
|
|
35
|
+
<input v-if="type === 'necessary' && cookie.name !== 'functional'" :id="getCookieFirstName(cookie.name)" type="checkbox" disabled checked/>
|
|
36
|
+
<input v-else :id="getCookieFirstName(cookie.name)" type="checkbox" :checked="cookies.enabledList.includes(cookie.identifier || cookies.slugify(getCookieFirstName(cookie.name))) || (cookies.get('cookie_control_consent').length === 0 && cookie.initialState === true)" @change="toogleCookie(cookie)"/>
|
|
37
|
+
<label :for="getCookieFirstName(cookie.name)" v-html="getName(cookie.name)"/>
|
|
38
|
+
<span class="cookieControl__ModalCookieName">
|
|
39
|
+
{{ getName(cookie.name) }}
|
|
40
|
+
<span v-if="cookie.description" v-html="getDescription(cookie.description)"/>
|
|
41
|
+
</span>
|
|
42
|
+
</div>
|
|
43
|
+
<template v-if="cookie.cookies">
|
|
44
|
+
<slot name="cookie" v-bind="{config: cookie}">
|
|
45
|
+
<ul>
|
|
46
|
+
<li v-for="item in cookie.cookies" :key="item.id" v-html="item"/>
|
|
47
|
+
</ul>
|
|
48
|
+
</slot>
|
|
49
|
+
</template>
|
|
50
|
+
</li>
|
|
51
|
+
</ul>
|
|
52
|
+
</template>
|
|
53
|
+
<div class="cookieControl__ModalButtons">
|
|
54
|
+
<button @click="setConsent({type: 'partial'})" v-text="cookies.text.save"/>
|
|
55
|
+
<button @click="setConsent" v-text="cookies.text.acceptAll"/>
|
|
56
|
+
<button @click="setConsent({declineAll: true})" v-text="cookies.text.declineAll"/>
|
|
57
|
+
</div>
|
|
58
|
+
</div>
|
|
59
|
+
</div>
|
|
60
|
+
</div>
|
|
61
|
+
</transition>
|
|
62
|
+
</section>
|
|
63
|
+
</client-only>
|
|
64
|
+
</template>
|
|
65
|
+
|
|
66
|
+
<script>
|
|
67
|
+
export default {
|
|
68
|
+
name: 'CookieControl',
|
|
69
|
+
props: {
|
|
70
|
+
locale: {
|
|
71
|
+
default: 'en'
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
data(){
|
|
75
|
+
return{
|
|
76
|
+
saved: true,
|
|
77
|
+
colorsSet: false,
|
|
78
|
+
cookies: this.$cookies
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
|
|
82
|
+
computed: {
|
|
83
|
+
expirationDate(){
|
|
84
|
+
let date = new Date();
|
|
85
|
+
date.setFullYear(date.getFullYear()+1);
|
|
86
|
+
return date.toUTCString();
|
|
87
|
+
},
|
|
88
|
+
|
|
89
|
+
optionalCookies(){
|
|
90
|
+
return this.cookies.optional;
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
|
|
94
|
+
methods: {
|
|
95
|
+
toogleCookie(cookie){
|
|
96
|
+
let cookieName = cookie.identifier || this.cookies.slugify(this.getCookieFirstName(cookie.name));
|
|
97
|
+
if(this.saved) this.saved = false;
|
|
98
|
+
if(!this.cookies.enabledList.includes(cookieName)) this.cookies.enabledList.push(cookieName);
|
|
99
|
+
else this.cookies.enabledList.splice(this.cookies.enabledList.indexOf(cookieName), 1);
|
|
100
|
+
},
|
|
101
|
+
|
|
102
|
+
setConsent({type, consent=true, reload=true, declineAll=false}){
|
|
103
|
+
this.cookies.set({name: 'cookie_control_consent', value: consent, expires: this.expirationDate});
|
|
104
|
+
let enabledCookies = declineAll ? [] : type === 'partial' && consent ? this.cookies.enabledList : [...this.optionalCookies.map(c => c.identifier || this.cookies.slugify(this.getCookieFirstName(c.name)))];
|
|
105
|
+
this.cookies.set({name: 'cookie_control_enabled_cookies', value: consent ? enabledCookies.join(',') : '', expires: this.expirationDate});
|
|
106
|
+
if(!reload){
|
|
107
|
+
this.cookies.setConsent()
|
|
108
|
+
this.$cookies.modal = false;
|
|
109
|
+
} else window.location.reload(true);
|
|
110
|
+
},
|
|
111
|
+
|
|
112
|
+
getDescription(description){
|
|
113
|
+
if(typeof(description) === 'string') return ` ${this.cookies.dashInDescription !== false ? '-' : ''} ${description}`;
|
|
114
|
+
else if(description[this.locale]) return ` ${this.cookies.dashInDescription !== false ? '-' : ''} ${description[this.locale]}`;
|
|
115
|
+
return '';
|
|
116
|
+
},
|
|
117
|
+
|
|
118
|
+
getName(name){
|
|
119
|
+
return name === 'functional' ? this.cookies.text['functional'] : typeof(name) === 'string' ? name : name[this.locale] ? name[this.locale] : name[Object.keys(name)[0]];
|
|
120
|
+
},
|
|
121
|
+
|
|
122
|
+
getCookieFirstName(name){
|
|
123
|
+
return typeof(name) === 'string' ? name : name[Object.keys(name)[0]]
|
|
124
|
+
},
|
|
125
|
+
|
|
126
|
+
async setTexts(isChanged=false){
|
|
127
|
+
let text = null;
|
|
128
|
+
let module = null;
|
|
129
|
+
try {
|
|
130
|
+
module = require(`../locale/${this.locale}`);
|
|
131
|
+
} catch (e) {
|
|
132
|
+
module = require(`../locale/en`);
|
|
133
|
+
}
|
|
134
|
+
text = module.default;
|
|
135
|
+
if(this.cookies.text && Object.keys(this.cookies.text).length > 0){
|
|
136
|
+
if(this.cookies.text.locale){
|
|
137
|
+
Object.assign(text, this.cookies.text.locale[this.locale])
|
|
138
|
+
}
|
|
139
|
+
if(!isChanged) Object.assign(text, this.cookies.text)
|
|
140
|
+
}
|
|
141
|
+
this.$set(this.$cookies, 'text', text);
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
|
|
145
|
+
async beforeMount (){
|
|
146
|
+
await this.setTexts();
|
|
147
|
+
if(process.browser && this.cookies.colors){
|
|
148
|
+
let key = null;
|
|
149
|
+
let variables = {};
|
|
150
|
+
for(key in this.cookies.colors){
|
|
151
|
+
let k = key.toLowerCase().includes('unactive') ? key.replace(/Unactive/g, 'Inactive') : key;
|
|
152
|
+
variables[`cookie-control-${k}`] = `${this.cookies.colors[key]}`
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if(this.cookies.cssPolyfill){
|
|
156
|
+
const module = await import('css-vars-ponyfill');
|
|
157
|
+
let cssVars = module.default
|
|
158
|
+
cssVars({variables})
|
|
159
|
+
} else if(process.client){
|
|
160
|
+
for(let cssVar in variables){
|
|
161
|
+
document.documentElement.style.setProperty(`--${cssVar}`, variables[cssVar]);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if(!this.cookies.get('cookie_control_consent') || this.cookies.get('cookie_control_consent').length === 0){
|
|
167
|
+
this.optionalCookies.forEach(c =>{
|
|
168
|
+
if(c.initialState === true) {
|
|
169
|
+
this.cookies.enabledList.push(c.identifier || this.cookies.slugify(this.getCookieFirstName(c.name)));
|
|
170
|
+
}
|
|
171
|
+
})
|
|
172
|
+
}
|
|
173
|
+
this.colorsSet = true;
|
|
174
|
+
},
|
|
175
|
+
|
|
176
|
+
watch: {
|
|
177
|
+
async locale(){
|
|
178
|
+
await this.setTexts(true);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
</script>
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<client-only>
|
|
3
|
+
<iframe v-if="iframeEnabled"/>
|
|
4
|
+
<div v-else class="cookieControl__BlockedIframe">
|
|
5
|
+
<p>
|
|
6
|
+
{{ iframeText }}
|
|
7
|
+
<a href="#" @click.prevent="cookies.modal = true" v-text="cookies.text.here" v-if="cookies && cookies.text"/>
|
|
8
|
+
</p>
|
|
9
|
+
</div>
|
|
10
|
+
</client-only>
|
|
11
|
+
</template>
|
|
12
|
+
|
|
13
|
+
<script>
|
|
14
|
+
export default {
|
|
15
|
+
name: 'CookieIframe',
|
|
16
|
+
data(){
|
|
17
|
+
return{
|
|
18
|
+
cookies: this.$cookies
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
computed: {
|
|
23
|
+
iframeEnabled(){
|
|
24
|
+
return this.cookies.enabled.filter(c =>{return c.name === 'functional'}).length > 0
|
|
25
|
+
},
|
|
26
|
+
|
|
27
|
+
iframeText(){
|
|
28
|
+
return this.cookies && this.cookies.text ? this.cookies.text.blockedIframe : '';
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
</script>
|
package/lib/module.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
import { ContextReplacementPlugin } from 'webpack';
|
|
3
|
+
|
|
4
|
+
module.exports = function cookies (_options) {
|
|
5
|
+
const defaultOptions = {
|
|
6
|
+
...this.options.cookies,
|
|
7
|
+
css: true,
|
|
8
|
+
cssPolyfill: true,
|
|
9
|
+
controlButton: true,
|
|
10
|
+
barPosition: 'bottom-full',
|
|
11
|
+
iframe: path.resolve(__dirname, '../components/CookieIframe.vue'),
|
|
12
|
+
component: path.resolve(__dirname, '../components/CookieControl.vue'),
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
let options = Object.assign(defaultOptions, _options);
|
|
16
|
+
|
|
17
|
+
if(options.css) this.options.css.push(path.resolve(__dirname, '../lib/styles.scss'));
|
|
18
|
+
if(this.options.globalName) options['globalName'] = this.options.globalName;
|
|
19
|
+
|
|
20
|
+
if(options.blockIframe){
|
|
21
|
+
let blockIframe = {
|
|
22
|
+
name: 'functional',
|
|
23
|
+
initialState: options.blockIframe.initialState !== undefined ? options.blockIframe.initialState : true
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if(options.optional) options.optional.push(blockIframe)
|
|
27
|
+
else options.optional = [blockIframe]
|
|
28
|
+
|
|
29
|
+
this.extendBuild((config) => {
|
|
30
|
+
config.module.rules.push({
|
|
31
|
+
test: /\.vue$/,
|
|
32
|
+
loader: 'string-replace-loader',
|
|
33
|
+
exclude: /node_modules/,
|
|
34
|
+
options: {
|
|
35
|
+
multiple: [
|
|
36
|
+
{ search: '<iframe', replace: '<CookieIframe', flags: 'g' },
|
|
37
|
+
{ search: '</iframe>', replace: '</CookieIframe>', flags: 'g' }
|
|
38
|
+
],
|
|
39
|
+
}
|
|
40
|
+
})
|
|
41
|
+
})
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if(options.locales){
|
|
45
|
+
let regex = new RegExp(options.locales.join('|'))
|
|
46
|
+
this.extendBuild((config) => {
|
|
47
|
+
config.plugins.push(
|
|
48
|
+
new ContextReplacementPlugin(/nuxt-cookie-control[\/\\]locale$/, regex)
|
|
49
|
+
)
|
|
50
|
+
})
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
this.addPlugin({
|
|
54
|
+
src: path.resolve(__dirname, 'plugin.js'),
|
|
55
|
+
fileName: 'nuxt-cookie-control.js',
|
|
56
|
+
options
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// Nuxt-purgecss fix
|
|
60
|
+
try {
|
|
61
|
+
if(require.resolve("nuxt-purgecss").length > 0) {
|
|
62
|
+
if(this.options.purgeCSS) {
|
|
63
|
+
if(this.options.purgeCSS.whitelistPatternsChildren) this.options.purgeCSS.whitelistPatternsChildren.push(/cookieControl/);
|
|
64
|
+
else this.options.purgeCSS.whitelistPatternsChildren = [/cookieControl/]
|
|
65
|
+
} else{
|
|
66
|
+
this.options.purgeCSS = {
|
|
67
|
+
whitelistPatternsChildren: [/cookieControl/]
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
} catch(e) {}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
module.exports.meta = require('../package.json')
|