Skip to content

Commit

Permalink
Merge branch '1.0.x' into 1-0-x/prevent-js-error-language-switcher-no…
Browse files Browse the repository at this point in the history
…t-found
  • Loading branch information
WengerK committed Sep 6, 2022
2 parents 2e1b6cc + 979b6cf commit 9249165
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 22 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +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 language switcher not found preventing JS console error
- handling of missing common JS library
- remove dependency on JQuery
9 changes: 2 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,8 @@ if (typeof Drupal.homeRedirectLang == "undefined") {

let links = document.querySelectorAll('.language-link');

// Don't process when standard language switcher not found.
if (links.length === 0) {
return;
}

links.forEach(box => {
box.addEventListener('click', function (event) {
links.forEach(link => {
link.addEventListener('click', function (event) {
var hreflang = event.target.getAttribute('hreflang');
Drupal.homeRedirectLang.setPreferredLanguage(hreflang);
});
Expand Down
3 changes: 0 additions & 3 deletions home_redirect_lang.libraries.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
common:
js:
js/home_redirect_lang.common.js: {}
dependencies:
- core/jquery
- core/jquery.cookie

language_switcher:
js:
Expand Down
4 changes: 2 additions & 2 deletions js/home_redirect_lang.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Common helper functions used by various parts of Homepage Redirect Language.
*/

(function ($, Drupal, drupalSettings) {
(function (Drupal) {

'use strict';

Expand All @@ -22,4 +22,4 @@
document.cookie = 'home_redirect_lang_preferred_langcode=' + langcode + '; expires=' + date.toUTCString() + '; path=/';
};

}(jQuery, Drupal, drupalSettings));
}(Drupal));
13 changes: 4 additions & 9 deletions js/home_redirect_lang.language_switcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Defines the behavior of the language switcher cookie storage.
*/

(function ($, Drupal, drupalSettings) {
(function (Drupal) {

'use strict';

Expand All @@ -23,13 +23,8 @@

let links = document.querySelectorAll('.language-switcher-language-url .language-link');

// Don't process when standard language switcher not found.
if (links.length === 0) {
return;
}

links.forEach(box => {
box.addEventListener('click', function (event) {
links.forEach(link => {
link.addEventListener('click', function (event) {
var hreflang = event.target.getAttribute('hreflang');
Drupal.homeRedirectLang.setPreferredLanguage(hreflang);
});
Expand All @@ -39,4 +34,4 @@
};


}(jQuery, Drupal, drupalSettings));
}(Drupal));

0 comments on commit 9249165

Please sign in to comment.