1/* 2 * Cookie Consent jQuery plugin v1.3.0 3 * http://PrivacyPolicies.com/cookie-consent/ 4 * 5 * Copyright 2012-2018, PrivacyPolicies.com 6 * Dual licensed under the MIT or GPL Version 2 licenses. 7 */ 8 9$.extend({ 10 cookieconsent: function(options){ 11 if(typeof(options) == 'undefined'){ options = {}; } 12 13 var current_level = null; 14 var notice_timeout = null; 15 var our_domain = 'privacypolicies.com'; 16 var cookieconsent_root_url = '//privacypolicies.com/cookie-consent/'; 17 18 // overridable config 19 var config = { 20 _demo_mode: false, 21 22 cookieconsent_css_filepath: '/css/cookie-consent.css', 23 cookie_name: 'cookie_consent_level', 24 cookie_expires: new Date((new Date()).getTime() + 365*24*60*60*1000), // default to 365 days in the future 25 26 autorun: true, 27 28 // the id of one of the supplied levels 29 default_level_id: 'functional', 30 31 // popup element 32 popup_container: 'body', 33 34 // can either be a string of html or an element containing the intial text explaning what's going on 35 cookie_notice: "The cookie settings on this website are set to 'allow all cookies' to give you the very best experience. If you continue without changing these settings, you consent to this - but if you want, you can change your settings at any time <strong>at the bottom of this page</strong>.", 36 37 // can either be a string of html or an element containing the intro text to the change settings dialog 38 edit_settings_intro: "<h2>Your cookie settings</h2><p>Cookies are very small text files that are stored on your computer when you visit some websites.</p><p>We use cookies to make our website easier for you to use. You can remove any cookies already stored on your computer, but these may prevent you from using parts of our website.</p>", 39 40 // time in seconds that the notice will be displayed before being automatically hidden 41 cookie_notice_autohide_timeout: 20, // 0 for never 42 43 // an element that when clicked will let the user edit their settings. if the element is empty, this plugin will add some call to action text 44 edit_settings_element: null, 45 46 // callback for when the level is changed *by the user* 47 on_change: function(){}, 48 49 // path to the css file for a jQuery UI theme (stock or custom - doesn't matter) 50 // set to an empty string in order to use one already specified elsewhere on the site 51 //jqueryui_theme_css: 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.10/themes/pepper-grinder/jquery-ui.css', 52 jqueryui_theme_css: '', 53 54 // url of a page explaning how cookies are to be used on the website 55 cookie_policy_url: '', 56 57 // consent levels, starting with basic (legal for all sites) and incrementally getting more cookies set 58 // when the run() method is called, callback functions will be invoked from level index 0 through to the current level 59 levels: [ 60 { 61 id: 'necessary', 62 title: 'Strictly necessary<br />& Performance', 63 permissions: ['Remember what is in your shopping basket', 'Remember how far you are through an order'], 64 callback: function(){ } 65 }, 66 { 67 id: 'functional', 68 title: 'Functional', 69 permissions: ['Remember your log-in details', 'Make sure you\'re secure when logged in to the website', 'Make sure the website looks consistent'], 70 callback: function(){ } 71 }, 72 { 73 id: 'tracking', 74 title: 'Tracking', 75 permissions: ['Monitor how you travel through the website'], 76 callback: function(){ } 77 }, 78 { 79 id: 'targeting', 80 title: 'Targeting', 81 permissions: ['Allow you to share pages with social networks like Facebook', 'Send information to other websites so that advertising is more relevant to you'], 82 callback: function(){ } 83 } 84 ] 85 }; 86 87 // if levels have been specified then remove default levels 88 if(options.levels && options.levels.length > 0){ config.levels = []; } 89 90 $.extend(true, config, options); 91 92 if(config.jqueryui_theme_css && config.jqueryui_theme_css .length){ 93 $('head').append('<link id="cookieconsent-theme-link" rel="stylesheet" href="'+config.jqueryui_theme_css+'" t
93ype="text/css" />'); 94 } 95 $('head').append('<link rel="stylesheet" href="'+config.cookieconsent_css_filepath+'" type="text/css" />'); 96 97 function error(message){ 98 if(window.console && window.console.error){ console.error(message, this); } 99 } 100 101 // sanity checks 102 if(config.levels.length == 1){ error('cookieconsent needs at least 2 levels. level 1 is legal without consent, so there\'d be no need for this plugin.'); return; } 103 if(config.levels.length > 4){ error('cookieconsent accepts a maximum of 4 levels.'); return; } 104 for(var i=0, level; level=config.levels[i]; i++){ 105 if(level.id.indexOf(' ') > -1){ error('cookieconsent level id properties cannot contain spaces.'); return; } 106 } 107 config.edit_settings_element = $(config.edit_settings_element); 108 if(config.edit_settings_element.length == 0){ error('cookieconsent could not find the element specific in the edit_settings_element property'); return; } 109 110 // level methods 111 config.levels.get = function(level_id){ 112 return get_by_id.call(this, level_id); 113 }; 114 config.levels.select = function(level){ 115 switch(typeof(level)){ 116 case 'string': 117 level = get_by_id.call(config.levels, level); 118 break; 119 case 'object': 120 level = get_by_id.call(config.levels, level.id); 121 break; 122 default: 123 error('select_level() requires a level id or an actual level object'); 124 return; 125 } 126 127 if(level){ 128 current_level = level; 129 130 // set cookie 131 cookies.set(config.cookie_name, current_level.id); 132 133 // update level changer 134 var buttons = level_changer.find('a'); 135 buttons.removeClass('activated'); 136 for(var i=0, button; button=buttons[i]; i++){ 137 $(button).addClass('activated'); 138 if($(button).data('level').id == level.id){ break; } 139 } 140 141 // update the permission lists 142 var permission_destination = permission_panels.find('.cookieconsent-permission-panel-allowed ul'); 143 permission_destination.find('*').remove(); 144 for(var i=0, level; level=this[i]; i++){ 145 for(var x=0, permission; permission=level.permissions[x]; x++){ 146 permission_destination.append('<li>'+permission+'</li>'); 147 } 148 if(level.id == current_level.id){ 149 permission_destination = permission_panels.find('.cookieconsent-permission-panel-disallowed ul'); 150 permission_destination.find('*').remove(); 151 } 152 } 153 permission_panels.find('ul').hide().fadeIn('normal'); 154 }else{ 155 // supplied level not found, so first try and fall back to the default level, if that fails, default to first level 156 level = config.levels.get(config.default_level_id); 157 if(!level){ 158 if(config.levels.length > 0){ 159 level = config.levels[0]; 160 }else{ 161 error('cookieconsent level supplied to select_level does not exist, and could not default'); 162 return; 163 } 164 } 165 return config.levels.select(level); 166 } 167 return level; 168 }; 169 config.levels.saved = function(){ 170 return get_by_id.call(config.levels, cookies.get(config.cookie_name)); 171 }; 172 173 // array helpers 174 function get_by_id(id){ 175 for(var i=0, elem; elem=this[i]; i++) 176 if(elem.id == id){ return elem;} 177 return null; 178 }; 179 180 // cookie methods 181 var cookies = { 182 set: function(name, value){ 183 document.cookie = name + "=" + escape(value) + "; expires=" + config.cookie_expires.toGMTString() + "; path=/;"; 184 }, 185 get: function(name){ 186 var dc = document.cookie; 187 var prefix = name + "="; 188 var begin = dc.indexOf("; " + prefix); 189 if (begin == -1) { 190 begin = dc.indexOf(prefix); 191 if (begin != 0) return ""; 192 } else 193 begin += 2; 194 var end = document.cookie.indexOf(";", begin); 195 if (end == -1) 196 end = dc.length; 197 return unescape(dc.substring(begin + prefix.length, end)); 198 } 199 }; 200 201 // popup function 202 function show_popup() { 203 var popup = $( 204 '<div class="ui-widget ui-widget-content ui-corner-top cookieconsent-popup">' + 205 (typeof(config.cookie_notice) == 'string' ? config.cookie_notice : config.cookie_notice.html()) + 206 '<div class="cookieconsent-button-wrap" />' + 207 (config.cookie_policy_url.length > 0?'<a href="'+config.cookie_policy_url+'" class="cookieconsent-cookie-policy-link" target="_blank">Read our Privacy Policy</a>':'') + 208 //'<a class="cookieconsent-toggle-magic-button cookieconsent-magic-button-related" href="#"><span class="ui-icon ui-icon-alert"></span>
208Not concerned with cookies?</a>' + 209 '</div>' 210 ); 211 var change_settings = make_button('Your Cookie Settings', 'ui-icon-wrench'); 212 var dismiss = make_button('Dismiss', 'ui-icon-close'); 213 214 popup.find('.cookieconsent-button-wrap').append(change_settings).append(dismiss); 215 popup.hover(function(){ $(this).data('mouseover', true); }, function(){ $(this).data('mouseover', false); }); 216 popup.find('.cookieconsent-toggle-magic-button').click(function(){ 217 $('.cookieconsent-magic-button-wrap').show(); 218 $('.cookieconsent-toggle-magic-button').hide(); 219 edit_settings(); 220 return false; 221 }); 222 223 change_settings.click(function(){ 224 edit_settings(); 225 }); 226 dismiss.click(function(){ 227 popup.fadeOut('normal'); 228 }); 229 230 $(config.popup_container).append(popup); 231 232 if(config.cookie_notice_autohide_timeout > 0){ 233 notice_timeout = setTimeout(function(){ 234 if(!popup.data('mouseover')){ popup.fadeOut('normal'); } 235 }, (config.cookie_notice_autohide_timeout * 1000)); 236 } 237 } 238 239 // show popup if no cookie_name is set 240 if(!cookies.get(config.cookie_name)) { 241 show_popup(); 242 } 243 244 // edit settings dialog 245 var overlay = $('<div class="ui-widget-overlay cookieconsent-overlay" />'); 246 var settings_dialog = $( 247 '<div class="ui-widget ui-widget-content ui-corner-all cookieconsent-dialog-content cookieconsent-edit-settings">' + 248 (typeof(config.edit_settings_intro) == 'string' ? config.edit_settings_intro : config.edit_settings_intro.html()) + 249 //'<a class="cookieconsent-toggle-magic-button cookieconsent-magic-button-related" href="#" onclick="$(\'.cookieconsent-magic-button-wrap\').fadeIn(\'normal\'); $(\'.cookieconsent-toggle-magic-button\').hide(); return false;"><span class="ui-icon ui-icon-alert"></span>Not concerned with cookies? Click here.</a>' + 250 '<div class="cookieconsent-magic-button-wrap cookieconsent-magic-button-related">' + 251 '<div class="ui-state-highlight ui-corner-all">' + 252 '<iframe allowtransparency="true" frameborder="0" scrolling="auto"></iframe>' + 253 '</div>' + 254 '</div>' + 255 '<div class="cookieconsent-level-changer-wrap">' + 256 '<p style="text-align:center; clear:both; padding:5px 10px;" class="ui-state-highlight">Use the buttons below to see the different types of cookies you can choose to allow.</p>' + 257 '<div class="cookieconsent-level-changer" />' + 258 '<div class="cookieconsent-permission-panels">' + 259 '<div class="ui-corner-all cookieconsent-permission-panel-disallowed"><div class="ui-corner-top ui-widget-header cookieconsent-permission-panel-title">This website cannot:</div><ul class="ui-widget ui-widget-content ui-corner-bottom" /></div>' + 260 '<div class="ui-corner-all cookieconsent-permission-panel-allowed"><div class="ui-corner-top ui-widget-header cookieconsent-permission-panel-title">This website is allowed to:</div><ul class="ui-widget ui-widget-content ui-corner-bottom" /></div>' + 261 '</div>' + 262 '</div>' + 263 (config.cookie_policy_url.length > 0?'<a href="'+config.cookie_policy_url+'" class="cookieconsent-cookie-policy-link" target="_blank">Read our Privacy Policy</a>':'') + 264 //'<a href="http://privacypolicies.com/cookie-consent/" target="_blank" class="ui-corner-all cookieconsent-logo-link">Powered by PrivacyPolicies.com</a>' + 265 '</div>' 266 ); 267 var close_settings_dialog = make_button('Save & Close', 'ui-icon-check').addClass('cookieconsent-dialog-close'); 268 settings_dialog.append(close_settings_dialog); 269 $('body').append(overlay.hide()).append($('<div class="cookieconsent-dialog" />').append(settings_dialog.hide())); 270 close_settings_dialog.click(function(){ close_settings(); }); 271 settings_dialog.parent().click(function(){ close_settings(); }); 272 settings_dialog.click(function(e){ e.stopPropagation(); }); 273 overlay.click(function(){ close_settings(); }); 274 275 // level changer 276 var level_changer = settings_dialog.find('.cookieconsent-level-changer'); 277 for(var i=0, level; level=config.levels[i]; i++){ 278 var width = (96 / config.levels.length); 279 var margin = ((4 / config.levels.length) / 2); 280 var button = $( 281 '<a href="#" class="ui-corner-all" style="width:'+width+'%; margin:'+margin+'%;">' + 282 '<span class="cookieconsent-level-button-icon cookieconsent-level-'+level.id+'" />' + 283 '<span class="cookieconsent-level-button-title">'+level.title+'</span>' + 284 '</a>' 285 ); 286 button.data('level', level); 287 button.click(function(){ 288 config.levels.select($(this).data('level'));
289 if(typeof(config.on_change) == 'function'){ config.on_change(); } 290 return false; 291 }); 292 293 // Trigger function from script tags 294 // Stop only when current_level meet 295 var scriptTrigger = function (stop_with_current_level) { 296 for(var i=0, level; level=config.levels[i]; i++){ 297 current_level = cookies.get(config.cookie_name); 298 299 var level_scripts = $('script[cookieconsent-level='+level.id+']'); 300 301 level_scripts.each(function(){ 302 303 var src = $(this).attr('src'); 304 305 if (typeof src !== typeof undefined && src !== false) { 306 $(this).attr('type', 'text/javascript'); 307 //console.log($(this).attr('src')); 308 } else { 309 $(this).replaceWith(eval($(this).text())); 310 //console.log($(this).text()); 311 } 312 313 }); 314 315 if (level.id === stop_with_current_level) { 316 break; 317 } 318 } 319 }; 320 321 // Trigger function init 322 current_level = cookies.get(config.cookie_name); 323 324 if (current_level) { 325 scriptTrigger(current_level); 326 } else { 327 cookies.set(config.cookie_name, config.default_level_id); 328 } 329 330 // Trigger function when click setting level 331 button.click(function () { 332 var new_current_level_id = $(this).data('level').id 333 if (typeof $(this).data('level').callback == 'function') { 334 run_callbacks(new_current_level_id); 335 } 336 scriptTrigger(new_current_level_id); 337 338 // Save new current_level into cookies 339 cookies.set(config.cookie_name, new_current_level_id); 340 }); 341 level_changer.append(button); 342 343 // set the icon (the bars) 344 var icon_wrap = button.find('.cookieconsent-level-button-icon'); 345 for(var x=0; x<config.levels.length; x++){ 346 var height = (100-((90/config.levels.length)*((config.levels.length-1)-x))); 347 var width = (100/config.levels.length); 348 var left = ((width*x)+(margin*x)); 349 icon_wrap.append('<div style="height:'+height+'%; width:'+width+'%; left:'+left+'%;"'+(x<=i?' class="activated"':'')+' />'); 350 } 351 } 352 353 // permission panels 354 var permission_panels = settings_dialog.find('.cookieconsent-permission-panels'); 355 356 // edit settings link 357 if(config.edit_settings_element != null){ 358 switch(config.edit_settings_element[0].nodeName.toLowerCase()){ 359 case 'input': 360 if(trim(config.edit_settings_element.val()).length == 0){ config.edit_settings_element.val('Change your cookie settings'); } 361 break; 362 default: 363 if(trim(config.edit_settings_element.html()).length == 0){ config.edit_settings_element.html('Change your cookie settings'); } 364 } 365 config.edit_settings_element.click(function(){ edit_settings(); return false; }); 366 } 367 368 function edit_settings(){ 369 overlay.show(); 370 settings_dialog.css({'top': $(window).scrollTop()+'px'}).fadeIn('fast'); 371 $('.cookieconsent-popup').hide(); 372 } 373 function close_settings(){ 374 overlay.hide(); 375 settings_dialog.fadeOut('fast'); 376 } 377 378 // ui elements 379 function make_button(text, icon_class){ 380 var button = $('<button class="ui-button ui-widget ui-state-default ui-corner-all">'+(icon_class?'<span class="ui-icon '+icon_class+' ui-button-icon-primary" />':'')+'<span class="ui-button-text">'+text+'</span></button>'); 381 if(icon_class){ 382 button.addClass('ui-button-text-icon-primary'); 383 }else{ 384 button.addClass('ui-button-text-only'); 385 } 386 return button; 387 } 388 389 // functional helpers 390 function trim(text, char){ 391 if(!char){ char = '\\s'; } 392 return text.replace(eval('/^'+char+'+/'), '').replace(eval('/'+char+'+$/'), ''); 393 }; 394 395 function run_callbacks(stop_with_current_level){ 396 var script_elems = []; 397 var loaded_script_count = 0; 398 399 // when all level-applicable scripts have completed loading (if any) execute callbacks 400 function check_loaded_and_exec(){ 401 if(script_elems.length > loaded_script_count){ return; } 402 403 for(var i=0, level; level=config.levels[i]; i++){ 404 if(typeof(level.callback) == 'function'){ level.callback(); } 405 406 if(stop_with_current_level && level.id == current_level.id){ return; } 407 } 408 } 409 410 // find the scripts to be converted 411 for(var i=0, level; level=config.levels[i]; i++){ 412 var level_scripts = $('script[cookieconsent-level='+level.id+']'); 413 level_scripts.each(function(){ 414 script_elems.push($(this)); 415 }); 416 417 if(stop_with_current_level && level.id == current_level.id){ break; } 418 } 419 420 // convert the scripts 421 for(var i=0, script; script=script_elems[i]; i++){ 422 var self = script; 423 if(self.attr('src')){ 424 $.getScript(self.attr('src'), function(){ 425 loaded_script_count++; 426 check_loaded_and_exec(); 427 });
428 } else { 429 self.attr('type', 'text/javascript') 430 $('head').append(self); 431 loaded_script_count++; 432 check_loaded_and_exec(); 433 } 434 } 435 436 // check immediately incase there's no scripts needed for callbacks 437 check_loaded_and_exec(); 438 } 439 440 // initialise and run 441 function initialise(){ 442 443 function non_global_consent_operations(prevent_callback_execution){ 444 445 // popup message if they haven't yet seen the cookie notice 446 if(config._demo_mode || config.levels.saved() == null){ 447 show_popup(); 448 } 449 450 initialise_level_changer(); 451 452 if(!prevent_callback_execution){ 453 // runs through each level's callbacks up to and including the current level 454 run_callbacks(true); 455 } 456 } 457 458 function initialise_level_changer(){ 459 var saved_level = config.levels.saved(); 460 461 if(saved_level == null){ 462 config.levels.select(config.default_level_id); 463 } else { 464 // initialise UI with current level 465 config.levels.select(saved_level); 466 } 467 } 468 469 470 // magic button 471 if(typeof(window.postMessage) == 'function'){ 472 473 function show_level_change(){ 474 $('.cookieconsent-level-changer-wrap').show(); 475 $('.cookieconsent-magic-button-wrap').hide(); 476 $('.cookieconsent-toggle-magic-button').show(); 477 initialise_level_changer(); 478 } 479 function hide_level_change(){ 480 $('.cookieconsent-level-changer-wrap').hide(); 481 $('.cookieconsent-magic-button-wrap').show(); 482 $('.cookieconsent-toggle-magic-button').hide(); 483 } 484 485 window.addEventListener("message", function(event){
486 if(event.origin.replace(/^http(s)?:\/\//, '') == our_domain){ 487 switch(event.data){ 488 case 'global_enabled': 489 hide_level_change(); 490 break; 491 case 'global_disabled': 492 show_level_change(); 493 break; 494 default: 495 var parts = event.data.split(':'); 496 if(parts.length == 2 && parts[0] == 'cookie_consent_global_allow'){ 497 switch(parts[1]){ 498 case 'true': 499 // run all callbacks regardless of set level 500 run_callbacks(false); 501 502 hide_level_change(); 503 504 if(config._demo_mode){ 505 non_global_consent_operations(true); 506 } 507 break; 508 case 'false': 509 non_global_consent_operations(); 510 break; 511 default: 512 error('unrecognised response from Magic Button frame'); 513 return; 514 } 515 } 516 } 517 } 518 }, false); 519 }else{ 520 // older browsers which don't support cross domain messaging. 521 // show the popup and don't allow Magic Button support 522 523 non_global_consent_operations(); 524 525 // hide Magic Button references 526 $('.cookieconsent-magic-button-related').hide(); 527 } 528 529 // now we've set up the event listener (or not), we can safely set the magic button iframe source, and wait for any responses 530 settings_dialog.find('iframe').attr('src', cookieconsent_root_url+'magic-button/'); 531 // magic button 532 533 } 534 if(config.autorun){ 535 initialise(); 536 } 537 538 // public 539 return { 540 get_levels: function(){ 541 return config.levels; 542 }, 543 get_level: function(level_id){ 544 return config.levels.get(level_id); 545 }, 546 select_level: function(level){ 547 return config.levels.select(level); 548 }, 549 saved_level: function(level){ 550 return config.levels.saved(); 551 }, 552 is_granted: function(level_id){ 553 for(var i=0, level; level=config.levels[i]; i++){ 554 if(level.id == level_id){ return true; } 555 if(level.id == current_level.id){ return false; } 556 } 557 return false; 558 }, 559 edit_settings: function(){ 560 edit_settings(); 561 }, 562 run: function(){ 563 initialise(); 564 } 565 }; 566 } 567});
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.