@dargmuesli/nuxt-cookie-control 1.9.9 → 2.0.0-beta.1

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.
Files changed (47) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +206 -285
  3. package/dist/module.cjs +5 -0
  4. package/dist/module.d.ts +2 -0
  5. package/dist/module.json +8 -0
  6. package/dist/module.mjs +6 -0
  7. package/dist/runtime/components/CookieControl.vue +274 -0
  8. package/dist/runtime/components/CookieIframe.vue +39 -0
  9. package/dist/runtime/composables.ts +1 -0
  10. package/dist/runtime/constants.ts +3 -0
  11. package/dist/runtime/locale/ar.ts +19 -0
  12. package/dist/runtime/locale/de.ts +20 -0
  13. package/dist/runtime/locale/en.ts +19 -0
  14. package/{locale/es.js → dist/runtime/locale/es.ts} +19 -15
  15. package/dist/runtime/locale/fr.ts +19 -0
  16. package/dist/runtime/locale/hr.ts +20 -0
  17. package/dist/runtime/locale/hu.ts +20 -0
  18. package/dist/runtime/locale/index.ts +16 -0
  19. package/{locale/it.js → dist/runtime/locale/it.ts} +19 -15
  20. package/dist/runtime/locale/ja.ts +19 -0
  21. package/dist/runtime/locale/nl.ts +20 -0
  22. package/dist/runtime/locale/no.ts +20 -0
  23. package/dist/runtime/locale/pt.ts +20 -0
  24. package/dist/runtime/locale/ru.ts +19 -0
  25. package/dist/runtime/locale/uk.ts +19 -0
  26. package/dist/runtime/methods.ts +190 -0
  27. package/dist/runtime/plugin.ts +35 -0
  28. package/dist/runtime/styles.css +347 -0
  29. package/dist/runtime/types.ts +132 -0
  30. package/dist/types.d.ts +13 -0
  31. package/package.json +63 -21
  32. package/components/CookieControl.vue +0 -182
  33. package/components/CookieIframe.vue +0 -32
  34. package/lib/module.js +0 -74
  35. package/lib/plugin.js +0 -206
  36. package/lib/postinstall.js +0 -1
  37. package/lib/styles.scss +0 -434
  38. package/locale/de.js +0 -15
  39. package/locale/en.js +0 -15
  40. package/locale/fr.js +0 -15
  41. package/locale/hr.js +0 -15
  42. package/locale/hu.js +0 -15
  43. package/locale/ja.js +0 -15
  44. package/locale/no.js +0 -16
  45. package/locale/pt.js +0 -15
  46. package/locale/ru.js +0 -15
  47. package/locale/uk.js +0 -15
