Skip to content

Commit

Permalink
Merge pull request #9 from antistatique/1-0-x/prevent-js-error-langua…
Browse files Browse the repository at this point in the history
…ge-switcher-not-found
  • Loading branch information
WengerK authored Sep 12, 2022
2 parents 979b6cf + 9249165 commit 8836611
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
7 changes: 7 additions & 0 deletions js/home_redirect_lang.language_switcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 8836611

Please sign in to comment.