-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! ✨(dashboard) update javascript language switcher and add docs
- Loading branch information
Showing
2 changed files
with
43 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,39 @@ | ||
const language_selectors = document.querySelectorAll(".fr-translate__language") | ||
/** | ||
* Common JavaScript used in dashboard project | ||
*/ | ||
|
||
language_selectors.forEach(el => el.addEventListener("click", event => { | ||
console.log(language_selectors) | ||
document.cookie = "django_language=" + el.lang + ";Path=\"/django-dsfr\";SameSite=Strict" | ||
window.location.reload() | ||
})); | ||
'use strict'; | ||
|
||
const app = window.app = { | ||
/** ### CALL FUNCTIONS ###*/ | ||
init: function () { | ||
this.languageSwitcher(); | ||
}, | ||
|
||
/** ### FUNCTIONS ###*/ | ||
|
||
/** | ||
* Language switcher | ||
* Sets django_language cookie, with the current language choice chosen by the user. | ||
*/ | ||
languageSwitcher: function () { | ||
const language_selectors = document.querySelectorAll(".fr-translate__language") | ||
|
||
language_selectors.forEach(el => el.addEventListener("click", event => { | ||
document.cookie = "django_language=" + el.lang + ";Path=\"/django-dsfr\";SameSite=Strict" | ||
window.location.reload() | ||
})); | ||
} | ||
} | ||
|
||
|
||
/** | ||
* | ||
* Wait for DOM ready and init() the app | ||
* | ||
*/ | ||
document.onreadystatechange = function () { | ||
if (document.readyState === "interactive") { | ||
app.init(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters