-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.js
More file actions
65 lines (59 loc) · 2.33 KB
/
main.js
File metadata and controls
65 lines (59 loc) · 2.33 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
jQuery(document).ready(function ($) {
var consentCategory = $('#example-plugin-content').data('consentcategory');
console.log("checking consent for category "+consentCategory);
/**
* cookie placing plugin can listen to consent change
*
*/
console.log("load plugin example");
document.addEventListener("wp_listen_for_consent_change", function (e) {
console.log('listen for consent events');
var changedConsentCategory = e.detail;
console.log(changedConsentCategory);
for (let key in changedConsentCategory) {
if (changedConsentCategory.hasOwnProperty(key)) {
if (key === consentCategory && changedConsentCategory[key] === 'allow') {
console.log("set "+consentCategory+" cookie on user actions");
activateConsent();
}
}
}
});
/**
* Or do stuff as soon as the consenttype is defined
*/
$(document).on("wp_consent_type_defined", activateMyCookies);
function activateMyCookies(consentData) {
console.log("check service");
if (wp_has_consent(consentCategory, 'service')) {
console.log("do "+consentCategory+" cookie stuff");
} else {
console.log("no "+consentCategory+" cookies please");
}
console.log("check category")
//your code here
if (wp_has_consent(consentCategory)) {
console.log("do "+consentCategory+" cookie stuff");
} else {
console.log("no "+consentCategory+" cookies please");
}
}
//check if we need to wait for the consenttype to be set
if (!window.waitfor_consent_hook) {
console.log("we don't have to wait for the consent type, we can check the consent level right away!");
if (wp_has_consent(consentCategory)) {
activateConsent();
console.log("set "+consentCategory+" stuff now!");
} else {
console.log("No "+consentCategory+" stuff please!");
}
}
/**
* Do stuff that normally would do stuff like tracking personal user data etc.
*/
function activateConsent() {
console.log("fire "+consentCategory);
$('#example-plugin-content .functional-content').hide();
$('#example-plugin-content .marketing-content').show();
}
});