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