PageSourceSearch

https://www.freereg.org.uk/assets/jquery.cookiesDirective-858d4ee1…52f280bb16ab11099dcb121f8857833318f6bd20.js

js freereg.org.uk collected 2026-10-02 04:23:43 UTC 9,347 bytes, 271 lines download raw bytes

1/* Cookies Directive - The rewrite. Now a jQuery plugin
2 * Version: 2.0.1
3 * Author: Ollie Phillips
4 * 24 October 2013
5 */
6
7;(function($) {
8	$.cookiesDirective = function(options) {
9
10		// Default Cookies Directive Settings
11		var settings = $.extend({
12			//Options
13			explicitConsent: false,
14			position: 'bottom',
15			duration: 10,
16			limit: 0,
17			message: null,
18			cookieScripts: null,
19			privacyPolicyUri: 'privacy.html',
20			scriptWrapper: function(){},
21			// Styling
22			fontFamily: 'helvetica',
23      fontColor: '#FFFFFF',
24      fontSize: '10px',
25      backgroundColor: '#008000',
26      backgroundOpacity: '80',
27      linkColor: '#CA0000'
28    }, options);
29		// Perform consent checks
30		if(!getCookie('cookiesDirective')) {
31			if(settings.limit > 0) {
32				// Display limit in force, record the view
33				if(!getCookie('cookiesDisclosureCount')) {
34					setCookie('cookiesDisclosureCount',1,1);
35				} else {
36					var disclosureCount = getCookie('cookiesDisclosureCount');
37					disclosureCount ++;
38					setCookie('cookiesDisclosureCount',disclosureCount,1);
39				}
40
41				// Have we reached the display limit, if not make disclosure
42				if(settings.limit >= getCookie('cookiesDisclosureCount')) {
43					disclosure(settings);
44				}
45			} else {
46				// No display limit
47				disclosure(settings);
48			}
49
50			// If we don't require explicit consent, load up our script wrapping function
51			if(!settings.explicitConsent) {
52				settings.scriptWrapper.call();
53			}
54		} else {
55			// Cookies accepted, load script wrapping function
56			settings.scriptWrapper.call();
57		}
58	};
59
60	// Used to load external javascript files into the DOM
61	$.cookiesDirective.loadScript = function(options) {
62		var settings = $.extend({
63			uri: 		'',
64			appendTo: 	'body'
65		}, options);
66
67		var elementId = String(settings.appendTo);
68		var sA = document.createElement("script");
69		sA.src = settings.uri;
70		sA.type = "text/javascript";
71		sA.onload = sA.onreadystatechange = function() {
72			if ((!sA.readyState || sA.readyState == "loaded" || sA.readyState == "complete")) {
73				return;
74			}
75		};
76		switch(settings.appendTo) {
77			case 'head':
78				$('head').append(sA);
79			  	break;
80			case 'body':
81				$('body').append(sA);
82			  	break;
83			default:
84				$('#' + elementId).append(sA);
85		}
86	};
87
88	// Helper scripts
89	// Get cookie
90	window.getCookie = function(name) {
91		var nameEQ = name + "=";
92		var ca = document.cookie.split(';');
93		for(var i=0;i < ca.length;i++) {
94			var c = ca[i];
95			while (c.charAt(0)==' ') c = c.substring(1,c.length);
96			if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length);
97		}
98		return null;
99	};
100
101	// Set cookie
102	window.setCookie = function(name,value,days) {
103		var expires = "";
104		if (days) {
105			var date = new Date();
106			date.setTime(date.getTime()+(days*24*60*60*1000));
107			expires = "; expires="+date.toGMTString();
108		}
109		document.cookie = name+"="+value+expires+"; path=/";
110	};
111
112	// Detect IE < 9
113	var checkIE = function(){
114		var version;
115		if (navigator.appName == 'Microsoft Internet Explorer') {
116	        var ua = navigator.userAgent;
117	        var re = new RegExp("MSIE ([0-9]{1,}[\\.0-9]{0,})");
118	        if (re.exec(ua) !== null) {
119	            version = parseFloat(RegExp.$1);
120			}
121			if (version <= 8.0) {
122				return true;
123			} else {
124				if(version == 9.0) {
125					if(document.compatMode == "BackCompat") {
126						// IE9 in quirks mode won't run the script properly, set to emulate IE8
127						var mA = document.createElement("meta");
128						mA.content = "IE=EmulateIE8";
129						document.getElementsByTagName('head')[0].appendChild(mA);
130						return true;
131					} else {
132						return false;
133					}
134				}
135				return false;
136			}
137	    } else {
138			return false;
139		}
140	};
141
142	// Disclosure routines
143	var disclosure = function(options) {
144		var settings = options;
145		settings.css = 'fixed';
146
147		// IE 9 and lower has issues with position:fixed, either out the box or in compatibility mode - fix that
148		if(checkIE()) {
149			settings.position = 'top';
150			settings.css = 'absolute';
151		}
152
153		// Any cookie setting scripts to disclose
154		var scriptsDisclosure = '';
155		if (settings.cookieScripts) {
156			var scripts = settings.cookieScripts.split(',');
157			var scriptsCount = scripts.length;
158			var scriptDisclosureTxt = '';
159			if(scriptsCount>1) {
160				for(var t=0; t < scriptsCount - 1; t++) {
161					 scriptDisclosureTxt += scripts[t] + ', ';
162				}
163				scriptsDisclosure = ' We use ' +  scriptDisclosureTxt.substring(0,  scriptDisclosureTxt.length - 2) + ' and ' + scripts[scriptsCount - 1] + ' scripts, which all set cookies. ';
164			} else {
165				scriptsDisclosure = ' We use a ' + scripts[0] + ' script which sets cookies.';
166			}
167		}
168
169		// Create overlay, vary the disclosure based on explicit/implied consent
170		// Set our disclosure/message if one not supplied
171		var html = '';
172		html += '<div id="epd">';
173		html += '<div id="cookiesdirective" style="position:'+ settings.css +';'+ settings.position + ':-300px;left:0px;width:100%;';
174		html += 'height:auto;background:' + settings.backgroundColor + ';opacity:.' + settings.backgroundOpacity + ';';
175		html += '-ms-filter: “alpha(opacity=' + settings.backgroundOpacity + ')”; filter: alpha(opacity=' + settings.backgroundOpacity + ');';
176		html += '-khtml-opacity: .' + settings.backgroundOpacity + '; -moz-opacity: .' + settings.backgroundOpacity + ';';
177		html += 'color:' + settings.fontColor + ';
177font-family:' + settings.fontFamily + ';font-size:' + settings.fontSize + ';';
178		html += 'text-align:center;z-index:1000;">';
179		html += '<div style="position:relative;height:auto;width:90%;padding:10px;margin-left:auto;margin-right:auto;">';
180
181		if(!settings.message) {
182			if(settings.explicitConsent) {
183				// Explicit consent message
184				settings.message = 'Cookies are essential for this website to operate, blocking them stops the search working. ';
185
186			} else {
187				// Implied consent message
188				settings.message = 'We use cookies to ensure you get the best experience with our website. By continuing to use our website you consent to our use of cookies. ';
189			}
190		}
191		html += settings.message;
192
193		// Build the rest of the disclosure for implied and explicit consent
194		if(settings.explicitConsent) {
195			// Explicit consent disclosure
196
197			html += scriptsDisclosure + 'Review our <a tabindex="1" style="color:'+ settings.linkColor + ';font-weight:bold;';
198			html += 'font-family:' + settings.fontFamily + ';font-size:' + settings.fontSize + ';" href="'+ settings.privacyPolicyUri + '">Cookie policy</a>.';
199			html += '<div style="margin-top:5px;"><label for="epdagree" style="font-weight: normal; display: inline;">Tick this box to accept their use &nbsp;<input type="checkbox" name="epdagree" id="epdagree" tabindex="2" />&nbsp;&nbsp;</label> and then click &nbsp;';
200			html += '<input class="btn btn--navy btn--small " tabindex="3" type="submit" name="explicitsubmit" id="explicitsubmit" value="Continue"/></div></div>';
201
202		} else {
203			// Implied consent disclosure
204			html += scriptsDisclosure + 'Review our <a tabindex="1" style="color:'+ settings.linkColor + ';font-weight:bold;';
205      html += 'font-family:' + settings.fontFamily + ';font-size:' + settings.fontSize + ';" href="'+ settings.privacyPolicyUri + '">Cookie policy</a>.';
206      html += '<div style="margin-top:5px;"><input class="btn btn--navy btn--small weight--light" tabindex="3" type="submit" name="impliedsubmit" id="impliedsubmit" value="Do not show this message again"/></div></div>';
207		}
208		html += '</div></div>';
209		$('body').append(html);
210
211		// Serve the disclosure, and be smarter about branching
212		var dp = settings.position.toLowerCase();
213		if(dp != 'top' && dp!= 'bottom') {
214			dp = 'top';
215		}
216		var opts = { in: null, out: null};
217		if(dp == 'top') {
218			opts.in = {'top':'0'};
219			opts.out = {'top':'-300'};
220		} else {
221			opts.in = {'bottom':'0'};
222			opts.out = {'bottom':'-300'};
223		}
224
225		// Start animation
226		$('#cookiesdirective').animate(opts.in, 1000, function() {
227			// Set event handlers depending on type of disclosure
228			if(settings.explicitConsent) {
229				// Explicit, need to check a box and click a button
230				$('#explicitsubmit').click(function() {
231					if($('#epdagree').is(':checked')) {
232						// Set a cookie to prevent this being displayed again
233						setCookie('cookiesDirective',1,365);
234						// Close the overlay
235						$('#cookiesdirective').animate(opts.out,1000,function() {
236							// Remove the elements from the DOM and reload page
237							$('#cookiesdirective').remove();
238							location.reload(true);
239						});
240					} else {
241						// We need the box checked we want "explicit consent", display message
242						$('#epdnotick').css('display', 'block');
243					}
244				});
245			} else {
246				// Implied consent, just a button to close it
247				$('#impliedsubmit').click(function() {
248					// Set a cookie to prevent this being displayed again
249					setCookie('cookiesDirective',1,365);
250					// Close the overlay
251					$('#cookiesdirective').animate(opts.out,1000,function() {
252						// Remove the elements from the DOM and reload page
253						$('#cookiesdirective').remove();
254					});
255				});
256			}
257
258			if(settings.duration > 0)
259			{
260				// Set a timer to remove the warning after 'settings.duration' seconds
261				setTimeout(function(){
262					$('#cookiesdirective').animate({
263						opacity:'0'
264					},2000, function(){
265						$('#cookiesdirective').css(dp,'-300px');
266					});
267				}, settings.duration * 1000);
268			}
269		});
270	};
271})(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.