Total Complexity | 5 |
Complexity/F | 1.67 |
Lines of Code | 33 |
Function Count | 3 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | /* global wpData, Cookies */ |
||
3 | import $ from 'jquery' |
||
4 | import 'file-loader?name=vendor/js-cookie.js!js-cookie/src/js.cookie' |
||
5 | |||
6 | const $gaOptoutLinks = $('.globalAction-optoutGa') |
||
7 | const data = wpData |
||
8 | |||
9 | const alreadyOptedOut = getOptoutCookie() |
||
10 | |||
11 | if (alreadyOptedOut) { |
||
12 | $gaOptoutLinks.remove() |
||
13 | window['ga-disable-' + data.gaId] = true |
||
14 | } else { |
||
15 | $gaOptoutLinks.on('click', function (e) { |
||
16 | e.preventDefault() |
||
17 | |||
18 | const confirmOptout = window.confirm(data.confirm) |
||
19 | |||
20 | if (confirmOptout) { |
||
21 | window['ga-disable-' + data.gaId] = true |
||
22 | window.alert(data.success) |
||
23 | setOptoutCookie() |
||
24 | } |
||
25 | }) |
||
26 | } |
||
27 | |||
28 | function setOptoutCookie () { |
||
29 | Cookies.set('disableGa', true) |
||
30 | $gaOptoutLinks.remove() |
||
31 | } |
||
32 | |||
33 | function getOptoutCookie () { |
||
34 | return Cookies.get('disableGa') |
||
35 | } |
||
36 |