PageSourceSearch

https://www.whp.cz/includes/jquery.cookiebar.js

js whp.cz collected 2026-10-07 20:48:53 UTC 7,444 bytes, 183 lines download raw bytes

1/*
2 * Copyright (C) 2012 PrimeBox ([email protected])
3 * 
4 * This work is licensed under the Creative Commons
5 * Attribution 3.0 Unported License. To view a copy
6 * of this license, visit
7 * http://creativecommons.org/licenses/by/3.0/.
8 * 
9 * Documentation available at:
10 * http://www.primebox.co.uk/projects/cookie-bar/
11 * 
12 * When using this software you use it at your own risk. We hold
13 * no responsibility for any damage caused by using this plugin
14 * or the documentation provided.
15 */
16(function($){
17	$.cookieBar = function(options,val){
18		if(options=='cookies'){
19			var doReturn = 'cookies';
20		}else if(options=='set'){
21			var doReturn = 'set';
22		}else{
23			var doReturn = false;
24		}
25		var defaults = {
26			message: 'Používáním tohoto webu souhlasíte s využitím cookies nutných pro správnou funkci webu.', //Message displayed on bar
27			acceptButton: true, //Set to true to show accept/enable button
28			acceptText: 'Rozumím', //Text on accept/enable button
29			declineButton: false, //Set to true to show decline/disable button
30			declineText: 'Nepoužívat Cookies', //Text on decline/disable button
31			policyButton: false, //Set to true to show Privacy Policy button
32			policyText: 'Ochrana osobních údajù', //Text on Privacy Policy button
33			policyURL: '/privacy-policy/', //URL of Privacy Policy
34			autoEnable: true, //Set to true for cookies to be accepted automatically. Banner still shows
35			acceptOnContinue: false, //Set to true to silently accept cookies when visitor moves to another page
36			expireDays: 365, //Number of days for cookieBar cookie to be stored for
37			forceShow: false, //Force cookieBar to show regardless of user cookie preference
38			effect: 'slide', //Options: slide, fade, hide
39			element: 'body', //Element to append/prepend cookieBar to. Remember "." for class or "#" for id.
40			append: false, //Set to true for cookieBar HTML to be placed at base of website. Actual position may change according to CSS
41			fixed: false, //Set to true to add the class "fixed" to the cookie bar. Default CSS should fix the position
42			bottom: false, //Force CSS when fixed, so bar appears at bottom of website
43			zindex: '', //Can be set in CSS, although some may prefer to set here
44			redirect: String(window.location.href), //Current location
45			domain: String(window.location.hostname), //Location of privacy policy
46			referrer: String(document.referrer) //Where visitor has come from
47		};
48		var options = $.extend(defaults,options);
49		
50		//Sets expiration date for cookie
51		var expireDate = new Date();
52		expireDate.setTime(expireDate.getTime()+(options.expireDays*24*60*60*1000));
53		expireDate = expireDate.toGMTString();
54		
55		var cookieEntry = 'cb-enabled={value}; expires='+expireDate+'; path=/';
56		
57		//Retrieves current cookie preference
58		var i,cookieValue='',aCookie,aCookies=document.cookie.split('; ');
59		for (i=0;i<aCookies.length;i++){
60			aCookie = aCookies[i].split('=');
61			if(aCookie[0]=='cb-enabled'){
62    			cookieValue = aCookie[1];
63			}
64		}
65		//Sets up default cookie preference if not already set
66		if(cookieValue=='' && options.autoEnable){
67			cookieValue = 'enabled';
68			document.cookie = cookieEntry.replace('{value}','enabled');
69		}
70		if(options.acceptOnContinue){
71			if(options.referrer.indexOf(options.domain)>=0 && String(window.location.href).indexOf(options.policyURL)==-1 && doReturn!='cookies' && doReturn!='set' && cookieValue!='accepted' && cookieValue!='declined'){
72				doReturn = 'set';
73				val = 'accepted';
74			}
75		}
76		if(doReturn=='cookies'){
77			//Returns true if cookies are enabled, false otherwise
78			if(cookieValue=='enabled' || cookieValue=='accepted'){
79				return true;
80			}else{
81				return false;
82			}
83		}else if(doReturn=='set' && (val=='accepted' || val=='declined')){
84			//Sets value of cookie to 'accepted' or 'declined'
85			document.cookie = cookieEntry.replace('{value}',val);
86			if(val=='accepted'){
87				return true;
88			}else{
89				return false;
90			}
91		}else{
92			//Sets up enable/accept button if required
93			var message = options.message.replace('{policy_url}',options.policyURL);
94			
95			if(options.acceptButton){
96				var acceptButton = '<a href="" class="cb-enable">'+options.acceptText+'</a>';
97			}else{
98				var acceptButton = '';
99			}
100			//Sets up disable/decline button if required
101			if(options.declineButton){
102				var declineButton = '<a href="" class="cb-disable">'+options.declineText+'</a>';
103			}else{
104				var declineButton = '';
105			}
106			//Sets up privacy policy button if required
107			if(options.policyButton){
108				var policyButton = '<a href="'+options.policyURL+'" class="cb-policy">
108'+options.policyText+'</a>';
109			}else{
110				var policyButton = '';
111			}
112			//Whether to add "fixed" class to cookie bar
113			if(options.fixed){
114				if(options.bottom){
115					var fixed = ' class="fixed bottom"';
116				}else{
117					var fixed = ' class="fixed"';
118				}
119			}else{
120				var fixed = '';
121			}
122			if(options.zindex!=''){
123				var zindex = ' style="z-index:'+options.zindex+';"';
124			}else{
125				var zindex = '';
126			}
127			
128			//Displays the cookie bar if arguments met
129			if(options.forceShow || cookieValue=='enabled' || cookieValue==''){
130				if(options.append){
131					$(options.element).append('<div id="cookie-bar"'+fixed+zindex+'><p>'+message+acceptButton+declineButton+policyButton+'</p></div>');
132				}else{
133					$(options.element).prepend('<div id="cookie-bar"'+fixed+zindex+'><p>'+message+acceptButton+declineButton+policyButton+'</p></div>');
134				}
135			}
136			
137			//Sets the cookie preference to accepted if enable/accept button pressed
138			$('#cookie-bar .cb-enable').click(function(){
139				document.cookie = cookieEntry.replace('{value}','accepted');
140				if(cookieValue!='enabled' && cookieValue!='accepted'){
141					window.location = options.currentLocation;
142				}else{
143					if(options.effect=='slide'){
144						$('#cookie-bar').slideUp(300,function(){$('#cookie-bar').remove();});
145					}else if(options.effect=='fade'){
146						$('#cookie-bar').fadeOut(300,function(){$('#cookie-bar').remove();});
147					}else{
148						$('#cookie-bar').hide(0,function(){$('#cookie-bar').remove();});
149					}
150					return false;
151				}
152			});
153			//Sets the cookie preference to declined if disable/decline button pressed
154			$('#cookie-bar .cb-disable').click(function(){
155				var deleteDate = new Date();
156				deleteDate.setTime(deleteDate.getTime()-(864000000));
157				deleteDate = deleteDate.toGMTString();
158				aCookies=document.cookie.split('; ');
159				for (i=0;i<aCookies.length;i++){
160					aCookie = aCookies[i].split('=');
161					if(aCookie[0].indexOf('_')>=0){
162						document.cookie = aCookie[0]+'=0; expires='+deleteDate+'; domain='+options.domain.replace('www','')+'; path=/';
163					}else{
164						document.cookie = aCookie[0]+'=0; expires='+deleteDate+'; path=/';
165					}
166				}
167				document.cookie = cookieEntry.replace('{value}','declined');
168				if(cookieValue=='enabled' && cookieValue!='accepted'){
169					window.location = options.currentLocation;
170				}else{
171					if(options.effect=='slide'){
172						$('#cookie-bar').slideUp(300,function(){$('#cookie-bar').remove();});
173					}else if(options.effect=='fade'){
174						$('#cookie-bar').fadeOut(300,function(){$('#cookie-bar').remove();});
175					}else{
176						$('#cookie-bar').hide(0,function(){$('#cookie-bar').remove();});
177					}
178					return false;
179				}
180			});
181		}
182	};
183})(jQuery);

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.