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   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 96
Code Lines 54

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 54
dl 0
loc 96
rs 8.5054
c 0
b 0
f 0
cc 1
nc 1
nop 1

1 Function

Rating   Name   Duplication   Size   Complexity  
B jQuery.fn.gdprCookieLawPopup 0 92 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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