Completed
Pull Request — master (#230)
by
unknown
04:14 queued 01:51
created

script.js ➔ getCookieValue   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
1
import $ from 'jquery'
2
3
export function getOptions (optionContainer) {
0 ignored issues
show
Unused Code introduced by
The parameter optionContainer is not used and could be removed.

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.

Loading history...
4
    return {
5
      expireDays: 7,
6
      cookieName: 'cookies_accepted'
7
    }
8
  }
9
10
export function acceptCookies ($container, cookieName, expireDays) {
11
  return function (e) {
0 ignored issues
show
Unused Code introduced by
The parameter e is not used and could be removed.

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.

Loading history...
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