1/* ====================================================== 2 # Cookies Policy Notification Bar for Joomla! - v5.1.2 (pro version) 3 # ------------------------------------------------------- 4 # For Joomla! CMS (v4.x, v5.x, v6.x) 5 # Author: Web357 (Yiannis Christodoulou) 6 # Copyright: (©) 2014-2026 Web357. All rights reserved. 7 # License: GNU/GPLv3, https://www.gnu.org/licenses/gpl-3.0.html 8 # Website: https://www.web357.com 9 # Demo: https://demo-joomla.web357.com/cookies-policy-notification-bar 10 # Support: [email protected] 11 # Last modified: Wednesday 07 October 2026, 07:45:30 AM 12 ========================================================= */ 13 14var categoriesSettingsCookie = {}; // Create array with all categories ID for: modalManager 15var categoriesSettingsCookieOuter = {}; //Create array with first id (outter) and second id (inner) 16var categoriesSettingsCookieInner = {}; //Create array with first id (inner) and second id (outter) 17var m_modalManager_confirmationText = ''; //Modal LOCKED-CHECKBOX Confirmation Alert 18var modalManagerSettings = []; 19 20var afterCategoriesSettingsCookie; 21var afterExpirationCookies; 22var cpnb_renderSettingsOverride = null; // temporary in-memory settings used for rendering scripts 23 24// CSP nonce this script itself was loaded with (Joomla stamps a nonce onto WebAssetManager- 25// registered scripts when the site has CSP nonce enabled). Captured now, synchronously - by the 26// time cpnb_renderBlockCookieScripts() runs (from a later event), document.currentScript would 27// already be null. Reused so the <script> elements it recreates from blocked Block Cookies 28// payloads carry the same nonce and execute under a nonce-based CSP script-src policy instead 29// of being blocked. 30var cpnb_cspNonce = (document.currentScript && document.currentScript.nonce) || ''; 31 32// CSP & WebAssetManager compatibility: load configuration from Joomla script options if present 33function cpnb_init_joomla_options() { 34 if (typeof Joomla !== 'undefined' && typeof Joomla.getOptions === 'function') { 35 if (typeof cpnb_config === 'undefined' && Joomla.getOptions('cpnb_config')) { 36 window.cpnb_config = Joomla.getOptions('cpnb_config'); 37 } 38 if (typeof cpnb_cookiesCategories === 'undefined' && Joomla.getOptions('cpnb_cookiesCategories')) { 39 window.cpnb_cookiesCategories = Joomla.getOptions('cpnb_cookiesCategories'); 40 } 41 if (typeof cpnb_manager === 'undefined' && Joomla.getOptions('cpnb_manager')) { 42 window.cpnb_manager = Joomla.getOptions('cpnb_manager'); 43 } 44 } 45} 46cpnb_init_joomla_options(); 47// Bound as early as possible so an [accept] link clicked before init is not lost (see 48// cpnb_finishInit). cpnb_bindAcceptLinks is a hoisted declaration, safe to call here. 49cpnb_bindAcceptLinks(); 50 51var settings = typeof cpnb_config !== 'undefined' ? cpnb_config : {}; 52 53window.addEventListener( 54 'load', 55 function cpnb_onLoad() { 56 cpnb_init_joomla_options(); 57 // HttpOnly mode: the consent cookies are invisible to JS, so learn the visitor's state 58 // from the server first. Nothing (bar, float button, blocked scripts) renders before it. 59 if (cpnb_isHttpOnlyMode() && !cpnb_stateLoaded) { 60 cpnb_loadConsentState(cpnb_onLoad); 61 return; 62 } 63 // Default Settings 64 var settings = { 65 w357_joomla_caching: 0, 66 w357_position: 'bottom', 67 w357_show_close_x_icon: 1, 68 w357_hide_after_time: 'yes', 69 w357_duration: 60, 70 w357_animate_duration: 1000, 71 w357_limit: 0, 72 w357_message: null, 73 w357_display_ok_btn: 1, 74 w357_buttonText: "Ok, I've understood!", 75 w357_display_decline_btn: 1, 76 w357_buttonDeclineText: 'Decline', 77 w357_display_cancel_btn: 1, 78 w357_buttonCancelText: 'Cancel', 79 w357_display_settings_btn: 1, 80 w357_buttonSettingsText: 'Settings', 81 w357_buttonMoreText: 'More Info', 82 w357_buttonMoreLink: '', 83 w357_display_more_info_btn: 1, 84 w357_fontColor: '#F1F1F3',
85 w357_linkColor: '#FFF', 86 w357_fontSize: '12px', 87 w357_backgroundColor: '#323A45', 88 w357_borderWidth: 1, 89 w357_body_cover: 1, 90 w357_overlay_state: 0, 91 w357_overlay_color: 'rgba(10,10,10, 0.3)', 92 w357_height: 'auto', 93 w357_cookie_name: 'cookiesDirective', 94 w357_cookie_name_declined: 'cpnbCookiesDeclined', 95 w357_cookie_name_cancelled: 'cpnbCookiesCancelled', 96 w357_has_consent_decision: 0, 97 w357_cookie_settings_value: null, 98 w357_cookie_httponly: 0, 99 w357_link_target: '_self', 100 w357_popup_width: '800', 101 w357_popup_height: '600', 102 w357_customText: 103 'Your custom text for the cookies policy goes here...', 104 w357_more_info_btn_type: 'custom_text', 105 w357_blockCookies: 0, 106 w357_autoAcceptAfterScrolling: 0, 107 w357_numOfScrolledPixelsBeforeAutoAccept: 300, 108 w357_reloadPageAfterAccept: 0, 109 w357_enableConfirmationAlerts: 0, 110 w357_enableConfirmationAlertsForAcceptBtn: 0, 111 w357_enableConfirmationAlertsForDeclineBtn: 0, 112 w357_enableConfirmationAlertsForDeleteBtn: 0, 113 w357_confirm_allow_msg: 114 'Performing this action will enable all cookies set by this website. Are you sure that you want to enable all cookies on this website?', 115 w357_confirm_delete_msg: 116 'Performing this action will remove all cookies set by this website. Are you sure that you want to disable and delete all cookies from your browser?', 117 w357_show_in_iframes: 0, 118 w357_shortcode_is_enabled_on_this_page: 1, 119 w357_base_url: '', 120 w357_base_ajax_url: '', 121 w357_current_url: '', 122 w357_always_display: 0, 123 w357_show_notification_bar: true, 124 w357_expiration_cookies: 365, // days 125 w357_expiration_cookieSettings: 365, // days 126 w357_expiration_cookieAccept: 365, // days 127 w357_expiration_cookieDecline: 180, // days 128 w357_expiration_cookieCancel: 3, // days 129 w357_accept_button_class_notification_bar: 'cpnb-accept-btn', 130 w357_decline_button_class_notification_bar: 'cpnb-decline-btn', 131 w357_cancel_button_class_notification_bar: 'cpnb-cancel-btn', 132 w357_settings_button_class_notification_bar: 'cpnb-settings-btn', 133 w357_moreinfo_button_class_notification_bar: 'cpnb-moreinfo-btn', 134 w357_accept_button_class_notification_bar_modal_window: 135 'cpnb-accept-btn-m', 136 w357_decline_button_class_notification_bar_modal_window: 137 'cpnb-decline-btn-m', 138 w357_save_button_class_notification_bar_modal_window: 139 'cpnb-save-btn-m', 140 w357_buttons_ordering: '', 141 }; 142 143 var modalManager = { 144 // base settings 145 w357_m_modalState: 1, 146 w357_m_floatButtonState: 1, 147 w357_m_floatButtonPosition: 'bottom_left', 148 w357_m_HashLink: 'cookies', 149 150 // styling 151 w357_m_modal_menuItemSelectedBgColor: 'rgba(200, 200, 200, 1)', 152 w357_m_saveChangesButtonColorAfterChange: 'rgba(255, 202, 152, 1)', 153 w357_m_floatButtonIconSrc: 154 'media/plg_system_cookiespolicynotificationbar/icons/cpnb-cookies-manager-icon-1-64x64.png', 155 w357_m_FloatButtonIconType: 'image', 156 w357_m_FloatButtonIconFontAwesomeName: 'fas fa-cookie-bite', 157 w357_m_FloatButtonIconFontAwesomeSize: 'fa-lg', 158 w357_m_FloatButtonIconFontAwesomeColor: 'rgba(61, 47, 44, 0.84)', 159 w357_m_FloatButtonIconUikitName: 'cog', 160 w357_m_FloatButtonIconUikitSize: '1', 161 w357_m_FloatButtonIconUikitColor: 'rgba(61, 47, 44, 0.84)', 162 163 // texts 164 w357_m_floatButtonText: 'Cookies Manager', 165 w357_m_modalHeadingText: 'Advanced Cookie Settings', 166 w357_m_checkboxText: 'Enable', 167 w357_m_lockedText: '(Locked)', 168 w357_m_EnableAllButtonText: 'Allow All Cookies', 169 w357_m_DeclineAllButtonText: 'Decline All Cookies', 170 w357_m_SaveChangesButtonText: 'Save Settings',
171 w357_m_confirmationAlertRequiredCookies: 172 "These cookies are strictly necessary for this website. You can't disable this category of cookies. Thank you for understanding!", 173 }; 174 175 // var cpnb_config = {}; 176 177 // Get data from server, check for each if empty or null then use default settings 178 // EXAMPLE: PHP ECHO SCRIPT -> var newSettings = { .. } 179 var varsToBeParsedInt = [ 180 'w357_joomla_caching', 181 'w357_overlay_state', 182 'w357_borderWidth', 183 'w357_body_cover', 184 'w357_expiration_cookies', 185 'w357_expiration_cookieSettings', 186 'w357_expiration_cookieAccept', 187 'w357_expiration_cookieDecline', 188 'w357_expiration_cookieCancel', 189 'w357_duration', 190 'w357_animate_duration', 191 'w357_limit', 192 'w357_display_ok_btn', 193 'w357_display_decline_btn', 194 'w357_display_cancel_btn', 195 'w357_display_settings_btn', 196 'w357_display_more_info_btn', 197 'w357_blockCookies', 198 'w357_autoAcceptAfterScrolling', 199 'w357_numOfScrolledPixelsBeforeAutoAccept', 200 'w357_reloadPageAfterAccept', 201 'w357_enableConfirmationAlerts', 202 'w357_enableConfirmationAlertsForAcceptBtn', 203 'w357_enableConfirmationAlertsForDeclineBtn', 204 'w357_enableConfirmationAlertsForDeleteBtn', 205 'w357_show_in_iframes', 206 'w357_shortcode_is_enabled_on_this_page', 207 'w357_always_display', 208 ]; 209 for (var obj in cpnb_config) { 210 if ((cpnb_config[obj] !== null) & (cpnb_config[obj] !== '')) { 211 if (varsToBeParsedInt.indexOf(obj) >= 0) { 212 var rawValue = cpnb_config[obj]; 213 if ( 214 typeof rawValue === 'string' && 215 rawValue.trim().toUpperCase() === 'SESSION' 216 ) { 217 settings[obj] = 'SESSION'; 218 } else { 219 settings[obj] = parseInt(rawValue); // Overwrite settings 220 } 221 } else { 222 settings[obj] = cpnb_config[obj]; //Overwrite settings 223 } 224 } 225 } 226 227 // Create-Read Cookie Limit => cpnb_cookie_limit + Check if higher + counter warning seen 228 if (settings.w357_limit > 0) { 229 if (cpnb_readCookie('cpnb_cookie_limit') == null) { 230 // Create cookie limit 231 cpnb_createCookie( 232 'cpnb_cookie_limit', 233 1, 234 settings.w357_expiration_cookies 235 ); 236 } else { 237 // Counter +1 and Check if higher 238 if (settings.w357_blockCookies == 0) { 239 var counterCookie = 240 parseInt(cpnb_readCookie('cpnb_cookie_limit')) + 1; 241 cpnb_createCookie( 242 'cpnb_cookie_limit', 243 counterCookie, 244 settings.w357_expiration_cookies 245 ); 246 } 247 } 248 } 249 250 // Used in "if statement" for design perpuse (margin-top), so as not to hide text 251 var warning_div_position = [ 252 'top-left', 253 'top-right', 254 'bottom-left', 255 'bottom-right', 256 'center', 257 ]; 258 259 // Check if Iframe 260 function cpnb_checkDIfIframeDisplay() { 261 if (settings.w357_show_in_iframes == 0) { 262 if (self == top) { 263 return true; // Not In frame 264 } else { 265 return false; // In frame 266 } 267 } else { 268 return true; 269 } 270 } 271 272 // Check Always Display 273 // cpnb_createCookie("cpnb_cookie_alwaysDisplay", settings.w357_always_display, settings.w357_expiration_cookies); 274 function cpnb_checkAlwaysDisplay() { 275 if (settings.w357_always_display == 1) { 276 return true; 277 } 278 return !cpnb_hasAnyConsentDecision(settings); 279 } 280 281 // Check Limit (cookie: cpnb_cookie_limit)
282 function cpnb_checkCookieLimitDisplay() { 283 if (settings.w357_always_display !== 1) { 284 if (settings.w357_limit > 0) { 285 if (cpnb_readCookie('cpnb_cookie_limit') !== null) { 286 var counterCookie = parseInt( 287 cpnb_readCookie('cpnb_cookie_limit') 288 ); 289 if (counterCookie > settings.w357_limit) { 290 return false; 291 } else { 292 return true; 293 } 294 } 295 } else { 296 return true; 297 } 298 } else { 299 return true; 300 } 301 } 302 303 window.cpnb_handleKeyboardActivate=function (event) { 304 var key = event.key || event.keyCode; 305 if (key === 'Enter' || key === ' ' || key === 13 || key === 32) { 306 event.preventDefault(); 307 event.target.click(); 308 } 309 } 310 311 // Max-height create 312 var windowHeight = 313 window.innerHeight || 314 document.documentElement.clientHeight || 315 document.body.clientHeight; 316 var maxHeight = windowHeight - 0.2 * windowHeight; 317 maxHeight = parseInt(maxHeight.toFixed(0)); 318 var marginTopWindow = windowHeight * 0.06; 319 marginTopWindow = parseInt(marginTopWindow.toFixed(0)); 320 321 // Check if => iFrame && Always Display (w357_always_display) && Limit (cpnb_cookie_limit) 322 if ( 323 cpnb_checkDIfIframeDisplay() && 324 cpnb_checkAlwaysDisplay() &&
325 cpnb_checkCookieLimitDisplay() && 326 settings.w357_show_notification_bar == true 327 ) { 328 // Create js to show warning 329 var elem = document.createElement('div'); 330 331 // MaxHeight for WarningBox 332 var maxHeightWarningBox = 333 window.innerHeight || 334 document.documentElement.clientHeight || 335 document.body.clientHeight; 336 maxHeightWarningBox -= 40; 337 338 var cnbwb = ''; 339 cnbwb += 340 ' <div id="cpnb" class="cpnb" data-cookie-name="' + 341 decodeURI(settings.w357_cookie_name) + 342 '">'; 343 cnbwb += 344 ' <div role="contentinfo" aria-label="Cookie consent notification" class="cpnb-warningBox-show-fade-in cpnb-outer cpnb-div-position-' + 345 settings.w357_position + 346 '" id="w357_cpnb_outer" style=" display: flex; justify-content: center; flex-direction: column; position: fixed; height: ' + 347 settings.w357_height + 348 '; background: ' + 349 settings.w357_backgroundColor + 350 '; color: ' + 351 settings.w357_fontColor + 352 '; font-size: ' + 353 settings.w357_fontSize + 354 ';">'; 355 356 // Close X icon 357 let cpnb_close_icon_html = ''; 358 if ( 359 settings.w357_show_close_x_icon == 1 && 360 settings.w357_position != 'top' && 361 settings.w357_position != 'bottom' 362 ) { 363 var cookieNameFun = settings.w357_cookie_name; 364 var linkFun = settings.w357_current_url; 365 var expiration = settings.w357_expiration_cookieCancel; 366 cpnb_close_icon_html = 367 ' <span id="cpnb-close-x-btn"' + 368 cpnb_actionAttrs('cancel', { 369 'cookie-name': cookieNameFun, 370 expiration: expiration, 371 link: linkFun, 372 overlay: settings.w357_overlay_state, 373 }) + 374 'class="cpnb-x-close-icon"></span>'; 375 } 376 377 if ( 378 (settings.w357_message !== null) & 379 (settings.w357_message !== '') 380 ) { 381 cnbwb += 382 ' <div class="cpnb-inner" style="max-height: ' + 383 maxHeightWarningBox + 384 'px;">' + 385 cpnb_close_icon_html + 386 '<div class="cpnb-message">' + 387 decodeURI(settings.w357_message) + 388 '</div>'; 389 } else { 390 cnbwb += 391 ' <div class="cpnb-inner" style="max-height: ' + 392 maxHeightWarningBox + 393 'px;">' + 394 cpnb_close_icon_html + 395 '<div class="cpnb-message">We use cookies to improve your experience on our website. By browsing this website, you agree to our use of cookies.</div>'; 396 } 397 398 if (warning_div_position.indexOf(settings.w357_position) >= 0) { 399 cnbwb += ' <div class="cpnb-buttons" style="margin-top:10px;">'; 400 } else { 401 cnbwb += ' <div class="cpnb-buttons">'; 402 } 403 404 // BEGIN: Buttons Sorting 405 var buttons_ordering_array = JSON.parse( 406 settings.w357_buttons_ordering 407 ); 408 for (var i = 0; i < buttons_ordering_array.length; i++) { 409 var btn = buttons_ordering_array[i]; 410 switch (btn) { 411 case 'ok': 412 // ACCEPT BUTTON 413 if (settings.w357_display_ok_btn == 1) { 414 var enableConfirFun = 415 settings.w357_enableConfirmationAlertsForAcceptBtn; 416 var msgFun = settings.w357_confirm_allow_msg; 417 var cookieNameFun = settings.w357_cookie_name; 418 var linkFun = settings.w357_current_url; 419 var expiration = 420 settings.w357_expiration_cookieAccept; 421 cnbwb += 422 ' <span id="cpnb-accept-btn" role="button" tabindex="0" aria-label="' + 423 decodeURI(settings.w357_buttonText) + 424 '"' + 425 cpnb_actionAttrs('accept', { 426 'joomla-caching': 427 settings.w357_joomla_caching, 428 'enable-confirmation': 429 decodeURI(enableConfirFun), 430 message: decodeURI(msgFun),
431 'cookie-name': cookieNameFun, 432 link: linkFun, 433 expiration: expiration, 434 'base-ajax-url': 435 settings.w357_base_ajax_url, 436 context: 'notification_bar', 437 reload: settings.w357_reloadPageAfterAccept, 438 overlay: settings.w357_overlay_state, 439 }) + 440 'class="cpnb-button cpnb-button-ok ' + 441 decodeURI( 442 settings.w357_accept_button_class_notification_bar 443 ) + 444 '">' + 445 decodeURI(settings.w357_buttonText) + 446 '</span>'; 447 } 448 break; 449 450 case 'decline': 451 // DECLINE BUTTON 452 if (settings.w357_display_decline_btn == 1) { 453 var enableConfirFun = 454 settings.w357_enableConfirmationAlertsForDeclineBtn; 455 var msgFun = settings.w357_confirm_delete_msg; 456 var cookieNameFun = settings.w357_cookie_name; 457 var linkFun = settings.w357_current_url; 458 var expiration = 459 settings.w357_expiration_cookieDecline; 460 cnbwb += 461 ' <span id="cpnb-decline-btn" role="button" tabindex="0" aria-label="' + 462 decodeURI(settings.w357_buttonDeclineText) + 463 '"' + 464 cpnb_actionAttrs('decline', { 465 'joomla-caching': 466 settings.w357_joomla_caching, 467 'enable-confirmation': 468 decodeURI(enableConfirFun), 469 message: decodeURI(msgFun), 470 'cookie-name': cookieNameFun, 471 link: linkFun, 472 expiration: expiration, 473 }) + 474 'class="cpnb-button cpnb-button-decline ' + 475 decodeURI( 476 settings.w357_decline_button_class_notification_bar 477 ) + 478 '">' + 479 decodeURI(settings.w357_buttonDeclineText) + 480 '</span>'; 481 } 482 break; 483 484 case 'cancel': 485 // CANCEL BUTTON 486 if (settings.w357_display_cancel_btn == 1) { 487 var cookieNameFun = settings.w357_cookie_name; 488 var linkFun = settings.w357_current_url; 489 var expiration = 490 settings.w357_expiration_cookieCancel; 491 cnbwb += 492 ' <span id="cpnb-cancel-btn" role="button" tabindex="0" aria-label="' + 493 decodeURI(settings.w357_buttonCancelText) + 494 '"' + 495 cpnb_actionAttrs('cancel', { 496 'cookie-name': cookieNameFun, 497 expiration: expiration, 498 link: linkFun, 499 overlay: settings.w357_overlay_state, 500 }) + 501 'class="cpnb-button cpnb-button-cancel ' + 502 decodeURI( 503 settings.w357_cancel_button_class_notification_bar 504 ) + 505 '">' + 506 decodeURI(settings.w357_buttonCancelText) + 507 '</span>'; 508 } 509 break; 510 511 case 'moreinfo': 512 // MORE INFO BUTTON 513 if (settings.w357_display_more_info_btn == 1) { 514 if ( 515 settings.w357_more_info_btn_type == 'link' || 516 settings.w357_more_info_btn_type == 'menu_item' 517 ) { 518 if (settings.w357_link_target == '_self') { 519 cnbwb += 520 ' <a id="cpnb-moreinfo-btn" href="' + 521 settings.w357_buttonMoreLink + 522 '" target="_self" class="cpnb-button cpnb-button-more-default ' + 523 decodeURI( 524 settings.w357_moreinfo_button_class_notification_bar 525 ) + 526 '">' + 527 decodeURI( 528 settings.w357_buttonMoreText 529 ) + 530 '</a>'; 531 } else if ( 532 settings.w357_link_target == '_blank' 533 ) { 534 cnbwb += 535 ' <a id="cpnb-moreinfo-btn" href="' + 536 settings.w357_buttonMoreLink + 537 '" target="_blank" class="cpnb-button cpnb-button-more-default ' + 538 decodeURI( 539 settings.w357_moreinfo_button_class_notification_bar 540 ) + 541 '">' + 542 decodeURI( 543 settings.w357_buttonMoreText 544 ) + 545 '</a>'; 546 } else if ( 547 settings.w357_link_target == 'popup' 548 ) { 549 cnbwb += 550 ' <span id="cpnb-moreinfo-btn" role="button" tabindex="0" aria-label="' + 551 decodeURI( 552 settings.w357_buttonMoreText 553 ) + 554 '"' + 555 cpnb_actionAttrs('popup-moreinfo', { 556 link: settings.w357_buttonMoreLink, 557 height: settings.w357_popup_height, 558 width: settings.w357_popup_width, 559 }) + 560 'class="cpnb-button cpnb-button-more-default ' + 561 decodeURI( 562 settings.w357_moreinfo_button_class_notification_bar 563 ) + 564 '">' + 565 decodeURI( 566 settings.w357_buttonMoreText 567 ) + 568 '</span>'; 569 } 570 } else if ( 571 settings.w357_more_info_btn_type == 572 'custom_text' 573 ) { 574 cnbwb += 575 ' <span id="cpnb-moreinfo-btn" role="button" tabindex="0" aria-label="' + 576 decodeURI(settings.w357_buttonMoreText) + 577 '" data-cpnb-action="open-moreinfo" class="cpnb-button cpnb-button-more-default ' + 578 decodeURI( 579 settings.w357_moreinfo_button_class_notification_bar 580 ) + 581 '" id="cpnb_button_more_modal">' + 582 decodeURI(settings.w357_buttonMoreText) + 583 '</span>'; 584 } 585 } 586 587 break; 588 589 case 'settings': 590 // SETTINGS BUTTON 591 if (settings.w357_display_settings_btn == 1) { 592 cnbwb += 593 ' <span id="cpnb-settings-btn" role="button" tabindex="0" aria-label="' + 594 decodeURI(settings.w357_buttonSettingsText) + 595 '" data-cpnb-action="open-modal" class="cpnb-button cpnb-button-settings ' + 596 decodeURI( 597 settings.w357_settings_button_class_notification_bar 598 ) + 599 '">' + 600 decodeURI(settings.w357_buttonSettingsText) + 601 '</span>'; 602 } 603 604 break; 605 606 default: 607 // nothing to display 608 break; 609 } 610 } 611 // END: Buttons Sorting 612 613 cnbwb += ' <div class="cpnb-clear-both"></div>';
614 cnbwb += ' </div>'; 615 cnbwb += ' </div>'; 616 cnbwb += ' </div>'; 617 cnbwb += '</div>'; 618 619 // Check if background overlay is enabled 620 if (settings.w357_overlay_state == 1) { 621 cnbwb += 622 '<div id="cpnb_warningBoxBgOverlay" style="background-color:' + 623 settings.w357_overlay_color + 624 ';">'; 625 } 626 627 elem.innerHTML = cnbwb; 628 document.body.insertBefore(elem, document.body.firstChild); 629 630 //Center WarningBox Style 631 if (settings.w357_position == 'center') { 632 var windowWidth = 633 window.innerWidth || 634 document.documentElement.clientWidth || 635 document.body.clientWidth; 636 var warningBoxHeight = 637 document.getElementById('w357_cpnb_outer').clientHeight; 638 var pus = document.createElement('style'); 639 pus.type = 'text/css'; 640 pus.innerHTML = 641 '.cpnb-div-position-center {top:0; left:0; margin-top: ' + 642 (windowHeight - warningBoxHeight) / 2 + 643 'px; margin-left: ' + 644 (windowWidth - 500) / 2 + 645 'px} '; 646 document.getElementsByTagName('head')[0].appendChild(pus); 647 } 648 649 // Auto-accept after scrolling 650 if (settings.w357_autoAcceptAfterScrolling) { 651 var scroll_counter = 0; 652 window.addEventListener('scroll', function () { 653 if (scroll_counter == 0) { 654 // if counter is 1, it will not execute 655 if ( 656 window.pageYOffset > 657 settings.w357_numOfScrolledPixelsBeforeAutoAccept 658 ) { 659 var enableConfirFun = 660 settings.w357_enableConfirmationAlertsForAcceptBtn; 661 var msgFun = settings.w357_confirm_allow_msg; 662 var cookieNameFun = settings.w357_cookie_name; 663 var linkFun = settings.w357_current_url; 664 var expiration = 665 settings.w357_expiration_cookieAccept; 666 667 cpnb_warning_accept_button( 668 settings.w357_joomla_caching, 669 decodeURI(enableConfirFun), 670 decodeURI(msgFun), 671 cookieNameFun, 672 linkFun, 673 expiration, 674 settings.w357_base_ajax_url, 675 'notification_bar', 676 settings.w357_reloadPageAfterAccept, 677 settings.w357_overlay_state 678 ); 679 680 scroll_counter++; // increment the counter by 1, new value = 1 681 } 682 } 683 }); 684 } 685 686 // Timeout Duration function, Hide warning box box-shadow => w357_duration 687 function cpnb_hideInfoBox(ms, gapMs) { 688 setTimeout(function () { 689 var e = document.getElementById('w357_cpnb_outer'); 690 if (e) { 691 e.classList.remove('cpnb-warningBox-show-fade-in'); 692 e.classList.add('cpnb-warningBox-show-fade-out'); 693 } 694 695 if (settings.w357_overlay_state == 1) { 696 var overlay = document.getElementById( 697 'cpnb_warningBoxBgOverlay' 698 ); 699 if (overlay) { 700 overlay.classList.add( 701 'cpnb-warningBox-show-fade-out' 702 ); 703 } 704 } 705 }, ms); 706 // Hide warning 707 setTimeout(function () { 708 var bar = document.getElementById('w357_cpnb_outer'); 709 if (bar) { 710 bar.style.display = 'none'; 711 } 712 if (settings.w357_overlay_state == 1) {
713 var overlay = document.getElementById( 714 'cpnb_warningBoxBgOverlay' 715 ); 716 if (overlay) { 717 overlay.style.display = 'none'; 718 } 719 } 720 }, ms + gapMs); 721 } 722 723 // Hide the notification bar after X seconds 724 if (settings.w357_hide_after_time != 'display_always') { 725 cpnb_hideInfoBox( 726 settings.w357_duration * 1000, 727 settings.w357_animate_duration 728 ); 729 } 730 731 // Create style WarningBox duration open & close 732 var stDur = settings.w357_animate_duration / 1000; 733 734 // If border on warning box, problem with animation height. 735 var offsetHeightBorderx1 = ['top', 'bottom']; 736 if (offsetHeightBorderx1.indexOf(settings.w357_position) >= 0) { 737 var subOffsetHeight = settings.w357_borderWidth; 738 } else { 739 var subOffsetHeight = settings.w357_borderWidth * 2; 740 } 741 742 var offsetHeight = 743 document.getElementById('w357_cpnb_outer').offsetHeight - 744 subOffsetHeight; 745 var w357_cpnb_outer_height = 746 document.getElementById('w357_cpnb_outer').offsetHeight; 747 748 var pus = document.createElement('style'); 749 pus.type = 'text/css'; 750 pus.innerHTML = 751 '.cpnb-warningBox-show-fade-in {overflow:hidden; animation-name: slidein; animation-duration: ' + 752 stDur + 753 's;} '; 754 pus.innerHTML += 755 '.cpnb-warningBox-show-fade-out { opacity:0; overflow:hidden; padding:0; animation-name: slideout; animation-duration: ' + 756 stDur + 757 's;} '; 758 pus.innerHTML += 759 '@keyframes slidein { from { height:0px; opacity:0; } to { height:' + 760 offsetHeight + 761 'px; opacity:1;} }'; 762 pus.innerHTML += 763 '@keyframes slideout { from { opacity:1; } to { opacity:0; } }'; 764 document.getElementsByTagName('head')[0].appendChild(pus); 765 766 // Create Modal 767 if (settings.w357_more_info_btn_type == 'custom_text') { 768 // Create style with modal duration open & close 769 var stDur = settings.w357_animate_duration / 5000; 770 var pus = document.createElement('style'); 771 pus.type = 'text/css'; 772 pus.innerHTML = 773 '.cpnb-modal-show-fade-in { visibility: visible; opacity: 1; -webkit-transition: opacity ' + 774 stDur + 775 's, visibility ' + 776 stDur + 777 's; transition: opacity ' + 778 stDur + 779 's, visibility ' + 780 stDur + 781 's; } '; 782 pus.innerHTML += 783 '.cpnb-modal-show-fade-out { visibility: hidden; opacity: 0; -webkit-transition: opacity ' + 784 stDur + 785 's, visibility ' + 786 stDur + 787 's; transition: opacity ' + 788 stDur + 789 's, visibility ' + 790 stDur + 791 's; } '; 792 document.getElementsByTagName('head')[0].appendChild(pus); 793 794 var elem = document.createElement('div'); 795 var cnbwb = 796 '<div id="cpnb_modal_wrap" class="cpnb-modal-wrap cpnb-modal-show-fade-out">'; 797 cnbwb += 798 ' <div class="cpnb-modal-outer cpnb-modal-bg cpnb-close" id="cpnb_outter-moreinfo" style="top: 0px; left: 0px; align-items: flex-start;">'; 799 cnbwb += 800 ' <div class="cpnb-modal-inner cpnb-modal--medium" id="cpnb_inner-moreinfo" style="z-index: 100000000; max-height:' + 801 maxHeight + 802 'px; margin-top:' + 803 marginTopWindow + 804 'px;">'; 805 cnbwb += 806 ''; 807 cnbwb += 808 ' <div class="cpnb-modal-inner-text">' + 809 settings.w357_customText + 810 '</div>'; 811 cnbwb += 812 ' <span role="button" tabindex="0" aria-label="Close" data-cpnb-action="close-moreinfo" id="cpnb-modal-close-moreinfo" class="cpnb-modal-close cpnb-close cpnb-close-icon-x"></span>'; 813 cnbwb += 814 ' <div id="close_cpnb_modal_footer" class="cpnb-modal-footer">'; 815 cnbwb += 816 ' <div id="close_cpnb_modal_actions" class="cpnb-modal-actions">'; 817 818 // BEGIN: Buttons Sorting 819 var buttons_ordering_array = JSON.parse( 820 settings.w357_buttons_ordering 821 ); 822 for (var i = 0; i < buttons_ordering_array.length; i++) { 823 var btn = buttons_ordering_array[i]; 824 switch (btn) { 825 case 'ok': 826 // ACCEPT BUTTON 827 if (settings.w357_display_ok_btn == 1) { 828 var msgFun = settings.w357_confirm_allow_msg; 829 var expiration = 830 settings.w357_expiration_cookieAccept; 831 var linkFun = settings.w357_current_url; 832 cnbwb += 833 ' <span id="cpnb-accept-btn-m-info" role="button" tabindex="0" aria-label="' + 834 decodeURI(settings.w357_buttonText) + 835 '"' + 836 cpnb_actionAttrs('accept', { 837 'joomla-caching': 838 settings.w357_joomla_caching, 839 'enable-confirmation': 840 decodeURI(enableConfirFun), 841 message: decodeURI(msgFun),
842 'cookie-name': cookieNameFun, 843 link: linkFun, 844 expiration: expiration, 845 'base-ajax-url': 846 settings.w357_base_ajax_url, 847 context: 'modal', 848 reload: settings.w357_reloadPageAfterAccept, 849 overlay: settings.w357_overlay_state, 850 }) + 851 'class="cpnb-button cpnb-button-ok ' + 852 decodeURI( 853 settings.w357_accept_button_class_notification_bar 854 ) + 855 '">' + 856 decodeURI(settings.w357_buttonText) + 857 '</span>'; 858 } 859 break; 860 861 case 'decline': 862 // DECLINE BUTTON 863 if (settings.w357_display_decline_btn == 1) { 864 var msgFun = settings.w357_confirm_delete_msg; 865 var expiration = 866 settings.w357_expiration_cookieDecline; 867 var linkFun = settings.w357_current_url; 868 cnbwb += 869 ' <span id="cpnb-decline-btn-m-info" role="button" tabindex="0" aria-label="' + 870 decodeURI(settings.w357_buttonDeclineText) + 871 '"' + 872 cpnb_actionAttrs('decline', { 873 'joomla-caching': 874 settings.w357_joomla_caching, 875 'enable-confirmation': 876 decodeURI(enableConfirFun), 877 message: decodeURI(msgFun), 878 'cookie-name': cookieNameFun, 879 link: linkFun, 880 expiration: expiration, 881 'is-modal': 'true', 882 }) + 883 'class="cpnb-button cpnb-button-decline ' + 884 decodeURI( 885 settings.w357_decline_button_class_notification_bar 886 ) + 887 '">' + 888 decodeURI(settings.w357_buttonDeclineText) + 889 '</span>'; 890 } 891 break; 892 893 case 'cancel': 894 // CANCEL BUTTON 895 if (settings.w357_display_cancel_btn == 1) { 896 var expiration = 897 settings.w357_expiration_cookieCancel; 898 var linkFun = settings.w357_current_url; 899 cnbwb += 900 ' <span id="cpnb-cancel-btn-m-info" role="button" tabindex="0" aria-label="' + 901 decodeURI(settings.w357_buttonCancelText) + 902 '"' + 903 cpnb_actionAttrs('cancel', { 904 'cookie-name': cookieNameFun, 905 expiration: expiration, 906 link: linkFun, 907 overlay: settings.w357_overlay_state, 908 'is-modal': 'true', 909 }) + 910 'class="cpnb-button cpnb-button-cancel ' + 911 decodeURI( 912 settings.w357_cancel_button_class_notification_bar 913 ) + 914 '">' + 915 decodeURI(settings.w357_buttonCancelText) + 916 '</span>'; 917 } 918 break; 919 920 case 'settings': 921 // SETTINGS BUTTON 922 if (settings.w357_display_settings_btn == 1) { 923 cnbwb += 924 ' <span id="cpnb-settings-btn-m-info" role="button" tabindex="0" aria-label="' + 925 decodeURI( 926 settings.w357_buttonSettingsText 927 ) + 928 '" data-cpnb-action="open-modal" data-cpnb-close-moreinfo="1" class="cpnb-button cpnb-button-settings ' + 929 decodeURI( 930 settings.w357_settings_button_class_notification_bar 931 ) + 932 '">' + 933 decodeURI( 934 settings.w357_buttonSettingsText 935 ) + 936 '</span>'; 937 } 938 939 break; 940 941 default: 942 // nothing to display 943 break; 944 } 945 } 946 // END: Buttons Sorting 947 948 cnbwb += ' </div>'; 949 cnbwb += ' </div>'; 950 cnbwb += ' </div>'; 951 cnbwb += 952 ' <div class="cpnb-modal-show-fade-out" id="modal_close_bg" role="button" tabindex="0" aria-label="Close modal" data-cpnb-action="close-moreinfo" style=" z-index: 99999999; top:0; left:0; position:fixed; width:100%; height:100%;"></div>'; 953 cnbwb += ' </div>'; 954 cnbwb += '</div>'; 955 elem.innerHTML = cnbwb; 956 document.body.insertBefore(elem, document.body.firstChild); 957 } 958 } // END: Check if => iFrame && Always Display (w357_always_display) && Limit (cpnb_cookie_limit) 959
960 // Do not cover the body of the page. 961 if (settings.w357_body_cover === 0) { 962 if (w357_cpnb_outer_height != null && w357_cpnb_outer_height > 0) { 963 if (settings.w357_position == 'top') { 964 document.getElementsByTagName('body')[0].style.paddingTop = 965 w357_cpnb_outer_height + 'px'; 966 } else { 967 document.getElementsByTagName( 968 'body' 969 )[0].style.paddingBottom = w357_cpnb_outer_height + 'px'; 970 } 971 } 972 } 973 974 ////***************** START MANAGER *****************//// 975 // Get data from server, check for each if empty or null then use default settings 976 // EXAMPLE: PHP ECHO SCRIPT -> var newSettings = { .. } 977 978 //Overide ModalManager settings 979 var varsToBeParsedInt = [ 980 'w357_m_modalState', 981 'w357_m_floatButtonState', 982 ]; 983 //var cpnb_manager = []; 984 for (var obj in cpnb_manager) { 985 if ((cpnb_manager[obj] !== null) & (cpnb_manager[obj] !== '')) { 986 if (varsToBeParsedInt.indexOf(obj) >= 0) { 987 modalManager[obj] = parseInt(cpnb_manager[obj]); // Overwrite settings 988 } else { 989 modalManager[obj] = cpnb_manager[obj]; //Overwrite settings 990 } 991 } 992 } 993 994 modalManagerSettings = modalManager; 995 996 //Get array with information about cookies categories (Read Cookie) 997 var settingsPayload = cpnb_getConsentCookiePayload( 998 'cpnb_cookiesSettings' 999 ); 1000 if (settingsPayload && settingsPayload.v) { 1001 categoriesSettingsCookie = settingsPayload.v; 1002 } else { 1003 categoriesSettingsCookie = {}; 1004 //categoriesSettingsCookie = {"required-cookies":1,"analytical-cookies":0,"social-media-cookies":0,"targeted-advertising-cookies":0}; 1005 } 1006 1007 //cpnb_createCookie("cpnb_cookiesSettings", JSON.stringify(categoriesSettingsCookie), settings.w357_expiration_cookies); 1008 afterCategoriesSettingsCookie = categoriesSettingsCookie; 1009 afterExpirationCookies = settings.w357_expiration_cookieSettings; 1010 cpnb_syncConsentCookieExpiration( 1011 settings.w357_cookie_name, 1012 settings.w357_expiration_cookieAccept 1013 ); 1014 cpnb_syncConsentCookieExpiration( 1015 settings.w357_cookie_name_declined, 1016 settings.w357_expiration_cookieDecline 1017 ); 1018 cpnb_syncConsentCookieExpiration( 1019 settings.w357_cookie_name_cancelled, 1020 settings.w357_expiration_cookieCancel 1021 ); 1022 cpnb_syncConsentCookieExpiration( 1023 'cpnb_cookiesSettings', 1024 settings.w357_expiration_cookieSettings 1025 ); 1026 cpnb_syncConsentCookieExpiration( 1027 'cpnb_cookiesSettingsTemp', 1028 settings.w357_expiration_cookieSettings 1029 ); 1030 1031 // Sync any blocked scripts that should run before/after consent on page load (init) 1032 cpnb_handleBlockCookieScripts(); 1033 1034 // After the first post-accept reload, poll until document.cookie stops changing 1035 // (meaning GA4/GTM scripts have finished writing their cookies), then reload so 1036 // the {cookiesinfo} shortcode table includes _ga_XXXX and similar async cookies. 1037 try { 1038 if (localStorage.getItem('cpnb_shortcode_cookie_reload') === '1' && settings.w357_shortcode_is_enabled_on_this_page == 1) { 1039 localStorage.removeItem('cpnb_shortcode_cookie_reload'); 1040 var _cpnbPollStart = Date.now(); 1041 var _cpnbPollBaseline = document.cookie; 1042 var _cpnbPollSnapshot = _cpnbPollBaseline; 1043 var _cpnbPollTimer = setInterval(function () { 1044 var _cpnbNow = Date.now(); 1045 var _cpnbCurrent = document.cookie; 1046 var _cpnbStable = (_cpnbCurrent === _cpnbPollSnapshot && (_cpnbNow - _cpnbPollStart) >= 1000);
1047 var _cpnbTimeout = (_cpnbNow - _cpnbPollStart) >= 8000; 1048 if (_cpnbStable || _cpnbTimeout) { 1049 clearInterval(_cpnbPollTimer); 1050 // Only re-fetch the table if GA4/GTM wrote new cookies since the page loaded. 1051 // If nothing changed, the DOMContentLoaded fetch already showed the correct state. 1052 if (_cpnbCurrent !== _cpnbPollBaseline) { 1053 var _cpnbCitEl = document.getElementById('cpnb-cit-container'); 1054 if (_cpnbCitEl && _cpnbCitEl.getAttribute('data-cpnb-table-ajax')) { 1055 cpnb_fetchCookiesInfoTable(); 1056 } else { 1057 window.location.reload(); 1058 } 1059 } 1060 } 1061 _cpnbPollSnapshot = _cpnbCurrent; 1062 }, 850); 1063 } 1064 } catch (e) { 1065 } 1066 1067 //Check if ModalManager is enabled (independent of Block Cookies Functionality) 1068 if ( 1069 cpnb_checkDIfIframeDisplay() && 1070 modalManager.w357_m_modalState == 1 1071 ) { 1072 //Pass Modal LOCKED-CHECKBOX Confirmation Alert 1073 m_modalManager_confirmationText = 1074 modalManager.w357_m_confirmationAlertRequiredCookies; 1075 1076 //Create Left Menu Item Selected Class 1077 var pus = document.createElement('style'); 1078 pus.type = 'text/css'; 1079 pus.innerHTML = 1080 '.cpnb-manager-modal-left-item-selected, .cpnb-manager-modal-left-item-unSelected:hover, .cpnb-manager-modal-left-item-unSelected:focus {background: ' + 1081 modalManager.w357_m_modal_menuItemSelectedBgColor + 1082 ';} '; 1083 document.getElementsByTagName('head')[0].appendChild(pus); 1084 1085 var HTMLleftMenu = ''; 1086 var HTMLinformationBoxes = ''; 1087 var categoriesCounter = 0; //Pick first category and first box with information to show. 1088 1089 // Open-Close Left Menu Button 1090 HTMLinformationBoxes += 1091 '<div class="cpnb-left-menu-toggle" role="button" tabindex="0" data-cpnb-action="toggle-menu">'; 1092 HTMLinformationBoxes += 1093 '<div class="cpnb-toggle-menu-container cpnb-left-menu-toggle-button">'; 1094 HTMLinformationBoxes += '<div class="cpnb-toggle-menu-bar1"></div>'; 1095 HTMLinformationBoxes += '<div class="cpnb-toggle-menu-bar2"></div>'; 1096 HTMLinformationBoxes += '<div class="cpnb-toggle-menu-bar3"></div>'; 1097 HTMLinformationBoxes += '</div>'; 1098 HTMLinformationBoxes += '</div>'; 1099 1100 // Modal Manager HEADER 1101 HTMLinformationBoxes += 1102 '<div class="h2 cpnb-m-header">' + 1103 modalManager.w357_m_modalHeadingText + 1104 '</div>'; 1105 1106 for (var categoryID in cpnb_cookiesCategories) { 1107 if ( 1108 cpnb_cookiesCategories[categoryID].cookie_category_status == 1109 1 1110 ) { 1111 var innerCookieCategory = 1112 cpnb_cookiesCategories[categoryID].cookie_category_id; 1113 1114 categoriesCounter++; 1115 1116 // Check if First Category 1117 if (categoriesCounter == 1) { 1118 // Create menu item 1119 HTMLleftMenu += 1120 '<div role="button" tabindex="0" aria-label="' + 1121 cpnb_cookiesCategories[categoryID] 1122 .cookie_category_name + 1123 '"' + 1124 cpnb_actionAttrs('change-category', { 1125 category: categoryID, 1126 }) + 1127 'id="mlm_menu_category_id_' + 1128 categoryID + 1129 '" class="cpnb-manager-modal-left-item-selected cpnb-manager-modal-left-item modal-left-menu-item-id-' + 1130 categoryID + 1131 '">' + 1132 cpnb_cookiesCategories[categoryID] 1133 .cookie_category_name + 1134 '</div>'; 1135 //Create new information box (right) 1136 HTMLinformationBoxes += 1137 '<div id="mmr_box_category_id_' + 1138 categoryID + 1139 '" class="cpnb-manager-modal-right-selected cpnb-manager-modal-right cpnb-manager-modal-right-scrollbar">'; 1140 } else { 1141 // Create menu item 1142 HTMLleftMenu += 1143 '<div role="button" tabindex="0" aria-label="' + 1144 cpnb_cookiesCategories[categoryID] 1145 .cookie_category_name + 1146 '"' + 1147 cpnb_actionAttrs('change-category', { 1148 category: categoryID, 1149 }) + 1150 'id="mlm_menu_category_id_' + 1151 categoryID + 1152 '" class="cpnb-manager-modal-left-item-unSelected cpnb-manager-modal-left-item modal-left-menu-item-id-' + 1153 categoryID + 1154 '">' + 1155 cpnb_cookiesCategories[categoryID] 1156 .cookie_category_name + 1157 '</div>'; 1158 // Create new information box (right) 1159 HTMLinformationBoxes += 1160 '<div id="mmr_box_category_id_' + 1161 categoryID + 1162 '" class="cpnb-manager-modal-right-unSelected cpnb-manager-modal-right cpnb-manager-modal-right-scrollbar">'; 1163 } 1164 1165 HTMLinformationBoxes += 1166 '<p><strong id="cpnb_category_heading_' + 1167 categoryID + 1168 '" class="cpnb-cookies-category-heading-responsive">' + 1169 cpnb_cookiesCategories[categoryID] 1170 .cookie_category_name + 1171 '</strong></p>'; 1172 HTMLinformationBoxes += 1173 cpnb_cookiesCategories[categoryID] 1174 .cookie_category_description; 1175 HTMLinformationBoxes += 1176 '<div class="cpnb-category-group" role="group" aria-labelledby="cpnb_category_heading_' + 1177 categoryID + 1178 '">'; 1179 1180 //Initialize vars for saveCategoryState 1181 var init_genericExp = settings.w357_expiration_cookies; 1182 var init_baseUrl = settings.w357_current_url; 1183 var init_cookieName = settings.w357_cookie_name; 1184 var init_acceptExp = settings.w357_expiration_cookieAccept; 1185 var init_declineExp = 1186 settings.w357_expiration_cookieDecline; 1187 1188 //(ENABLE-DISABLE BUTTON) - Check if cookie for category state exists. If exists check what state has been saved.
1189 if (categoriesSettingsCookie[innerCookieCategory] == null) { 1190 if ( 1191 cpnb_cookiesCategories[categoryID] 1192 .cookie_category_checked_by_default == 1 1193 ) { 1194 HTMLinformationBoxes += 1195 '<div class="modalCheckBox"><input data-cpnb-save="1" data-cpnb-category-id="' + 1196 categoryID + 1197 '" data-cpnb-exp="' + 1198 init_genericExp + 1199 '" data-cpnb-base-url="' + 1200 init_baseUrl + 1201 '" data-cpnb-cookie-name="' + 1202 init_cookieName + 1203 '" data-cpnb-accept-exp="' + 1204 init_acceptExp + 1205 '" data-cpnb-decline-exp="' + 1206 init_declineExp + 1207 '" class="cpnb-checkbox" type="checkbox" value="1" id="modalCheckBox_id_' + 1208 categoryID + 1209 '" name="modalCheckBox_id_' + 1210 categoryID + 1211 '" checked/><label for="modalCheckBox_id_' + 1212 categoryID + 1213 '">' + 1214 modalManager.w357_m_checkboxText + 1215 '</label></div>'; 1216 categoriesSettingsCookie[innerCookieCategory] = 1; 1217 } else if ( 1218 cpnb_cookiesCategories[categoryID] 1219 .cookie_category_checked_by_default == 2 1220 ) { 1221 //DISABLED CHECKBOX - cpnb_m_lockedCheckbox 1222 HTMLinformationBoxes += 1223 '<div class="modalCheckBox"><input data-cpnb-locked="1" data-cpnb-category-id="' + 1224 categoryID + 1225 '" data-cpnb-exp="' + 1226 settings.w357_expiration_cookies + 1227 '" data-cpnb-confirmation="' + 1228 settings.w357_enableConfirmationAlerts + 1229 '" class="cpnb-checkbox" type="checkbox" value="1" id="modalCheckBox_id_' + 1230 categoryID + 1231 '" name="modalCheckBox_id_' + 1232 categoryID + 1233 '" checked/><label for="modalCheckBox_id_' + 1234 categoryID + 1235 '">' + 1236 modalManager.w357_m_checkboxText + 1237 '</label></div>'; 1238 categoriesSettingsCookie[innerCookieCategory] = 1; 1239 } else { 1240 HTMLinformationBoxes += 1241 '<div class="modalCheckBox"><input data-cpnb-save="1" data-cpnb-category-id="' + 1242 categoryID + 1243 '" data-cpnb-exp="' + 1244 init_genericExp + 1245 '" data-cpnb-base-url="' + 1246 init_baseUrl + 1247 '" data-cpnb-cookie-name="' + 1248 init_cookieName + 1249 '" data-cpnb-accept-exp="' + 1250 init_acceptExp + 1251 '" data-cpnb-decline-exp="' + 1252 init_declineExp + 1253 '" class="cpnb-checkbox" type="checkbox" value="1" id="modalCheckBox_id_' + 1254 categoryID + 1255 '" name="modalCheckBox_id_' + 1256 categoryID + 1257 '" /><label for="modalCheckBox_id_' + 1258 categoryID + 1259 '">' + 1260 modalManager.w357_m_checkboxText + 1261 '</label></div>';
1262 categoriesSettingsCookie[innerCookieCategory] = 0; 1263 } 1264 } else { 1265 //Check if LOCKED 1266 if ( 1267 cpnb_cookiesCategories[categoryID] 1268 .cookie_category_checked_by_default != 2 1269 ) { 1270 if ( 1271 categoriesSettingsCookie[ 1272 '' + innerCookieCategory + '' 1273 ] == 1 1274 ) { 1275 HTMLinformationBoxes += 1276 '<div class="modalCheckBox"><input class="cpnb-checkbox" data-cpnb-save="1" data-cpnb-category-id="' + 1277 categoryID + 1278 '" data-cpnb-exp="' + 1279 init_genericExp + 1280 '" data-cpnb-base-url="' + 1281 init_baseUrl + 1282 '" data-cpnb-cookie-name="' + 1283 init_cookieName + 1284 '" data-cpnb-accept-exp="' + 1285 init_acceptExp + 1286 '" data-cpnb-decline-exp="' + 1287 init_declineExp + 1288 '" type="checkbox" value="1" id="modalCheckBox_id_' + 1289 categoryID + 1290 '" name="modalCheckBox_id_' + 1291 categoryID + 1292 '" checked/><label for="modalCheckBox_id_' + 1293 categoryID + 1294 '">' + 1295 modalManager.w357_m_checkboxText + 1296 '</label></div>'; 1297 categoriesSettingsCookie[ 1298 innerCookieCategory 1299 ] = 1; 1300 } else { 1301 HTMLinformationBoxes += 1302 '<div class="modalCheckBox"><input data-cpnb-save="1" data-cpnb-category-id="' + 1303 categoryID + 1304 '" data-cpnb-exp="' + 1305 init_genericExp + 1306 '" data-cpnb-base-url="' + 1307 init_baseUrl + 1308 '" data-cpnb-cookie-name="' + 1309 init_cookieName + 1310 '" data-cpnb-accept-exp="' + 1311 init_acceptExp + 1312 '" data-cpnb-decline-exp="' + 1313 init_declineExp + 1314 '" class="cpnb-checkbox" type="checkbox" value="1" id="modalCheckBox_id_' + 1315 categoryID + 1316 '" name="modalCheckBox_id_' + 1317 categoryID + 1318 '" /><label for="modalCheckBox_id_' + 1319 categoryID + 1320 '">' + 1321 modalManager.w357_m_checkboxText + 1322 '</label></div>'; 1323 categoriesSettingsCookie[ 1324 innerCookieCategory 1325 ] = 0; 1326 } 1327 } else { 1328 //DISABLED CHECKBOX - cpnb_m_lockedCheckbox 1329 HTMLinformationBoxes += 1330 '<div class="modalCheckBox"><input data-cpnb-locked="1" data-cpnb-category-id="' + 1331 categoryID + 1332 '" data-cpnb-exp="' + 1333 settings.w357_expiration_cookies + 1334 '" data-cpnb-confirmation="' + 1335 settings.w357_enableConfirmationAlerts + 1336 '" class="cpnb-checkbox" type="checkbox" value="1" id="modalCheckBox_id_' + 1337 categoryID + 1338 '" name="modalCheckBox_id_' + 1339 categoryID + 1340 '" checked/><label for="modalCheckBox_id_' + 1341 categoryID + 1342 '">' + 1343 modalManager.w357_m_checkboxText + 1344 ' ' + 1345 modalManager.w357_m_lockedText + 1346 '</label></div>';
1347 categoriesSettingsCookie[innerCookieCategory] = 1; 1348 } 1349 } 1350 1351 HTMLinformationBoxes += '</div>'; 1352 HTMLinformationBoxes += 1353 '<div style="display:block; width:100%; height:30px;"></div>'; 1354 HTMLinformationBoxes += '</div>'; 1355 1356 //Create IO ARRAY with IDs 1357 categoriesSettingsCookieInner[innerCookieCategory] = 1358 categoryID; 1359 categoriesSettingsCookieOuter[categoryID] = 1360 innerCookieCategory; 1361 } 1362 } 1363 1364 HTMLinformationBoxes += '<div class="cpnb-m-bottom-buttons">'; 1365 var enableConfirFun = 1366 settings.w357_enableConfirmationAlertsForAcceptBtn; 1367 var cookieNameFun = settings.w357_cookie_name; 1368 var msgFun = settings.w357_confirm_allow_msg; 1369 var expiration = settings.w357_expiration_cookieAccept; 1370 var linkFun = settings.w357_current_url; 1371 var encodedAcceptMsg = encodeURIComponent(decodeURI(msgFun)); 1372 var encodedAcceptCookieName = encodeURIComponent(cookieNameFun); 1373 var encodedAcceptLink = encodeURIComponent(linkFun); 1374 var encodedAcceptBaseAjaxUrl = encodeURIComponent( 1375 settings.w357_base_ajax_url 1376 ); 1377 HTMLinformationBoxes += 1378 '<button id="cpnb-accept-btn-m" class="cpnb-button cpnb-m-enableAllButton ' + 1379 decodeURI( 1380 settings.w357_accept_button_class_notification_bar_modal_window 1381 ) + 1382 '" type="button" data-cpnb-action="accept" data-cpnb-joomla-caching="' + 1383 settings.w357_joomla_caching + 1384 '" data-cpnb-enable-confirmation="' + 1385 decodeURI(enableConfirFun) + 1386 '" data-cpnb-message="' + 1387 encodedAcceptMsg + 1388 '" data-cpnb-cookie-name="' + 1389 encodedAcceptCookieName + 1390 '" data-cpnb-link="' + 1391 encodedAcceptLink + 1392 '" data-cpnb-expiration="' + 1393 expiration + 1394 '" data-cpnb-base-ajax-url="' + 1395 encodedAcceptBaseAjaxUrl + 1396 '" data-cpnb-context="modal" data-cpnb-reload="' + 1397 settings.w357_reloadPageAfterAccept + 1398 '" data-cpnb-overlay="' + 1399 settings.w357_overlay_state + 1400 '">' + 1401 modalManager.w357_m_EnableAllButtonText + 1402 '</button>'; 1403 1404 var enableConfirFun = 1405 settings.w357_enableConfirmationAlertsForDeclineBtn; 1406 var msgFun = settings.w357_confirm_delete_msg; 1407 var expiration = settings.w357_expiration_cookieDecline; 1408 var linkFun = settings.w357_current_url; 1409 var encodedDeclineMsg = encodeURIComponent(decodeURI(msgFun)); 1410 var encodedDeclineCookieName = encodeURIComponent(cookieNameFun); 1411 var encodedDeclineLink = encodeURIComponent(linkFun); 1412 HTMLinformationBoxes += 1413 '<button id="cpnb-decline-btn-m" class="cpnb-button cpnb-m-DeclineAllButton ' + 1414 decodeURI( 1415 settings.w357_decline_button_class_notification_bar_modal_window 1416 ) + 1417 '" type="button" data-cpnb-action="decline" data-cpnb-joomla-caching="' + 1418 settings.w357_joomla_caching + 1419 '" data-cpnb-enable-confirmation="' + 1420 decodeURI(enableConfirFun) + 1421 '" data-cpnb-message="' + 1422 encodedDeclineMsg + 1423 '" data-cpnb-cookie-name="' + 1424 encodedDeclineCookieName + 1425 '" data-cpnb-link="' + 1426 encodedDeclineLink + 1427 '" data-cpnb-expiration="' + 1428 expiration + 1429 '" data-cpnb-is-modal="true">' + 1430 modalManager.w357_m_DeclineAllButtonText + 1431 '</button>'; 1432 var linkFun = settings.w357_current_url; 1433 var init_genericExp = settings.w357_expiration_cookies; 1434 var init_baseUrl = settings.w357_current_url; 1435 var init_cookieName = settings.w357_cookie_name; 1436 var init_acceptExp = settings.w357_expiration_cookieAccept; 1437 var init_declineExp = settings.w357_expiration_cookieDecline; 1438 var encodedSaveLink = encodeURIComponent(linkFun); 1439 var encodedSaveBaseUrl = encodeURIComponent(init_baseUrl); 1440 var encodedSaveCookieName = encodeURIComponent(init_cookieName); 1441 HTMLinformationBoxes += 1442 '<button type="button" id="cpnb-save-btn-m" class="cpnb-button cpnb-m-SaveChangesButton ' + 1443 decodeURI( 1444 settings.w357_save_button_class_notification_bar_modal_window 1445 ) + 1446 '" data-cpnb-action="save-settings" data-cpnb-link="' + 1447 encodedSaveLink + 1448 '" data-cpnb-expiration="' + 1449 init_genericExp + 1450 '" data-cpnb-base-url="' + 1451 encodedSaveBaseUrl + 1452 '" data-cpnb-cookie-name="' + 1453 encodedSaveCookieName + 1454 '" data-cpnb-accept-expiration="' + 1455 init_acceptExp + 1456 '" data-cpnb-decline-expiration="' + 1457 init_declineExp + 1458 '" data-cpnb-joomla-caching="' + 1459 settings.w357_joomla_caching + 1460 '" data-cpnb-reload="' + 1461 settings.w357_reloadPageAfterAccept + 1462 '">' + 1463 modalManager.w357_m_SaveChangesButtonText + 1464 '</button>'; 1465 HTMLinformationBoxes += '</div>'; 1466 1467 afterCategoriesSettingsCookie = categoriesSettingsCookie; 1468 afterExpirationCookies = settings.w357_expiration_cookies; 1469 1470 var cnbwb = 1471 '<div id="cpnb_manager_wrap" class="cpnb-modal-wrap cpnb-modal-show-fade-out">'; 1472 cnbwb +=
1473 ' <div class="cpnb-modal-outer cpnb-modal-bg cpnb-close" id="cpnb_outter" style="top: 0px; left: 0px; align-items: flex-start;">'; 1474 cnbwb += 1475 ' <div class="cpnb-modal-inner cpnb-modal--medium" id="cpnb_inner" style="z-index: 100000000; height:' + 1476 maxHeight + 1477 'px; margin-top:' + 1478 marginTopWindow + 1479 'px; overflow:hidden;">'; 1480 if (modalManager.w357_m_FloatButtonIconType == 'fontawesome_icon') { 1481 cnbwb += 1482 ' <span role="button" tabindex="0" aria-label="Close" data-cpnb-action="close-modal" id="cpnb-modal-close" class="cpnb-modal-close-fontawesome"><i class="fa fas fa-times"></i></span>'; 1483 } else { 1484 cnbwb += 1485 ' <span role="button" tabindex="0" aria-label="Close" data-cpnb-action="close-modal" id="cpnb-modal-close" class="cpnb-modal-close cpnb-close cpnb-close-icon-x"></span>'; 1486 } 1487 cnbwb += 1488 ' <section class="cpnb-m-content" aria-label="' + 1489 modalManager.w357_m_modalHeadingText + 1490 '">'; 1491 cnbwb += 1492 ' <div id="cpnb_manager_modal_left" class="cpnb-manager-modal-left">'; 1493 cnbwb += HTMLleftMenu; 1494 cnbwb += ' </div>'; 1495 1496 cnbwb += HTMLinformationBoxes; 1497 1498 cnbwb += ' </section>'; 1499 cnbwb += ' </div>'; 1500 cnbwb += 1501 ' <div class="cpnb-modal-show-fade-out" id="cpnb_manager_wrap_close_bg" aria-label="Close modal" style=" z-index: 99999999; top:0; left:0; position:fixed; width:100%; height:100%;"></div>'; 1502 cnbwb += ' </div>'; 1503 cnbwb += '</div>'; 1504 var elem = document.createElement('div'); 1505 elem.innerHTML = cnbwb; 1506 var bar = document.getElementById('w357_cpnb_outer'); 1507 if (bar && bar.parentNode) { 1508 bar.parentNode.insertBefore(elem, bar.nextSibling); 1509 } else { 1510 document.body.insertBefore(elem, document.body.firstChild); 1511 } 1512 1513 var closeModalOverlay = document.getElementById( 1514 'cpnb_manager_wrap_close_bg' 1515 ); 1516 if (closeModalOverlay) { 1517 closeModalOverlay.addEventListener( 1518 'click', 1519 cpnb_m_closeModal, 1520 false 1521 ); 1522 } 1523 1524 var closeModalOuter = document.getElementById('cpnb_outter'); 1525 if (closeModalOuter) { 1526 closeModalOuter.addEventListener( 1527 'click', 1528 function (event) { 1529 if (event.target === closeModalOuter) { 1530 cpnb_m_closeModal(); 1531 } 1532 }, 1533 false 1534 ); 1535 } 1536 1537 // Check if floatButton is enabled 1538 if ( 1539 modalManager.w357_m_floatButtonState == 1 && 1540 cpnb_hasAnyConsentDecision(settings) 1541 ) { 1542 //Floating Button 1543 var tooltipPosition = 1544 modalManager.w357_m_floatButtonPosition === 'bottom_right' 1545 ? 'left' 1546 : 'right'; 1547 var floatingButton = 1548 '<div role="button" tabindex="0" aria-label="' + 1549 modalManager.w357_m_floatButtonText + 1550 '" data-cpnb-action="open-modal" class="cpnb-m-cookies-floatButton cpnb-m-cookies-floatButtonPosition_' + 1551 modalManager.w357_m_floatButtonPosition + 1552 '">'; 1553 floatingButton += 1554 '<div class="cpnb-m-cookies-floatButton-icon" data-balloon="' + 1555 modalManager.w357_m_floatButtonText + 1556 '" data-balloon-pos="' + 1557 tooltipPosition + 1558 '">'; 1559 1560 if ( 1561 modalManager.w357_m_FloatButtonIconType == 1562 'fontawesome_icon' 1563 ) { 1564 floatingButton +=
1565 '<i class="cpnb-m-cookies-floatButton-icon-fontawesome-icon ' + 1566 modalManager.w357_m_FloatButtonIconFontAwesomeName + 1567 ' ' + 1568 modalManager.w357_m_FloatButtonIconFontAwesomeSize + 1569 '" style="color: ' + 1570 modalManager.w357_m_FloatButtonIconFontAwesomeColor + 1571 ';"></i>'; 1572 } else if ( 1573 modalManager.w357_m_FloatButtonIconType == 'uikit_icon' 1574 ) { 1575 floatingButton += 1576 '<span class="cpnb-m-cookies-floatButton-icon-uikit-icon" uk-icon="icon:' + 1577 modalManager.w357_m_FloatButtonIconUikitName + 1578 '; ratio: ' + 1579 modalManager.w357_m_FloatButtonIconUikitSize + 1580 '" style="color: ' + 1581 modalManager.w357_m_FloatButtonIconUikitColor + 1582 ';"></span>'; 1583 } else { 1584 floatingButton += 1585 '<img alt="Cookies manager" class="cpnb-m-cookies-floatButton-icon-img" src="' + 1586 modalManager.w357_m_floatButtonIconSrc + 1587 '"/>'; 1588 } 1589 1590 floatingButton += '</div>'; 1591 floatingButton += '</div>'; 1592 var elem = document.createElement('div'); 1593 elem.innerHTML = floatingButton; 1594 document.body.insertBefore(elem, document.body.firstChild); 1595 } 1596 1597 var click_to_open_modal = null; 1598 var el_w357_m_HashLink = document.getElementById( 1599 modalManager.w357_m_HashLink 1600 ); 1601 if (el_w357_m_HashLink) { 1602 click_to_open_modal = el_w357_m_HashLink.addEventListener( 1603 'click', 1604 cpnb_m_openModal, 1605 false 1606 ); 1607 } 1608 1609 var classTriggerName = modalManager.w357_m_HashLink; 1610 var classTriggers = []; 1611 if (classTriggerName) { 1612 classTriggers = document.getElementsByClassName( 1613 classTriggerName 1614 ); 1615 } 1616 var hashTriggers = []; 1617 if (classTriggerName) { 1618 hashTriggers = Array.prototype.slice.call( 1619 document.querySelectorAll( 1620 'a[href$="#' + classTriggerName + '"]' 1621 ) 1622 ); 1623 } 1624 var menuItemTriggers = Array.prototype.slice.call( 1625 document.querySelectorAll( 1626 'a[href*="view=cpnbcookiemanager"]' 1627 ) 1628 ); 1629 if (menuItemTriggers.length) { 1630 menuItemTriggers.forEach(function (menuEl) { 1631 if (menuEl && menuEl.classList) { 1632 menuEl.classList.add('cpnb-modal-trigger'); 1633 } 1634 }); 1635 } 1636 var modalTriggers = Array.prototype.slice.call( 1637 document.getElementsByClassName('cpnb-modal-trigger') 1638 ); 1639 var combinedTriggers = modalTriggers; 1640 if (classTriggers.length) { 1641 combinedTriggers = combinedTriggers.concat( 1642 Array.prototype.slice.call(classTriggers) 1643 ); 1644 } 1645 if (hashTriggers.length) { 1646 combinedTriggers = combinedTriggers.concat(hashTriggers); 1647 } 1648 if (combinedTriggers.length) { 1649 combinedTriggers.forEach(function (triggerEl) { 1650 triggerEl.addEventListener( 1651 'click', 1652 function (event) { 1653 if (event && event.preventDefault) { 1654 event.preventDefault(); 1655 } 1656 click_to_open_modal = true; 1657 cpnb_m_openModal(); 1658 }, 1659 false 1660 ); 1661 }); 1662 } 1663 document.addEventListener( 1664 'click', 1665 function (event) { 1666 var target = event.target; 1667 while (target && target !== document) { 1668 if ( 1669 target.classList && 1670 target.classList.contains('cpnb-modal-trigger') 1671 ) { 1672 if (event && event.preventDefault) { 1673 event.preventDefault(); 1674 } 1675 click_to_open_modal = true; 1676 cpnb_m_openModal(); 1677 break; 1678 } 1679 target = target.parentNode; 1680 } 1681 }, 1682 false 1683 ); 1684 1685 // Check Hash Link to open modal 1686 if ( 1687 window.location.hash == '#' + modalManager.w357_m_HashLink || 1688 click_to_open_modal 1689 ) { 1690 var e = document.getElementById('cpnb_manager_wrap'); 1691 if (e) { 1692 e.classList.remove('cpnb-modal-show-fade-out'); 1693 e.classList.add('cpnb-modal-show-fade-in'); 1694 } 1695 1696 var ec = document.getElementById('cpnb_manager_wrap_close_bg'); 1697 if (ec) { 1698 ec.classList.remove('cpnb-modal-show-fade-out'); 1699 ec.classList.add('cpnb-modal-show-fade-in'); 1700 } 1701 } 1702 } //End - Check if ModalManager is enabled 1703 1704 cpnb_bindKeyboardAccessibility(); 1705 cpnb_bindAcceptLinks(); 1706 cpnb_finishInit(); 1707
1708 ////***************** END MANAGER *****************//// 1709 }, 1710 false 1711); // END: WINDOW.ONLOAD 1712 1713/////******* START MANAGER *******///// 1714 1715//DISABLED CHECKBOX - cpnb_m_lockedCheckbox 1716function cpnb_m_lockedCheckbox(id, exp, confirmationAlert) { 1717 document.getElementById('modalCheckBox_id_' + id).checked = true; 1718 alert(m_modalManager_confirmationText); 1719 return; 1720} 1721 1722function cpnb_handleLockedCheckboxChange(event) { 1723 var target = event.target; 1724 if ( 1725 !target || 1726 !target.matches || 1727 !target.matches('input.cpnb-checkbox[data-cpnb-locked="1"]') 1728 ) { 1729 return; 1730 } 1731 1732 cpnb_m_lockedCheckbox( 1733 target.getAttribute('data-cpnb-category-id'), 1734 target.getAttribute('data-cpnb-exp'), 1735 target.getAttribute('data-cpnb-confirmation') 1736 ); 1737} 1738 1739function cpnb_handleCategoryCheckboxChange(event) { 1740 var target = event.target; 1741 if ( 1742 !target || 1743 !target.matches || 1744 !target.matches('input.cpnb-checkbox[data-cpnb-save="1"]') 1745 ) { 1746 return; 1747 } 1748 1749 cpnb_m_saveCategoryCookiesState( 1750 target.getAttribute('data-cpnb-category-id'), 1751 target.getAttribute('data-cpnb-exp'), 1752 target.getAttribute('data-cpnb-base-url'), 1753 target.getAttribute('data-cpnb-cookie-name'), 1754 target.getAttribute('data-cpnb-accept-exp'), 1755 target.getAttribute('data-cpnb-decline-exp') 1756 ); 1757} 1758 1759// Save Settings Button 1760function cpnb_warning_save_settings_button( 1761 link, 1762 exp, 1763 baseUrl, 1764 acceptCookieName, 1765 acceptCookieExpiration, 1766 declineCookieExpiration, 1767 w357_joomla_caching, 1768 reloadPageAfterAccept 1769) { 1770 var shouldReload = reloadPageAfterAccept == 1; 1771 var closeModalIfOpen = function () { 1772 if (document.getElementById('cpnb_manager_wrap')) { 1773 cpnb_m_closeModal(); 1774 } 1775 }; 1776 var closeBarIfOpen = function () { 1777 cpnb_closeNotificationBar(); 1778 }; 1779 1780 cpnb_setConsentCookie( 1781 'cpnb_cookiesSettings', 1782 afterCategoriesSettingsCookie, 1783 afterExpirationCookies 1784 ); 1785 // Use the temp settings until the "cpnb_warning_save_settings_button" function is called 1786 if (cpnb_getConsentCookiePayload('cpnb_cookiesSettingsTemp') == null) { 1787 cpnb_setConsentCookie( 1788 'cpnb_cookiesSettingsTemp', 1789 cpnb_getConsentCookieValue('cpnb_cookiesSettings'), 1790 exp 1791 ); 1792 } 1793 1794 cpnb_setConsentCookie( 1795 'cpnb_cookiesSettings', 1796 cpnb_getConsentCookieValue('cpnb_cookiesSettingsTemp'), 1797 exp 1798 ); 1799 1800 // save settings 1801 cpnb_handleBlockCookieScripts(); 1802 1803 var savedCookieSettings = cpnb_getConsentCookieValue( 1804 'cpnb_cookiesSettingsTemp' 1805 ); 1806 if (savedCookieSettings) { 1807 afterCategoriesSettingsCookie = savedCookieSettings || {}; 1808 } else { 1809 afterCategoriesSettingsCookie = {}; 1810 } 1811 afterExpirationCookies = exp; 1812 var funCookieSettings = cpnb_getConsentCookieValue( 1813 'cpnb_cookiesSettings' 1814 ); 1815 1816 //CHECK+CHANGE CookieName & cpnb_cookieDeclined = 1 1817 var countAllCategoriesCookies = 0; 1818 var countDisabledCategoriesCookies = 0; 1819 var countLockedCategoriesCookies = 0; 1820 for (var item in funCookieSettings) { 1821 countAllCategoriesCookies++; 1822 1823 if (cpnb_cookiesCategories[categoriesSettingsCookieInner[item]]) { 1824 if ( 1825 cpnb_cookiesCategories[categoriesSettingsCookieInner[item]] 1826 .cookie_category_checked_by_default == 2 1827 ) { 1828 countLockedCategoriesCookies++; 1829 } 1830 1831 if (funCookieSettings[item] == 0) { 1832 countDisabledCategoriesCookies++; 1833 } 1834 } 1835 } 1836 1837 //If remaining cookies are all disabled, delete cookieName and create cookieDeclined=1 1838 if ( 1839 countAllCategoriesCookies - countLockedCategoriesCookies == 1840 countDisabledCategoriesCookies 1841 ) { 1842 if (!cpnb_hasConsentCookie(cpnb_getDeclinedCookieName())) { 1843 cpnb_setConsentCookie( 1844 cpnb_getDeclinedCookieName(), 1845 '1', 1846 declineCookieExpiration 1847 ); 1848 cpnb_eraseCookie(acceptCookieName); 1849 cpnb_eraseCookie(cpnb_getCancelledCookieName()); 1850 cpnb_eraseCookie('cpnb_cookiesSettingsTemp'); 1851 1852 var postData = { 1853 cpnb_method: 'cpnbCookiesDeclined', 1854 dt: w357_joomla_caching > 0 ? new Date().getTime() : undefined, 1855 }; 1856 sendPostRequest(baseUrl, postData); 1857 closeModalIfOpen(); 1858 cpnb_m_ensureFloatButton(); 1859 closeBarIfOpen(); 1860 return; 1861 } 1862 } else { 1863 if (!cpnb_hasConsentCookie(acceptCookieName)) { 1864 cpnb_setConsentCookie( 1865 acceptCookieName, 1866 '1', 1867 acceptCookieExpiration 1868 ); 1869 cpnb_eraseCookie(cpnb_getDeclinedCookieName()); 1870 cpnb_eraseCookie(cpnb_getCancelledCookieName()); 1871 cpnb_eraseCookie('cpnb_cookiesSettingsTemp'); 1872 var postData = { 1873 cpnb_method: 'cpnbCookiesAccepted', 1874 dt: w357_joomla_caching > 0 ? new Date().getTime() : undefined, 1875 }; 1876 sendPostRequest(baseUrl, postData); 1877 if (shouldReload) { 1878 cpnb_reloadAfterPost(850); 1879 return; 1880 } 1881 closeModalIfOpen(); 1882 cpnb_m_ensureFloatButton(); 1883 closeBarIfOpen(); 1884 return; 1885 } 1886 } 1887 1888 // Settings were just copied from the staging cookie; drop it so the [cookiesinfo] 1889 // table is not mistaken for a mid-decision state (it hides the cookie list). 1890 cpnb_eraseCookie('cpnb_cookiesSettingsTemp'); 1891 1892 var postData = { 1893 cpnb_method: 'cpnbCookiesManagerSaveSettings', 1894 dt: w357_joomla_caching > 0 ? new Date().getTime() : undefined, 1895 }; 1896 1897 sendPostRequest(link, postData); 1898 if (shouldReload) { 1899 cpnb_reloadAfterPost(850); 1900 return; 1901 } 1902 closeModalIfOpen(); 1903 cpnb_m_ensureFloatButton(); 1904 closeBarIfOpen(); 1905} 1906
1907function cpnb_m_saveCategoryCookiesState( 1908 id, 1909 exp, 1910 baseUrl, 1911 acceptCookieName, 1912 acceptCookieExpiration, 1913 declineCookieExpiration 1914) { 1915 if (cpnb_cookiesCategories[id].cookie_category_checked_by_default != 2) { 1916 // Use the temp settings until the "cpnb_warning_save_settings_button" function is called 1917 if (cpnb_getConsentCookiePayload('cpnb_cookiesSettingsTemp') == null) { 1918 cpnb_setConsentCookie( 1919 'cpnb_cookiesSettingsTemp', 1920 afterCategoriesSettingsCookie || {}, 1921 exp 1922 ); 1923 } 1924 var tempCookie = cpnb_getConsentCookieValue('cpnb_cookiesSettingsTemp'); 1925 var funCookieSettings = tempCookie || {}; 1926 1927 if ( 1928 document.getElementById('modalCheckBox_id_' + id).checked === true 1929 ) { 1930 funCookieSettings[categoriesSettingsCookieOuter[id]] = 1; 1931 } else { 1932 funCookieSettings[categoriesSettingsCookieOuter[id]] = 0; 1933 } 1934 1935 afterCategoriesSettingsCookie = funCookieSettings; 1936 1937 document.getElementById('cpnb-save-btn-m').style.background = 1938 modalManagerSettings.w357_m_saveChangesButtonColorAfterChange; 1939 1940 cpnb_setConsentCookie( 1941 'cpnb_cookiesSettingsTemp', 1942 funCookieSettings, 1943 exp 1944 ); 1945 } 1946} 1947 1948function cpnb_m_changeModalCategory(id) { 1949 // Move the "selected" state to the chosen category. Every currently selected item is reset 1950 // (not just the first), so an unexpected state can never leave the target unselected. 1951 var swap = function (selected, unSelected, targetId) { 1952 var current = document.querySelectorAll('.' + selected); 1953 for (var i = 0; i < current.length; i++) { 1954 current[i].classList.add(unSelected); 1955 current[i].classList.remove(selected); 1956 } 1957 var target = document.getElementById(targetId + id); 1958 if (target) { 1959 target.classList.remove(unSelected); 1960 target.classList.add(selected); 1961 } 1962 }; 1963 //CHANGE LEFT MENU ITEM 1964 swap( 1965 'cpnb-manager-modal-left-item-selected', 1966 'cpnb-manager-modal-left-item-unSelected', 1967 'mlm_menu_category_id_' 1968 ); 1969 //CHANGE RIGHT INFORMATION BOX 1970 swap( 1971 'cpnb-manager-modal-right-selected', 1972 'cpnb-manager-modal-right-unSelected', 1973 'mmr_box_category_id_' 1974 ); 1975 1976 //Responsive Hide SelectCategoryMenu on ChangeCategory 1977 cpnb_toggle_responsive_menu_hide_menu(); 1978} 1979 1980function cpnb_m_openModal() { 1981 var e = document.getElementById('cpnb_manager_wrap'); 1982 if (e) { 1983 e.classList.remove('cpnb-modal-show-fade-out'); 1984 e.classList.add('cpnb-modal-show-fade-in'); 1985 } 1986 1987 var ec = document.getElementById('cpnb_manager_wrap_close_bg'); 1988 if (ec) { 1989 ec.classList.remove('cpnb-modal-show-fade-out'); 1990 ec.classList.add('cpnb-modal-show-fade-in'); 1991 } 1992} 1993 1994function cpnb_m_ensureFloatButton() { 1995 var cfg = typeof cpnb_config !== 'undefined' ? cpnb_config : settings; 1996 if ( 1997 !modalManagerSettings || 1998 modalManagerSettings.w357_m_floatButtonState != 1 || 1999 modalManagerSettings.w357_m_modalState != 1 || 2000 (typeof cpnb_checkDIfIframeDisplay === 'function' && 2001 !cpnb_checkDIfIframeDisplay()) 2002 ) { 2003 return; 2004 } 2005 if (document.querySelector('.cpnb-m-cookies-floatButton')) { 2006 return; 2007 } 2008 2009 if (!cpnb_hasAnyConsentDecision(cfg)) { 2010 return; 2011 } 2012 2013 var tooltipPosition = 2014 modalManagerSettings.w357_m_floatButtonPosition === 'bottom_right' 2015 ? 'left' 2016 : 'right'; 2017 var floatingButton = 2018 '<div role="button" tabindex="0" aria-label="' + 2019 modalManagerSettings.w357_m_floatButtonText + 2020 '" data-cpnb-action="open-modal" class="cpnb-m-cookies-floatButton cpnb-m-cookies-floatButtonPosition_' + 2021 modalManagerSettings.w357_m_floatButtonPosition + 2022 '">'; 2023 floatingButton += 2024 '<div class="cpnb-m-cookies-floatButton-icon" data-balloon="' + 2025 modalManagerSettings.w357_m_floatButtonText + 2026 '" data-balloon-pos="' + 2027 tooltipPosition + 2028 '">'; 2029 2030 if (modalManagerSettings.w357_m_FloatButtonIconType == 'fontawesome_icon') { 2031 floatingButton +=
2032 '<i class="cpnb-m-cookies-floatButton-icon-fontawesome-icon ' + 2033 modalManagerSettings.w357_m_FloatButtonIconFontAwesomeName + 2034 ' ' + 2035 modalManagerSettings.w357_m_FloatButtonIconFontAwesomeSize + 2036 '" style="color: ' + 2037 modalManagerSettings.w357_m_FloatButtonIconFontAwesomeColor + 2038 ';"></i>'; 2039 } else if ( 2040 modalManagerSettings.w357_m_FloatButtonIconType == 'uikit_icon' 2041 ) { 2042 floatingButton += 2043 '<span class="cpnb-m-cookies-floatButton-icon-uikit-icon" uk-icon="icon:' + 2044 modalManagerSettings.w357_m_FloatButtonIconUikitName + 2045 '; ratio: ' + 2046 modalManagerSettings.w357_m_FloatButtonIconUikitSize + 2047 '" style="color: ' + 2048 modalManagerSettings.w357_m_FloatButtonIconUikitColor + 2049 ';"></span>'; 2050 } else { 2051 floatingButton += 2052 '<img alt="Cookies manager" class="cpnb-m-cookies-floatButton-icon-img" src="' + 2053 modalManagerSettings.w357_m_floatButtonIconSrc + 2054 '"/>'; 2055 } 2056 2057 floatingButton += '</div>'; 2058 floatingButton += '</div>'; 2059 2060 var elem = document.createElement('div'); 2061 elem.innerHTML = floatingButton; 2062 document.body.insertBefore(elem, document.body.firstChild); 2063} 2064 2065function cpnb_m_closeModal() { 2066 var e = document.getElementById('cpnb_manager_wrap'); 2067 if (e) { 2068 e.classList.remove('cpnb-modal-show-fade-in'); 2069 e.classList.add('cpnb-modal-show-fade-out'); 2070 } 2071 2072 var ec = document.getElementById('cpnb_manager_wrap_close_bg'); 2073 if (ec) { 2074 ec.classList.remove('cpnb-modal-show-fade-in'); 2075 ec.classList.add('cpnb-modal-show-fade-out'); 2076 } 2077} 2078 2079// Enable Enter/Space activation for focusable non-button controls (e.g. modal tabs). 2080function cpnb_bindKeyboardAccessibility() { 2081 if (window.cpnb_keyboard_bound) { 2082 return; 2083 } 2084 window.cpnb_keyboard_bound = true; 2085 document.addEventListener('keydown', function (event) { 2086 var key = event.key || event.keyCode; 2087 var isEnter = key === 'Enter' || key === 13; 2088 var isSpace = key === ' ' || key === 'Spacebar' || key === 32; 2089 if (!isEnter && !isSpace) { 2090 return; 2091 } 2092 var target = event.target; 2093 if (!target || !target.getAttribute) { 2094 return; 2095 } 2096 if (target.getAttribute('role') === 'button' || target.tagName === 'BUTTON') { 2097 event.preventDefault(); 2098 target.click(); 2099 } 2100 }); 2101} 2102 2103function cpnb_closeNotificationBar() { 2104 var bar = document.getElementById('w357_cpnb_outer'); 2105 if (bar) { 2106 bar.classList.add('cpnb-warningBox-show-fade-out'); 2107 setTimeout(function () { 2108 if (bar.parentNode) { 2109 bar.parentNode.removeChild(bar); 2110 } 2111 }, 500); 2112 } 2113 var overlay = document.getElementById('cpnb_warningBoxBgOverlay'); 2114 if (overlay) { 2115 overlay.style.display = 'none'; 2116 } 2117} 2118/////******* END MANAGER *******///// 2119 2120// OK - Accept Button 2121function acceptFunction( 2122 w357_joomla_caching, 2123 confirmationAlert, 2124 confirmMsg, 2125 AcceptCookieName, 2126 link, 2127 expiration, 2128 base_url, 2129 type, 2130 reloadPageAfterAccept, 2131 overlayState 2132) { 2133 cpnb_setConsentCookie( 2134 'cpnb_cookiesSettings', 2135 afterCategoriesSettingsCookie, 2136 afterExpirationCookies 2137 ); 2138 cpnb_setConsentCookie(AcceptCookieName, '1', expiration); 2139 cpnb_eraseCookie(cpnb_getCancelledCookieName()); 2140 cpnb_eraseCookie(cpnb_getDeclinedCookieName()); 2141 cpnb_eraseCookie('cpnb_cookiesSettingsTemp'); 2142 2143 var shouldReload = reloadPageAfterAccept == 1; 2144 if (!shouldReload) { 2145 // Render any scripts that should run after consent is given (accept) 2146 cpnb_handleBlockCookieScripts(); 2147 } 2148 2149 // Modal Manager 2150 var funCookieSettings = cpnb_getConsentCookieValue('cpnb_cookiesSettings'); 2151 for (var item in funCookieSettings) { 2152 funCookieSettings[item] = 1; 2153 } 2154 cpnb_setConsentCookie( 2155 'cpnb_cookiesSettings', 2156 funCookieSettings, 2157 afterExpirationCookies 2158 ); 2159 2160 var postData = { 2161 cpnb_method: 'cpnbCookiesAccepted', 2162 dt: w357_joomla_caching > 0 ? new Date().getTime() : undefined, 2163 }; 2164 2165 if (type == 'notification_bar') { 2166 // hide notification bar 2167 if (shouldReload) { 2168 sendPostRequest(link, postData); 2169 cpnb_handleBlockCookieScripts(); 2170 try { 2171 if (cpnb_config.w357_shortcode_is_enabled_on_this_page == 1) { 2172 localStorage.setItem('cpnb_shortcode_cookie_reload', '1'); 2173 } 2174 } catch (e) {} 2175 cpnb_reloadAfterPost(850); 2176 return; 2177 } else { 2178 // Store decision to DB, same request as the reload branch above 2179 sendPostRequest(link, postData); 2180 2181 // hide the notification bar 2182 document 2183 .getElementById('w357_cpnb_outer') 2184 .classList.add('cpnb-warningBox-show-fade-out'); 2185 if (overlayState == 1) { 2186 document.getElementById( 2187 'cpnb_warningBoxBgOverlay' 2188 ).style.display = 'none'; 2189 } 2190 } 2191 } // shortcode_table or modal 2192 else { 2193 if (shouldReload) { 2194 sendPostRequest(link, postData); 2195 cpnb_handleBlockCookieScripts(); 2196 try { 2197 if (cpnb_config.w357_shortcode_is_enabled_on_this_page == 1) { 2198 localStorage.setItem('cpnb_shortcode_cookie_reload', '1'); 2199 } 2200 } catch (e) {} 2201 cpnb_reloadAfterPost(850); 2202 return; 2203 } else { 2204 sendPostRequest(link, postData);
2205 cpnb_fetchCookiesInfoTable(); 2206 return; 2207 } 2208 } 2209} 2210 2211function checkCookieCategoriesAfterAccept(expiration) { 2212 // after accept check all checkboxes asynchronously. 2213 cpnb_checkboxes = document.getElementsByClassName('cpnb-checkbox'); 2214 for (var i = 0, n = cpnb_checkboxes.length; i < n; i++) { 2215 cpnb_checkboxes[i].checked = true; 2216 } 2217 2218 for (var categoryID in cpnb_cookiesCategories) { 2219 if (cpnb_cookiesCategories[categoryID].cookie_category_status == 1) { 2220 var innerCookieCategory = 2221 cpnb_cookiesCategories[categoryID].cookie_category_id; 2222 categoriesSettingsCookie[innerCookieCategory] = 1; 2223 } 2224 } 2225 2226 // Get the total of enabled categories and if is more than one then create the cpnb_cookiesSettings cookie, or if is only the required-cookies category do not create the cpnb_cookiesSettings cookie to pass the Cookiebot validation service 2227 var categoriesSettingsCookie_arr_values = Object.keys( 2228 categoriesSettingsCookie 2229 ).map(function (itm) { 2230 return categoriesSettingsCookie[itm]; 2231 }); // IE compatibility 2232 2233 var categoriesSettingsCookie_count_of_enabled = 2234 categoriesSettingsCookie_arr_values.reduce(function (a, b) { 2235 return a + b; 2236 }, 0); 2237 2238 if (categoriesSettingsCookie_count_of_enabled > 1) { 2239 cpnb_setConsentCookie( 2240 'cpnb_cookiesSettings', 2241 categoriesSettingsCookie, 2242 expiration 2243 ); 2244 } 2245 2246 afterCategoriesSettingsCookie = categoriesSettingsCookie; 2247 afterExpirationCookies = expiration; 2248} 2249 2250function checkCookieCategoriesAfterDecline(expiration) { 2251 // after decline uncheck all checkboxes and keep the locked ones checked 2252 var cpnb_checkboxes = document.getElementsByClassName('cpnb-checkbox'); 2253 for (var i = 0, n = cpnb_checkboxes.length; i < n; i++) { 2254 cpnb_checkboxes[i].checked = false; 2255 } 2256 2257 for (var categoryID in cpnb_cookiesCategories) { 2258 if (cpnb_cookiesCategories[categoryID].cookie_category_status == 1) { 2259 var innerCookieCategory = 2260 cpnb_cookiesCategories[categoryID].cookie_category_id; 2261 if ( 2262 cpnb_cookiesCategories[categoryID] 2263 .cookie_category_checked_by_default == 2 2264 ) { 2265 categoriesSettingsCookie[innerCookieCategory] = 1; 2266 var lockedCheckbox = document.getElementById( 2267 'modalCheckBox_id_' + categoryID 2268 ); 2269 if (lockedCheckbox) { 2270 lockedCheckbox.checked = true; 2271 } 2272 } else { 2273 categoriesSettingsCookie[innerCookieCategory] = 0; 2274 } 2275 } 2276 } 2277 2278 cpnb_setConsentCookie( 2279 'cpnb_cookiesSettings', 2280 categoriesSettingsCookie, 2281 expiration 2282 ); 2283 2284 afterCategoriesSettingsCookie = categoriesSettingsCookie; 2285 afterExpirationCookies = expiration; 2286} 2287 2288function cpnb_warning_accept_button( 2289 w357_joomla_caching, 2290 confirmationAlert, 2291 confirmMsg, 2292 AcceptCookieName, 2293 link, 2294 expiration, 2295 base_url, 2296 type, 2297 reloadPageAfterAccept, 2298 overlayState 2299) { 2300 if (confirmationAlert != 1 || confirm(confirmMsg)) { 2301 checkCookieCategoriesAfterAccept(expiration); 2302 acceptFunction( 2303 w357_joomla_caching, 2304 confirmationAlert, 2305 confirmMsg, 2306 AcceptCookieName, 2307 link, 2308 expiration, 2309 base_url, 2310 type, 2311 reloadPageAfterAccept, 2312 overlayState 2313 ); 2314 } 2315 if (type == 'modal') { 2316 cpnb_m_closeModal(); 2317 cpnb_closeModalMoreInfo(); 2318 } 2319 cpnb_m_ensureFloatButton(); 2320 cpnb_closeNotificationBar(); 2321} 2322 2323// Decline Button 2324function cpnb_warning_decline_button( 2325 w357_joomla_caching, 2326 confirmationAlert, 2327 confirmMsg, 2328 cookieName, 2329 link, 2330 expiration, 2331 isModalWindow = false 2332) { 2333 var postData = { 2334 cpnb_method: 'cpnbCookiesDeclined', 2335 cpnb_btn_area: isModalWindow ? 'cookiesManager' : 'notificationBar', 2336 dt: w357_joomla_caching > 0 ? new Date().getTime() : undefined, 2337 }; 2338 2339 var declineAction = function () { 2340 checkCookieCategoriesAfterDecline(expiration); 2341 cpnb_setConsentCookie( 2342 cpnb_getDeclinedCookieName(), 2343 '1', 2344 expiration 2345 ); 2346 cpnb_eraseCookie(cookieName); 2347 cpnb_eraseCookie(cpnb_getCancelledCookieName()); 2348 cpnb_eraseCookie('cpnb_cookiesSettingsTemp'); 2349 2350 // Modal Manager 2351 var funCookieSettings = cpnb_getConsentCookieValue( 2352 'cpnb_cookiesSettings' 2353 ); 2354 for (var item in funCookieSettings) { 2355 var catId = categoriesSettingsCookieInner[item];
2356 var isLocked = 2357 catId && 2358 cpnb_cookiesCategories[catId] && 2359 cpnb_cookiesCategories[catId] 2360 .cookie_category_checked_by_default == 2; 2361 funCookieSettings[item] = isLocked ? 1 : 0; 2362 } 2363 cpnb_setConsentCookie( 2364 'cpnb_cookiesSettings', 2365 funCookieSettings, 2366 expiration 2367 ); 2368 2369 // decline 2370 cpnb_handleBlockCookieScripts(); 2371 sendPostRequest(link, postData); 2372 }; 2373 2374 if (confirmationAlert == 1) { 2375 if (confirm(confirmMsg)) { 2376 declineAction(); 2377 } 2378 } else { 2379 declineAction(); 2380 } 2381 if (isModalWindow) { 2382 cpnb_m_closeModal(); 2383 cpnb_closeModalMoreInfo(); 2384 } 2385 cpnb_m_ensureFloatButton(); 2386 cpnb_closeNotificationBar(); 2387} 2388 2389// Delete Button 2390function cpnb_warning_delete_button( 2391 w357_joomla_caching, 2392 confirmationAlert, 2393 confirmMsg, 2394 cookieName, 2395 link 2396) { 2397 var postData = { 2398 cpnb_method: 'cpnbCookiesDeleted', 2399 dt: w357_joomla_caching > 0 ? new Date().getTime() : undefined, 2400 }; 2401 2402 if (confirmationAlert == 1) { 2403 if (confirm(confirmMsg)) { 2404 cpnb_eraseCookie('cpnb_cookiesSettings'); 2405 cpnb_eraseCookie(cpnb_getDeclinedCookieName()); 2406 cpnb_eraseCookie(cookieName); 2407 cpnb_eraseCookie(cpnb_getCancelledCookieName()); 2408 sendPostRequest(link, postData); 2409 return; 2410 } 2411 } else { 2412 cpnb_eraseCookie('cpnb_cookiesSettings'); 2413 cpnb_eraseCookie(cpnb_getDeclinedCookieName()); 2414 cpnb_eraseCookie(cookieName); 2415 cpnb_eraseCookie(cpnb_getCancelledCookieName()); 2416 sendPostRequest(link, postData); 2417 return; 2418 } 2419} 2420 2421// Cancel Button 2422function cpnb_warning_cancel_button( 2423 cookieName, 2424 expiration, 2425 link, 2426 overlayState, 2427 isModalWindow = false 2428) { 2429 cpnb_setConsentCookie(cpnb_getCancelledCookieName(), '1', expiration); 2430 cpnb_eraseCookie(cookieName); 2431 cpnb_eraseCookie(cpnb_getDeclinedCookieName()); 2432 if (cpnb_isHttpOnlyMode()) { 2433 // The browser cannot write this cookie, so the server stores it. 2434 sendPostRequest(link, { cpnb_method: 'cpnbCookiesCancelled' }); 2435 } 2436 2437 // hide the notification bar 2438 var bar = document.getElementById('w357_cpnb_outer'); 2439 if (bar) { 2440 bar.classList.add('cpnb-warningBox-show-fade-out'); 2441 } 2442 if (overlayState == 1) { 2443 var overlay = document.getElementById('cpnb_warningBoxBgOverlay'); 2444 if (overlay) { 2445 overlay.style.display = 'none'; 2446 } 2447 } 2448 2449 setTimeout(function () { 2450 var bar = document.getElementById('w357_cpnb_outer'); 2451 if (bar) { 2452 bar.remove(); 2453 } 2454 }, 500); 2455 2456 cpnb_closeModalMoreInfo(); 2457} 2458 2459// Open POP UP 2460function w357_openPopUpWindowMoreInfo(url, title, w, h) { 2461 wLeft = window.screenLeft ? window.screenLeft : window.screenX; 2462 wTop = window.screenTop ? window.screenTop : window.screenY; 2463 2464 var left = wLeft + window.innerWidth / 2 - w / 2; 2465 var top = wTop + window.innerHeight / 2 - h / 2; 2466 window.open( 2467 url, 2468 title, 2469 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=' + 2470 w + 2471 ', height=' + 2472 h + 2473 ', top=' + 2474 top + 2475 ', left=' + 2476 left 2477 ); 2478} 2479 2480function cpnb_openModalMoreInfo() { 2481 var e = document.getElementById('cpnb_modal_wrap'); 2482 if (e) { 2483 e.classList.remove('cpnb-modal-show-fade-out'); 2484 e.classList.add('cpnb-modal-show-fade-in'); 2485 } 2486 2487 var ec = document.getElementById('modal_close_bg'); 2488 if (ec) { 2489 ec.classList.remove('cpnb-modal-show-fade-out'); 2490 ec.classList.add('cpnb-modal-show-fade-in'); 2491 } 2492} 2493 2494function cpnb_closeModalMoreInfo() { 2495 var e = document.getElementById('cpnb_modal_wrap'); 2496 if (e) { 2497 e.classList.remove('cpnb-modal-show-fade-in'); 2498 e.classList.add('cpnb-modal-show-fade-out'); 2499 } 2500 2501 var ec = document.getElementById('modal_close_bg'); 2502 if (ec) { 2503 ec.classList.remove('cpnb-modal-show-fade-in'); 2504 ec.classList.add('cpnb-modal-show-fade-out'); 2505 } 2506} 2507 2508function cpnb_createCookie(name, value, days) { 2509 var expires; 2510 var expValue = days; 2511 if (typeof expValue === 'string') { 2512 expValue = expValue.trim(); 2513 } 2514 if ( 2515 expValue && 2516 String(expValue).toUpperCase() !== 'SESSION' && 2517 !isNaN(expValue) 2518 ) { 2519 var date = new Date(); 2520 date.setTime(date.getTime() + expValue * 24 * 60 * 60 * 1000); 2521 expires = ';SameSite=Lax; expires=' + date.toGMTString(); 2522 } else { 2523 expires = ''; 2524 } 2525 // Get cookie domain from config (for sharing cookies across subdomains) 2526 var domainStr = ''; 2527 if (typeof cpnb_config !== 'undefined' && cpnb_config.w357_co
2527okie_domain) { 2528 domainStr = '; domain=' + cpnb_config.w357_cookie_domain; 2529 } 2530 document.cookie = 2531 encodeURIComponent(name) + 2532 '=' + 2533 encodeURIComponent(value) + 2534 expires + 2535 '; path=/' + 2536 domainStr; 2537} 2538 2539function cpnb_buildConsentPayload(value, exp) { 2540 return JSON.stringify({ v: value, exp: exp }); 2541} 2542 2543// In-page consent state. Every consent write lands here first; in default mode it is mirrored 2544// to document.cookie, in HttpOnly mode the server persists it (see sendPostRequest). A null 2545// entry means "erased". Reads prefer this store, so a write the browser rejected (e.g. over a 2546// cookie that is still HttpOnly from an earlier setting) is still seen by the rest of the page. 2547var cpnb_stateStore = {}; 2548var cpnb_stateLoaded = false; 2549 2550function cpnb_isHttpOnlyMode() { 2551 return typeof cpnb_config !== 'undefined' && cpnb_config.w357_cookie_httponly == 1; 2552} 2553 2554// Per-visitor state baked into the page HTML is wrong behind a page cache or CDN, so HttpOnly 2555// mode never uses it; it asks the uncached endpoint instead. 2556function cpnb_configSettingsValue() { 2557 if (cpnb_isHttpOnlyMode() || typeof cpnb_config === 'undefined') { 2558 return null; 2559 } 2560 return cpnb_config.w357_cookie_settings_value; 2561} 2562 2563// HttpOnly mode: load the visitor's consent cookies from the uncached endpoint, then call done. 2564// Any failure or a 3s timeout falls back to "no decision yet" (bar shown, scripts blocked). 2565function cpnb_loadConsentState(done) { 2566 var finished = false; 2567 var finish = function () { 2568 if (finished) { 2569 return; 2570 } 2571 finished = true; 2572 clearTimeout(timer); 2573 cpnb_stateLoaded = true; 2574 done(); 2575 }; 2576 var timer = setTimeout(finish, 3000); 2577 var baseUrl = cpnb_config.w357_base_ajax_url || ''; 2578 var url = 2579 baseUrl + 2580 'index.php?option=com_ajax&plugin=cookiespolicynotificationbar&format=raw&method=getConsentState&_=' + 2581 Date.now(); 2582 2583 fetch(url, { credentials: 'same-origin', cache: 'no-store' }) 2584 .then(function (response) { 2585 return response.ok ? response.json() : null; 2586 }) 2587 .then(function (data) { 2588 if (!finished && data && data.cookies) { 2589 for (var name in data.cookies) { 2590 cpnb_stateStore[name] = data.cookies[name]; 2591 } 2592 } 2593 }) 2594 .catch(function () {}) 2595 .then(finish); 2596} 2597 2598function cpnb_setConsentCookie(name, value, exp) { 2599 cpnb_stateStore[name] = JSON.parse(cpnb_buildConsentPayload(value, exp)); 2600 if (!cpnb_isHttpOnlyMode()) { 2601 cpnb_createCookie(name, cpnb_buildConsentPayload(value, exp), exp); 2602 } 2603} 2604 2605function cpnb_getDeclinedCookieName() { 2606 if ( 2607 typeof cpnb_config !== 'undefined' && 2608 cpnb_config.w357_cookie_name_declined 2609 ) { 2610 return cpnb_config.w357_cookie_name_declined; 2611 } 2612 return 'cpnbCookiesDeclined'; 2613} 2614 2615function cpnb_getCancelledCookieName() { 2616 if ( 2617 typeof cpnb_config !== 'undefined' && 2618 cpnb_config.w357_cookie_name_cancelled 2619 ) { 2620 return cpnb_config.w357_cookie_name_cancelled; 2621 } 2622 return 'cpnbCookiesCancelled'; 2623} 2624 2625function cpnb_getConsentCookiePayload(name) { 2626 if (Object.prototype.hasOwnProperty.call(cpnb_stateStore, name)) { 2627 // A copy, so callers that edit the value in place do not change the store by accident. 2628 return cpnb_stateStore[name] 2629 ? JSON.parse(JSON.stringify(cpnb_stateStore[name])) 2630 : null; 2631 } 2632 if (cpnb_isHttpOnlyMode()) { 2633 return null; 2634 } 2635 var raw = cpnb_readCookie(name); 2636 if (!raw) { 2637 return null; 2638 } 2639 try { 2640 var payload = JSON.parse(raw); 2641 if (!payload || typeof payload !== 'object') { 2642 return null; 2643 } 2644 return payload; 2645 } catch (error) { 2646 return null; 2647 } 2648} 2649 2650function cpnb_getConsentCookieValue(name) { 2651 var payload = cpnb_getConsentCookiePayload(name); 2652 return payload ? payload.v : null; 2653} 2654 2655function cpnb_hasConsentCookie(name) { 2656 return cpnb_getConsentCookiePayload(name) !== null; 2657} 2658 2659/** 2660 * Whether a consent decision (Accept/Decline/Cancel) has been made, combining two signals: 2661 * - cfg.w357_has_consent_decision, computed server-side from $_COOKIE at page load - this
2662 * is what sees a decision made in an earlier session once its cookie is HttpOnly, which 2663 * document.cookie cannot. 2664 * - document.cookie, checked directly as a fallback for the instant after a click in *this* 2665 * page load - the client's own optimistic cookie write is still plain (not yet upgraded to 2666 * HttpOnly by the async server response) at that exact moment, so cfg.w357_has_consent_decision 2667 * (fixed at page load, before the click) would otherwise read as stale/false here. 2668 */ 2669function cpnb_hasAnyConsentDecision(cfg) { 2670 return ( 2671 (!cpnb_isHttpOnlyMode() && !!cfg.w357_has_consent_decision) || 2672 cpnb_hasConsentCookie(cfg.w357_cookie_name) || 2673 cpnb_hasConsentCookie(cfg.w357_cookie_name_declined) || 2674 cpnb_hasConsentCookie(cfg.w357_cookie_name_cancelled) 2675 ); 2676} 2677 2678function cpnb_syncConsentCookieExpiration(name, exp) { 2679 if (cpnb_isHttpOnlyMode()) { 2680 return; // the server owns these cookies and their expiry 2681 } 2682 var payload = cpnb_getConsentCookiePayload(name); 2683 if (!payload) { 2684 return; 2685 } 2686 var current = String(payload.exp).toUpperCase(); 2687 var expected = String(exp).toUpperCase(); 2688 if (current !== expected) { 2689 cpnb_setConsentCookie(name, payload.v, exp); 2690 } 2691} 2692 2693function cpnb_readCookie(name) { 2694 var nameEQ = encodeURIComponent(name) + '='; 2695 var ca = document.cookie.split(';'); 2696 for (var i = 0; i < ca.length; i++) { 2697 var c = ca[i]; 2698 while (c.charAt(0) === ' ') c = c.substring(1, c.length); 2699 if (c.indexOf(nameEQ) === 0) 2700 return decodeURIComponent(c.substring(nameEQ.length, c.length)); 2701 } 2702 return null; 2703} 2704 2705function cpnb_eraseCookie(name) { 2706 cpnb_stateStore[name] = null; 2707 cpnb_createCookie(name, '', -1); 2708} 2709 2710function cpnb_decodeBlockCookiePayload(encodedPayload) { 2711 if (!encodedPayload) { 2712 return ''; 2713 } 2714 2715 try { 2716 return atob(encodedPayload); 2717 } catch (error) { 2718 console.error('CPNB: Failed to decode blocked script payload', error); 2719 return ''; 2720 } 2721} 2722 2723// Builds the data-cpnb-* attributes read by cpnb_handleActionButtonClick. 2724// Used instead of inline onClick handlers, which a strict CSP (script-src-attr) blocks. 2725function cpnb_actionAttrs(action, data) { 2726 var attrs = ' data-cpnb-action="' + action + '"'; 2727 for (var key in data) { 2728 attrs += 2729 ' data-cpnb-' + key + '="' + encodeURIComponent(data[key]) + '"'; 2730 } 2731 return attrs + ' '; 2732} 2733 2734function cpnb_getDataAttribute(element, attributeName) { 2735 if (!element) { 2736 return ''; 2737 } 2738 var value = element.getAttribute(attributeName); 2739 return value === null ? '' : value; 2740} 2741 2742function cpnb_decodeDataAttribute(value) { 2743 if (!value) { 2744 return ''; 2745 } 2746 try { 2747 return decodeURIComponent(value); 2748 } catch (error) { 2749 return value; 2750 } 2751} 2752 2753function cpnb_handleActionButtonClick(event) { 2754 var target = event.target; 2755 if (!target || !target.closest) { 2756 return; 2757 } 2758 var actionButton = target.closest('[data-cpnb-action]'); 2759 if (!actionButton) { 2760 return; 2761 } 2762 2763 var action = cpnb_getDataAttribute(actionButton, 'data-cpnb-action'); 2764 if (!action) { 2765 return; 2766 } 2767 2768 switch (action) { 2769 case 'accept': 2770 cpnb_warning_accept_button( 2771 cpnb_getDataAttribute( 2772 actionButton, 2773 'data-cpnb-joomla-caching' 2774 ), 2775 cpnb_getDataAttribute( 2776 actionButton, 2777 'data-cpnb-enable-confirmation' 2778 ), 2779 cpnb_decodeDataAttribute( 2780 cpnb_getDataAttribute(actionButton, 'data-cpnb-message') 2781 ), 2782 cpnb_decodeDataAttribute( 2783 cpnb_getDataAttribute( 2784 actionButton, 2785 'data-cpnb-cookie-name' 2786 ) 2787 ), 2788 cpnb_decodeDataAttribute( 2789 cpnb_getDataAttribute(actionButton, 'data-cpnb-link') 2790 ), 2791 cpnb_getDataAttribute( 2792 actionButton, 2793 'data-cpnb-expiration' 2794 ), 2795 cpnb_decodeDataAttribute( 2796 cpnb_getDataAttribute( 2797 actionButton, 2798 'data-cpnb-base-ajax-url' 2799 ) 2800 ), 2801 cpnb_getDataAttribute(actionButton, 'data-cpnb-context'), 2802 cpnb_getDataAttribute(actionButton, 'data-cpnb-reload'), 2803 cpnb_getDataAttribute(actionButton, 'data-cpnb-overlay') 2804 ); 2805 break; 2806 case 'decline': 2807 cpnb_warning_decline_button( 2808 cpnb_getDataAttribute( 2809 actionButton, 2810 'data-cpnb-joomla-caching' 2811 ), 2812 cpnb_getDataAttribute( 2813 actionButton, 2814 'data-cpnb-enable-confirmation' 2815 ), 2816 cpnb_decodeDataAttribute( 2817 cpnb_getDataAttribute(actionButton, 'data-cpnb-message') 2818 ), 2819 cpnb_decodeDataAttribute( 2820 cpnb_getDataAttribute( 2821 actionButton, 2822 'data-cpnb-cookie-name' 2823 ) 2824 ), 2825 cpnb_decodeDataAttribute( 2826 cpnb_getDataAttribute(actionButton, 'data-cpnb-link') 2827 ), 2828 cpnb_getDataAttribute( 2829 actionButton, 2830 'data-cpnb-expiration' 2831 ), 2832 cpnb_getDataAttribute(actionButton, 'data-cpnb-is-modal') 2833 ); 2834 break; 2835 case 'cancel': 2836 cpnb_warning_cancel_button( 2837 cpnb_decodeDataAttribute( 2838 cpnb_getDataAttribute(actionButton, 'data-cpnb-cookie-name') 2839 ), 2840 cpnb_getDataAttribute(actionButton, 'data-cpnb-expiration'), 2841 cpnb_decodeDataAttribute( 2842 cpnb_getDataAttribute(actionButton, 'data-cpnb-link') 2843 ), 2844 cpnb_getDataAttribute(actionButton, 'data-cpnb-overlay'), 2845 cpnb_getDataAttribute(actionButton, 'data-cpnb-is-modal') 2846 ); 2847 break; 2848 case 'popup-moreinfo': 2849 w357_openPopUpWindowMoreInfo( 2850 cpnb_decodeDataAttribute( 2851 cpnb_getDataAttribute(actionButton, 'data-cpnb-link') 2852 ), 2853 'titlos', 2854 cpnb_getDataAttribute(actionButton, 'data-cpnb-height'), 2855 cpnb_getDataAttribute(actionButton, 'data-cpnb-width') 2856 ); 2857 break; 2858 case 'open-moreinfo': 2859 cpnb_openModalMoreInfo(); 2860 break; 2861 case 'close-moreinfo': 2862 cpnb_closeModalMoreInfo(); 2863 break;
2864 case 'open-modal': 2865 cpnb_m_openModal(); 2866 if (cpnb_getDataAttribute(actionButton, 'data-cpnb-close-moreinfo')) { 2867 cpnb_closeModalMoreInfo(); 2868 } 2869 break; 2870 case 'close-modal': 2871 cpnb_m_closeModal(); 2872 break; 2873 case 'toggle-menu': 2874 cpnb_toggle_responsive_menu(actionButton); 2875 break; 2876 case 'change-category': 2877 cpnb_m_changeModalCategory( 2878 cpnb_decodeDataAttribute( 2879 cpnb_getDataAttribute(actionButton, 'data-cpnb-category') 2880 ) 2881 ); 2882 break; 2883 case 'save-settings': 2884 event.preventDefault(); 2885 cpnb_warning_save_settings_button( 2886 cpnb_decodeDataAttribute( 2887 cpnb_getDataAttribute(actionButton, 'data-cpnb-link') 2888 ), 2889 cpnb_getDataAttribute( 2890 actionButton, 2891 'data-cpnb-expiration' 2892 ), 2893 cpnb_decodeDataAttribute( 2894 cpnb_getDataAttribute(actionButton, 'data-cpnb-base-url') 2895 ), 2896 cpnb_decodeDataAttribute( 2897 cpnb_getDataAttribute( 2898 actionButton, 2899 'data-cpnb-cookie-name' 2900 ) 2901 ), 2902 cpnb_getDataAttribute( 2903 actionButton, 2904 'data-cpnb-accept-expiration' 2905 ), 2906 cpnb_getDataAttribute( 2907 actionButton, 2908 'data-cpnb-decline-expiration' 2909 ), 2910 cpnb_getDataAttribute( 2911 actionButton, 2912 'data-cpnb-joomla-caching' 2913 ), 2914 cpnb_getDataAttribute(actionButton, 'data-cpnb-reload') 2915 ); 2916 break; 2917 case 'delete': 2918 cpnb_warning_delete_button( 2919 cpnb_getDataAttribute( 2920 actionButton, 2921 'data-cpnb-joomla-caching' 2922 ), 2923 cpnb_getDataAttribute( 2924 actionButton, 2925 'data-cpnb-enable-confirmation' 2926 ), 2927 cpnb_decodeDataAttribute( 2928 cpnb_getDataAttribute(actionButton, 'data-cpnb-message') 2929 ), 2930 cpnb_decodeDataAttribute( 2931 cpnb_getDataAttribute( 2932 actionButton, 2933 'data-cpnb-cookie-name' 2934 ) 2935 ), 2936 cpnb_decodeDataAttribute( 2937 cpnb_getDataAttribute(actionButton, 'data-cpnb-link') 2938 ) 2939 ); 2940 if (cpnb_getDataAttribute(actionButton, 'data-cpnb-reload') == 1) { 2941 cpnb_reloadAfterPost(850); 2942 } 2943 break; 2944 default: 2945 break; 2946 } 2947} 2948 2949function cpnb_isBlockCookieCategoryEnabled(categoryId, loadState) { 2950 if (!categoryId) { 2951 return true; 2952 } 2953 2954 // Find category config by key or by inner category_id 2955 var categoryConfig = null; 2956 if (typeof cpnb_cookiesCategories !== 'undefined') { 2957 if (cpnb_cookiesCategories[categoryId]) { 2958 categoryConfig = cpnb_cookiesCategories[categoryId]; 2959 } else { 2960 for (var key in cpnb_cookiesCategories) { 2961 if ( 2962 cpnb_cookiesCategories[key].cookie_category_id === 2963 categoryId 2964 ) { 2965 categoryConfig = cpnb_cookiesCategories[key]; 2966 break; 2967 } 2968 } 2969 } 2970 } 2971 2972 var decisionMade = 2973 typeof cpnb_config !== 'undefined' && 2974 cpnb_hasAnyConsentDecision(cpnb_config); 2975 2976 var cookieSettingsRaw = 2977 cpnb_renderSettingsOverride || 2978 cpnb_getConsentCookieValue('cpnb_cookiesSettingsTemp') || 2979 cpnb_getConsentCookieValue('cpnb_cookiesSettings') || 2980 cpnb_configSettingsValue(); 2981 2982 // No decision stored yet: fall back to default config per loadState 2983 if (!decisionMade || !cookieSettingsRaw) { 2984 if (!categoryConfig) { 2985 return loadState === 'before' ? true : false;
2986 } 2987 2988 if (loadState === 'before') { 2989 return categoryConfig.cookie_category_checked_by_default == 0; 2990 } 2991 2992 if (loadState === 'after') { 2993 return categoryConfig.cookie_category_checked_by_default > 0; 2994 } 2995 2996 return loadState === 'before' ? true : false; 2997 } 2998 2999 try { 3000 var parsedSettings = cookieSettingsRaw; 3001 if (Object.prototype.hasOwnProperty.call(parsedSettings, categoryId)) { 3002 if (loadState === 'before') { 3003 return parsedSettings[categoryId] === 0; 3004 } 3005 if (loadState === 'after') { 3006 return parsedSettings[categoryId] === 1; 3007 } 3008 if (loadState === 'decline') { 3009 return parsedSettings[categoryId] === 0; 3010 } 3011 return parsedSettings[categoryId] === 1; 3012 } 3013 // If the specific categoryId is not in settings, fall back to defaults 3014 if (categoryConfig) { 3015 if (loadState === 'before') { 3016 return categoryConfig.cookie_category_checked_by_default == 0; 3017 } 3018 if (loadState === 'after') { 3019 return categoryConfig.cookie_category_checked_by_default > 0; 3020 } 3021 } 3022 } catch (error) { 3023 console.error('CPNB: Failed to parse cpnb_cookiesSettings', error); 3024 } 3025 3026 return loadState === 'before' ? false : true; 3027} 3028 3029function cpnb_insertUrlPlaceholders(categoryId) { 3030 // "Block elements" placeholders are now emitted server-side: when the mapped category is not 3031 // consented, the PHP plugin removes the matched element from the delivered HTML and replaces it 3032 // with a <div data-cpnb-placeholder-for> + an inert <template data-cpnb-blocked-for> copy. So 3033 // there is nothing to insert client-side â the blocked element never reached the browser. This 3034 // function is kept for call-site compatibility with cpnb_renderBlockCookieScripts(). 3035 return; 3036} 3037 3038function cpnb_removeUrlPlaceholders(categoryId) { 3039 // Consent was granted for this category: restore each blocked element from its inert <template> 3040 // copy and drop the placeholder. Inserting the template content into the live DOM lets iframes 3041 // load; <script> tags are recreated so they execute (cloned script nodes do not run otherwise). 3042 // Category ids can contain a double quote (admin-configurable), so escape it for the attribute 3043 // selector below - otherwise querySelectorAll() throws on an invalid selector and consent for 3044 // that category never restores anything. 3045 var escapedCategoryId = String(categoryId).replace(/(["\\])/g, '\\$1'); 3046 var placeholders = document.querySelectorAll('[data-cpnb-placeholder-for="' + escapedCategoryId + '"]'); 3047 3048 for (var i = 0; i < placeholders.length; i++) { 3049 var ph = placeholders[i]; 3050 var parent = ph.parentNode; 3051 if (!parent) continue; 3052 3053 // The inert original markup lives in the <template data-cpnb-blocked-for> right after the placeholder. 3054 var tpl = ph.nextElementSibling; 3055 var hasTemplate = tpl 3056 && tpl.tagName === 'TEMPLATE' 3057 && tpl.getAttribute('data-cpnb-blocked-for') === categoryId; 3058 3059 if (!hasTemplate) { 3060 // Nothing to restore (e.g. a legacy placeholder) â just remove it. 3061 parent.removeChild(ph); 3062 continue; 3063 } 3064 3065 try { 3066 var content = (tpl.content && tpl.content.cloneNode) 3067 ? tpl.content.cloneNode(true) 3068 : null; 3069 3070 if (content === null) { 3071 // <template> not supported: fall back to a reload so the server can render the element. 3072 window.location.reload(); 3073 return; 3074 } 3075 3076 // Recreate <script> elements so the browser executes them. 3077 var scripts = content.querySelectorAll ? content.querySelectorAll('script') : []; 3078 for (var s = 0; s < scripts.length; s++) { 3079 var oldScript = scripts[s]; 3080 var newScript = document.createElement('script'); 3081 for (var a = 0; a < oldScript.attributes.length; a++) { 3082 newScript.setAttribute(oldScript.attributes[a].name, oldScript.attributes[a].value); 3083 } 3084 newScript.text = oldScript.textContent; 3085 if (oldScript.parentNode) { 3086 oldScript.parentNode.replaceChild(newScript, oldScript); 3087 } 3088 } 3089 3090 parent.insertBefore(content, ph); 3091 parent.removeChild(ph); 3092 parent.removeChild(tpl); 3093 } catch (e) { 3094 // Restoration failed for this element â reload so the server renders it (now consented). 3095 window.location.reload(); 3096 return; 3097 } 3098 } 3099} 3100 3101function cpnb_renderBlockCookieScripts(loadState) { 3102 // Retrieve cookie settings and check if a decision was made 3103 var settingsObj = 3104 cpnb_getConsentCookieValue('cpnb_cookiesSettings') || 3105 cpnb_configSettingsValue(); 3106 3107 for (var catId in cpnb_cookiesCategories) { 3108 var category = cpnb_cookiesCategories[catId]; 3109 3110 // Skip if the category is disabled 3111 if (category.cookie_category_status != 1) continue; 3112 3113 var categoryId = category.cookie_category_id; 3114 var checkedByDefault = category.cookie_category_checked_by_default; 3115 3116 var shouldRender = false;
3117 3118 if (!settingsObj) { 3119 // Logic for when no decision has been made yet 3120 if (loadState === 'before') { 3121 // "Load Before Consent" only for "No (allow change by User)" (0) 3122 shouldRender = checkedByDefault == 0; 3123 } else if (loadState === 'after') { 3124 // "Load After Consent" for "Yes (allow change)" (1) and "Yes (locked)" (2) 3125 shouldRender = checkedByDefault == 1 || checkedByDefault == 2; 3126 } 3127 } else { 3128 // Logic for after a decision (Accept/Decline) has been made 3129 var isAccepted = 3130 (settingsObj && settingsObj[categoryId] == 1) || 3131 checkedByDefault == 2; 3132 3133 if (loadState === 'after') { 3134 // "Load After Consent" if the category is accepted or locked 3135 shouldRender = isAccepted; 3136 } else if (loadState === 'decline') { 3137 // "Load After Decline" if the category is declined and not locked 3138 shouldRender = !isAccepted && checkedByDefault != 2; 3139 } 3140 } 3141 3142 // Select all script placeholders for the current state and category 3143 var placeholders = document.querySelectorAll( 3144 'template[data-cpnb-js][data-cpnb-load="' + 3145 loadState + 3146 '"][data-cpnb-category="' + 3147 categoryId + 3148 '"]' 3149 ); 3150 3151 for (var i = 0; i < placeholders.length; i++) { 3152 var placeholder = placeholders[i]; 3153 // Remove previously injected nodes for this placeholder 3154 if (placeholder._cpnbInjectedNodes) { 3155 for ( 3156 var r = 0; 3157 r < placeholder._cpnbInjectedNodes.length; 3158 r++ 3159 ) { 3160 var oldNode = placeholder._cpnbInjectedNodes[r]; 3161 if (oldNode && oldNode.parentNode) { 3162 oldNode.parentNode.removeChild(oldNode); 3163 } 3164 } 3165 } 3166 placeholder._cpnbInjectedNodes = []; 3167 3168 if (!shouldRender) continue; 3169 3170 var decoded = cpnb_decodeBlockCookiePayload( 3171 placeholder.getAttribute('data-cpnb-js') 3172 ); 3173 3174 if (!decoded) continue; 3175 3176 // Parse the decoded payload 3177 var template = document.createElement('template'); 3178 template.innerHTML = decoded; 3179 var fragment = document.createDocumentFragment(); 3180 var nodes = template.content.childNodes; 3181 3182 for (var n = 0; n < nodes.length; n++) { 3183 var node = nodes[n]; 3184 if ( 3185 node.nodeName && 3186 node.nodeName.toLowerCase() === 'script' 3187 ) { 3188 var script = document.createElement('script'); 3189 if (node.attributes) { 3190 for (var a = 0; a < node.attributes.length; a++) { 3191 script.setAttribute( 3192 node.attributes[a].name, 3193 node.attributes[a].value 3194 ); 3195 } 3196 } 3197 // The decoded payload never carries a nonce of its own (it's admin-authored 3198 // content, not something Joomla rendered) - without this, a nonce-based CSP 3199 // script-src policy blocks it. Set the IDL property, not setAttribute(): 3200 // browsers blank the nonce HTML attribute once a script is inserted, so only 3201 // .nonce read/written on the element actually carries the real value. 3202 // Only trust placeholders the server stamped with the nonce: an injected 3203 // look-alike (e.g. a <div data-cpnb-js>) can't know it, so it can't mint one. 3204 if (cpnb_cspNonce && placeholder.nonce === cpnb_cspNonce) { 3205 script.nonce = cpnb_cspNonce; 3206 } 3207 script.text = node.text || node.textContent || ''; 3208 fragment.appendChild(script); 3209 } else { 3210 fragment.appendChild(node.cloneNode(true)); 3211 } 3212 } 3213 3214 // Inject as siblings after the <template>: nodes appended inside it would land in its 3215 // inert content and never run. 3216 var parent = placeholder.parentNode; 3217 if (!parent) continue; 3218 3219 var injectedNodes = []; 3220 var childNodes = fragment.childNodes; 3221 for (var c = 0; c < childNodes.length; c++) { 3222 injectedNodes.push(childNodes[c]); 3223 } 3224 3225 parent.insertBefore(fragment, placeholder.nextSibling); 3226 placeholder._cpnbInjectedNodes = injectedNodes; 3227 placeholder._cpnbWasEverInjected = true; 3228 } 3229 3230 // Block elements: when consent for this category is now granted ('after' + shouldRender), 3231 // restore the server-blocked elements from their inert <template> copies. When still blocked, 3232 // there is nothing to do â the element was already removed server-side. 3233 if (loadState === 'after') { 3234 if (shouldRender) { 3235 cpnb_removeUrlPlaceholders(categoryId); 3236 } else { 3237 cpnb_insertUrlPlaceholders(categoryId); 3238 } 3239 } 3240 } 3241} 3242 3243function cpnb_handleBlockCookieScripts() { 3244 // Check if cpnb_cookiesSettings has been saved yet. NOTE: this must check 3245 // cpnb_cookiesSettings specifically, not the Accept/Decline cookie - the "Save Settings" 3246 // modal flow commits cpnb_cookiesSettings and calls this function *before* it determines 3247 // and writes the Accept/Decline cookie, so checking that cookie here would be stale. 3248 var decisionMade = 3249 cpnb_hasConsentCookie('cpnb_cookiesSettings') || 3250 !!cpnb_configSettingsValue(); 3251 3252 if (!decisionMade) { 3253 // Initial run where no decision has been made yet 3254 cpnb_renderBlockCookieScripts('before'); 3255 cpnb_renderBlockCookieScripts('after'); 3256 } else { 3257 // After a decision (Accept/Decline) or on subsequent page loads 3258 cpnb_renderBlockCookieScripts('after'); 3259 cpnb_renderBlockCookieScripts('decline'); 3260 } 3261} 3262 3263// Accepts consent for exactly one category (an [accept] placeholder link), without touching any 3264// other category and without opening the cookie manager modal. Mirrors the single-category cookie
3265// write acceptFunction/cpnb_m_saveCategoryCookiesState already do, scoped down to one category. 3266function cpnb_acceptSingleCategoryConsent(categoryId) { 3267 var settings = cpnb_getConsentCookieValue('cpnb_cookiesSettings') || afterCategoriesSettingsCookie || {}; 3268 settings[categoryId] = 1; 3269 afterCategoriesSettingsCookie = settings; 3270 cpnb_setConsentCookie('cpnb_cookiesSettings', settings, afterExpirationCookies); 3271 if (cpnb_isHttpOnlyMode()) { 3272 // No cookie write is possible from here, so ask the server to store it. 3273 sendPostRequest(cpnb_config.w357_current_url, { cpnb_method: 'cpnbSettingsSync' }); 3274 } 3275} 3276 3277function cpnb_applySingleCategoryAccept(categoryId) { 3278 cpnb_acceptSingleCategoryConsent(categoryId); 3279 cpnb_removeUrlPlaceholders(categoryId); 3280 cpnb_handleBlockCookieScripts(); 3281} 3282 3283// End of init: from now on [accept] clicks are applied at once, and any click that came earlier 3284// is applied now. 3285var cpnb_initDone = false; 3286var cpnb_pendingAcceptCategories = []; 3287 3288function cpnb_finishInit() { 3289 cpnb_initDone = true; 3290 while (cpnb_pendingAcceptCategories.length) { 3291 cpnb_applySingleCategoryAccept(cpnb_pendingAcceptCategories.shift()); 3292 } 3293} 3294 3295// Delegated click handler for [accept]-rendered links (.cpnb-accept-link), shared by the <cpnb> tag 3296// and Block Elements placeholders. Bound once at plugin init. 3297function cpnb_bindAcceptLinks() { 3298 if (window.cpnb_accept_links_bound) { 3299 return; 3300 } 3301 window.cpnb_accept_links_bound = true; 3302 3303 document.addEventListener( 3304 'click', 3305 function (event) { 3306 var target = event.target; 3307 while (target && target !== document) { 3308 if (target.classList && target.classList.contains('cpnb-accept-link')) { 3309 // Only act inside the plugin's own placeholder, for a known category, with the 3310 // matching <template data-cpnb-blocked-for> sibling buildPlaceholder() always 3311 // pairs it with - article content can otherwise carry the same class/attribute. 3312 // Before init the category data may not be read from Joomla's script options yet 3313 cpnb_init_joomla_options(); 3314 var categoryId = target.getAttribute('data-cpnb-accept-category'); 3315 var placeholderAncestor = target.closest('[data-cpnb-placeholder-for]'); 3316 var pairedTemplate = placeholderAncestor && placeholderAncestor.nextElementSibling; 3317 var isPluginRendered = placeholderAncestor 3318 && placeholderAncestor.getAttribute('data-cpnb-placeholder-for') === categoryId 3319 && pairedTemplate 3320 && pairedTemplate.tagName === 'TEMPLATE' 3321 && pairedTemplate.getAttribute('data-cpnb-blocked-for') === categoryId; 3322 // cpnb_cookiesCategories is keyed by group index, not category id - the id is 3323 // each entry's .cookie_category_id (same lookup cpnb_renderBlockCookieScripts uses). 3324 var isKnownCategory = false; 3325 if (categoryId && typeof cpnb_cookiesCategories !== 'undefined') { 3326 for (var knownCatKey in cpnb_cookiesCategories) { 3327 if (cpnb_cookiesCategories[knownCatKey] && cpnb_cookiesCategories[knownCatKey].cookie_category_id === categoryId) { 3328 isKnownCategory = true; 3329 break; 3330 } 3331 } 3332 } 3333 3334 if (isPluginRendered && isKnownCategory) { 3335 event.preventDefault(); 3336 if (!cpnb_initDone) { 3337 // Clicked before the plugin finished starting (in HttpOnly mode it 3338 // waits for the server's answer): remember it and apply it right 3339 // after init, when the visitor's current choices are known. 3340 if (cpnb_pendingAcceptCategories.indexOf(categoryId) === -1) { 3341 cpnb_pendingAcceptCategories.push(categoryId); 3342 } 3343 return; 3344 } 3345 cpnb_applySingleCategoryAccept(categoryId); 3346 } 3347 return; 3348 } 3349 target = target.parentNode; 3350 } 3351 }, 3352 false 3353 ); 3354} 3355 3356// Responsive left menu 3357function cpnb_toggle_responsive_menu(x) { 3358 x.classList.toggle('cpnb-toggle-menu-change'); 3359 3360 if ( 3361 document.getElementsByClassName('cpnb-manager-modal-left')[0].style 3362 .display == 'block' 3363 ) { 3364 document.getElementsByClassName( 3365 'cpnb-manager-modal-left' 3366 )[0].style.display = 'none'; 3367 } else { 3368 document.getElementsByClassName( 3369 'cpnb-manager-modal-left' 3370 )[0].style.display = 'block'; 3371 } 3372} 3373 3374function cpnb_toggle_responsive_menu_hide_menu() { 3375 if (window.innerWidth < 601) { 3376 document.getElementsByClassName( 3377 'cpnb-manager-modal-left' 3378 )[0].style.display = 'none'; 3379 } 3380} 3381
3382function cpnb_fetchCookiesInfoTable() { 3383 var container = document.getElementById('cpnb-cit-container'); 3384 if (!container || !container.getAttribute('data-cpnb-table-ajax')) { 3385 return; 3386 } 3387 3388 container.innerHTML = '<div class="cpnb-cit-spinner"></div>'; 3389 3390 var baseUrl = 3391 typeof cpnb_config !== 'undefined' && cpnb_config.w357_base_ajax_url 3392 ? cpnb_config.w357_base_ajax_url 3393 : ''; 3394 3395 var url = 3396 baseUrl + 3397 'index.php?option=com_ajax&plugin=cookiespolicynotificationbar&format=raw&method=getCookiesInfoTable&_=' + 3398 Date.now(); 3399 3400 fetch(url) 3401 .then(function (response) { 3402 if (!response.ok) { 3403 throw new Error('CPNB: getCookiesInfoTable responded with ' + response.status); 3404 } 3405 return response.text(); 3406 }) 3407 .then(function (html) { 3408 container.innerHTML = html; 3409 }) 3410 .catch(function (err) { 3411 console.error(err); 3412 }); 3413} 3414 3415/** 3416 * TRIGGER EVENTS 3417 */ 3418document.addEventListener('click', cpnb_handleActionButtonClick, false); 3419document.addEventListener('change', cpnb_handleLockedCheckboxChange, false); 3420document.addEventListener('change', cpnb_handleCategoryCheckboxChange, false); 3421document.addEventListener('DOMContentLoaded', cpnb_fetchCookiesInfoTable, false); 3422document.addEventListener('click', function (event) { 3423 var reloadBtn = event.target.closest('#cpnb-reload-btn-cit'); 3424 if (!reloadBtn) { 3425 return; 3426 } 3427 event.preventDefault(); 3428 cpnb_fetchCookiesInfoTable(); 3429}, false); 3430 3431function sendPostRequest(url, params) { 3432 // Params should be an object containing key-value pairs 3433 // The category choices travel with the request: the server validates and stores them, which 3434 // is the only way to store them when the cookie is HttpOnly (and fixes a stale one otherwise). 3435 var settingsPayload = cpnb_getConsentCookiePayload('cpnb_cookiesSettings'); 3436 if (settingsPayload && params.cpnb_settings === undefined) { 3437 params = Object.assign({}, params, { 3438 cpnb_settings: JSON.stringify(settingsPayload), 3439 }); 3440 } 3441 let formData = new URLSearchParams(params).toString(); 3442 3443 cpnb_lastPost = fetch(url, { 3444 method: 'POST', 3445 headers: { 3446 'Content-Type': 'application/x-www-form-urlencoded', 3447 }, 3448 body: formData, // Sending the URL-encoded string 3449 }) 3450 .then((response) => { 3451 if (!response.ok) { 3452 throw new Error('Network response was not ok'); 3453 } 3454 // Reload the page after successful POST 3455 //window.location.reload(); 3456 }) 3457 .catch((error) => { 3458 console.error('Failed to send POST request:', error); 3459 }); 3460 return cpnb_lastPost; 3461} 3462 3463// The most recent consent POST, so a page reload can wait for it. 3464var cpnb_lastPost = null; 3465 3466// Reloads the page after delayMs. In HttpOnly mode the POST is the only thing that stores the 3467// decision (the browser cannot write the cookie), so a reload that cancels a slow POST would 3468// lose the visitor's consent: wait for it to finish (at most 5s), but never reload sooner than 3469// delayMs, which is what the fade-out animation expects. 3470function cpnb_reloadAfterPost(delayMs) { 3471 var started = Date.now(); 3472 var reload = function () { 3473 setTimeout(function () { 3474 window.location.reload(); 3475 }, Math.max(0, delayMs - (Date.now() - started))); 3476 }; 3477 if (!cpnb_isHttpOnlyMode() || !cpnb_lastPost) { 3478 reload(); 3479 return; 3480 } 3481 var finished = false; 3482 var go = function () { 3483 if (!finished) { 3484 finished = true; 3485 reload(); 3486 } 3487 }; 3488 setTimeout(go, 5000); 3489 cpnb_lastPost.then(go, go); 3490}
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.