@dargmuesli/nuxt-cookie-control 9.0.0-beta.1 → 9.0.0
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 +21 -1
- package/dist/module.d.mts +2 -1
- package/dist/module.json +2 -2
- package/dist/module.mjs +7 -25
- package/dist/runtime/components/ClientOnlyPrerender.vue +12 -0
- package/dist/runtime/components/ClientOnlyPrerender.vue.d.ts +19 -0
- package/dist/runtime/components/CookieControl.vue +293 -357
- package/dist/runtime/components/CookieControl.vue.d.ts +223 -0
- package/dist/runtime/components/CookieIframe.vue +30 -32
- package/dist/runtime/components/CookieIframe.vue.d.ts +23 -0
- package/dist/runtime/locale/index.d.ts +1 -1
- package/dist/runtime/locale/index.js +2 -2
- package/dist/runtime/types.d.ts +1 -1
- package/dist/types.d.mts +2 -2
- package/package.json +38 -34
- package/dist/module.cjs +0 -5
- package/dist/module.d.ts +0 -67
- package/dist/types.d.ts +0 -7
- /package/dist/runtime/locale/{zh.d.ts → zh-CN.d.ts} +0 -0
- /package/dist/runtime/locale/{zh.js → zh-CN.js} +0 -0
|
@@ -1,446 +1,382 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<
|
|
3
|
-
<
|
|
4
|
-
<
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
<div>
|
|
10
|
-
<
|
|
11
|
-
<
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
<
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
2
|
+
<ClientOnlyPrerender>
|
|
3
|
+
<aside class="cookieControl">
|
|
4
|
+
<transition :name="`cookieControl__Bar--${moduleOptions.barPosition}`">
|
|
5
|
+
<div
|
|
6
|
+
v-if="!isConsentGiven && !moduleOptions.isModalForced"
|
|
7
|
+
:class="`cookieControl__Bar cookieControl__Bar--${moduleOptions.barPosition}`"
|
|
8
|
+
>
|
|
9
|
+
<div class="cookieControl__BarContainer">
|
|
10
|
+
<div>
|
|
11
|
+
<slot name="bar">
|
|
12
|
+
<h2 v-text="localeStrings?.bannerTitle" />
|
|
13
|
+
<p v-text="localeStrings?.bannerDescription" />
|
|
14
|
+
</slot>
|
|
15
|
+
</div>
|
|
16
|
+
<div class="cookieControl__BarButtons">
|
|
17
|
+
<button
|
|
18
|
+
type="button"
|
|
19
|
+
@click="acceptAll()"
|
|
20
|
+
v-text="localeStrings?.accept"
|
|
21
|
+
/>
|
|
22
|
+
<button
|
|
23
|
+
v-if="moduleOptions.isAcceptNecessaryButtonEnabled"
|
|
24
|
+
type="button"
|
|
25
|
+
@click="acceptNecessary()"
|
|
26
|
+
v-text="localeStrings?.decline"
|
|
27
|
+
/>
|
|
28
|
+
<button
|
|
29
|
+
type="button"
|
|
30
|
+
@click="isModalActive = true"
|
|
31
|
+
v-text="localeStrings?.manageCookies"
|
|
32
|
+
/>
|
|
33
|
+
</div>
|
|
32
34
|
</div>
|
|
33
35
|
</div>
|
|
34
|
-
</
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
@click="isModalActive = true"
|
|
43
|
-
>
|
|
44
|
-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
|
|
45
|
-
<path
|
|
46
|
-
fill="currentColor"
|
|
47
|
-
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"
|
|
48
|
-
/>
|
|
49
|
-
</svg>
|
|
50
|
-
</button>
|
|
51
|
-
<transition name="cookieControl__Modal">
|
|
52
|
-
<div
|
|
53
|
-
v-if="isModalActive"
|
|
54
|
-
class="cookieControl__Modal"
|
|
55
|
-
@click.self="onModalClick"
|
|
36
|
+
</transition>
|
|
37
|
+
<button
|
|
38
|
+
v-if="moduleOptions.isControlButtonEnabled && isConsentGiven"
|
|
39
|
+
aria-label="Cookie control"
|
|
40
|
+
class="cookieControl__ControlButton"
|
|
41
|
+
data-testid="nuxt-cookie-control-control-button"
|
|
42
|
+
type="button"
|
|
43
|
+
@click="isModalActive = true"
|
|
56
44
|
>
|
|
57
|
-
<
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
<div class="cookieControl__ModalContent">
|
|
63
|
-
<div class="cookieControl__ModalContentInner">
|
|
64
|
-
<slot name="modal" />
|
|
65
|
-
<button
|
|
66
|
-
v-if="!moduleOptions.isModalForced"
|
|
67
|
-
class="cookieControl__ModalClose"
|
|
68
|
-
type="button"
|
|
69
|
-
@click="isModalActive = false"
|
|
70
|
-
v-text="localeStrings?.close"
|
|
45
|
+
<slot name="controlButton">
|
|
46
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
|
|
47
|
+
<path
|
|
48
|
+
fill="currentColor"
|
|
49
|
+
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"
|
|
71
50
|
/>
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
/>
|
|
112
|
-
<button type="button" @click="toggleButton($event)">
|
|
113
|
-
{{ getName(cookie.name) }}
|
|
114
|
-
</button>
|
|
115
|
-
<label
|
|
116
|
-
class="cookieControl__ModalCookieName"
|
|
117
|
-
:for="resolveTranslatable(cookie.name, props.locale)"
|
|
118
|
-
tabindex="0"
|
|
119
|
-
@keydown="toggleLabel($event)"
|
|
120
|
-
>
|
|
121
|
-
{{ getName(cookie.name) }}
|
|
122
|
-
<span v-if="cookie.description">
|
|
123
|
-
{{ getDescription(cookie.description) }}
|
|
124
|
-
</span>
|
|
125
|
-
<span
|
|
51
|
+
</svg>
|
|
52
|
+
</slot>
|
|
53
|
+
</button>
|
|
54
|
+
<transition name="cookieControl__Modal">
|
|
55
|
+
<div
|
|
56
|
+
v-if="isModalActive"
|
|
57
|
+
class="cookieControl__Modal"
|
|
58
|
+
@click.self="onModalClick"
|
|
59
|
+
>
|
|
60
|
+
<p
|
|
61
|
+
v-if="isSaved"
|
|
62
|
+
class="cookieControl__ModalUnsaved"
|
|
63
|
+
v-text="localeStrings?.settingsUnsaved"
|
|
64
|
+
/>
|
|
65
|
+
<div class="cookieControl__ModalContent">
|
|
66
|
+
<div class="cookieControl__ModalContentInner">
|
|
67
|
+
<slot name="modal" />
|
|
68
|
+
<button
|
|
69
|
+
v-if="!moduleOptions.isModalForced"
|
|
70
|
+
class="cookieControl__ModalClose"
|
|
71
|
+
type="button"
|
|
72
|
+
@click="isModalActive = false"
|
|
73
|
+
v-text="localeStrings?.close"
|
|
74
|
+
/>
|
|
75
|
+
<template v-for="cookieType in CookieType" :key="cookieType">
|
|
76
|
+
<template v-if="moduleOptions.cookies[cookieType].length">
|
|
77
|
+
<h2
|
|
78
|
+
v-text="
|
|
79
|
+
localeStrings && (cookieType === CookieType.NECESSARY ? localeStrings.cookiesNecessary : localeStrings.cookiesOptional)
|
|
80
|
+
"
|
|
81
|
+
/>
|
|
82
|
+
<ul>
|
|
83
|
+
<li
|
|
84
|
+
v-for="cookie in moduleOptions.cookies[cookieType]"
|
|
85
|
+
:key="cookie.id"
|
|
86
|
+
>
|
|
87
|
+
<slot name="cookie" v-bind="{ cookie }">
|
|
88
|
+
<div class="cookieControl__ModalInputWrapper">
|
|
89
|
+
<input
|
|
126
90
|
v-if="
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
"
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
91
|
+
cookieType === CookieType.NECESSARY && cookie.name !== 'functional'
|
|
92
|
+
"
|
|
93
|
+
:id="resolveTranslatable(cookie.name, locale)"
|
|
94
|
+
type="checkbox"
|
|
95
|
+
disabled
|
|
96
|
+
checked
|
|
97
|
+
/>
|
|
98
|
+
<input
|
|
99
|
+
v-else
|
|
100
|
+
:id="resolveTranslatable(cookie.name, locale)"
|
|
101
|
+
type="checkbox"
|
|
102
|
+
:checked="
|
|
103
|
+
isConsentGiven === void 0 ? cookie.isPreselected : getCookieIds(localCookiesEnabled).includes(
|
|
104
|
+
cookie.id
|
|
105
|
+
)
|
|
106
|
+
"
|
|
107
|
+
@change="toogleCookie(cookie)"
|
|
108
|
+
/>
|
|
109
|
+
<button type="button" @click="toggleButton($event)">
|
|
110
|
+
{{ getName(cookie.name) }}
|
|
111
|
+
</button>
|
|
112
|
+
<label
|
|
113
|
+
class="cookieControl__ModalCookieName"
|
|
114
|
+
:for="resolveTranslatable(cookie.name, locale)"
|
|
115
|
+
tabindex="0"
|
|
116
|
+
@keydown="toggleLabel($event)"
|
|
141
117
|
>
|
|
118
|
+
{{ getName(cookie.name) }}
|
|
119
|
+
<span v-if="cookie.description">
|
|
120
|
+
{{ getDescription(cookie.description) }}
|
|
121
|
+
</span>
|
|
142
122
|
<span
|
|
143
|
-
v-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
:key="entry[0]"
|
|
123
|
+
v-if="
|
|
124
|
+
moduleOptions.isCookieIdVisible && cookie.targetCookieIds
|
|
125
|
+
"
|
|
147
126
|
>
|
|
148
127
|
<br />
|
|
149
|
-
|
|
150
|
-
:
|
|
151
|
-
|
|
152
|
-
!entry[0].toLowerCase().startsWith('http')
|
|
153
|
-
? (isModalActive = false)
|
|
154
|
-
: null
|
|
155
|
-
"
|
|
156
|
-
>
|
|
157
|
-
{{ entry[1] || entry[0] }}
|
|
158
|
-
</NuxtLink>
|
|
128
|
+
{{
|
|
129
|
+
"IDs: " + cookie.targetCookieIds.map((id) => `"${id}"`).join(", ")
|
|
130
|
+
}}
|
|
159
131
|
</span>
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
132
|
+
<template
|
|
133
|
+
v-if="Object.entries(cookie.links || {}).length"
|
|
134
|
+
>
|
|
135
|
+
<span
|
|
136
|
+
v-for="entry in Object.entries(
|
|
137
|
+
cookie.links || {}
|
|
138
|
+
)"
|
|
139
|
+
:key="entry[0]"
|
|
140
|
+
>
|
|
141
|
+
<br />
|
|
142
|
+
<NuxtLink
|
|
143
|
+
:to="entry[0]"
|
|
144
|
+
@click="
|
|
145
|
+
!entry[0].toLowerCase().startsWith('http') ? isModalActive = false : null
|
|
146
|
+
"
|
|
147
|
+
>
|
|
148
|
+
{{ entry[1] || entry[0] }}
|
|
149
|
+
</NuxtLink>
|
|
150
|
+
</span>
|
|
151
|
+
</template>
|
|
152
|
+
</label>
|
|
153
|
+
</div>
|
|
154
|
+
</slot>
|
|
155
|
+
</li>
|
|
156
|
+
</ul>
|
|
157
|
+
</template>
|
|
166
158
|
</template>
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
159
|
+
<div class="cookieControl__ModalButtons">
|
|
160
|
+
<button
|
|
161
|
+
type="button"
|
|
162
|
+
@click="
|
|
163
|
+
() => {
|
|
164
|
+
acceptPartial();
|
|
165
|
+
isModalActive = false;
|
|
166
|
+
}
|
|
167
|
+
"
|
|
168
|
+
v-text="localeStrings?.save"
|
|
169
|
+
/>
|
|
170
|
+
<button
|
|
171
|
+
type="button"
|
|
172
|
+
@click="
|
|
173
|
+
() => {
|
|
174
|
+
acceptNecessary();
|
|
175
|
+
isModalActive = false;
|
|
176
|
+
}
|
|
177
|
+
"
|
|
178
|
+
v-text="localeStrings?.acceptAll"
|
|
179
|
+
/>
|
|
180
|
+
<button
|
|
181
|
+
v-if="!moduleOptions.isModalForced"
|
|
182
|
+
type="button"
|
|
183
|
+
@click="
|
|
184
|
+
() => {
|
|
185
|
+
acceptNone();
|
|
186
|
+
isModalActive = false;
|
|
187
|
+
}
|
|
188
|
+
"
|
|
189
|
+
v-text="localeStrings?.declineAll"
|
|
190
|
+
/>
|
|
191
|
+
</div>
|
|
200
192
|
</div>
|
|
201
193
|
</div>
|
|
202
194
|
</div>
|
|
203
|
-
</
|
|
204
|
-
</
|
|
205
|
-
</
|
|
195
|
+
</transition>
|
|
196
|
+
</aside>
|
|
197
|
+
</ClientOnlyPrerender>
|
|
206
198
|
</template>
|
|
207
199
|
|
|
208
|
-
<script setup
|
|
209
|
-
import { ref, computed, onBeforeMount, watch } from
|
|
210
|
-
|
|
211
|
-
import {
|
|
212
|
-
type Cookie,
|
|
213
|
-
CookieType,
|
|
214
|
-
type Locale,
|
|
215
|
-
type Translatable,
|
|
216
|
-
} from '#cookie-control/types'
|
|
200
|
+
<script setup>
|
|
201
|
+
import { ref, computed, onBeforeMount, watch } from "vue";
|
|
202
|
+
import { COOKIE_ID_SEPARATOR } from "#cookie-control/constants";
|
|
217
203
|
import {
|
|
218
204
|
getAllCookieIdsString,
|
|
219
205
|
getCookieIds,
|
|
220
206
|
removeCookie,
|
|
221
|
-
resolveTranslatable
|
|
222
|
-
} from
|
|
223
|
-
import
|
|
224
|
-
import
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
locale: 'en',
|
|
232
|
-
})
|
|
233
|
-
|
|
207
|
+
resolveTranslatable
|
|
208
|
+
} from "#cookie-control/methods";
|
|
209
|
+
import setCssVariables from "#cookie-control/set-vars";
|
|
210
|
+
import { useCookieControl, useCookie, useNuxtApp } from "#imports";
|
|
211
|
+
const { locale = "en" } = defineProps({
|
|
212
|
+
locale: {
|
|
213
|
+
type: String,
|
|
214
|
+
required: false
|
|
215
|
+
}
|
|
216
|
+
});
|
|
234
217
|
const {
|
|
235
218
|
cookiesEnabled,
|
|
236
219
|
cookiesEnabledIds,
|
|
237
220
|
isConsentGiven,
|
|
238
221
|
isModalActive,
|
|
239
|
-
moduleOptions
|
|
240
|
-
} = useCookieControl()
|
|
241
|
-
const nuxtApp = useNuxtApp()
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
const
|
|
245
|
-
const localCookiesEnabled = ref([...(cookiesEnabled.value || [])])
|
|
246
|
-
const allCookieIdsString = getAllCookieIdsString(moduleOptions)
|
|
222
|
+
moduleOptions
|
|
223
|
+
} = useCookieControl();
|
|
224
|
+
const nuxtApp = useNuxtApp();
|
|
225
|
+
const expires = new Date(Date.now() + moduleOptions.cookieExpiryOffsetMs);
|
|
226
|
+
const localCookiesEnabled = ref([...cookiesEnabled.value || []]);
|
|
227
|
+
const allCookieIdsString = getAllCookieIdsString(moduleOptions);
|
|
247
228
|
const cookieIsConsentGiven = useCookie(moduleOptions.cookieNameIsConsentGiven, {
|
|
248
229
|
expires,
|
|
249
|
-
...moduleOptions.cookieOptions
|
|
250
|
-
})
|
|
251
|
-
|
|
230
|
+
...moduleOptions.cookieOptions
|
|
231
|
+
});
|
|
252
232
|
const cookieCookiesEnabledIds = useCookie(
|
|
253
233
|
moduleOptions.cookieNameCookiesEnabledIds,
|
|
254
234
|
{
|
|
255
235
|
expires,
|
|
256
|
-
...moduleOptions.cookieOptions
|
|
257
|
-
}
|
|
258
|
-
)
|
|
259
|
-
|
|
260
|
-
// computations
|
|
236
|
+
...moduleOptions.cookieOptions
|
|
237
|
+
}
|
|
238
|
+
);
|
|
261
239
|
const isSaved = computed(
|
|
262
|
-
() =>
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
getCookieIds(localCookiesEnabled.value).sort().join(COOKIE_ID_SEPARATOR),
|
|
267
|
-
)
|
|
268
|
-
const localeStrings = computed(() => moduleOptions.localeTexts[props.locale])
|
|
269
|
-
|
|
270
|
-
// methods
|
|
271
|
-
const accept = () => {
|
|
240
|
+
() => getCookieIds(cookiesEnabled.value || []).sort().join(COOKIE_ID_SEPARATOR) !== getCookieIds(localCookiesEnabled.value).sort().join(COOKIE_ID_SEPARATOR)
|
|
241
|
+
);
|
|
242
|
+
const localeStrings = computed(() => moduleOptions.localeTexts[locale]);
|
|
243
|
+
const acceptAll = () => {
|
|
272
244
|
setCookies({
|
|
273
245
|
isConsentGiven: true,
|
|
274
|
-
cookiesOptionalEnabled: moduleOptions.cookies.optional
|
|
275
|
-
})
|
|
276
|
-
}
|
|
246
|
+
cookiesOptionalEnabled: moduleOptions.cookies.optional
|
|
247
|
+
});
|
|
248
|
+
};
|
|
277
249
|
const acceptPartial = () => {
|
|
278
|
-
const localCookiesEnabledIds = getCookieIds(localCookiesEnabled.value)
|
|
279
|
-
|
|
250
|
+
const localCookiesEnabledIds = getCookieIds(localCookiesEnabled.value);
|
|
280
251
|
setCookies({
|
|
281
252
|
isConsentGiven: true,
|
|
282
253
|
cookiesOptionalEnabled: [
|
|
283
254
|
...moduleOptions.cookies.necessary,
|
|
284
|
-
...moduleOptions.cookies.optional
|
|
285
|
-
].filter((cookie) => localCookiesEnabledIds.includes(cookie.id))
|
|
286
|
-
})
|
|
287
|
-
}
|
|
288
|
-
const
|
|
255
|
+
...moduleOptions.cookies.optional
|
|
256
|
+
].filter((cookie) => localCookiesEnabledIds.includes(cookie.id))
|
|
257
|
+
});
|
|
258
|
+
};
|
|
259
|
+
const acceptNecessary = () => {
|
|
289
260
|
setCookies({
|
|
290
261
|
isConsentGiven: true,
|
|
291
|
-
cookiesOptionalEnabled: moduleOptions.cookies.necessary
|
|
292
|
-
})
|
|
293
|
-
}
|
|
294
|
-
const
|
|
262
|
+
cookiesOptionalEnabled: moduleOptions.cookies.necessary
|
|
263
|
+
});
|
|
264
|
+
};
|
|
265
|
+
const acceptNone = () => {
|
|
295
266
|
setCookies({
|
|
296
267
|
isConsentGiven: false,
|
|
297
|
-
cookiesOptionalEnabled: []
|
|
298
|
-
})
|
|
299
|
-
}
|
|
300
|
-
const getDescription = (description:
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
const getName = (name: Translatable) => {
|
|
305
|
-
return name === 'functional'
|
|
306
|
-
? localeStrings.value?.cookiesFunctional
|
|
307
|
-
: resolveTranslatable(name, props.locale)
|
|
308
|
-
}
|
|
268
|
+
cookiesOptionalEnabled: []
|
|
269
|
+
});
|
|
270
|
+
};
|
|
271
|
+
const getDescription = (description) => `${moduleOptions.isDashInDescriptionEnabled === false ? "" : "-"} ${resolveTranslatable(description, locale)}`;
|
|
272
|
+
const getName = (name) => {
|
|
273
|
+
return name === "functional" ? localeStrings.value?.cookiesFunctional : resolveTranslatable(name, locale);
|
|
274
|
+
};
|
|
309
275
|
const init = () => {
|
|
310
|
-
nuxtApp.$cookies.locale.value =
|
|
311
|
-
}
|
|
276
|
+
nuxtApp.$cookies.locale.value = locale;
|
|
277
|
+
};
|
|
312
278
|
const onModalClick = () => {
|
|
313
279
|
if (moduleOptions.closeModalOnClickOutside) {
|
|
314
|
-
isModalActive.value = false
|
|
280
|
+
isModalActive.value = false;
|
|
315
281
|
}
|
|
316
|
-
}
|
|
282
|
+
};
|
|
317
283
|
const setCookies = ({
|
|
318
284
|
cookiesOptionalEnabled: cookiesOptionalEnabledNew,
|
|
319
|
-
isConsentGiven: isConsentGivenNew
|
|
320
|
-
}: {
|
|
321
|
-
cookiesOptionalEnabled: Cookie[]
|
|
322
|
-
isConsentGiven: boolean
|
|
285
|
+
isConsentGiven: isConsentGivenNew
|
|
323
286
|
}) => {
|
|
324
|
-
isConsentGiven.value = isConsentGivenNew
|
|
325
|
-
cookiesEnabled.value = isConsentGivenNew
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
}
|
|
337
|
-
const
|
|
338
|
-
;
|
|
339
|
-
($event.target as HTMLButtonElement | null)
|
|
340
|
-
?.nextSibling as HTMLLabelElement | null
|
|
341
|
-
)?.click()
|
|
342
|
-
}
|
|
343
|
-
const toogleCookie = (cookie: Cookie) => {
|
|
344
|
-
const cookieIndex = getCookieIds(localCookiesEnabled.value).indexOf(cookie.id)
|
|
345
|
-
|
|
287
|
+
isConsentGiven.value = isConsentGivenNew;
|
|
288
|
+
cookiesEnabled.value = isConsentGivenNew ? [
|
|
289
|
+
...moduleOptions.cookies.necessary,
|
|
290
|
+
...moduleOptions.cookies.optional.filter(
|
|
291
|
+
(cookieOptional) => cookiesOptionalEnabledNew.includes(cookieOptional)
|
|
292
|
+
)
|
|
293
|
+
] : [];
|
|
294
|
+
cookiesEnabledIds.value = isConsentGivenNew ? getCookieIds(cookiesEnabled.value) : [];
|
|
295
|
+
};
|
|
296
|
+
const toggleButton = ($event) => {
|
|
297
|
+
;
|
|
298
|
+
$event.target?.nextSibling?.click();
|
|
299
|
+
};
|
|
300
|
+
const toogleCookie = (cookie) => {
|
|
301
|
+
const cookieIndex = getCookieIds(localCookiesEnabled.value).indexOf(cookie.id);
|
|
346
302
|
if (cookieIndex < 0) {
|
|
347
|
-
localCookiesEnabled.value.push(cookie)
|
|
303
|
+
localCookiesEnabled.value.push(cookie);
|
|
348
304
|
} else {
|
|
349
|
-
localCookiesEnabled.value.splice(cookieIndex, 1)
|
|
305
|
+
localCookiesEnabled.value.splice(cookieIndex, 1);
|
|
350
306
|
}
|
|
351
|
-
}
|
|
352
|
-
const toggleLabel = ($event
|
|
353
|
-
if ($event.key ===
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
// lifecycle
|
|
307
|
+
};
|
|
308
|
+
const toggleLabel = ($event) => {
|
|
309
|
+
if ($event.key === " ") $event.target?.click();
|
|
310
|
+
};
|
|
357
311
|
onBeforeMount(() => {
|
|
358
312
|
if (moduleOptions.colors) {
|
|
359
|
-
const variables
|
|
360
|
-
|
|
313
|
+
const variables = {};
|
|
361
314
|
for (const key in moduleOptions.colors) {
|
|
362
|
-
variables[`cookie-control-${key}`] = `${moduleOptions.colors[key]}
|
|
315
|
+
variables[`cookie-control-${key}`] = `${moduleOptions.colors[key]}`;
|
|
363
316
|
}
|
|
364
|
-
|
|
365
|
-
setCssVariables(variables)
|
|
317
|
+
setCssVariables(variables);
|
|
366
318
|
}
|
|
367
|
-
|
|
368
319
|
if (moduleOptions.isModalForced && !isConsentGiven.value) {
|
|
369
|
-
isModalActive.value = true
|
|
320
|
+
isModalActive.value = true;
|
|
370
321
|
}
|
|
371
|
-
})
|
|
322
|
+
});
|
|
372
323
|
watch(
|
|
373
324
|
() => cookiesEnabled.value,
|
|
374
325
|
(current, _previous) => {
|
|
375
|
-
localCookiesEnabled.value = [...
|
|
376
|
-
|
|
326
|
+
localCookiesEnabled.value = [...current || []];
|
|
377
327
|
if (isConsentGiven.value) {
|
|
378
328
|
cookieCookiesEnabledIds.value = getCookieIds(current || []).join(
|
|
379
|
-
COOKIE_ID_SEPARATOR
|
|
380
|
-
)
|
|
381
|
-
|
|
329
|
+
COOKIE_ID_SEPARATOR
|
|
330
|
+
);
|
|
382
331
|
for (const cookieEnabled of current || []) {
|
|
383
|
-
if (!cookieEnabled.src) continue
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
if (!headElement) return
|
|
390
|
-
|
|
391
|
-
headElement.appendChild(script)
|
|
332
|
+
if (!cookieEnabled.src) continue;
|
|
333
|
+
const script = document.createElement("script");
|
|
334
|
+
script.src = cookieEnabled.src;
|
|
335
|
+
const headElement = document.getElementsByTagName("head")[0];
|
|
336
|
+
if (!headElement) return;
|
|
337
|
+
headElement.appendChild(script);
|
|
392
338
|
}
|
|
393
339
|
} else {
|
|
394
|
-
cookieCookiesEnabledIds.value =
|
|
340
|
+
cookieCookiesEnabledIds.value = void 0;
|
|
395
341
|
}
|
|
396
|
-
|
|
397
|
-
// delete formerly enabled cookies that are now disabled
|
|
398
342
|
const cookiesOptionalDisabled = moduleOptions.cookies.optional.filter(
|
|
399
|
-
(cookieOptional) => !(current || []).includes(cookieOptional)
|
|
400
|
-
)
|
|
401
|
-
|
|
343
|
+
(cookieOptional) => !(current || []).includes(cookieOptional)
|
|
344
|
+
);
|
|
402
345
|
for (const cookieOptionalDisabled of cookiesOptionalDisabled) {
|
|
403
|
-
if (!cookieOptionalDisabled.targetCookieIds) continue
|
|
404
|
-
|
|
346
|
+
if (!cookieOptionalDisabled.targetCookieIds) continue;
|
|
405
347
|
for (const cookieOptionalDisabledId of cookieOptionalDisabled.targetCookieIds) {
|
|
406
|
-
removeCookie(cookieOptionalDisabledId)
|
|
348
|
+
removeCookie(cookieOptionalDisabledId);
|
|
407
349
|
}
|
|
408
|
-
|
|
409
350
|
if (cookieOptionalDisabled.src) {
|
|
410
351
|
for (const script of [
|
|
411
352
|
...document.head.querySelectorAll(
|
|
412
|
-
`script[src="${cookieOptionalDisabled.src}"]
|
|
413
|
-
)
|
|
353
|
+
`script[src="${cookieOptionalDisabled.src}"]`
|
|
354
|
+
)
|
|
414
355
|
]) {
|
|
415
|
-
script.parentNode?.removeChild(script)
|
|
356
|
+
script.parentNode?.removeChild(script);
|
|
416
357
|
}
|
|
417
358
|
}
|
|
418
359
|
}
|
|
419
360
|
},
|
|
420
|
-
{ deep: true }
|
|
421
|
-
)
|
|
422
|
-
|
|
361
|
+
{ deep: true }
|
|
362
|
+
);
|
|
423
363
|
watch(isConsentGiven, (current, _previous) => {
|
|
424
|
-
if (current ===
|
|
425
|
-
cookieIsConsentGiven.value =
|
|
364
|
+
if (current === void 0) {
|
|
365
|
+
cookieIsConsentGiven.value = void 0;
|
|
426
366
|
} else {
|
|
427
|
-
cookieIsConsentGiven.value = current ? allCookieIdsString :
|
|
367
|
+
cookieIsConsentGiven.value = current ? allCookieIdsString : "0";
|
|
428
368
|
}
|
|
429
|
-
})
|
|
430
|
-
|
|
369
|
+
});
|
|
431
370
|
watch(
|
|
432
|
-
() =>
|
|
433
|
-
(
|
|
434
|
-
nuxtApp.$cookies.locale.value =
|
|
435
|
-
}
|
|
436
|
-
)
|
|
437
|
-
|
|
438
|
-
// initialization
|
|
439
|
-
init()
|
|
440
|
-
|
|
371
|
+
() => locale,
|
|
372
|
+
(locale2) => {
|
|
373
|
+
nuxtApp.$cookies.locale.value = locale2;
|
|
374
|
+
}
|
|
375
|
+
);
|
|
376
|
+
init();
|
|
441
377
|
defineExpose({
|
|
442
|
-
accept,
|
|
378
|
+
accept: acceptAll,
|
|
443
379
|
acceptPartial,
|
|
444
|
-
decline
|
|
445
|
-
})
|
|
380
|
+
decline: acceptNecessary
|
|
381
|
+
});
|
|
446
382
|
</script>
|