Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix empty language select in iOS Safari on initial page load #233

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions webpage/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ function initLanguageDropdown(language) {

let languageSelect = document.getElementById("language");

// The following four lines are a bugfix for Safari on iOS.
// The state of the currently selected option would not change in the select until you click on
// it (showing an initial empty select).
// The workaround clones the complete select, removes it from the DOM and then adds it again. When changing
// the currently selected option on the clone, the UI updates accordingly even on iOS Safari.
// Interestingly the problem does not occur with Safari for macOS (or e.g. Firefox for macOS).
let cloneLanguageSelect = languageSelect.cloneNode(true);
languageSelect.remove();
document.getElementById("language-select-container").append(cloneLanguageSelect);
languageSelect = cloneLanguageSelect;

// set initial language for the dropdown
languageSelect.value = language;

Expand Down
2 changes: 1 addition & 1 deletion webpage/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
<li class="pure-menu-item"><a href="#" class="pure-menu-link" data-navigation="about" data-i18next="about.h1"></a></li>

<li class="pure-menu-heading"><label for="language" data-i18next="menu.language.label"></label></li>
<li class="pure-menu-item pure-form">
<li class="pure-menu-item pure-form" id="language-select-container">
<select id="language" class="language" size="1">
<option value="de" data-i18next="menu.language.de"></option>
<option value="en" data-i18next="menu.language.en"></option>
Expand Down