MCPcopy
hub / github.com/compiler-explorer/compiler-explorer / initPolicies

Function initPolicies

static/main.ts:402–464  ·  view source on GitHub ↗
(options: CompilerExplorerOptions)

Source from the content-addressed store, hash-verified

400}
401
402function 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 }

Callers 1

startFunction · 0.85

Calls 7

setOnDoConsentMethod · 0.80
setOnDontConsentMethod · 0.80
setOnHideMethod · 0.80
getMethod · 0.65
setMethod · 0.65
onMethod · 0.45
showMethod · 0.45

Tested by

no test coverage detected