iframe_consent-1.0.x-dev/js/iframe-consent-eu-cookie-compliance.js
js/iframe-consent-eu-cookie-compliance.js
/**
* @file
* Do not let iframes be loaded until accept EU Cookie Compliance categories.
*/
(function (Drupal, once) {
Drupal.iframeConsentEuCookieCompliance = {};
/**
* Update iframeConsent with the current categories accepted on EU Cookie Compliance.
*/
Drupal.iframeConsentEuCookieCompliance.setupEuCookieCompliance = () => {
Drupal.iframeConsent.setAcceptedCategories(
Drupal.eu_cookie_compliance.getAcceptedCategories(),
);
};
Drupal.iframeConsentEuCookieCompliance.manageCookiesCallback = () => {
// There is currently no action in the EU Cookie Compliance module to reconfigure the
// categories. This is a workaround to not lose the categories currently
// selected by the user.
// Another option is to re-accept the cookies with the Withdraw action.
// Drupal.eu_cookie_compliance.withdrawAction();
Drupal.eu_cookie_compliance.setStatus(null);
window.location.reload();
};
/**
* Behavior description.
*/
Drupal.behaviors.iframeConsentEuCookieCompliance = {
attach(context) {
once('iframeConsentEuCookieCompliance', 'body', context).forEach(() => {
if (Drupal.eu_cookie_compliance) {
Drupal.iframeConsent.setManageCookiesCallback(
Drupal.iframeConsentEuCookieCompliance.manageCookiesCallback,
);
const postStatusLoadHandler = () => {
Drupal.iframeConsentEuCookieCompliance.setupEuCookieCompliance();
};
Drupal.eu_cookie_compliance('postStatusLoad', postStatusLoadHandler);
const postPreferencesSaveHandler = () => {
Drupal.iframeConsentEuCookieCompliance.setupEuCookieCompliance();
};
Drupal.eu_cookie_compliance(
'postPreferencesSave',
postPreferencesSaveHandler,
);
}
});
},
};
})(Drupal, once);
