1/** 2 * @file 3 * eu_cookie_compliance.js 4 * 5 * Defines the behavior of the eu cookie compliance banner. 6 * 7 * Statuses: 8 * null: not yet agreed (or withdrawn), show popup 9 * 0: Disagreed 10 * 1: Agreed, show thank you banner 11 * 2: Agreed 12 */ 13 14(function ($, Drupal, drupalSettings) { 15 16 'use strict'; 17 var euCookieComplianceBlockCookies; 18 19 Drupal.behaviors.euCookieCompliancePopup = { 20 attach: function (context) { 21 $(drupalSettings.eu_cookie_compliance.containing_element).once('eu-cookie-compliance').each(function () { 22 23 // Initialize internal variables. 24 _euccCurrentStatus = self.getCurrentStatus(); 25 _euccSelectedCategories = self.getAcceptedCategories(); 26 // If configured, check JSON callback to determine if in EU. 27 if (drupalSettings.eu_cookie_compliance.popup_eu_only_js) { 28 if (Drupal.eu_cookie_compliance.showBanner()) { 29 var url = drupalSettings.path.baseUrl + drupalSettings.path.pathPrefix + 'eu-cookie-compliance-check'; 30 var data = {}; 31 $.getJSON(url, data, function (data) { 32 // If in the EU, show the compliance banner. 33 if (data.in_eu) { 34 Drupal.eu_cookie_compliance.execute(); 35 } 36 37 // If not in EU, set an agreed cookie automatically. 38 else { 39 Drupal.eu_cookie_compliance.setStatus(2); 40 // Also set all the categories as agreed if applicable, and load 41 // scripts. 42 if (drupalSettings.eu_cookie_compliance.method === 'categories') { 43 var categories = drupalSettings.eu_cookie_compliance.cookie_categories; 44 Drupal.eu_cookie_compliance.setAcceptedCategories(categories); 45 Drupal.eu_cookie_compliance.loadCategoryScripts(categories); 46 } 47 } 48 }); 49 } 50 } 51 52 // Otherwise, fallback to standard behavior which is to render the banner. 53 else { 54 Drupal.eu_cookie_compliance.execute(); 55 } 56 $(this).addClass('eu-cookie-compliance-status-' + Drupal.eu_cookie_compliance.getCurrentStatus()); 57 }); 58 }, 59 }; 60 61 // Set up the namespace as a function to store list of arguments in a queue. 62 Drupal.eu_cookie_compliance = Drupal.eu_cookie_compliance || function () { 63 (Drupal.eu_cookie_compliance.queue = Drupal.eu_cookie_compliance.queue || []).push(arguments) 64 }; 65 // Initialize the object with some data. 66 Drupal.eu_cookie_compliance.a = +new Date; 67 // A shorter name to use when accessing the namespace. 68 var self = Drupal.eu_cookie_compliance; 69 // Save our cookie preferences locally only. 70 // Used by external scripts to modify data before it is used. 71 var _euccSelectedCategories = []; 72 var _euccCurrentStatus = null; 73 self.updateSelectedCategories = function (categories) { 74 _euccSelectedCategories = categories; 75 } 76 self.updateCurrentStatus = function (status) { 77 _euccCurrentStatus = status; 78 } 79 80 Drupal.eu_cookie_compliance.execute = function () { 81 try { 82 if (!drupalSettings.eu_cookie_compliance.popup_enabled) { 83 return; 84 } 85 86 if (!Drupal.eu_cookie_compliance.cookiesEnabled()) { 87 return; 88 } 89 90 Drupal.eu_cookie_compliance.getCurrentStatus(); 91 92 if (typeof Drupal.eu_cookie_compliance.getVersion() === 'undefined') { 93 // If version doesn't exist as a cookie, set it to the current one. 94 // For modules that update to this, it prevents needless retriggering 95 // For first time runs, it makes no difference as the other IF statements 96 // below will still cause the popup to trigger 97 // For incrementing the version, it also makes no difference as either it's 98 // a returning user and will have a version set, or it's a new user and 99 // the other checks will trigger it. 100 Drupal.eu_cookie_compliance.setVersion(); 101 } 102 103 var versionChanged = Drupal.eu_cookie_compliance.getVersion() !== drupalSettings.eu_cookie_compliance.cookie_policy_version; 104 // Closed if status has a value and the version hasn't changed. 105 var closed = _euccCurrentStatus !== null && !versionChanged; 106 // Only worried about OPT_IN / GDPR method at present for the perm. settings tab. 107 if (_euccCurrentStatus == 0 && drupalSettings.eu_cookie_compliance.settings_tab_enabled && drupalSettings.eu_cookie_compliance.method === 'opt_in' && !versionChanged) { 108 Drupal.eu_cookie_compliance.createPopup(drupalSettings.eu_cookie_compliance.popup_html_info, (_euccCurrentStatus !== null)); 109 $('.eu-cookie-withdraw-tab').click(Drupal.eu_cookie_compliance.toggleWithdrawBanner); 110 Drupal.eu_cookie_compliance.attachAgreeEvents(); 111 } 112 else if ((_euccCurrentStatus === 0 && drupalSettings.eu_cookie_compliance.method === 'default') || _euccCurrentStatus === null || (_euccCurrentStatus !== 1 && drupalSettings.eu_cookie_compliance.withdraw_enabled && drupalSettings.eu_cookie_compliance.withdraw_button_on_info_popup) || (_euccCurrentStatus !== 1 && versionChanged)) { 113 if (drupalSettings.eu_cookie_compliance.withdraw_enabled || !drupalSettings.eu_cookie_compliance.disagree_do_not_show_popup || _euccCurrentStatus === null) { 114 // Detect mobile here and use mobile_popup_html_info, if we have a mobile device. 115 if (window.matchMedia('(max-width: ' + drupalSettings.eu_cookie_compliance.mobile_breakpoint + 'px)').matches && drupalSettings.eu_cookie_compliance.use_mobile_message) { 116 Drupal.eu_cookie_compliance.createPopup(drupalSettings.eu_cookie_compliance.mobile_popup_html_info, closed); 117 } 118 else { 119 Drupal.eu_cookie_compliance.createPopup(drupalSettings.eu_cookie_compliance.popup_html_info, closed); 120 } 121 Drupal.eu_cookie_compliance.initPopup(); 122 Drupal.eu_cookie_compliance.resizeListener(); 123 } 124 } 125 else if (_euccCurrentStatus === 1 && drupalSettings.eu_cookie_compliance.popup_agreed_enabled) { 126 // Thank you banner. 127 Drupal.eu_cookie_compliance.createPopup(drupalSettings.eu_cookie_compliance.popup_html_agreed); 128 Drupal.eu_cookie_compliance.attachHideEvents(); 129 } 130 else if (_euccCurrentStatus === 2 && drupalSettings.eu_cookie_compliance.withdraw_enabled) { 131 if (!drupalSettings.eu_cookie_compliance.withdraw_button_on_info_popup) { 132 Drupal.eu_cookie_compliance.createWithdrawBanner(drupalSettings.eu_cookie_compliance.withdraw_markup); 133 Drupal.eu_cookie_compliance.initPopup(); 134 Drupal.eu_cookie_compliance.resizeListener(); 135 } 136 } 137 } 138 catch (e) { 139 } 140 }; 141 142 Drupal.eu_cookie_compliance.initPopup = function () { 143 Drupal.eu_cookie_compliance.attachAgreeEvents(); 144 145 if (drupalSettings.eu_cookie_compliance.method === 'categories') { 146 Drupal.eu_cookie_compliance.setPreferenceCheckboxes(_euccSelectedCategories); 147 Drupal.eu_cookie_compliance.attachSavePreferencesEvents(); 148 } 149 150 if (drupalSettings.eu_cookie_compliance.withdraw_enabled) { 151 Drupal.eu_cookie_compliance.attachWithdrawEvents(); 152 if (_euccCurrentStatus === 1 || _euccCurrentStatus === 2) { 153 $('.eu-cookie-withdraw-button').show(); 154 } 155 } 156 } 157 158 Drupal.eu_cookie_compliance.positionTab = function () { 159 if (drupalSettings.eu_cookie_compliance.popup_position) { 160 var totalHeight = $('.eu-cookie-withdraw-tab').outerHeight() + $('.eu-cookie-compliance-banner').outerHeight(); 161 $('.eu-cookie-withdraw-tab').css('margin-top', totalHeight + 'px'); 162 } 163 }; 164 165 166 Drupal.eu_cookie_compliance.createWithdrawBanner = function (html) { 167 var $html = $('<div></div>').html(html); 168 var $banner = $('.eu-cookie-withdraw-banner', $html); 169 $html.attr('id', 'sliding-popup'); 170 $html.addClass('eu-cookie-withdraw-wrapper'); 171 172 if (!drupalSettings.eu_cookie_compliance.popup_use_bare_css) { 173 $banner.height(drupalSettings.eu_cookie_compliance.popup_height) 174 .width(drupalSettings.eu_cookie_compliance.popup_width); 175 } 176 $html.hide(); 177 var height = 0; 178 if (drupalSettings.eu_cookie_compliance.popup_position) { 179 $html.prependTo(drupalSettings.eu_cookie_compliance.containing_element); 180 height = $html.outerHeight(); 181 182 $html.show() 183 .addClass('sliding-popup-top') 184 .addClass('clearfix') 185 .css({ top: !drupalSettings.eu_cookie_compliance.fixed_top_position ? -(parseInt($(drupalSettings.eu_cookie_compliance.containing_element).css('padding-top')) + parseInt($(drupalSettings.eu_cookie_compliance.containing_element).css('margin-top')) + height) : -1 * height }); 186 // For some reason, the tab outerHeight is -10 if we don't use a timeout 187 // function to reveal the tab. 188 setTimeout(function () { 189 var height = $html.outerHeight(); 190 191 $html.animate({ top: !drupalSettings.eu_cookie_compliance.fixed_top_position ? -(parseInt($(drupalSettings.eu_cookie_compliance.containing_element).css('padding-top')) + parseInt($(drupalSettings.eu_cookie_compliance.containing_element).css('margin-top')) + height) : -1 * height }, drupalSettings.eu_cookie_compliance.popup_delay, null, function () { 192 $html.trigger('eu_cookie_compliance_popup_open'); 193 $('body').addClass('eu-cookie-compliance-popup-open'); 194 Drupal.eu_cookie_compliance.positionTab(); 195 }); 196 }.bind($html), 0); 197 } 198 else { 199 if (drupalSettings.eu_cookie_compliance.better_support_for_screen_readers) { 200 $html.prependTo(drupalSettings.eu_cookie_compliance.containing_element); 201 } 202 else { 203 $html.appendTo(drupalSettings.eu_cookie_compliance.containing_element); 204 } 205 height = $html.outerHeight(); 206 $html.show() 207 .addClass('sliding-popup-bottom') 208 .css({ bottom: -1 * height }); 209 // For some reason, the tab outerHeight is -10 if we don't use a timeout 210 // function to reveal the tab. 211 setTimeout(function () { 212 var height = $html.outerHeight(); 213 214 $html.animate({ bottom: -1 * (height) }, drupalSettings.eu_cookie_compliance.popup_delay, null, function () { 215 $html.trigger('eu_cookie_compliance_popup_open'); 216 $('body').addClass('eu-cookie-compliance-popup-open'); 217 }); 218 }.bind($html), 0); 219 } 220 }; 221 222 Drupal.eu_cookie_compliance.toggleWithdrawBanner = function () { 223 var $wrapper = $('#sliding-popup'); 224 var height = $wrapper.outerHeight(); 225 var bannerIsShowing = ($wrapper.find('.eu-cookie-compliance-banner, .eu-cookie-withdraw-banner').is(':visible')); 226 if (bannerIsShowing) { 227 bannerIsShowing = drupalSettings.eu_cookie_compliance.popup_position ? parseInt($wrapper.css('top')) === (!drupalSettings.eu_cookie_compliance.fixed_top_position ? -(parseInt($(drupalSettings.eu_cookie_compliance.containing_element).css('padding-top')) + parseInt($(drupalSettings.eu_cookie_compliance.containing_element).css('margin-top'))) : 0) : parseInt($wrapper.css('bottom')) === 0; 228 } 229 if (drupalSettings.eu_cookie_compliance.popup_position) { 230 if (bannerIsShowing) { 231 $wrapper.animate({ top: !drupalSettings.eu_cookie_compliance.fixed_top_position ? -(parseInt($(drupalSettings.eu_cookie_compliance.containing_element).css('padding-top')) + parseInt($(drupalSettings.eu_cookie_compliance.containing_element).css('margin-top')) + height) : -1 * height }, drupalSettings.eu_cookie_compliance.popup_delay).trigger('eu_cookie_compliance_popup_close'); 232 $('body').removeClass('eu-cookie-compliance-popup-open'); 233 } 234 else { 235 // If "Do not show cookie policy when the user clicks the Cookie policy button." is 236 // selected, the inner banner may be hidden. 237 $wrapper.find('.eu-cookie-compliance-banner').show(); 238 $wrapper.animate({ top: !drupalSettings.eu_cookie_compliance.fixed_top_position ? -(parseInt($(drupalSettings.eu_cookie_compliance.containing_element).css('padding-top')) + parseInt($(drupalSettings.eu_cookie_compliance.containing_element).css('margin-top'))) : 0 }, drupalSettings.eu_cookie_compliance.popup_delay).trigger('eu_cookie_compliance_popup_open'); 239 $('body').addClass('eu-cookie-compliance-popup-open'); 240 } 241 } 242 else { 243 if (bannerIsShowing) { 244 $wrapper.animate({ 'bottom': -1 * (height) }, drupalSettings.eu_cookie_compliance.popup_delay).trigger('eu_cookie_compliance_popup_close'); 245 $('body').removeClass('eu-cookie-compliance-popup-open'); 246 } 247 else { 248 // If "Do not show cookie policy when the user clicks the Cookie policy button." is 249 // selected, the inner banner may be hidden. 250 $wrapper.find('.eu-cookie-compliance-banner').show(); 251 $wrapper.animate({ 'bottom': 0 }, drupalSettings.eu_cookie_compliance.popup_delay).trigger('eu_cookie_compliance_popup_open'); 252 $('body').addClass('eu-cookie-compliance-popup-open'); 253 } 254 } 255 }; 256 257 Drupal.eu_cookie_compliance.resizeListener = function () { 258 var $wrapper = $('#sliding-popup'); 259 260 var debounce = function (func, wait) { 261 var timeout; 262
263 return function executedFunction() { 264 var later = function () { 265 clearTimeout(timeout); 266 func(); 267 }; 268 269 clearTimeout(timeout); 270 timeout = setTimeout(later, wait); 271 }; 272 }; 273 274 var checkIfPopupIsClosed = debounce(function () { 275 var wrapperHeight = $wrapper.outerHeight(); 276 if (drupalSettings.eu_cookie_compliance.popup_position) { 277 var wrapperTopProperty = parseFloat($wrapper.css('bottom')); 278 if (wrapperTopProperty !== 0) { 279 $wrapper.css('top', wrapperHeight * -1); 280 } 281 } 282 else { 283 var wrapperBottomProperty = parseFloat($wrapper.css('bottom')); 284 if (wrapperBottomProperty !== 0) { 285 $wrapper.css('bottom', wrapperHeight * -1); 286 } 287 } 288 }, 50); 289 290 setTimeout(function () { 291 checkIfPopupIsClosed(); 292 }); 293 294 window.addEventListener('resize', checkIfPopupIsClosed); 295 }; 296 297 Drupal.eu_cookie_compliance.createPopup = function (html, closed) { 298 // This fixes a problem with jQuery 1.9. 299 var popup = $('<div></div>').html(html); 300 popup.attr('id', 'sliding-popup'); 301 if (!drupalSettings.eu_cookie_compliance.popup_use_bare_css) { 302 popup.height(drupalSettings.eu_cookie_compliance.popup_height) 303 .width(drupalSettings.eu_cookie_compliance.popup_width); 304 } 305 306 popup.hide(); 307 var height = 0; 308 if (drupalSettings.eu_cookie_compliance.popup_position) { 309 popup.prependTo(drupalSettings.eu_cookie_compliance.containing_element); 310 height = popup.outerHeight(); 311 popup.show() 312 .addClass('sliding-popup-top clearfix') 313 .css({ top: -1 * height }); 314 if (closed !== true) { 315 popup.animate({top: 0}, drupalSettings.eu_cookie_compliance.popup_delay, null, function () { 316 popup.trigger('eu_cookie_compliance_popup_open'); 317 $('body').addClass('eu-cookie-compliance-popup-open'); 318 Drupal.eu_cookie_compliance.positionTab(); 319 }); 320 } 321 else { 322 setTimeout(function () { 323 Drupal.eu_cookie_compliance.positionTab(); 324 }, 0); 325 } 326 } 327 else { 328 if (drupalSettings.eu_cookie_compliance.better_support_for_screen_readers) { 329 popup.prependTo(drupalSettings.eu_cookie_compliance.containing_element); 330 } 331 else { 332 popup.appendTo(drupalSettings.eu_cookie_compliance.containing_element); 333 } 334 335 height = popup.outerHeight(); 336 popup.show() 337 .addClass('sliding-popup-bottom') 338 .css({bottom: -1 * height}); 339 if (closed !== true) { 340 popup.animate({bottom: 0}, drupalSettings.eu_cookie_compliance.popup_delay, null, function () { 341 popup.trigger('eu_cookie_compliance_popup_open'); 342 $('body').addClass('eu-cookie-compliance-popup-open'); 343 }); 344 } 345 } 346 }; 347 348 Drupal.eu_cookie_compliance.attachAgreeEvents = function () { 349 var clickingConfirms = drupalSettings.eu_cookie_compliance.popup_clicking_confirmation; 350 var scrollConfirms = drupalSettings.eu_cookie_compliance.popup_scrolling_confirmation; 351 352 if (drupalSettings.eu_cookie_compliance.method === 'categories' && drupalSettings.eu_cookie_compliance.enable_save_preferences_button) { 353 // The agree button becomes an agree to all categories button when the 'save preferences' button is present. 354 $('.agree-button').click(Drupal.eu_cookie_compliance.acceptAllAction); 355 } 356 else { 357 $('.agree-button').click(Drupal.eu_cookie_compliance.acceptAction); 358 } 359 $('.decline-button').click(Drupal.eu_cookie_compliance.declineAction); 360 361 if (clickingConfirms) { 362 $('a, input[type=submit], button[type=submit]').not('.popup-content *').bind('click.euCookieCompliance', Drupal.eu_cookie_compliance.acceptAction); 363 } 364 365 if (scrollConfirms) { 366 var alreadyScrolled = false; 367 var scrollHandler = function () { 368 if (alreadyScrolled) { 369 Drupal.eu_cookie_compliance.acceptAction(); 370 $(window).off('scroll', scrollHandler); 371 } 372 else { 373 alreadyScrolled = true; 374 } 375 }; 376 377 $(window).bind('scroll', scrollHandler); 378 } 379 380 $('.find-more-button').not('.find-more-button-processed').addClass('find-more-button-processed').click(Drupal.eu_cookie_compliance.moreInfoAction); 381 }; 382 383 Drupal.eu_cookie_compliance.attachSavePreferencesEvents = function () { 384 $('.eu-cookie-compliance-save-preferences-button').click(Drupal.eu_cookie_compliance.savePreferencesAction); 385 }; 386 387 Drupal.eu_cookie_compliance.attachHideEvents = function () { 388 var popupHideAgreed = drupalSettings.eu_cookie_compliance.popup_hide_agreed; 389 var clickingConfirms = drupalSettings.eu_cookie_compliance.popup_clicking_confirmation; 390 $('.hide-popup-button').click(function () { 391 Drupal.eu_cookie_compliance.changeStatus(2); 392 } 393 ); 394 if (clickingConfirms) { 395 $('a, input[type=submit], button[type=submit]').unbind('click.euCookieCompliance'); 396 } 397 398 if (popupHideAgreed) { 399 $('a, input[type=submit], button[type=submit]').bind('click.euCookieComplianceHideAgreed', function () { 400 Drupal.eu_cookie_compliance.changeStatus(2); 401 }); 402 } 403 404 $('.find-more-button').not('.find-more-button-processed').addClass('find-more-button-processed').click(Drupal.eu_cookie_compliance.moreInfoAction); 405 }; 406 407 Drupal.eu_cookie_compliance.attachWithdrawEvents = function () { 408 $('.eu-cookie-withdraw-button').click(Drupal.eu_cookie_compliance.withdrawAction); 409 $('.eu-cookie-withdraw-tab').click(Drupal.eu_cookie_compliance.toggleWithdrawBanner); 410 }; 411 412 Drupal.eu_cookie_compliance.acceptAction = function () { 413 var agreedEnabled = drupalSettings.eu_cookie_compliance.popup_agreed_enabled; 414 var nextStatus = 1; 415 if (!agreedEnabled) { 416 Drupal.eu_cookie_compliance.setStatus(1); 417 nextStatus = 2; 418 } 419 420 if (!euCookieComplianceHasLoadedScripts && typeof euCookieComplianceLoadScripts === "function") { 421 euCookieComplianceLoadScripts(); 422 } 423 424 if (typeof euCookieComplianceBlockCookies !== 'undefined') { 425 clearInterval(euCookieComplianceBlockCookies); 426 } 427 428 if (drupalSettings.eu_cookie_compliance.method === 'categories') { 429 // Select Checked categories. 430 var categories = $("#eu-cookie-compliance-categories input:checkbox:checked").map(function () { 431 return $(this).val(); 432 }).get(); 433 Drupal.eu_cookie_compliance.setAcceptedCategories(categories); 434 // Load scripts for all categories. If no categories selected, none 435 // will be loaded. 436 Drupal.eu_cookie_compliance.loadCategoryScripts(categories); 437 if (!categories.length) { 438 // No categories selected is the same as declining all cookies. 439 nextStatus = 0; 440 } 441 } 442 443 Drupal.eu_cookie_compliance.changeStatus(nextStatus); 444 445 if (drupalSettings.eu_cookie_compliance.withdraw_enabled && drupalSettings.eu_cookie_compliance.withdraw_button_on_info_popup) { 446 Drupal.eu_cookie_compliance.attachWithdrawEvents(); 447 if (_euccCurrentStatus === 1 || _euccCurrentStatus === 2) { 448 $('.eu-cookie-withdraw-button').show(); 449 } 450 } 451 }; 452 453 Drupal.eu_cookie_compliance.acceptAllAction = function () { 454 var allCategories = drupalSettings.eu_cookie_compliance.cookie_categories; 455 Drupal.eu_cookie_compliance.setPreferenceCheckboxes(allCategories); 456 Drupal.eu_cookie_compliance.acceptAction(); 457 } 458 459 Drupal.eu_cookie_compliance.savePreferencesAction = function () { 460 var categories = $("#eu-cookie-compliance-categories input:checkbox:checked").map(function () { 461 return $(this).val(); 462 }).get(); 463 var agreedEnabled = drupalSettings.eu_cookie_compliance.popup_agreed_enabled; 464 var nextStatus = 1; 465 if (!agreedEnabled) { 466 Drupal.eu_cookie_compliance.setStatus(1); 467 nextStatus = 2; 468 } 469 470 Drupal.eu_cookie_compliance.setAcceptedCategories(categories); 471 // Load scripts for all categories. If no categories selected, none 472 // will be loaded. 473 Drupal.eu_cookie_compliance.loadCategoryScripts(categories); 474 if (!categories.length) { 475 // No categories selected is the same as declining all cookies. 476 nextStatus = 0; 477 } 478 479 Drupal.eu_cookie_compliance.changeStatus(nextStatus); 480 }; 481 482 Drupal.eu_cookie_compliance.loadCategoryScripts = function (categories) { 483 for (var cat in categories) { 484 if (euCookieComplianceHasLoadedScriptsForCategory[cat] !== true && typeof euCookieComplianceLoadScripts === "function") { 485 euCookieComplianceLoadScripts(categories[cat]); 486 euCookieComplianceHasLoadedScriptsForCategory[cat] = true; 487 } 488 } 489 } 490 491 Drupal.eu_cookie_compliance.declineAction = function () { 492 var set_cookie_session_zero_on_disagree = parseInt(drupalSettings.eu_cookie_compliance.set_cookie_session_zero_on_disagree); 493 if (set_cookie_session_zero_on_disagree) { 494 drupalSettings.eu_cookie_compliance.cookie_session = 1; 495 } 496 Drupal.eu_cookie_compliance.setStatus(0); 497 var popup = $('#sliding-popup'); 498 if (popup.hasClass('sliding-popup-top')) { 499 if (drupalSettings.eu_cookie_compliance.settings_tab_enabled) { 500 popup.animate({top: !drupalSettings.eu_cookie_compliance.fixed_top_position ? -(parseInt($(drupalSettings.eu_cookie_compliance.containing_element).css('padding-top')) + parseInt($(drupalSettings.eu_cookie_compliance.containing_element).css('margin-top')) + popup.outerHeight()) : popup.outerHeight() * -1}, drupalSettings.eu_cookie_compliance.popup_delay, null).trigger('eu_cookie_compliance_popup_close'); 501 $('.eu-cookie-withdraw-tab').click(Drupal.eu_cookie_compliance.toggleWithdrawBanner); 502 } 503 else { 504 popup.animate({top: !drupalSettings.eu_cookie_compliance.fixed_top_position ? -(parseInt($(drupalSettings.eu_cookie_compliance.containing_element).css('padding-top')) + parseInt($(drupalSettings.eu_cookie_compliance.containing_element).css('margin-top')) + popup.outerHeight()) : popup.outerHeight() * -1}, drupalSettings.eu_cookie_compliance.popup_delay, null, function () { 505 popup.hide(); 506 }).trigger('eu_cookie_compliance_popup_close'); 507 $('body').removeClass('eu-cookie-compliance-popup-open'); 508 } 509 } 510 else { 511 if (drupalSettings.eu_cookie_compliance.settings_tab_enabled) { 512 popup.animate({ bottom: popup.outerHeight() * -1 }, drupalSettings.eu_cookie_compliance.popup_delay, null).trigger('eu_cookie_compliance_popup_close'); 513 $('.eu-cookie-withdraw-tab').click(Drupal.eu_cookie_compliance.toggleWithdrawBanner); 514 } 515 else { 516 popup.animate({ bottom: popup.outerHeight() * -1 }, drupalSettings.eu_cookie_compliance.popup_delay, null, function () { 517 popup.hide(); 518 }).trigger('eu_cookie_compliance_popup_close'); 519 $('body').removeClass('eu-cookie-compliance-popup-open'); 520 } 521 } 522 }; 523 524 Drupal.eu_cookie_compliance.withdrawAction = function () { 525 var set_cookie_session_zero_on_disagree = parseInt(drupalSettings.eu_cookie_compliance.set_cookie_session_zero_on_disagree); 526 if (set_cookie_session_zero_on_disagree) { 527 drupalSettings.eu_cookie_compliance.cookie_session = 1; 528 } 529 Drupal.eu_cookie_compliance.setStatus(null); 530 Drupal.eu_cookie_compliance.setAcceptedCategories([]); 531 location.reload(); 532 }; 533 534 Drupal.eu_cookie_compliance.moreInfoAction = function () { 535 if (drupalSettings.eu_cookie_compliance.disagree_do_not_show_popup) { 536 Drupal.eu_cookie_compliance.setStatus(0); 537 if (drupalSettings.eu_cookie_compliance.withdraw_enabled && drupalSettings.eu_cookie_compliance.withdraw_button_on_info_popup) { 538 $('#sliding-popup .eu-cookie-compliance-banner').trigger('eu_cookie_compliance_popup_close').hide(); 539 $('body').removeClass('eu-cookie-compliance-popup-open'); 540 } 541 else { 542 $('#sliding-popup').trigger('eu_cookie_compliance_popup_close').remove(); 543 $('body').removeClass('eu-cookie-compliance-popup-open'); 544 } 545 } 546 else { 547 if (drupalSettings.eu_cookie_compliance.popup_link_new_window) { 548 window.open(drupalSettings.eu_cookie_compliance.popup_link); 549 } 550 else { 551 window.location.href = drupalSettings.eu_cookie_compliance.popup_link; 552 } 553 } 554 }; 555 556 Drupal.eu_cookie_compliance.getCookieStatus = function () { 557 var cookieName = (typeof drupalSettings.eu_cookie_compliance.cookie_name === 'undefined' || drupalSettings.eu_cookie_compliance.cookie_name === '') ? 'cookie-agreed' : drupalSettings.eu_cookie_compliance.cookie_name; 558 var storedStatus = $.cookie(cookieName); 559 var currentStatus = parseInt(storedStatus); 560 if (isNaN(currentStatus)) { 561 currentStatus = null; 562 } 563 return currentStatus; 564 } 565 566 Drupal.eu_cookie_compliance.getCurrentStatus = function () { 567 // Make a new observer & fire it to allow other scripts to hook in. 568 var preStatusLoadObject = new PreStatusLoad(); 569 self.handleEvent('preStatusLoad', preStatusLoadObject); 570 571 _euccCurrentStatus = Drupal.eu_cookie_compliance.getCookieStatus(); 572 573 // Make a new observer & fire it to allow other scripts to hook in. 574 var postStatusLoadObject = new PostStatusLoad(); 575 self.handleEvent('postStatusLoad', postStatusLoadObject); 576 577 return _euccCurrentStatus; 578 }; 579 580 Drupal.eu_cookie_compliance.setPreferenceCheckboxes = function (categories) { 581 for (var i in categories) { 582 $("#eu-cookie-compliance-categories input:checkbox[value='" + categories[i] + "']").prop("checked", true); 583 } 584 } 585 586 Drupal.eu_cookie_compliance.getAcceptedCategories = function () { 587 // Make a new observer & fire it to allow other scripts to hook in. 588 var prePreferencesLoadObject = new PrePreferencesLoad(); 589 self.handleEvent('prePreferencesLoad', prePreferencesLoadObject); 590 591 var cookieName = (typeof drupalSettings.eu_cookie_compliance.cookie_name === 'undefined' || drupalSettings.eu_cookie_compliance.cookie_name === '') ? 'cookie-agreed-categories' : drupalSettings.eu_cookie_compliance.cookie_name + '-categories'; 592 var storedCategories = $.cookie(cookieName); 593 594 if (storedCategories !== null && typeof storedCategories !== 'undefined') { 595 _euccSelectedCategories = JSON.parse(storedCategories); 596 } 597 else { 598 _euccSelectedCategories = []; 599 } 600 601 // Merge in required categories if not already present. Mimics old 602 // logic where "fix first category" changed logic in 603 // .hasAgreedWithCategory and this function. 604 for (var _categoryName in drupalSettings.eu_cookie_compliance.cookie_categories_details) { 605 var _category = drupalSettings.eu_cookie_compliance.cookie_categories_details[_categoryName]; 606 if (_category.checkbox_default_state === 'required' && $.inArray(_category.id, _euccSelectedCategories) === -1) { 607 _euccSelectedCategories.push(_category.id); 608 } 609 } 610 611 // Make a new observer & fire it to allow other scripts to hook in. 612 var postPreferencesLoadObject = new PostPreferencesLoad(); 613 self.handleEvent('postPreferencesLoad', postPreferencesLoadObject); 614 615 return _euccSelectedCategories; 616 }; 617 618 Drupal.eu_cookie_compliance.changeStatus = function (value) { 619 var reloadPage = drupalSettings.eu_cookie_compliance.reload_page; 620 var previousState = _euccCurrentStatus; 621 if (_euccCurrentStatus === value) { 622 return; 623 } 624 625 if (drupalSettings.eu_cookie_compliance.popup_position) { 626 $('.sliding-popup-top').animate({ top: !drupalSettings.eu_cookie_compliance.fixed_top_position ? -(parseInt($(drupalSettings.eu_cookie_compliance.containing_element).css('padding-top')) + parseInt($(drupalSettings.eu_cookie_compliance.containing_element).css('margin-top')) + $('#sliding-popup').outerHeight()) : $('#sliding-popup').outerHeight() * -1 }, drupalSettings.eu_cookie_compliance.popup_delay, function () { 627 if (value === 1 && previousState === null && !reloadPage) { 628 $('.sliding-popup-top').not('.eu-cookie-withdraw-wrapper').html(drupalSettings.eu_cookie_compliance.popup_html_agreed).animate({ top: !drupalSettings.eu_cookie_compliance.fixed_top_position ? -(parseInt($(drupalSettings.eu_cookie_compliance.containing_element).css('padding-top')) + parseInt($(drupalSettings.eu_cookie_compliance.containing_element).css('margin-top'))) : 0 }, drupalSettings.eu_cookie_compliance.popup_delay); 629 Drupal.eu_cookie_compliance.attachHideEvents(); 630 } 631
631 else if (previousState === 1) { 632 if (drupalSettings.eu_cookie_compliance.withdraw_enabled && drupalSettings.eu_cookie_compliance.withdraw_button_on_info_popup) { 633 // Restore popup content. 634 if (window.matchMedia('(max-width: ' + drupalSettings.eu_cookie_compliance.mobile_breakpoint + 'px)').matches && drupalSettings.eu_cookie_compliance.use_mobile_message) { 635 $('.sliding-popup-top').not('.eu-cookie-withdraw-wrapper').html(drupalSettings.eu_cookie_compliance.mobile_popup_html_info); 636 } 637 else { 638 $('.sliding-popup-top').not('.eu-cookie-withdraw-wrapper').html(drupalSettings.eu_cookie_compliance.popup_html_info); 639 } 640 Drupal.eu_cookie_compliance.initPopup(); 641 Drupal.eu_cookie_compliance.resizeListener(); 642 } 643 else { 644 $('.sliding-popup-top').not('.eu-cookie-withdraw-wrapper').trigger('eu_cookie_compliance_popup_close').remove(); 645 } 646 } 647 if (drupalSettings.eu_cookie_compliance.withdraw_enabled) { 648 Drupal.eu_cookie_compliance.showWithdrawBanner(value); 649 } 650 }); 651 } 652 else { 653 $('.sliding-popup-bottom').animate({ bottom: $('#sliding-popup').outerHeight() * -1 }, drupalSettings.eu_cookie_compliance.popup_delay, function () { 654 if (value === 1 && previousState === null && !reloadPage) { 655 $('.sliding-popup-bottom').not('.eu-cookie-withdraw-wrapper').html(drupalSettings.eu_cookie_compliance.popup_html_agreed).animate({ bottom: 0 }, drupalSettings.eu_cookie_compliance.popup_delay); 656 Drupal.eu_cookie_compliance.attachHideEvents(); 657 } 658 else if (previousState === 1) { 659 if (drupalSettings.eu_cookie_compliance.withdraw_enabled && drupalSettings.eu_cookie_compliance.withdraw_button_on_info_popup) { 660 // Restore popup content. 661 if (window.matchMedia('(max-width: ' + drupalSettings.eu_cookie_compliance.mobile_breakpoint + 'px)').matches && drupalSettings.eu_cookie_compliance.use_mobile_message) { 662 $('.sliding-popup-bottom').not('.eu-cookie-withdraw-wrapper').html(drupalSettings.eu_cookie_compliance.mobile_popup_html_info); 663 } 664 else { 665 $('.sliding-popup-bottom').not('.eu-cookie-withdraw-wrapper').html(drupalSettings.eu_cookie_compliance.popup_html_info); 666 } 667 Drupal.eu_cookie_compliance.initPopup(); 668 Drupal.eu_cookie_compliance.resizeListener(); 669 } 670 else { 671 $('.sliding-popup-bottom').not('.eu-cookie-withdraw-wrapper').trigger('eu_cookie_compliance_popup_close').remove(); 672 $('body').removeClass('eu-cookie-compliance-popup-open'); 673 } 674 } 675 if (drupalSettings.eu_cookie_compliance.withdraw_enabled) { 676 Drupal.eu_cookie_compliance.showWithdrawBanner(value); 677 } 678 }); 679 } 680 681 if (drupalSettings.eu_cookie_compliance.reload_page) { 682 var reloadRoutesList; 683 // Checks if there's any route on the settings. 684 if ((reloadRoutesList = drupalSettings.eu_cookie_compliance.reload_routes_list).length !== 0) { 685 var currentPath = drupalSettings.path.currentPath; 686 var match = false; 687 688 // If there are routes specified on the settings, it checks if any of 689 // it matches with the current path. 690 for (var n = 0; !match && n < reloadRoutesList.length; n++) { 691 var regExp = new RegExp(reloadRoutesList[n], "g"); 692 match = currentPath.match(regExp) !== null; 693 } 694 695 /* 696 * It will reload the page whether if the current path matches with one of the specified routes and the 697 * reload_options setting is set to "Include", which indicates that all matches should reload; OR if 698 * there's no match and the reload_options settings is set to "Exclude", which indicates that if the 699 * current path doesn't match with one of the specified routes, it should be reloaded. 700 */ 701 if ((match && !drupalSettings.eu_cookie_compliance.reload_options) || (!match && drupalSettings.eu_cookie_compliance.reload_options)) { 702 location.reload(); 703 } 704 } 705 // If no routes specified, then the page will be always reloaded. 706 else { 707 location.reload(); 708 } 709 } 710 711 Drupal.eu_cookie_compliance.setStatus(value); 712 }; 713 714 Drupal.eu_cookie_compliance.showWithdrawBanner = function (value) { 715 if (value === 2 && drupalSettings.eu_cookie_compliance.withdraw_enabled) { 716 if (!drupalSettings.eu_cookie_compliance.withdraw_button_on_info_popup) { 717 Drupal.eu_cookie_compliance.createWithdrawBanner(drupalSettings.eu_cookie_compliance.withdraw_markup); 718 Drupal.eu_cookie_compliance.resizeListener(); 719 } 720 Drupal.eu_cookie_compliance.attachWithdrawEvents(); 721 Drupal.eu_cookie_compliance.positionTab(); 722 } 723 }; 724 725 Drupal.eu_cookie_compliance.setStatus = function (status) { 726 // Make a new observer & fire it to allow other scripts to hook in. 727 var preStatusSaveObject = new PreStatusSave(); 728 self.handleEvent('preStatusSave', preStatusSaveObject); 729 730 var date = new Date(); 731 var domain = drupalSettings.eu_cookie_compliance.domain ? drupalSettings.eu_cookie_compliance.domain : ''; 732 var path = drupalSettings.eu_cookie_compliance.domain_all_sites ? '/' : drupalSettings.path.baseUrl; 733 var cookieName = (typeof drupalSettings.eu_cookie_compliance.cookie_name === 'undefined' || drupalSettings.eu_cookie_compliance.cookie_name === '') ? 'cookie-agreed' : drupalSettings.eu_cookie_compliance.cookie_name; 734 if (path.length > 1) { 735 var pathEnd = path.length - 1; 736 if (path.lastIndexOf('/') === pathEnd) { 737 path = path.substring(0, pathEnd); 738 } 739 } 740 741 var cookie_session = parseInt(drupalSettings.eu_cookie_compliance.cookie_session); 742 if (cookie_session) { 743 $.cookie(cookieName, status, { path: path, domain: domain }); 744 } 745 else { 746 var lifetime = parseInt(drupalSettings.eu_cookie_compliance.cookie_lifetime); 747 date.setDate(date.getDate() + lifetime); 748 $.cookie(cookieName, status, { expires: date, path: path, domain: domain }); 749 } 750 _euccCurrentStatus = status; 751 $(document).trigger('eu_cookie_compliance.changeStatus', [status]); 752 // Status set means something happened, update the version. 753 Drupal.eu_cookie_compliance.setVersion(); 754 755 // Store consent if applicable. 756 if (drupalSettings.eu_cookie_compliance.store_consent && ((status === 1 && drupalSettings.eu_cookie_compliance.popup_agreed_enabled) || (status === 2 && !drupalSettings.eu_cookie_compliance.popup_agreed_enabled))) { 757 var url = drupalSettings.path.baseUrl + drupalSettings.path.pathPrefix + 'eu-cookie-compliance/store_consent/banner'; 758 $.post(url, {}, function (data) { }); 759 } 760 761 // Make a new observer & fire it to allow other scripts to hook in. 762 var postStatusSaveObject = new PostStatusSave(); 763 self.handleEvent('postStatusSave', postStatusSaveObject); 764 765 if (status === 0 && drupalSettings.eu_cookie_compliance.method === 'opt_out') { 766 euCookieComplianceBlockCookies = setInterval(Drupal.eu_cookie_compliance.BlockCookies, 5000); 767 } 768 }; 769 770 Drupal.eu_cookie_compliance.setAcceptedCategories = function (categories) { 771 // Make a new observer & fire it to allow other scripts to hook in. 772 var prePreferencesSaveObject = new PrePreferencesSave(); 773 self.handleEvent('prePreferencesSave', prePreferencesSaveObject); 774 775 var date = new Date(); 776 var domain = drupalSettings.eu_cookie_compliance.domain ? drupalSettings.eu_cookie_compliance.domain : ''; 777 var path = drupalSettings.eu_cookie_compliance.domain_all_sites ? '/' : drupalSettings.path.baseUrl; 778 var cookieName = (typeof drupalSettings.eu_cookie_compliance.cookie_name === 'undefined' || drupalSettings.eu_cookie_compliance.cookie_name === '') ? 'cookie-agreed-categories' : drupalSettings.eu_cookie_compliance.cookie_name + '-categories'; 779 if (path.length > 1) { 780 var pathEnd = path.length - 1; 781 if (path.lastIndexOf('/') === pathEnd) { 782 path = path.substring(0, pathEnd); 783 } 784 } 785 var categoriesString = JSON.stringify(categories); 786 var cookie_session = parseInt(drupalSettings.eu_cookie_compliance.cookie_session); 787 if (cookie_session) { 788 $.cookie(cookieName, categoriesString, { path: path, domain: domain }); 789 } 790 else { 791 var lifetime = parseInt(drupalSettings.eu_cookie_compliance.cookie_lifetime); 792 date.setDate(date.getDate() + lifetime); 793 $.cookie(cookieName, categoriesString, { expires: date, path: path, domain: domain }); 794 } 795 _euccSelectedCategories = categories; 796 $(document).trigger('eu_cookie_compliance.changePreferences', [categories]); 797 798 // TODO: Store categories with consent if applicable? 799 // Make a new observer & fire it to allow other scripts to hook in. 800 var postPreferencesSaveObject = new PostPreferencesSave(); 801 self.handleEvent('postPreferencesSave', postPreferencesSaveObject); 802 }; 803 804 Drupal.eu_cookie_compliance.hasAgreed = function (category) { 805 var agreed = (_euccCurrentStatus === 1 || _euccCurrentStatus === 2); 806 807 if (category !== undefined && agreed) { 808 agreed = Drupal.eu_cookie_compliance.hasAgreedWithCategory(category); 809 } 810 811 return agreed; 812 }; 813 814 Drupal.eu_cookie_compliance.hasAgreedWithCategory = function (category) { 815 return $.inArray(category, _euccSelectedCategories) !== -1; 816 }; 817 818 Drupal.eu_cookie_compliance.showBanner = function () { 819 var showBanner = false;
820 if ((_euccCurrentStatus === 0 && drupalSettings.eu_cookie_compliance.method === 'default') || _euccCurrentStatus === null) { 821 if (!drupalSettings.eu_cookie_compliance.disagree_do_not_show_popup || _euccCurrentStatus === null) { 822 showBanner = true; 823 } 824 } 825 else if (_euccCurrentStatus === 1 && drupalSettings.eu_cookie_compliance.popup_agreed_enabled) { 826 showBanner = true; 827 } 828 829 return showBanner; 830 }; 831 832 Drupal.eu_cookie_compliance.cookiesEnabled = function () { 833 var cookieEnabled = (navigator.cookieEnabled); 834 if (typeof navigator.cookieEnabled === 'undefined' && !cookieEnabled) { 835 $.cookie('testcookie', 'testcookie', { expires: 100 }); 836 cookieEnabled = ($.cookie('testcookie').indexOf('testcookie') !== -1); 837 } 838 839 return (cookieEnabled); 840 }; 841 842 Drupal.eu_cookie_compliance.cookieMatches = function (cookieName, pattern) { 843 if (cookieName === pattern) { 844 return true; 845 } 846 if (pattern.indexOf('*') < 0) { 847 return false; 848 } 849 try { 850 var regexp = new RegExp('^' + pattern.replace(/\./g, '\\.').replace(/\*/g, '.+') + '$', 'g'); 851 return regexp.test(cookieName); 852 } 853 catch (err) { 854 return false; 855 } 856 }; 857 858 Drupal.eu_cookie_compliance.isAllowed = function (cookieName) { 859 // Skip the PHP session cookie. 860 if (cookieName.indexOf('SESS') === 0 || cookieName.indexOf('SSESS') === 0) { 861 return true; 862 } 863 // Split the allowed cookies. 864 var euCookieComplianceAllowlist = drupalSettings.eu_cookie_compliance.allowed_cookies.split(/\r\n|\n|\r/g); 865 866 // Add the EU Cookie Compliance cookie. 867 euCookieComplianceAllowlist.push((typeof drupalSettings.eu_cookie_compliance.cookie_name === 'undefined' || drupalSettings.eu_cookie_compliance.cookie_name === '') ? 'cookie-agreed' : drupalSettings.eu_cookie_compliance.cookie_name); 868 euCookieComplianceAllowlist.push((typeof drupalSettings.eu_cookie_compliance.cookie_name === 'undefined' || drupalSettings.eu_cookie_compliance.cookie_name === '') ? 'cookie-agreed-categories' : drupalSettings.eu_cookie_compliance.cookie_name + '-categories'); 869 euCookieComplianceAllowlist.push((typeof drupalSettings.eu_cookie_compliance.cookie_name === 'undefined' || drupalSettings.eu_cookie_compliance.cookie_name === '') ? 'cookie-agreed-version' : drupalSettings.eu_cookie_compliance.cookie_name + '-version'); 870 // Check if the cookie is allowed. 871 for (var item in euCookieComplianceAllowlist) { 872 if (Drupal.eu_cookie_compliance.cookieMatches(cookieName, euCookieComplianceAllowlist[item])) { 873 return true; 874 } 875 // Handle cookie names that are prefixed with a category. 876 if (drupalSettings.eu_cookie_compliance.method === 'categories') { 877 var separatorPos = euCookieComplianceAllowlist[item].indexOf(":"); 878 if (separatorPos !== -1) { 879 var category = euCookieComplianceAllowlist[item].substr(0, separatorPos); 880 var wlCookieName = euCookieComplianceAllowlist[item].substr(separatorPos + 1); 881 882 if (Drupal.eu_cookie_compliance.cookieMatches(cookieName, wlCookieName) && Drupal.eu_cookie_compliance.hasAgreedWithCategory(category)) { 883 return true; 884 } 885 } 886 } 887 } 888 889 return false; 890 } 891 892 Drupal.eu_cookie_compliance.getVersion = function () { 893 var cookieName = (typeof drupalSettings.eu_cookie_compliance.cookie_name === 'undefined' || drupalSettings.eu_cookie_compliance.cookie_name === '') ? 'cookie-agreed-version' : drupalSettings.eu_cookie_compliance.cookie_name + '-version'; 894 return $.cookie(cookieName); 895 }; 896 897 Drupal.eu_cookie_compliance.setVersion = function () { 898 var date = new Date(); 899 var domain = drupalSettings.eu_cookie_compliance.domain ? drupalSettings.eu_cookie_compliance.domain : ''; 900 var path = drupalSettings.eu_cookie_compliance.domain_all_sites ? '/' : drupalSettings.path.baseUrl; 901 var cookieName = (typeof drupalSettings.eu_cookie_compliance.cookie_name === 'undefined' || drupalSettings.eu_cookie_compliance.cookie_name === '') ? 'cookie-agreed-version' : drupalSettings.eu_cookie_compliance.cookie_name + '-version'; 902 if (path.length > 1) { 903 var pathEnd = path.length - 1; 904 if (path.lastIndexOf('/') === pathEnd) { 905 path = path.substring(0, pathEnd); 906 } 907 } 908 909 var eucc_version = drupalSettings.eu_cookie_compliance.cookie_policy_version; 910 var cookie_session = parseInt(drupalSettings.eu_cookie_compliance.cookie_session); 911 if (cookie_session) { 912 $.cookie(cookieName, eucc_version, { path: path, domain: domain }); 913 } 914 else { 915 var lifetime = parseInt(drupalSettings.eu_cookie_compliance.cookie_lifetime); 916 date.setDate(date.getDate() + lifetime); 917 $.cookie(cookieName, eucc_version, { expires: date, path: path, domain: domain }); 918 } 919 }; 920 921 // Load blocked scripts if the user has agreed to being tracked. 922 var euCookieComplianceHasLoadedScripts = false;
923 var euCookieComplianceHasLoadedScriptsForCategory = []; 924 $(function () { 925 if (Drupal.eu_cookie_compliance.hasAgreed() 926 || (_euccCurrentStatus === null && drupalSettings.eu_cookie_compliance.method !== 'opt_in' && drupalSettings.eu_cookie_compliance.method !== 'categories') 927 ) { 928 if (typeof euCookieComplianceLoadScripts === "function") { 929 euCookieComplianceLoadScripts(); 930 } 931 euCookieComplianceHasLoadedScripts = true; 932 933 if (drupalSettings.eu_cookie_compliance.method === 'categories') { 934 Drupal.eu_cookie_compliance.loadCategoryScripts(_euccSelectedCategories); 935 } 936 } 937 }); 938 939 Drupal.eu_cookie_compliance.BlockCookies = function () { 940 var cookieStatus = Drupal.eu_cookie_compliance.getCookieStatus(); 941 if (cookieStatus === 1 || cookieStatus === 2) { 942 // Stop blocking the cookies if it's already been agreed to (e.g. in a different tab). 943 if (typeof euCookieComplianceBlockCookies !== 'undefined') { 944 clearInterval(euCookieComplianceBlockCookies); 945 return; 946 } 947 } 948 // Load all cookies from jQuery. 949 var cookies = $.cookie(); 950 951 // Check each cookie and try to remove it if it's not allowed. 952 for (var i in cookies) { 953 var remove = true; 954 var hostname = window.location.hostname; 955 var cookieRemoved = false; 956 var index = 0; 957 958 remove = !Drupal.eu_cookie_compliance.isAllowed(i); 959 960 // Remove the cookie if it's not allowed. 961 if (remove) { 962 while (!cookieRemoved && hostname !== '') { 963 // Attempt to remove. 964 cookieRemoved = $.removeCookie(i, { domain: '.' + hostname, path: '/' }); 965 if (!cookieRemoved) { 966 cookieRemoved = $.removeCookie(i, { domain: hostname, path: '/' }); 967 } 968 969 index = hostname.indexOf('.'); 970 971 // We can be on a sub-domain, so keep checking the main domain as well. 972 hostname = (index === -1) ? '' : hostname.substring(index + 1); 973 } 974 975 // Some jQuery Cookie versions don't remove cookies well. Try again
976 // using plain js. 977 if (!cookieRemoved) { 978 document.cookie = i + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT; path=/;'; 979 } 980 } 981 } 982 } 983 984 // Block cookies when the user hasn't agreed. 985 if (drupalSettings.eu_cookie_compliance.automatic_cookies_removal && 986 ( 987 (drupalSettings.eu_cookie_compliance.method === 'opt_in' && (_euccCurrentStatus === null || !Drupal.eu_cookie_compliance.hasAgreed())) 988 || (drupalSettings.eu_cookie_compliance.method === 'opt_out' && !Drupal.eu_cookie_compliance.hasAgreed() && _euccCurrentStatus !== null) 989 || (drupalSettings.eu_cookie_compliance.method === 'categories') 990 )) { 991 euCookieComplianceBlockCookies = setInterval(Drupal.eu_cookie_compliance.BlockCookies, 5000); 992 } 993 994 /** 995 * Filter the event listeners by event name and return the list of handlers. 996 * 997 * @param forEventName 998 * 999 * @returns {[]} 1000 */ 1001 var filterQueue = function (forEventName) { 1002 var handlers = []; 1003 if (typeof Drupal.eu_cookie_compliance !== 'undefined' && 1004 typeof Drupal.eu_cookie_compliance.queue !== 'undefined' && 1005 Drupal.eu_cookie_compliance.queue.length) { 1006 // Loop over the list of arguments (objects) pushed into the queue. 1007 for (var i = 0; i < Drupal.eu_cookie_compliance.queue.length; i++) { 1008 if (Drupal.eu_cookie_compliance.queue[i].length) { 1009 var queueItem = Drupal.eu_cookie_compliance.queue[i]; 1010 var eventName = queueItem[0]; 1011 var eventHandler = queueItem[1]; 1012 // If the first element is a string and the second is a function. 1013 if (typeof eventName === 'string' && typeof eventHandler === 'function') { 1014 // And the string matches the event name. 1015 if (eventName === forEventName) { 1016 // Return the functions so they can be executed. 1017 handlers.push(eventHandler); 1018 } 1019 } 1020 } 1021 } 1022 } 1023 return handlers; 1024 } 1025 1026 /** 1027 * Handle event by finding and executing handlers pushed to the queue. 1028 */ 1029 self.handleEvent = function (eventName, observer) { 1030 var handlers = filterQueue(eventName); 1031 for (var i = 0; i < handlers.length; i++) { 1032 if (typeof handlers[i] !== 'undefined') { 1033 observer.subscribe(handlers[i]); 1034 observer.fire({ 1035 currentStatus: _euccCurrentStatus, 1036 currentCategories: _euccSelectedCategories 1037 }); 1038 observer.unsubscribe(handlers[i]); 1039 } 1040 } 1041 }; 1042 1043 /** 1044 * Observer: triggered before status gets read from cookie. 1045 */ 1046 var PreStatusLoad = (function () { 1047 // Constructor. 1048 var PreStatusLoad = function () { 1049 // Observers. 1050 this.handlers = []; 1051 }; 1052 // Convenience var for the prototype. 1053 var prototype = PreStatusLoad.prototype; 1054 prototype.subscribe = function (fn) { 1055 this.handlers.push(fn); 1056 }; 1057 prototype.unsubscribe = function (fn) { 1058 this.handlers = this.handlers.filter( 1059 function (item) { 1060 if (item !== fn) { 1061 return item; 1062 } 1063 } 1064 ); 1065 }; 1066 prototype.fire = function (o, thisObj) { 1067 var scope = thisObj || window; 1068 this.handlers.forEach(function (item) { 1069 item.call(scope, o); 1070 }); 1071 }; 1072 return PreStatusLoad; 1073 })(); 1074 1075 /** 1076 * Observer: when status was read from cookie and stored in private variable. 1077 */ 1078 var PostStatusLoad = (function () { 1079 // Constructor. 1080 var PostStatusLoad = function () { 1081 // Observers. 1082 this.handlers = []; 1083 }; 1084 // Convenience var for the prototype. 1085 var prototype = PostStatusLoad.prototype; 1086 prototype.subscribe = function (fn) { 1087 this.handlers.push(fn); 1088 }; 1089 prototype.unsubscribe = function (fn) { 1090 this.handlers = this.handlers.filter( 1091 function (item) { 1092 if (item !== fn) { 1093 return item; 1094 } 1095 } 1096 ); 1097 }; 1098 prototype.fire = function (o, thisObj) { 1099 var scope = thisObj || window; 1100 this.handlers.forEach(function (item) { 1101 item.call(scope, o); 1102 }); 1103 }; 1104 return PostStatusLoad; 1105 })(); 1106 1107 /** 1108 * Observer: triggered before status gets saved into cookie. 1109 */ 1110 var PreStatusSave = (function () { 1111 // Constructor. 1112 var PreStatusSave = function () { 1113 // Observers. 1114 this.handlers = []; 1115 }; 1116 // Convenience var for the prototype. 1117 var prototype = PreStatusSave.prototype; 1118 prototype.subscribe = function (fn) { 1119 this.handlers.push(fn); 1120 }; 1121 prototype.unsubscribe = function (fn) { 1122 this.handlers = this.handlers.filter( 1123 function (item) { 1124 if (item !== fn) { 1125 return item; 1126 } 1127 } 1128 ); 1129 }; 1130 prototype.fire = function (o, thisObj) { 1131 var scope = thisObj || window;
1132 this.handlers.forEach(function (item) { 1133 item.call(scope, o); 1134 }); 1135 }; 1136 return PreStatusSave; 1137 })(); 1138 1139 /** 1140 * Observer: triggered after status was saved into cookie. 1141 */ 1142 var PostStatusSave = (function () { 1143 // Constructor. 1144 var PostStatusSave = function () { 1145 // Observers. 1146 this.handlers = []; 1147 }; 1148 // Convenience var for the prototype. 1149 var prototype = PostStatusSave.prototype; 1150 prototype.subscribe = function (fn) { 1151 this.handlers.push(fn); 1152 }; 1153 prototype.unsubscribe = function (fn) { 1154 this.handlers = this.handlers.filter( 1155 function (item) { 1156 if (item !== fn) { 1157 return item; 1158 } 1159 } 1160 ); 1161 }; 1162 prototype.fire = function (o, thisObj) { 1163 var scope = thisObj || window; 1164 this.handlers.forEach(function (item) { 1165 item.call(scope, o); 1166 }); 1167 }; 1168 return PostStatusSave; 1169 })(); 1170 1171 /** 1172 * Observer: triggered before categories are read from cookie. 1173 */ 1174 var PrePreferencesLoad = (function () { 1175 // Constructor. 1176 var prePreferencesLoad = function () { 1177 // Observers. 1178 this.handlers = []; 1179 }; 1180 // Convenience var for the prototype. 1181 var prototype = prePreferencesLoad.prototype; 1182 prototype.subscribe = function (fn) { 1183 this.handlers.push(fn); 1184 }; 1185 prototype.unsubscribe = function (fn) { 1186 this.handlers = this.handlers.filter( 1187 function (item) { 1188 if (item !== fn) { 1189 return item; 1190 } 1191 } 1192 ); 1193 }; 1194 prototype.fire = function (o, thisObj) { 1195 var scope = thisObj || window; 1196 this.handlers.forEach(function (item) { 1197 item.call(scope, o); 1198 }); 1199 }; 1200 return prePreferencesLoad; 1201 })(); 1202 1203 /** 1204 * Observer: triggered after categories were read from cookie. 1205 */ 1206 var PostPreferencesLoad = (function () { 1207 // Constructor. 1208 var postPreferencesLoad = function () { 1209 // Observers. 1210 this.handlers = []; 1211 }; 1212 // Convenience var for the prototype. 1213 var prototype = postPreferencesLoad.prototype; 1214 prototype.subscribe = function (fn) { 1215 this.handlers.push(fn); 1216 }; 1217 prototype.unsubscribe = function (fn) { 1218 this.handlers = this.handlers.filter( 1219 function (item) { 1220 if (item !== fn) { 1221 return item; 1222 } 1223 } 1224 ); 1225 }; 1226 prototype.fire = function (o, thisObj) { 1227 var scope = thisObj || window; 1228 this.handlers.forEach(function (item) { 1229 item.call(scope, o); 1230 }); 1231 }; 1232 return postPreferencesLoad; 1233 })(); 1234 1235 /** 1236 * Observer: triggered before categories are being saved to cookie. 1237 */ 1238 var PrePreferencesSave = (function () { 1239 // Constructor. 1240 var prePreferencesSave = function () { 1241 // Observers. 1242 this.handlers = []; 1243 }; 1244 // Convenience var for the prototype. 1245 var prototype = prePreferencesSave.prototype; 1246 prototype.subscribe = function (fn) { 1247 this.handlers.push(fn); 1248 }; 1249 prototype.unsubscribe = function (fn) { 1250 this.handlers = this.handlers.filter( 1251 function (item) { 1252 if (item !== fn) { 1253 return item; 1254 } 1255 } 1256 ); 1257 }; 1258 prototype.fire = function (o, thisObj) { 1259 var scope = thisObj || window; 1260 this.handlers.forEach(function (item) { 1261 item.call(scope, o); 1262 }); 1263 }; 1264 return prePreferencesSave; 1265 })(); 1266 1267 /** 1268 * Observer: triggered after categories were saved to cookie. 1269 */ 1270 var PostPreferencesSave = (function () { 1271 // Constructor. 1272 var postPreferencesSave = function () { 1273 // Observers. 1274 this.handlers = []; 1275 }; 1276 // Convenience var for the prototype. 1277 var prototype = postPreferencesSave.prototype; 1278 prototype.subscribe = function (fn) { 1279 this.handlers.push(fn); 1280 }; 1281 prototype.unsubscribe = function (fn) { 1282 this.handlers = this.handlers.filter( 1283 function (item) { 1284 if (item !== fn) { 1285 return item; 1286 } 1287 } 1288 ); 1289 }; 1290 prototype.fire = function (o, thisObj) { 1291 var scope = thisObj || window;
1292 this.handlers.forEach(function (item) { 1293 item.call(scope, o); 1294 }); 1295 }; 1296 return postPreferencesSave; 1297 })(); 1298 1299})(jQuery, Drupal, drupalSettings);
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.