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