PageSourceSearch

https://fahrradstrasse-bi.de/wp-content/plugins/cookie-notice/js/front.js?ver=1.3.2

js fahrradstrasse-bi.de collected 2026-10-05 11:31:11 UTC 17,146 bytes, 544 lines download raw bytes

1// CustomEvent polyfil for IE support
2( function () {
3
4	if ( typeof window.CustomEvent === "function" )
5		return false;
6
7	function CustomEvent( event, params ) {
8		params = params || { bubbles: false, cancelable: false, detail: undefined };
9
10		var evt = document.createEvent( 'CustomEvent' );
11
12		evt.initCustomEvent( event, params.bubbles, params.cancelable, params.detail );
13
14		return evt;
15	}
16
17	CustomEvent.prototype = window.Event.prototype;
18
19	window.CustomEvent = CustomEvent;
20} )();
21
22// ClassList polyfil for IE/Safari support
23( function () {
24	var regExp = function ( name ) {
25		return new RegExp( '(^| )' + name + '( |$)' );
26	};
27
28	var forEach = function ( list, fn, scope ) {
29		for ( var i = 0; i < list.length; i++ ) {
30			fn.call( scope, list[i] );
31		}
32	};
33
34	function ClassList( element ) {
35		this.element = element;
36	}
37
38	ClassList.prototype = {
39		add: function () {
40			forEach( arguments, function ( name ) {
41				if ( !this.contains( name ) ) {
42					this.element.className += this.element.className.length > 0 ? ' ' + name : name;
43				}
44			}, this );
45		},
46		remove: function () {
47			forEach( arguments, function ( name ) {
48				this.element.className =
49					this.element.className.replace( regExp( name ), '' );
50			}, this );
51		},
52		toggle: function ( name ) {
53			return this.contains( name )
54				? ( this.remove( name ), false ) : ( this.add( name ), true );
55		},
56		contains: function ( name ) {
57			return regExp( name ).test( this.element.className );
58		},
59		// bonus..
60		replace: function ( oldName, newName ) {
61			this.remove( oldName ), this.add( newName );
62		}
63	};
64
65	// IE8/9, Safari
66	if ( !( 'classList' in Element.prototype ) ) {
67		Object.defineProperty( Element.prototype, 'classList', {
68			get: function () {
69				return new ClassList( this );
70			}
71		} );
72	}
73
74	if ( window.DOMTokenList && DOMTokenList.prototype.replace == null )
75		DOMTokenList.prototype.replace = ClassList.prototype.replace;
76} )();
77
78// cookieNotice
79( function ( window, document, undefined ) {
80
81	var cookieNotice = new function () {
82		// cookie status
83		this.cookiesAccepted = null;
84
85		// notice container
86		this.noticeContainer = null;
87
88		// set cookie value
89		this.setStatus = function ( cookieValue ) {
90			var _this = this;
91
92			// remove listening to scroll event
93			if ( cnArgs.onScroll === '1' )
94				window.removeEventListener( 'scroll', this.handleScroll );
95
96			var date = new Date(),
97				laterDate = new Date();
98
99			// set cookie type and expiry time in seconds
100			if ( cookieValue === 'accept' ) {
101				cookieValue = 'true';
102				laterDate.setTime( parseInt( date.getTime() ) + parseInt( cnArgs.cookieTime ) * 1000 );
103			} else {
104				cookieValue = 'false';
105				laterDate.setTime( parseInt( date.getTime() ) + parseInt( cnArgs.cookieTimeRejected ) * 1000 );
106			}
107
108			// set cookie
109			document.cookie = cnArgs.cookieName + '=' + cookieValue + ';expires=' + laterDate.toUTCString() + ';' + ( !!cnArgs.cookieDomain ? 'domain=' + cnArgs.cookieDomain + ';' : '' ) + ( !!cnArgs.cookiePath ? 'path=' + cnArgs.cookiePath + ';' : '' ) + ( cnArgs.secure === '1' ? 'secure;' : '' );
110
111			// update global status
112			this.cookiesAccepted = cookieValue === 'true';
113
114			// trigger custom event
115			var event = new CustomEvent(
116				'setCookieNotice',
117				{
118					detail: {
119						value: cookieValue,
120						time: date,
121						expires: laterDate,
122						data: cnArgs
123					}
124				}
125			);
126
127			document.dispatchEvent( event );
128
129			this.setBodyClass( [ 'cookies-set', cookieValue === 'true' ? 'cookies-accepted' : 'cookies-refused' ] );
130
131			this.hideCookieNotice();
132
133			// show revoke notice if enabled
134			if ( cnArgs.revokeCookiesOpt === 'automatic' ) {
135				// show cookie notice after the revoke is hidden
136				this.noticeContainer.addEventListener( 'animationend', function handler() {
137					_this.noticeContainer.removeEventListener( 'animationend', handler );
138					_this.showRevokeNotice();
139				} );
140				this.noticeContainer.addEventListener( 'webkitAnimationEnd', function handler() {
141					_this.noticeContainer.removeEventListener( 'webkitAnimationEnd', handler );
142					_this.showRevokeNotice();
143				} );
144			}
145
146			// redirect?
147			if ( cnArgs.redirection === '1' && ( ( cookieValue === 'true' && this.cookiesAccepted === null ) || ( co
147okieValue !== this.cookiesAccepted && this.cookiesAccepted !== null ) ) ) {
148				var url = window.location.protocol + '//',
149					hostname = window.location.host + '/' + window.location.pathname;
150
151				// enabled cache?
152				if ( cnArgs.cache === '1' ) {
153					url = url + hostname.replace( '//', '/' ) + ( window.location.search === '' ? '?' : window.location.search + '&' ) + 'cn-reloaded=1' + window.location.hash;
154
155					window.location.href = url;
156				} else {
157					url = url + hostname.replace( '//', '/' ) + window.location.search + window.location.hash;
158
159					window.location.reload( true );
160				}
161
162				return;
163			}
164		};
165
166		// get cookie value
167		this.getStatus = function ( bool ) {
168			var value = "; " + document.cookie,
169				parts = value.split( '; cookie_notice_accepted=' );
170
171			if ( parts.length === 2 ) {
172				var val = parts.pop().split( ';' ).shift();
173
174				if ( bool )
175					return val === 'true';
176				else
177					return val;
178			} else
179				return null;
180		};
181
182		// display cookie notice
183		this.showCookieNotice = function () {
184			var _this = this;
185
186			// trigger custom event
187			var event = new CustomEvent(
188				'showCookieNotice',
189				{
190					detail: {
191						data: cnArgs
192					}
193				}
194			);
195
196			document.dispatchEvent( event );
197
198			this.noticeContainer.classList.remove( 'cookie-notice-hidden' );
199			this.noticeContainer.classList.add( 'cn-animated' );
200			this.noticeContainer.classList.add( 'cookie-notice-visible' );
201
202			// detect animation
203			this.noticeContainer.addEventListener( 'animationend', function handler() {
204				_this.noticeContainer.removeEventListener( 'animationend', handler );
205				_this.noticeContainer.classList.remove( 'cn-animated' );
206			} );
207			this.noticeContainer.addEventListener( 'webkitAnimationEnd', function handler() {
208				_this.noticeContainer.removeEventListener( 'webkitAnimationEnd', handler );
209				_this.noticeContainer.classList.remove( 'cn-animated' );
210			} );
211		};
212
213		// hide cookie notice
214		this.hideCookieNotice = function () {
215			var _this = this;
216
217			// trigger custom event
218			var event = new CustomEvent(
219				'hideCookieNotice',
220				{
221					detail: {
222						data: cnArgs
223					}
224				}
225			);
226
227			document.dispatchEvent( event );
228
229			this.noticeContainer.classList.add( 'cn-animated' );
230			this.noticeContainer.classList.remove( 'cookie-notice-visible' );
231
232			// detect animation
233			this.noticeContainer.addEventListener( 'animationend', function handler() {
234				_this.noticeContainer.removeEventListener( 'animationend', handler );
235				_this.noticeContainer.classList.remove( 'cn-animated' );
236				_this.noticeContainer.classList.add( 'cookie-notice-hidden' );
237			} );
238			this.noticeContainer.addEventListener( 'webkitAnimationEnd', function handler() {
239				_this.noticeContainer.removeEventListener( 'webkitAnimationEnd', handler );
240				_this.noticeContainer.classList.remove( 'cn-animated' );
241				_this.noticeContainer.classList.add( 'cookie-notice-hidden' );
242			} );
243		};
244
245		// display revoke notice
246		this.showRevokeNotice = function () {
247			var _this = this;
248
249			// trigger custom event
250			var event = new CustomEvent(
251				'showRevokeNotice',
252				{
253					detail: {
254						data: cnArgs
255					}
256				}
257			);
258
259			document.dispatchEvent( event );
260
261			this.noticeContainer.classList.remove( 'cookie-revoke-hidden' );
262			this.noticeContainer.classList.add( 'cn-animated' );
263			this.noticeContainer.classList.add( 'cookie-revoke-visible' );
264
265			// detect animation
266			this.noticeContainer.addEventListener( 'animationend', function handler() {
267				_this.noticeContainer.removeEventListener( 'animationend', handler );
268				_this.noticeContainer.classList.remove( 'cn-animated' );
269			} );
270			this.noticeContainer.addEventListener( 'webkitAnimationEnd', function handler() {
271				_this.noticeContainer.removeEventListener( 'webkitAnimationEnd', handler );
272				_this.noticeContainer.classList.remove( 'cn-animated' );
273			} );
274		};
275
276		// hide revoke notice
277		this.hideRevokeNotice = function () {
278			var _this = this;
279
280			// trigger custom event
281			var event = new CustomEvent(
282				'hideRevokeNotice',
283				{
284					detail: {
285						data: cnArgs
286					}
287				}
288			);
289
290			document.dispatchEvent( event );
291
292			this.noticeContainer.classList.add( 'cn-animated' );
293			this.noticeContainer.classList.remove( 'cookie-revoke-visible' );
294
295			// detect animation
296			this.noticeContainer.addEventListener( 'animationend', function handler() {
297				_this.noticeContainer.removeEventListener( 'animationend', handler );
298				_this.noticeContainer.classList.remove( 'cn-animated' );
299				_this.noticeContainer.classList.add( 'cookie-revoke-hidden' );
300			} );
301			this.noticeContainer.addEventListener( 'webkitAnimationEnd', function handler() {
302				_this.noticeContainer.removeEventListener( 'webkitAnimationEnd', handler );
303				_this.noticeContainer.classList.remove( 'cn-animated' );
304				_this.noticeContainer.classList.add( 'cookie-revoke-hidden' );
305			} );
306		};
307
308		// change body classes
309		this.setBodyClass = function ( classes ) {
310			// remove body classes
311			document.body.classList.remove( 'cookies-revoke' );
312			document.body.classList.remove( 'cookies-accepted' );
313			document.body.classList.remove( 'cookies-refused' );
314			document.body.classList.remove( 'cookies-set' );
315			document.body.classList.remove( 'cookies-not-set' );
316
317			// add body classes
318			for ( var i = 0; i < classes.length; i++ ) {
319				document.body.classList.add( classes[i] );
320			}
321		};
322
323		// handle mouse scrolling
324		this.handleScroll = function () {
325			var scrollTop = window.pageYOffset || ( document.documentElement || document.body.parentNode || document.body ).scrollTop
326
327			// accept cookie
328			if ( scrollTop > parseInt( cnArgs.onScrollOffset ) )
329				this.setStatus( 'accept' );
330		};
331		
332		// adjust the notice offset
333		this.adjustOffset = function() {
334			var coronabarContainer = document.getElementById( 'coronabar' ),
335				adminbarContainer = document.getElementById( 'wpadminbar' ),
336				coronabarOffset = 0,
337				adminbarOffset = 0;
338			
339			// adjust when admin bar is visible
340			if ( cnArgs.position === 'top' && adminbarContainer !== null ) {
341				adminbarOffset = adminbarContainer.offsetHeight;
342
343				this.noticeContainer.style.top = adminbarOffset + 'px';
344			}
345
346			// adjust when coronabar is visible
347			if ( coronabarContainer !== null ) {
348				coronabarOffset = coronabarContainer.offsetHeight - 1;
349				
350				if ( cnArgs.position === 'top' ) {
351					coronabarContainer.style.top = adminbarOffset + 'px';
352
353					this.noticeContainer.style.top = coronabarOffset + adminbarOffset + 'px';
354				} else {
355					this.noticeContainer.style.bottom = coronabarOffset + 'px';
356				}
357			}
358		}
359
360		// cross browser compatible closest function
361		this.getClosest = function ( elem, selector ) {
362			// element.matches() polyfill
363			if ( !Element.prototype.matches ) {
364				Element.prototype.matches =
365					Element.prototype.matchesSelector ||
366					Element.prototype.mozMatchesSelector ||
367					Element.prototype.msMatchesSelector ||
368					Element.prototype.oMatchesSelector ||
369					Element.prototype.webkitMatchesSelector ||
370					function ( s ) {
371						var matches = ( this.document || this.ownerDocument ).querySelectorAll( s ),
372							i = matches.length;
373						while ( --i >= 0 && matches.item( i ) !== this ) {
374						}
375						return i > -1;
376					};
377			}
378
379			// get the closest matching element
380			for ( ; elem && elem !== document; elem = elem.parentNode ) {
381				if ( elem.matches( selector ) )
382					return elem;
383			}
384
385			return null;
386		};
387
388		// initialize
389		this.init = function () {
390			var _this = this;
391
392			this.cookiesAccepted = this.getStatus( true );
393			this.noticeContainer = document.getElementById( 'cookie-notice' );
394
395			var cookieButtons = document.getElementsByClassName( 'cn-set-cookie' ),
396				revokeButtons = document.getElementsByClassName( 'cn-revoke-cookie' ),
397				closeIcon = document.getElementById( 'cn-close-notice' );
398
399			// add effect class
400			this.noticeContainer.classList.add( 'cn-effect-' + cnArgs.hideEffect );
401			
402			// adjust on init
403			_this.adjustOffset();
404			
405			// adjust on resize
406			window.addEventListener( 'resize', function( event ) {
407				_this.adjustOffset();
408			} );
409
410			// adjust when coronabar is active
411			if ( cnArgs.coronabarActive === '1' ) {
412				// on display
413				document.addEventListener( 'display.coronabar', function( event ) {
414					_this.adjustOffset();
415				} );
416				// on hide
417				document.addEventListener( 'hide.coronabar', function( event ) {
418					_this.adjustOffset();
419				} );
420				// on save data
421				document.addEventListener( 'saveData.coronabar', function( event ) {
422					var casesData = event.detail;
423					
424					if ( casesData !== null ) {	
425						// alpha JS request // no jQuery
426						var request = new XMLHttpRequest();
427
428						request.open( 'POST', cnArgs.ajaxUrl, true );
429						request.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded;' );
430						request.onload = function () {
431							if ( this.status >= 200 && this.status < 400 ) {
432								// ff successful
433							} else {
434								// if fail
435							}
436						};
437						request.onerror = function () {
438							// connection error
439						};
440						request.send( 'action=cn_save_cases&nonce=' + cnArgs.nonce + '&data=' + JSON.stringify( casesData ) );
441					}
442				} );
443			}
444
445			/*
446			 // add refuse class
447			 this.noticeContainer.classList.add( cnArgs.refuse === '1' ? 'cn-refuse-active' : 'cn-refuse-inactive' );
448			 
449			 // add revoke class
450			 if ( cnArgs.revokeCookies === '1' ) {
451			 this.noticeContainer.classList.add( 'cn-revoke-active' );
452			 
453			 // add revoke type class (manual or automatic)
454			 this.noticeContainer.classList.add( 'cn-revoke-' + cnArgs.revokeCookiesOpt );
455			 } else {
456			 this.noticeContainer.classList.add( 'cn-revoke-inactive' );
457			 }
458			 */
459
460			// check cookies status
461			if ( this.cookiesAccepted === null ) {
462				// handle on scroll
463				if ( cnArgs.onScroll === '1' )
464					window.addEventListener( 'scroll', function ( e ) {
465						_this.handleScroll();
466					} );
467
468				// handle on click
469				if ( cnArgs.onClick === '1' )
470					window.addEventListener( 'click', function ( e ) {
471						var outerContainer = _this.getClosest( e.target, '#cookie-notice' );
472
473						// accept notice if clicked element is not inside the container
474						if ( outerContainer === null )
475							_this.setStatus( 'accept' );
476					}, true );
477
478				this.setBodyClass( [ 'cookies-not-set' ] );
479
480				// show cookie notice
481				this.showCookieNotice();
482			} else {
483				this.setBodyClass( [ 'cookies-set', this.cookiesAccepted === true ? 'co
483okies-accepted' : 'cookies-refused' ] );
484
485				// show revoke notice if enabled
486				if ( cnArgs.revokeCookies === '1' && cnArgs.revokeCookiesOpt === 'automatic' )
487					this.showRevokeNotice();
488			}
489
490			// handle cookie buttons click
491			for ( var i = 0; i < cookieButtons.length; i++ ) {
492				cookieButtons[i].addEventListener( 'click', function ( e ) {
493					e.preventDefault();
494					// Chrome double click event fix
495					e.stopPropagation();
496
497					_this.setStatus( this.dataset.cookieSet );
498				} );
499			}
500			
501			// handle close icon
502			if ( closeIcon !== 'null' ) {
503				closeIcon.addEventListener( 'click', function ( e ) {
504					e.preventDefault();
505					// Chrome double click event fix
506					e.stopPropagation();
507
508					_this.setStatus( this.dataset.cookieSet );
509				} );
510			}
511
512			// handle revoke buttons click
513			for ( var i = 0; i < revokeButtons.length; i++ ) {
514				revokeButtons[i].addEventListener( 'click', function ( e ) {
515					e.preventDefault();
516
517					// hide revoke notice
518					if ( _this.noticeContainer.classList.contains( 'cookie-revoke-visible' ) ) {
519						_this.hideRevokeNotice();
520
521						// show cookie notice after the revoke is hidden
522						_this.noticeContainer.addEventListener( 'animationend', function handler() {
523							_this.noticeContainer.removeEventListener( 'animationend', handler );
524							_this.showCookieNotice();
525						} );
526						_this.noticeContainer.addEventListener( 'webkitAnimationEnd', function handler() {
527							_this.noticeContainer.removeEventListener( 'webkitAnimationEnd', handler );
528							_this.showCookieNotice();
529						} );
530						// show cookie notice
531					} else if ( _this.noticeContainer.classList.contains( 'cookie-notice-hidden' ) && _this.noticeContainer.classList.contains( 'cookie-revoke-hidden' ) ) {
532						_this.showCookieNotice();
533					}
534				} );
535			}
536		};
537	}
538
539	// initialie plugin
540	window.addEventListener( 'load', function () {
541		cookieNotice.init();
542	}, false );
543
544} )( window, document, undefined );

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.