-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcookie-customization.js
More file actions
87 lines (72 loc) · 3.4 KB
/
cookie-customization.js
File metadata and controls
87 lines (72 loc) · 3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
if (jQuery) {
$ = jQuery;
const {
YES_LABEL = 'Acconsento',
NO_LABEL = 'No',
PRIVACY_POLICY_LABEL = 'Privacy policy',
PRIVACY_POLICY_URL = '/privacy-policy/',
PRIVACY_POLICY_CLASS = 'btn btn-xs btn-default',
YES_CLASS = 'btn btn-xs btn-primary',
YES_BACKGROUND = '#337ab7', // #09c8ee
MAX_SECONDS_TRYING = 5,
HIDE_NO_BUTTON = true, // true/false
ACCEPT_AFTER_SCROLLING = 0.25, // % of page OR true/false
ACCEPT_BEFORE_FORM_SUBMIT = true // true/false
} = typeof CookieCustomizationOptions !== 'undefined' ? CookieCustomizationOptions : {};
$(function(){
let i = 0;
let pardotDeniedConsent = window.localStorage.getItem('pardot-denied-consent') || false;
const pardotDenyConsent = () => {
window.localStorage.setItem('pardot-denied-consent', true);
pardotDeniedConsent = true;
};
const INTERVAL_MILLISECONDS_STEP = 500;
const interval = setInterval(() => {
i++;
const yesBtn = $('a[onclick^=piEnableTracking]');
const noBtn = $('a[onclick^=piDisableTracking]');
const cookieBarInitialized = yesBtn.length > 0 && noBtn.length > 0;
if (cookieBarInitialized) {
const container = yesBtn.parent('div');
const privacyPolicyBtn = $(` <a>${PRIVACY_POLICY_LABEL}</a>`)
.addClass(PRIVACY_POLICY_CLASS)
.attr('target', '_blank')
.attr('href', PRIVACY_POLICY_URL);
container.find('div').detach(); // tolgo il div vuoto alla fine
container.append(privacyPolicyBtn); // aggiunto il link alla privacy policy
yesBtn
.css({
'background': YES_BACKGROUND,
'margin-left': '5px',
})
.text(YES_LABEL)
.addClass(YES_CLASS); // stilizzo il bottone 'yes' per renderlo piú visibile
noBtn.text(NO_LABEL).click(pardotDenyConsent);
if (HIDE_NO_BUTTON) noBtn.detach();
const responsiveClearfix = $('<div></div>')
.addClass('clearfix visible-xs');
responsiveClearfix.insertBefore(yesBtn);
const acceptCookies = (evt, element) => {
if (!pardotDeniedConsent) yesBtn.click();
$(element).off(evt); // stacco l'evento dopo aver cliccato su si
};
if (ACCEPT_AFTER_SCROLLING !== undefined && ACCEPT_AFTER_SCROLLING !== false) {
$(window).on('scroll', function (evt) {
if ($(window).scrollTop() >= (($(document).height() - $(window).height()) * ACCEPT_AFTER_SCROLLING)) {
acceptCookies(evt, window);
}
});
}
if (ACCEPT_BEFORE_FORM_SUBMIT) {
$(document).on('submit', 'form', (evt) => {
acceptCookies(evt, 'form');
});
}
}
if( ( cookieBarInitialized ) ||
i > (MAX_SECONDS_TRYING * 1000 / INTERVAL_MILLISECONDS_STEP) ) {
clearInterval(interval);
}
}, INTERVAL_MILLISECONDS_STEP);
});
}