GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( c7377c...b42d2f )
by Christian
04:24
created

assets/js/gdpr.js   A

Complexity

Total Complexity 19
Complexity/F 1.73

Size

Lines of Code 106
Function Count 11

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 19
eloc 59
dl 0
loc 106
rs 10
c 0
b 0
f 0
cc 0
nc 1
mnd 2
bc 19
fnc 11
bpm 1.7272
cpm 1.7272
noi 1

3 Functions

Rating   Name   Duplication   Size   Complexity  
A gdpr.js ➔ jQuery 0 3 1
B jQuery.fn.gdprCookieLawPopup 0 92 1
B 0 96 1
1
import jQuery from 'jquery';
2
3
// Styles
4
import '../css/gdpr.css';
5
6
(function (jQuery) {
7
  "use strict";
8
9
  jQuery.fn.gdprCookieLawPopup = (function () {
10
    const _self = this;
11
12
    _self.params = {
13
      agreementExpiresInDays: 30,
14
      autoAcceptCookiePolicy: false
15
    };
16
17
    _self.vars = {
18
      INITIALISED: false,
19
      COOKIE_NAME: 'GDPR_COOKIE_LAW_CONSENT'
20
    };
21
22
    // Overwrite default parameters if any of those is present
23
    const parseParameters = function (settings) {
24
      if (settings) {
25
        if (typeof settings.agreementExpiresInDays !== 'undefined') {
26
          _self.params.agreementExpiresInDays = settings.agreementExpiresInDays;
27
        }
28
        if (typeof settings.autoAcceptCookiePolicy !== 'undefined') {
29
          _self.params.autoAcceptCookiePolicy = settings.autoAcceptCookiePolicy;
30
        }
31
      }
32
    };
33
34
    // Storing the consent in a cookie
35
    const setUserAcceptsCookies = function (consent) {
36
      let d = new Date();
37
      const expiresInDays = _self.params.agreementExpiresInDays * 24 * 60 * 60 * 1000;
38
      d.setTime(d.getTime() + expiresInDays);
39
      const expires = "expires=" + d.toGMTString();
40
      document.cookie = _self.vars.COOKIE_NAME + '=' + consent + "; " + expires + ";path=/";
41
    };
42
43
    // Let's see if we have a consent cookie already
44
    const userAlreadyAcceptedCookies = function () {
45
      let userAcceptedCookies = false;
46
      const cookies = document.cookie.split(";");
47
      for (let i = 0; i < cookies.length; i++) {
48
        const c = cookies[i].trim();
49
        if (c.indexOf(_self.vars.COOKIE_NAME) == 0) {
0 ignored issues
show
Best Practice introduced by
Comparing c.indexOf(_self.vars.COOKIE_NAME) to 0 using the == operator is not safe. Consider using === instead.
Loading history...
50
          userAcceptedCookies = c.substring(_self.vars.COOKIE_NAME.length + 1, c.length);
51
        }
52
      }
53
54
      return userAcceptedCookies;
55
    };
56
57
    const hideContainer = function () {
58
      jQuery('.gdprpopup-container').animate({
59
        opacity: 0,
60
        height: 0
61
      }, 200, function () {
62
        jQuery('.gdprpopup-container').hide(0);
63
      });
64
    };
65
66
    return {
67
      init: function (settings) {
68
        parseParameters(settings);
69
70
        // No need to display this if user already accepted the policy
71
        if (userAlreadyAcceptedCookies()) {
72
          return;
73
        }
74
75
        // We should initialise only once
76
        if (_self.vars.INITIALISED) {
77
          return;
78
        }
79
        _self.vars.INITIALISED = true;
80
81
        jQuery('.gdprpopup-button-confirm').click(function () {
82
          setUserAcceptsCookies(true);
83
          hideContainer();
84
          return false;
85
        });
86
        jQuery('.gdprpopup-closebutton').click(function () {
87
          hideContainer();
88
          return false;
89
        });
90
91
        // Ready to start!
92
        jQuery('.gdprpopup-container').show();
93
94
        // In case it's alright to just display the message once
95
        if (_self.params.autoAcceptCookiePolicy) {
96
          setUserAcceptsCookies(true);
97
        }
98
      }
99
    };
100
  });
101
}(jQuery));
102
103
104
jQuery(function () {
105
  jQuery(document).gdprCookieLawPopup().init();
106
});
107