diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f68759..fbb393e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,4 +6,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] - init module with Cookies & Browser redirection on Homepage only +- handling of missing common JS library - remove dependency on JQuery diff --git a/README.md b/README.md index 0b80489..b19da99 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,13 @@ Drupal.homeRedirectLang.setPreferredLanguage('fr'); ``` ```javascript +// Prevent attempting to attach cookie if the common library is not available. +if (typeof Drupal.homeRedirectLang == "undefined") { + return; +} + let links = document.querySelectorAll('.language-link'); + links.forEach(link => { link.addEventListener('click', function (event) { var hreflang = event.target.getAttribute('hreflang'); diff --git a/js/home_redirect_lang.language_switcher.js b/js/home_redirect_lang.language_switcher.js index 110e96d..a1a8f62 100644 --- a/js/home_redirect_lang.language_switcher.js +++ b/js/home_redirect_lang.language_switcher.js @@ -15,7 +15,14 @@ */ Drupal.behaviors.homeRedirectLangSwitcher = { attach: function (context) { + + // Prevent attempting to attach cookie if the common library is not available. + if (typeof Drupal.homeRedirectLang == "undefined") { + return; + } + let links = document.querySelectorAll('.language-switcher-language-url .language-link'); + links.forEach(link => { link.addEventListener('click', function (event) { var hreflang = event.target.getAttribute('hreflang');