PageSourceSearch

https://anantsoch.com/wp-content/plugins/cookieadmin-pro/assets/js/consent.js?ver=1.2.3

js anantsoch.com collected 2026-09-24 09:48:42 UTC 7,829 bytes, 259 lines download raw bytes

1(function(){
2	window.addEventListener('cookieadmin_before_consent_display', function(){
3		if(cookieadmin_pro_handle_gpc()){
4			cookieadmin_policy.hide_banner = true;
5		}
6	});
7	
8	// Handle click on blocked content to accept and show
9	document.addEventListener('click', function(e){
10		var blockedElement = e.target.closest('.cookieadmin-content-blocker');
11		if(blockedElement){			
12			const category = blockedElement.getAttribute('data-cookieadmin-category');
13			var preference = {};
14
15			if(cookieadmin_is_obj(cookieadmin_is_consent) && cookieadmin_is_consent.action){
16				preference = cookieadmin_is_consent.action;
17			}
18
19			if(category){
20
21				if(preference.reject && ((preference.reject === true) || (preference.reject === 'true'))){
22					preference = {};
23				}
24
25				preference[category] = 'true';
26				if(preference.functional && preference.marketing && preference.analytics){
27					preference = {accept : 'true'};
28				}
29				var gpc_message = cookieadmin_pro_vars.gpc_alert_load_content ? cookieadmin_pro_vars.gpc_alert_load_content : '';
30				if(cookieadmin_pro_set_consent(preference, 365, gpc_message)){
31					cookieadmin_pro_enable_blocked_content(preference);
32				}
33			}
34		}
35	});
36})()
37
38function cookieadmin_pro_set_consent(prefrenc, days, gpc_message = '') {
39	
40	// Handling GPC override, preventing GPC signal
41	if(cookieadmin_pro_vars && cookieadmin_pro_vars.respect_gpc){
42		if(!cookieadmin_pro_handle_set_gpc(gpc_message)){
43			return false;
44		}
45	}
46
47	const data = 'action=cookieadmin_pro_ajax_handler&cookieadmin_act=save_consent' +
48		'&cookieadmin_preference=' + encodeURIComponent(JSON.stringify(Object.keys(prefrenc)));
49
50
51	let payload = data;
52	if (cookieadmin_is_obj(cookieadmin_is_consent) && !!cookieadmin_is_consent.consent) {
53		payload += '&cookieadmin_consent_id=' + cookieadmin_is_consent.consent;
54	}
55
56	// Make async request — don't block or wait
57	const xhttp = new XMLHttpRequest();
58
59	xhttp.open('POST', cookieadmin_pro_vars.ajax_url, true); // true = async
60
61	xhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
62
63	xhttp.onload = function () {
64		if(this.status === 200){
65			try {
66				const parsed = JSON.parse(this.responseText);
67				if (parsed.success && parsed.data && parsed.data.response) {
68					cookieadmin_save_consent_cookie(prefrenc, days, parsed.data.response);
69					
70					// Showing override option if we have GPC enabled.
71					if(cookieadmin_pro_vars && cookieadmin_pro_vars.respect_gpc){
72						var overrideEle = document.getElementById('cookieadmin_gpc_override');
73						
74						if(overrideEle){
75							overrideEle.style.display = 'block';
76						}
77					}
78
79					// Enable blocked content after consent
80					cookieadmin_pro_enable_blocked_content(prefrenc);
81				}
82			} catch (e) {
83				console.error("Invalid JSON response:", e);
84			}
85		}
86	};
87
88	xhttp.onerror = function () {
89		console.error("AJAX request failed");
90	};
91
92	xhttp.send(payload);
93
94	// Immediately return
95	return true;
96}
97
98function cookieadmin_pro_enable_blocked_content(prefrenc){
99	const blockedElements = document.querySelectorAll('.cookieadmin-content-blocker');
100	
101	blockedElements.forEach(function(element){
102		const category = element.getAttribute('data-cookieadmin-category');
103		
104		if(!category){
105			return;
106		}
107
108		// Check if user has consented to this category
109		const hasCategoryConsent = prefrenc.hasOwnProperty(category) && (prefrenc[category] === true || prefrenc[category] === 'true');
110		
111		// Check if user accepted all (accept: true means all categories)
112		const hasAcceptAll = prefrenc.hasOwnProperty('accept') && (prefrenc.accept === true || prefrenc.accept === 'true');
113		
114		if(hasCategoryConsent || hasAcceptAll){
115			cookieadmin_pro_replace_blocked_element(element);
116		}
117	});
118}
119
120function cookieadmin_pro_replace_blocked_element(element){
121	const placeholder = element;
122	
123
124	const iframe = placeholder.getElementsByTagName('iframe')[0];
125	if(iframe && iframe.dataset.cookieadminSrc){
126		iframe.src = iframe.dataset.cookieadminSrc;
127		iframe.removeAttribute('data-cookieadmin-src');
128	}
129
130	placeholder.parentNode.replaceChild(iframe, placeholder);
131}
132
133// Decided if GPC is enabled and if user has enabled the override when saving preference
134function cookieadmin_pro_handle_set_gpc(message){
135	var consentData = cookieadmin_is_cookie("cookieadmin_consent");
136	if (consentData && consentData.respect_gpc) {
137		var override = document.getElementById('cookieadmin-override_gpc');
138		
139		if(!override || !override.checked){
140			alert(message ? message : (cookieadmin_pro_vars.gpc_alert ? cookieadmin_pro_vars.gpc_alert : 'Please accept override GPC before saving preference.'));
141			return false;
142		}
143	}
144
145	return true;
146}
147
148// GPC (Global Privacy Control) Detection and Handling
149function cookieadmin_pro_check_gpc(){
150	// Check if respect_gpc setting is enabled
151	if(!cookieadmin_pro_vars || !cookieadmin_pro_vars.respect_gpc){
152		return false;
153	}
154
155	// Check navigator.globalPrivacyControl property (browser-level GPC signal)
156	if(typeof navigator !== 'undefined' && typeof navigator.globalPrivacyControl !== 'undefined'){
157		if(navigator.globalPrivacyControl === true || navigator.globalPrivacyControl === 'true'){
158			return true;
159		}
160	}
161
162	// Check if GPC was detected server-side (Sec-GPC header)
163	if(cookieadmin_pro_vars && cookieadmin_pro_vars.gpc_enabled){
164		return true;
165	}
166
167	return false;
168}
169
170function cookieadmin_pro_handle_gpc(){
171	// Check if GPC is enabled and should be respected
172	if(!cookieadmin_pro_check_gpc()){
173		return false;
174	}
175	
176	// Handling visibility of Override option in Cookie Customizer modal
177	var overRideEle = document.getElementById('cookieadmin_gpc_override');
178	var consentData = cookieadmin_is_cookie("cookieadmin_consent");
179
180	if(overRideEle){
181		overRideEle.style.display = (consentData && consentData.respect_gpc === true) ? '' : 'none';
182	}
183
184	// Check if consent was already saved
185	if(consentData){
186		return false;
187	}
188
189	// Apply auto-reject consent for GPC users
190	// Only allow necessary/functional cookies, reject analytics and marketing
191	const gpc_preferences = {
192		'functional': true,
193		'respect_gpc': true,
194	};
195
196	// Set consent for 365 days
197	cookieadmin_pro_set_consent(gpc_preferences, 365);
198
199	// Show GPC honored message if banner element exists
200	cookieadmin_pro_show_gpc_message();
201
202	return true;
203}
204
205function cookieadmin_pro_show_gpc_message() {
206	
207	var toast = document.getElementById('cookieadmin-gpc-toast');
208    
209	if(!toast){
210		return;
211	}
212	
213	closeBtn = toast.querySelector('button');
214	
215	if(!closeBtn){
216		return;
217	}
218	
219	// Add hover effects for the close button
220	closeBtn.addEventListener('mouseenter', () => closeBtn.style.opacity = '1');
221	closeBtn.addEventListener('mouseleave', () => closeBtn.style.opacity = '0.7');
222
223	// Add click event to remove the toast with a fade-out animation
224	closeBtn.addEventListener('click', () => {
225		toast.style.opacity = '0';
226		toast.style.transform = 'translateY(20px)';
227		toast.style.transition = 'opacity 0.3s ease, transform 0.3s ease, visibility 0s 0.3s';
228		toast.style.visibility = 'hidden';
229		setTimeout(() => {
230			if (document.body.contains(toast)) {
231				document.body.removeChild(toast);
232			}
233		}, 300); // Wait for transition to finish
234	});
235
236	// Trigger the fade-in animation
237	requestAnimationFrame(() => {
238		toast.style.visibility = 'visible';
239		toast.style.opacity = '1';
240		toast.style.transform = 'translateY(0)';
241		toast.style.transition = 'opacity 0.3s ease, transform 0.3s ease, visibility 0s';
242	});
243
244	// Auto-hide after 10 seconds
245	setTimeout(() => {
246		if(document.body.contains(toast)){
247			toast.style.opacity = '0';
248			toast.style.transform = 'translateY(20px)';
249			toast.style.transition = 'opacity 0.3s ease, transform 0.3s ease, visibility 0s 0.3s';
250			toast.style.visibility = 'hidden';
251			setTimeout(() => {
252				if (document.body.contains(toast)) {
253					document.body.removeChild(toast);
254				}
255			}, 300);
256		}
257	}, 10000);
258}
259

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.