package/package.json CHANGED
@@ -1,11 +1,9 @@
1
1
  {
2
2
  "name": "@dargmuesli/nuxt-cookie-control",
3
- "version": "1.9.9",
3
+ "version": "2.0.0-beta.1",
4
4
  "description": "Nuxt Cookies Control Module",
5
- "license": "MIT",
6
5
  "author": "Dario Ferderber <dario.ferderber@broj42.com>",
7
- "contributors": [
8
- "Davor Teskera",
6
+ "maintainers": [
9
7
  "Jonas Thelemann"
10
8
  ],
11
9
  "keywords": [
@@ -14,29 +12,73 @@
14
12
  "nuxt cookie consent",
15
13
  "nuxt gdpr consent"
16
14
  ],
17
- "main": "lib/module.js",
18
- "repository": "https://gitlab.com/dargmuesli/nuxt-cookie-control",
19
- "publishConfig": {
20
- "access": "public"
15
+ "repository": "https://github.com/dargmuesli/nuxt-cookie-control",
16
+ "license": "MIT",
17
+ "type": "module",
18
+ "exports": {
19
+ ".": {
20
+ "import": "./dist/module.mjs",
21
+ "require": "./dist/module.cjs"
22
+ }
21
23
  },
22
- "eslintIgnore": [
23
- "*"
24
+ "main": "./dist/module.cjs",
25
+ "types": "./dist/module.d.ts",
26
+ "files": [
27
+ "dist/**/*",
28
+ "src/components",
29
+ "src/locale"
24
30
  ],
25
31
  "scripts": {
26
- "postinstall": "node lib/postinstall.js"
32
+ "build": "nuxt-module-build",
33
+ "dev": "nuxi dev playground",
34
+ "dev:build": "nuxi build playground",
35
+ "lint": "eslint --ext .js,.ts,.vue . && nuxi typecheck playground",
36
+ "prepack": "npm run build",
37
+ "prepare": "nuxt-module-build --stub && nuxi prepare playground",
38
+ "release": "release-it"
27
39
  },
28
- "files": [
29
- "lib",
30
- "components",
31
- "locale"
32
- ],
33
40
  "dependencies": {
34
- "css-vars-ponyfill": "^2.4.7",
35
- "sass": "^1.43.4",
36
- "sass-loader": "^10.2.0",
37
- "string-replace-loader": "^2.3.0"
41
+ "@nuxt/kit": "3.0.0",
42
+ "css-vars-ponyfill": "2.4.8",
43
+ "js-cookie": "3.0.1",
44
+ "slugify": "1.6.5",
45
+ "string-replace-loader": "3.1.0"
46
+ },
47
+ "devDependencies": {
48
+ "@nuxt/module-builder": "0.2.1",
49
+ "@nuxtjs/eslint-config-typescript": "12.0.0",
50
+ "@release-it/conventional-changelog": "5.1.1",
51
+ "@types/js-cookie": "3.0.2",
52
+ "eslint": "8.29.0",
53
+ "eslint-config-prettier": "8.5.0",
54
+ "eslint-plugin-prettier": "4.2.1",
55
+ "husky": "8.0.2",
56
+ "lint-staged": "13.1.0",
57
+ "nuxt": "3.0.0",
58
+ "prettier": "2.8.0",
59
+ "release-it": "15.5.1",
60
+ "typescript": "4.9.3",
61
+ "vite": "3.2.5",
62
+ "vue": "3.2.45",
63
+ "vue-tsc": "1.0.11",
64
+ "webpack": "5.75.0"
38
65
  },
39
66
  "peerDependencies": {
40
- "webpack": "^4"
67
+ "vite": "^3",
68
+ "webpack": "^5"
69
+ },
70
+ "peerDependenciesMeta": {
71
+ "vite": {
72
+ "optional": true
73
+ },
74
+ "webpack": {
75
+ "optional": true
76
+ }
77
+ },
78
+ "resolutions": {
79
+ "@dargmuesli/nuxt-cookie-control": "link:./"
80
+ },
81
+ "publishConfig": {
82
+ "access": "public"
41
83
  }
42
84
  }
@@ -1,182 +0,0 @@
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>
@@ -1,32 +0,0 @@
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 DELETED
@@ -1,74 +0,0 @@
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')
package/lib/plugin.js DELETED
@@ -1,206 +0,0 @@
1
- import Vue from 'vue';
2
- import CookieControl from <%= serialize(options.component) %>;
3
- import CookieIframe from <%= serialize(options.iframe) %>;
4
- export default(context, inject) =>{
5
- let cookies = {
6
- modal: false,
7
- consent: false,
8
- enabled: [],
9
- enabledList: [],
10
- optional: []
11
- }
12
-
13
- Object.assign(cookies, <%= serialize(options) %>);
14
- if(<%= serialize(options.colors) %> !== false){
15
- cookies.colors = {
16
- barTextColor: '#fff',
17
- modalOverlay: '#000',
18
- barBackground: '#000',
19
- barButtonColor: '#000',
20
- modalTextColor: '#000',
21
- modalBackground: '#fff',
22
- modalOverlayOpacity: 0.8,
23
- modalButtonColor: '#fff',
24
- modalUnsavedColor: '#fff',
25
- barButtonHoverColor: '#fff',
26
- barButtonBackground: '#fff',
27
- modalButtonHoverColor: '#fff',
28
- controlButtonIconColor: '#000',
29
- modalButtonBackground: '#000',
30
- controlButtonBackground: '#fff',
31
- barButtonHoverBackground: '#333',
32
- checkboxActiveBackground: '#000',
33
- controlButtonIconHoverColor: '#fff',
34
- checkboxInactiveBackground: '#000',
35
- modalButtonHoverBackground: '#333',
36
- checkboxDisabledBackground: '#ddd',
37
- controlButtonHoverBackground: '#000',
38
- checkboxActiveCircleBackground: '#fff',
39
- checkboxInactiveCircleBackground: '#fff',
40
- checkboxDisabledCircleBackground: '#fff',
41
- };
42
- Object.assign(cookies.colors, <%= serialize(options.colors) %>);
43
- }
44
-
45
- let methods = {
46
- get: (cookie) => {
47
- if(process.browser){
48
- let decodedCookie = decodeURIComponent(document.cookie);
49
- let ca = decodedCookie.split(';');
50
- let name = `${cookie}=`;
51
- for(let i = 0; i <ca.length; i++) {
52
- let c = ca[i];
53
- while (c.charAt(0) == ' ') {
54
- c = c.substring(1);
55
- }
56
- if (c.indexOf(name) == 0) {
57
- return c.substring(name.length, c.length);
58
- }
59
- }
60
- }
61
- return '';
62
- },
63
-
64
- set: ({name, value='', expires='', path='/', domain}) => {
65
- let domainName = domain ? domain : cookies.domain ? `.${cookies.domain}` : domain;
66
- if(process.browser){
67
- document.cookie = `${name}=${value};expires=${expires};path=${path}${domainName !== undefined ? `;domain=${domainName}` : ';'}`;
68
- } else if(process.server){
69
- context.res.setHeader('Set-Cookie', [`${name}=${value}; Expires=${expires}; Path=${path}${domainName !== undefined ? `; Domain=${domainName}` : ';'}`]);
70
- }
71
- },
72
-
73
- isEnabled: (identifier) => {
74
- return cookies.enabledList.includes(identifier) || cookies.enabledList.includes(cookies.slugify(identifier))
75
- },
76
-
77
- setBlockedIframes: (content) =>{
78
- let type = (typeof(content)).toLowerCase();
79
- let c = type !== 'string' ? JSON.stringify(content) : content;
80
- c = c.replace(/&lt;/g, '<');
81
- c = c.replace(/&gt;/g, '>');
82
- if(context.app.$cookies.enabled.filter(c =>{return c.name === 'functional'}).length === 0){
83
- c = c.replace(/<iframe/g, `<div class='cookieControl__BlockedIframe '`);
84
- c = c.replace(/<\/iframe/g, `<p>${context.app.$cookies.text.blockedIframe !== undefined ? context.app.$cookies.text.blockedIframe : ''} <a href='#' onclick='event.preventDefault(); $${cookies.globalName}.$cookies.modal = true'>${context.app.$cookies.text.here !== undefined ? context.app.$cookies.text.here: ''}</a></p></div`);
85
- }
86
- return type !== 'string' ? JSON.parse(c) : c
87
- },
88
-
89
- slugify: (str) =>{
90
- str = str.replace(/^\s+|\s+$/g, '');
91
- str = str.toLowerCase();
92
- let from = "ÁÄÂÀÃÅČÇĆĎÉĚËÈÊẼĔȆÍÌÎÏŇÑÓÖÒÔÕØŘŔŠŤÚŮÜÙÛÝŸŽáäâàãåčçćďéěëèêẽĕȇíìîïňñóöòôõøðřŕšťúůüùûýÿžþÞĐđ߯a·/_,:;";
93
- let to = "AAAAAACCCDEEEEEEEEIIIINNOOOOOORRSTUUUUUYYZaaaaaacccdeeeeeeeeiiiinnooooooorrstuuuuuyyzbBDdBAa------";
94
- for (let i = 0, l = from.length; i < l ; i++){
95
- str = str.replace(new RegExp(from.charAt(i), 'g'), to.charAt(i));
96
- }
97
-
98
- str = str.replace(/[^a-z0-9 -]/g, '').replace(/\s+/g, '-').replace(/-+/g, '-');
99
-
100
- return str;
101
- },
102
-
103
- remove: (name) =>{
104
- if(process.browser){
105
- let domain = window.location.hostname;
106
- cookies.set({name, expires: 'Thu, 01 Jan 1970 00:00:00 GMT', domain });
107
- for (let j = domain.split('.'); j.length;) {
108
- let o = j.join('.');
109
- cookies.set({name, expires: 'Thu, 01 Jan 1970 00:00:00 GMT', domain: `.${o}` });
110
- j.shift();
111
- }
112
- }
113
- },
114
-
115
- setConsent: (isInit=false) =>{
116
- cookies.consent = cookies.get('cookie_control_consent') === 'true' ? true : false;
117
- cookies.enabled = [];
118
- cookies.enabledList = [];
119
- if(cookies.consent === true){
120
- let enabledFromCookie = cookies.get('cookie_control_enabled_cookies');
121
- cookies.enabled.push(...cookies.optional.filter(c => {
122
- let cookieName = typeof(c.name) === 'string' ? c.name : c.name[Object.keys(c.name)[0]]
123
- return enabledFromCookie.includes(c.identifier || cookies.slugify(cookieName))
124
- }));
125
- cookies.enabledList = cookies.enabled.length > 0 ? cookies.enabled.map(c => {
126
- let cookieName = typeof(c.name) === 'string' ? c.name : c.name[Object.keys(c.name)[0]]
127
- return c.identifier || cookies.slugify(cookieName)
128
- }) : [];
129
- }
130
-
131
- if(cookies.necessary) cookies.enabled.push(...cookies.necessary.filter(c => {return c.src || c.accepted}))
132
-
133
- if(process.client && !isInit){
134
- setHead();
135
- clearCookies();
136
- callAcceptedFunctions();
137
- }
138
- }
139
- }
140
-
141
- Object.assign(cookies, methods);
142
-
143
- const clearCookies = () =>{
144
- let disabled = cookies.optional.filter(c => {
145
- let cookieName = typeof(c.name) === 'string' ? c.name : c.name[Object.keys(c.name)[0]]
146
- return !cookies.enabledList.includes(c.identifier || cookies.slugify(cookieName))
147
- });
148
- if(disabled.length > 0){
149
- disabled.forEach(c => {
150
- if(c.declined) c.declined();
151
- if(c.cookies && c.cookies.length > 0){
152
- c.cookies.forEach(i => {
153
- cookies.remove(i);
154
- })
155
- }
156
- // if(c.src){
157
- // for(let s of [...document.head.querySelectorAll(`script[src="${c.src}"]`)]){
158
- // s.parentNode.removeChild(s)
159
- // }
160
- // }
161
- })
162
- }
163
- }
164
-
165
- const setHead = () =>{
166
- if(cookies.enabled.length > 0){
167
- let head = document.getElementsByTagName('head')[0];
168
- cookies.enabled.forEach(c =>{
169
- if(c.src){
170
- let script = document.createElement('script');
171
- script.src = c.src;
172
- head.appendChild(script);
173
- script.addEventListener('load', () =>{
174
- if(c.accepted) c.accepted();
175
- })
176
- }
177
- })
178
- }
179
- }
180
-
181
- const callAcceptedFunctions = () =>{
182
- if(cookies.enabled.length > 0){
183
- cookies.enabled.forEach(c =>{
184
- if(c.accepted) c.accepted();
185
- })
186
- }
187
- }
188
-
189
- const capitalize = (s) =>{
190
- if(typeof s !== 'string') return ''
191
- return s.charAt(0).toUpperCase() + s.slice(1)
192
- }
193
-
194
- cookies.setConsent(true)
195
-
196
- if(process.client){
197
- let globalName = capitalize(cookies.globalName) || 'Nuxt';
198
- window[`on${globalName}Ready`](() => {
199
- cookies.setConsent()
200
- })
201
- }
202
-
203
- inject('cookies', cookies);
204
- if(cookies.blockIframe) Vue.component('CookieIframe', CookieIframe);
205
- Vue.component('CookieControl', CookieControl);
206
- }
@@ -1 +0,0 @@
1
- console.log('\nThank you for using nuxt-cookie-control!\nPlease consider supporting: https://ko-fi.com/darioferderber\n')