(options: CompilerExplorerOptions)
| 400 | } |
| 401 | |
| 402 | function initPolicies(options: CompilerExplorerOptions) { |
| 403 | if (options.policies.privacy.enabled) { |
| 404 | if (jsCookie.get(options.policies.privacy.key) == null) { |
| 405 | $('#privacy').trigger('click', { |
| 406 | title: 'New Privacy Policy. Please take a moment to read it', |
| 407 | }); |
| 408 | } else if (policyDocuments.privacy.hash !== jsCookie.get(options.policies.privacy.key)) { |
| 409 | // When the user has already accepted the privacy, just show a pretty notification. |
| 410 | const ppolicyBellNotification = $('#policyBellNotification'); |
| 411 | const pprivacyBellNotification = $('#privacyBellNotification'); |
| 412 | const pcookiesBellNotification = $('#cookiesBellNotification'); |
| 413 | ppolicyBellNotification.removeClass('d-none'); |
| 414 | pprivacyBellNotification.removeClass('d-none'); |
| 415 | $('#privacy').on('click', () => { |
| 416 | // Only hide if the other policy does not also have a bell |
| 417 | if (pcookiesBellNotification.hasClass('d-none')) { |
| 418 | ppolicyBellNotification.addClass('d-none'); |
| 419 | } |
| 420 | pprivacyBellNotification.addClass('d-none'); |
| 421 | }); |
| 422 | } |
| 423 | } |
| 424 | simpleCooks.setOnDoConsent(() => { |
| 425 | jsCookie.set(options.policies.cookies.key, policyDocuments.cookies.hash, { |
| 426 | expires: 365, |
| 427 | sameSite: 'strict', |
| 428 | }); |
| 429 | }); |
| 430 | simpleCooks.setOnDontConsent(() => { |
| 431 | jsCookie.set(options.policies.cookies.key, '', { |
| 432 | sameSite: 'strict', |
| 433 | }); |
| 434 | }); |
| 435 | simpleCooks.setOnHide(() => { |
| 436 | const spolicyBellNotification = $('#policyBellNotification'); |
| 437 | const sprivacyBellNotification = $('#privacyBellNotification'); |
| 438 | const scookiesBellNotification = $('#cookiesBellNotification'); |
| 439 | // Only hide if the other policy does not also have a bell |
| 440 | if (sprivacyBellNotification.hasClass('d-none')) { |
| 441 | spolicyBellNotification.addClass('d-none'); |
| 442 | } |
| 443 | scookiesBellNotification.addClass('d-none'); |
| 444 | $(window).trigger('resize'); |
| 445 | }); |
| 446 | // '' means no consent. Hash match means consent of old. Null means new user! |
| 447 | const storedCookieConsent = jsCookie.get(options.policies.cookies.key); |
| 448 | if (options.policies.cookies.enabled) { |
| 449 | if (storedCookieConsent !== '' && policyDocuments.cookies.hash !== storedCookieConsent) { |
| 450 | simpleCooks.show(); |
| 451 | const cpolicyBellNotification = $('#policyBellNotification'); |
| 452 | const cprivacyBellNotification = $('#privacyBellNotification'); |
| 453 | const ccookiesBellNotification = $('#cookiesBellNotification'); |
| 454 | cpolicyBellNotification.removeClass('d-none'); |
| 455 | ccookiesBellNotification.removeClass('d-none'); |
| 456 | $('#cookies').on('click', () => { |
| 457 | if (cprivacyBellNotification.hasClass('d-none')) { |
| 458 | cpolicyBellNotification.addClass('d-none'); |
| 459 | } |
no test coverage detected