PageSourceSearch

https://pepiniere-ellebore.com/plugins/system/cookiesck/assets/front.js?ver=3.3.4

js pepiniere-ellebore.com collected 2026-10-08 08:15:03 UTC 17,506 bytes, 468 lines download raw bytes

1(function() {
2
3	"use strict";
4
5	var opts;
6
7	var Cookiesck = function (options) {
8		//set default options  
9		var defaults = {
10			lifetime: ''
11			,layout: ''
12			,reload: ''
13		};
14
15		if (!(this instanceof Cookiesck)) return new Cookiesck(options);
16
17		opts = Object.assign(defaults, options);
18
19		initHtml();
20		initInterface();
21		initEvents();
22		initIframes();
23	}
24
25	function initHtml() {
26		// remove the banner from the page if exists
27		let banner = document.getElementById('cookiesck');
28		if (banner) banner.remove();
29
30		// create the banner in the page
31		banner = document.createElement('div');
32		banner.id = 'cookiesck';
33		banner.setAttribute('data-layout', opts.layout);
34		banner.innerHTML = createBannerHtml();
35		document.body.appendChild(banner);
36
37		// create the overlay
38		let overlay = document.createElement('div');
39		overlay.id = 'cookiesck_overlay';
40		document.body.appendChild(overlay);
41
42		// create the overlay
43		let options = document.createElement('div');
44		options.id = 'cookiesck_options';
45		options.innerHTML = '<div class="inner">' + COOKIESCK.TEXT.OPTIONS + '</div>';
46		document.body.appendChild(options);
47	}
48
49	function createBannerHtml() {
50		let html = '<div class="inner">'
51			+ '<span id="cookiesck_text">' + COOKIESCK.TEXT.INFO + '</span>'
52			+ '<span id="cookiesck_buttons">'
53				+ '<a class="cookiesck_button" id="cookiesck_accept">' + COOKIESCK.TEXT.ACCEPT_ALL + '</a>'
54				+ '<a class="cookiesck_button" id="cookiesck_decline">' + COOKIESCK.TEXT.DECLINE_ALL + '</a>'
55				+ '<a class="cookiesck_button" id="cookiesck_settings">' + COOKIESCK.TEXT.SETTINGS + '</a>'
56				+ '<div style="clear:both;"></div>'
57			+ '</div>'
58			
59			+ '</div>';
60
61		return html;
62	}
63
64	function initInterface() {
65		let cookie = readCookie('cookiesck');
66		document.getElementById('cookiesck').style.display = 'none';
67		document.getElementById('cookiesck_overlay').style.display = 'none';
68		// cookies not set, display the bar
69		if(cookie == null) {
70			document.getElementById('cookiesck').style.display = 'block';
71			document.getElementById('cookiesck_overlay').style.display = 'block';
72		} else {
73			COOKIESCK.VALUE = decodeURIComponent(decodeURIComponent(cookie));
74			debug('COOKIESCK.VALUE : ' + COOKIESCK.VALUE);
75		}
76
77		var cookieArray = toObject();
78		let interfac = document.getElementById('cookiesck_interface');
79		let platforms = interfac.querySelectorAll('.cookiesck-platform');
80		debug('platforms :');
81		debug(platforms);
82		platforms.forEach(function(platform) {
83			let platformName = platform.getAttribute('data-platform');
84			let buttons = platform.querySelectorAll('.cookiesck_button');
85
86			buttons.forEach(function(button) {
87				button.onclick = function() {
88					if (this.classList.contains('cookiesck-accept')) {
89						doAction(this, 'accept');
90					} else {
91						doAction(this, 'decline');
92					}
93					interfac.querySelectorAll('.cookiesck-main-buttons .cookiesck_button').forEach(function(btn) { btn.classList.remove('cookiesck-active'); });
94					highlightAllButton();
95				}
96			});
97
98			// set active button
99			if (cookieArray[platformName]) {
100				if (cookieArray[platformName] == 1) {
101					platform.querySelector('.cookiesck-accept').classList.add('cookiesck-active');
102				} else {
103					platform.querySelector('.cookiesck-decline').classList.add('cookiesck-active');
104				}
105			}
106		});
107
108		if (COOKIESCK.VALUE === 'yes') {
109			interfac.querySelectorAll('.cookiesck-accept').forEach(function(btn) { btn.classList.add('cookiesck-active'); });
110		} else if (COOKIESCK.VALUE === 'no' || COOKIESCK.VALUE === 'null') {
111			interfac.querySelectorAll('.cookiesck-decline').forEach(function(btn) { btn.classList.add('cookiesck-active'); });
112		}
113
114		// force essential to be active
115		if (interfac.querySelector('[data-category="essential"]')) {
116			interfac.querySelectorAll('[data-category="essential"] .cookiesck-accept').forEach(function(btn) { btn.classList.add('cookiesck-active'); }); 
117		}
118
119		highlightAllButton();
120
121		// close the interface
122		interfac.querySelector('.cookiesck-main-close').onclick = function() {
123			updateCookieValue();
124			interfac.style.display = 'none';
125			document.getElementById('cookiesck_options').style.display = 'block';
126			document.getElementById('cookiesck_overlay').style.display = 'none';
127			if (opts.reload === '1') location.reload();
128		}
129	}
130
131	function highlightAllButton() {
132		let interfac = document.getElementById('cookiesck_interface');
133		if (interfac.querySelectorAll('.cookiesck-category .cookiesck-accept').length === interfac.querySelectorAll('.cookiesck-category .cookiesck-accept.cookiesck-active').length) {
134			interfac.querySelectorAll('.cookiesck-accept').forEach(function(btn) { btn.classList.add('cookiesck-active'); });
135		} else if (interfac.querySelectorAll('.cookiesck-category .cookiesck-decline').length === interfac.querySelectorAll('.cookiesck-category .cookiesck-decline.cookiesck-active').length) {
136			interfac.querySelectorAll('.cookiesck-decline').forEach(function(btn) { btn.classList.add('cookiesck-active'); });
137		}
138	}
139
140	function initEvents() {
141		let acceptButtons = document.querySelectorAll('#cookiesck_accept,.cookiesck-main-buttons .cookiesck-accept');
142		acceptButtons.forEach(function(acceptButton) {
143			acceptButton.onclick = function() {
144				debug('acceptButton.onclick');
145				if (this.classList.contains('cookiesck-accept')) { acceptAll(); }
146				setCookie("cookiesck","yes",COOKIESCK.LIFETIME);
147				if (COOKIESCK.LOG === '1') {
148					// if not unique key has been set, set it now with the session ID
149					if (! readCookie('cookiesckuniquekey')) {
150						setCookie('cookiesckuniquekey', COOKIESCK.UNIQUE_KEY, opts.lifetime);
151					}
152				}
153				doAjax(location.href, 'set_cookieck=1');
154				document.getElementById('cookiesck').classList.add('cookiesck-hide');
155				document.getElementById('cookiesck').style.display = 'none';
156				document.getElementById('cookiesck_options').style.display = 'block';
157				document.getElementById('cookiesck_overlay').style.display = 'none';
158				loadIframes();
159				if (opts.reload === '1' && this.id == 'cookiesck_accept') location.reload();
160			}
161		});
162		let declineButtons = document.querySelectorAll('#cookiesck_decline, .cookiesck-main-buttons .cookiesck-decline');
163		declineButtons.forEach(function(declineButton) {
164			declineButton.onclick = function() {
165				debug('declineButton.onclick');
166				if (this.classList.contains('cookiesck-decline')) { declineAll(); }
167				// remove the cookies for all platforms
168				let interfac = document.getElementById('cookiesck_interface');
169				let categories = interfac.querySelectorAll('.cookiesck-category');
170				categories.forEach(function(category) {
171					let categoryName = category.getAttribute('data-category');
172					if (categoryName !== 'Essential') {
173						let platforms = category.querySelectorAll('.cookiesck-platform');
174						platforms.forEach(function(platform) {
175							let platformName = platform.getAttribute('data-platform');
176							removeCookie(platformName);
177						})
178					}
179				})
180				
181
182				setCookie("cookiesck","no",COOKIESCK.LIFETIME);
183				if (COOKIESCK.LOG === '1') {
184					// if not unique key has been set, set it now with the session ID
185					if (! readCookie('cookiesckuniquekey')) {
186						setCookie('cookiesckuniquekey', COOKIESCK.UNIQUE_KEY, opts.lifetime);
187					}
188				}
189				doAjax(location.href, 'set_cookieck=0');
190				document.getElementById('cookiesck').classList.add('cookiesck-hide');
191				document.getElementById('cookiesck').style.display = 'none';
192				document.getElementById('cookiesck_options').style.display = 'block';
193				document.getElementById('cookiesck_overlay').style.display = 'none';
194			}
195		});
196		document.getElementById('cookiesck_settings').onclick = function(){
197			document.getElementById('cookiesck_interface').style.display = 'block';
198			document.getElementById('cookiesck').style.display = 'none';
199		}
200		// add management button to update the decision
201		document.getElementById('cookiesck_options').onclick = function(){
202			document.getElementById('cookiesck_interface').style.display = 'block';
203			document.getElementById('cookiesck_overlay').style.display = 'block';
204		}
205	}
206
207	function initIframes() {
208		let iframes = document.querySelectorAll('.cookiesck-iframe-wrap');
209		debug('iframes  : ');
210		debug(iframes);
211		iframes.forEach(function(iframe) {
212			iframe.onclick = function() {
213				if (! confirm(COOKIESCK.TEXT.CONFIRM_IFRAMES)) return; 
214				this.outerHTML = this.outerHTML.replace('data-cookiesck-src', 'src');
215				loadIframes();
216				setCookie('cookiesckiframes', '1', COOKIESCK.LIFETIME);
217			}
218		});
219	}
220
221	function setCookie(c_name,value,exdays) {
222		debug('setCookie  : {name : ' + c_name + ', value : ' + value + ', exdays : ' + exdays);
223		var exdate=new Date(Date.now());
224		exdate.setDate(exdate.getDate() + parseInt(exdays));
225		var c_value=escape(value) + ((exdays===null) ? "" : "; expires="+exdate.toUTCString()) + "; path=/";
226		document.cookie=c_name + "=" + c_value;
227	}
228
229	function readCookie(name) {
230		debug('readCookie  : ' + name);
231		var nameEQ = name + "=";
232		var cooks = document.cookie.split(';');
233		for(var i=0;i < cooks.length;i++) {
234			var c = cooks[i];
235			while (c.charAt(0)==' ') c = c.substring(1,c.length);
236				if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
237			}
238		return null;
239	}
240
241	function removeCookie(platformName) {
242		debug('removeCookie  : ' + platformName);
243
244		var keys = getKeyFromPlatform(platformName);
245		var domain = location.hostname.split('.').reverse();
246		if (domain.length == 1) {
247			domain = '.' + domain[0];
248		} else {
249			domain = '.' + domain[1] + '.' + domain[0];
250		}
251
252		for (var i=0; i < keys.length; i++) {
253			debug('Platform Key to remove  : ' + keys[i]);
254			let cookie = keys[i] + "=; expires=Thu, 18 Dec 2013 12:00:00 UTC; path=/";
255			document.cookie = cookie;
256			document.cookie = cookie + '; domain=' + domain;
257		}
258	}
259
260	function getKeyFromPlatform(platformName) {
261		var list = JSON.parse(COOKIESCK.LIST.replace(/\|QQ\|/g, '"'));
262		var keys = new Array();
263		for (const category in list) {
264			for (const platform in list[category]['platforms']) {
265				if (platform === platformName) {
266					for (var cookie in list[category]['platforms'][platform]['cookies']) {
267						keys.push(list[category]['platforms'][platform]['cookies'][cookie]['key']);
268					}
269				}
270			}
271		}
272
273		return keys;
274	}
275
276	function toObject() {
277		let list = new Object();
278		let rows = COOKIESCK.VALUE.split('|ck|');
279		for (var i=0; i < rows.length; i++) {
280			let cols = rows[i].split('|val|');
281			list[cols[0]] = cols[1];
282		}
283		return list;
284	}
285
286	function doAction(btn, action) {
287		btn.parentNode.querySelectorAll('.cookiesck_button').forEach(function(button) {
288			button.classList.remove('cookiesck-active');
289		});
290		btn.classList.add('cookiesck-active');
291		updateCookieValue();
292		// if (opts.reload === '1') location.reload();
293	}
294
295	function updateCookieValue() {
296		debug('updateCookieValue');
297		let interfac = document.getElementById('cookiesck_interface');
298		let list = new Array();
299		let platforms = interfac.querySelectorAll('.cookiesck-platform');
300		platforms.forEach(function(platform) {
301			let selection = platform.querySelector('.cookiesck_button.cookiesck-active');
302			let name = platform.getAttribute('data-platform');
303			if (selection && selection.classList.contains('cookiesck-accept')) {
304				list.push(name + '|val|1');
305				var state = '1';
306				// trigger event
307				let event = new CustomEvent('cookieckstate', { "detail": {"name": name, "state": "1"} });
308				document.dispatchEvent(event);
309				debug('cookieckstate  : {name : ' + name + ', state : 1');
310			} else {
311				list.push(name + '|val|0');
312				var state = '0';
313				removeCookie(name);
314				// trigger event
315				let event = new CustomEvent('cookieckstate', { "detail": {"name": name, "state": "0"} });
316				document.dispatchEvent(event);
317				debug('cookieckstate  : {name : ' + name + ', state : 0');
318			}
319			if (name === 'cookiesckgoogleanalytics' || name === 'cookiesckgooglead') {
320				consentGrantedAdStorage(name, state);
321			}
322		});
323		COOKIESCK.VALUE = list.join('|ck|');
324		setCookie('cookiesck', encodeURIComponent(COOKIESCK.VALUE), opts.lifetime);
325		if (COOKIESCK.LOG === '1') {
326			// if not unique key has been set, set it now with the session ID
327			if (! readCookie('cookiesckuniquekey')) {
328				setCookie('cookiesckuniquekey', COOKIESCK.UNIQUE_KEY, opts.lifetime);
329			}
330		}
331		doAjax(location.href, 'set_cookieck=update&cookiesck_vars=' + encodeURIComponent(COOKIESCK.VALUE));
332	}
333
334	function acceptAll() {
335		let interfac = document.getElementById('cookiesck_interface');
336		interfac.querySelectorAll('.cookiesck-active').forEach(function(btn
336) { btn.classList.remove('cookiesck-active'); });
337		interfac.querySelectorAll('.cookiesck-accept').forEach(function(btn) { btn.classList.add('cookiesck-active'); });
338		loadIframes();
339		// trigger event
340		let event = new CustomEvent('cookieckstate', { "detail": {"name": "all", "state": "1"} });
341		document.dispatchEvent(event);
342	}
343
344	function declineAll() {
345		let interfac = document.getElementById('cookiesck_interface');
346		interfac.querySelectorAll('.cookiesck-active').forEach(function(btn) { btn.classList.remove('cookiesck-active'); });
347		interfac.querySelectorAll('.cookiesck-decline').forEach(function(btn) { btn.classList.add('cookiesck-active'); });
348		// force essential to be active
349		if (interfac.querySelector('[data-category="essential"]')) {
350			interfac.querySelectorAll('[data-category="essential"] .cookiesck-accept').forEach(function(btn) { btn.classList.add('cookiesck-active'); });
351		}
352		// trigger event
353		let event = new CustomEvent('cookieckstate', { "detail": {"name": "all", "state": "0"} });
354		document.dispatchEvent(event);
355	}
356
357	function loadIframes() {
358		let iframes = document.querySelectorAll('.cookiesck-iframe-wrap');
359		iframes.forEach(function(iframetoenable) {
360			iframetoenable.closest('.cookiesck-iframe-wrap').className = 'cookiesck-iframe-wrap-allowed';
361			iframetoenable.outerHTML = iframetoenable.outerHTML.replace('data-cookiesck-src', 'src');
362		});
363	}
364
365	function doAjax(url, vars) {
366		// ancien code de compatibilité, aujourd’hui inutile
367		if (window.XMLHttpRequest) { // Mozilla, Safari, IE7+...
368			var httpRequest = new XMLHttpRequest();
369		}
370		else if (window.ActiveXObject) { // IE 6 et antérieurs
371			var httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
372		}
373		httpRequest.onreadystatechange = function() {
374			// instructions de traitement de la réponse
375		};
376		httpRequest.open('POST', url, true);
377		httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
378		httpRequest.send(vars);
379	}
380
381	function debug(str) {
382		if (COOKIESCK.DEBUG === '1') {
383			console.log(str);
384		}
385	}
386
387	// for Google Tag Manager
388	function consentGrantedAdStorage(name, state) {
389		var grant = state === '1' ? 'granted' : 'denied';
390		if (name === 'cookiesckgoogleanalytics') {
391			gtag('consent', 'update', {
392				'analytics_storage': grant
393			});
394		}
395		if (name === 'cookiesckgooglead') {
396			gtag('consent', 'update', {
397				'ad_storage': grant,
398				'ad_user_data': grant,
399				'ad_personalization': grant
400			});
401		}
402	}
403	window.Cookiesck = Cookiesck;
404	window.ckInitCookiesckIframes = initIframes;
405})();
406
407// initialize the setter and getter for the cookies
408if (! document.__defineGetter__) {
409	Object.defineProperty(document, 'cookie',{
410		get: function g(){ return ''; },
411		set: function h(){ return true;}
412	});
413} else {
414	var oldSetter = document.__lookupSetter__('cookie');
415	var oldGetter = document.__lookupGetter__('cookie');
416	if (oldSetter) {
417		Object.defineProperty(document, 'cookie', {
418			get: function g(){ return oldGetter.call(document); },
419			set: function h(v){
420				let name = v.split('=')[0];
421
422				if (COOKIESCK.DEBUG === '1') {
423					console.log('v.match(/cookiesck\=/)');
424					console.log(v.match(/cookiesck\=/));
425					console.log('COOKIESCK.VALUE');
426					console.log(COOKIESCK.VALUE);
427					console.log('COOKIESCK.ALLOWED');
428					console.log(COOKIESCK.ALLOWED);
429					console.log('COOKIESCK.ALLOWED.indexOf(name)');
430					console.log(COOKIESCK.ALLOWED.indexOf(name));
431					console.log('ckCookiesSearchNameIn(name, COOKIESCK.ALLOWED)');
432					console.log(ckCookiesSearchNameIn(name, COOKIESCK.ALLOWED));
433				}
434
435				if(v.match(/cookiesck\=/) || COOKIESCK.VALUE === 'yes' || COOKIESCK.ALLOWED.indexOf(name) != -1 || ckCookiesSearchNameIn(name, COOKIESCK.ALLOWED)) {
436					oldSetter.call(document, v);
437					if (COOKIESCK.DEBUG === '1') {
438						console.log('>> set cookie allowed :');
439						console.log(name);
440					}
441				} else {
442					let cookie = name + "=; expires=Thu, 18 Dec 2013 12:00:00 UTC; path=/;";
443					oldSetter.call(document, cookie);
444					if (COOKIESCK.DEBUG === '1') {
445						console.log('>> set cookie blocked for :');
446						console.log(name);
447					}
448				}
449				return true;
450			}
451		});
452	}
453}
454
455function ckCookiesSearchNameIn(name, list) {
456	for (var i=0; i<list.length; i++) {
457		if (name.substr(0, list[i].length) == list[i]) return true;
458	}
459	return false;
460}
461
462// example of how to get the event
463//document.addEventListener("cookieckstate", function(e) {
464//	console.log(e.detail)
465//	console.log(e.detail.name);
466//	console.log(e.detail.state);
467//});
468

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.