Total Complexity | 7 |
Complexity/F | 1.4 |
Lines of Code | 40 |
Function Count | 5 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | import $ from 'jquery' |
||
2 | |||
3 | export function getOptions (optionContainer) { |
||
|
|||
4 | return { |
||
5 | expireDays: 7, |
||
6 | cookieName: 'cookies_accepted' |
||
7 | } |
||
8 | } |
||
9 | |||
10 | export function acceptCookies ($container, cookieName, expireDays) { |
||
11 | return function (e) { |
||
12 | const date = new Date() |
||
13 | date.setTime(date.getTime() + (expireDays*24*60*60*1000)) |
||
14 | document.cookie = cookieName + "=true; expires=" + date.toGMTString() |
||
15 | |||
16 | $container.remove() |
||
17 | } |
||
18 | } |
||
19 | |||
20 | export function checkCookies ($container, cookieName) { |
||
21 | const cookiesAccepted = getCookieValue(cookieName) |
||
22 | |||
23 | if (!cookiesAccepted) { |
||
24 | $container.addClass('cookieNotification-isVisible') |
||
25 | } else { |
||
26 | $container.remove() |
||
27 | } |
||
28 | } |
||
29 | |||
30 | |||
31 | |||
32 | function getCookieValue (cookie) { |
||
33 | const value = "; " + document.cookie |
||
34 | const parts = value.split('; ' + cookie + '=') |
||
35 | if (parts.length == 2) { |
||
36 | return parts.pop().split(';').shift() |
||
37 | } else { |
||
38 | return false |
||
39 | } |
||
40 | } |
||
41 |
This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.