Skip to content

Commit 8836611

Browse files
authored
Merge pull request #9 from antistatique/1-0-x/prevent-js-error-language-switcher-not-found
2 parents 979b6cf + 9249165 commit 8836611

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88
- init module with Cookies & Browser redirection on Homepage only
9+
- handling of missing common JS library
910
- remove dependency on JQuery

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,13 @@ Drupal.homeRedirectLang.setPreferredLanguage('fr');
4343
```
4444

4545
```javascript
46+
// Prevent attempting to attach cookie if the common library is not available.
47+
if (typeof Drupal.homeRedirectLang == "undefined") {
48+
return;
49+
}
50+
4651
let links = document.querySelectorAll('.language-link');
52+
4753
links.forEach(link => {
4854
link.addEventListener('click', function (event) {
4955
var hreflang = event.target.getAttribute('hreflang');

js/home_redirect_lang.language_switcher.js

+7
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,14 @@
1515
*/
1616
Drupal.behaviors.homeRedirectLangSwitcher = {
1717
attach: function (context) {
18+
19+
// Prevent attempting to attach cookie if the common library is not available.
20+
if (typeof Drupal.homeRedirectLang == "undefined") {
21+
return;
22+
}
23+
1824
let links = document.querySelectorAll('.language-switcher-language-url .language-link');
25+
1926
links.forEach(link => {
2027
link.addEventListener('click', function (event) {
2128
var hreflang = event.target.getAttribute('hreflang');

0 commit comments

Comments
 (0)