Skip to content
Open
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
81 changes: 81 additions & 0 deletions example/src/main/resources/static/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,84 @@ body {
.eu-logo-fixed img {
height: 86px;
}

.language-dropdown {
position: relative;
display: inline-block;
}

.language-btn {
background-color: #f8f9fa;
color: #212529;
border: 1px solid #e9ecef;
padding: 8px 12px;
border-radius: 4px;
cursor: pointer;
display: flex;
align-items: center;
gap: 8px;
font-size: 14px;
font-weight: 500;
min-width: 60px;
justify-content: space-between;
transition: background-color 0.2s, border-color 0.2s;
}

.language-btn:hover {
background-color: #e9ecef;
}

.dropdown-arrow {
font-size: 10px;
transition: transform 0.2s;
}

.language-btn.active .dropdown-arrow {
transform: rotate(180deg);
}

.language-menu {
position: absolute;
top: 100%;
left: 0;
background-color: #f8f9fa;
border: 1px solid #e9ecef;
border-radius: 4px;
padding: 8px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.15);
z-index: 1000;
display: none;
min-width: 200px;
margin-top: 2px;
}

.language-menu.show {
display: block;
}

.language-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 4px;
}

.language-option {
background: none;
border: none;
color: #212529;
padding: 8px 12px;
text-align: left;
cursor: pointer;
border-radius: 2px;
font-size: 14px;
white-space: nowrap;
transition: background-color 0.2s;
}

.language-option:hover {
background-color: #e9ecef;
}

.language-option.selected {
font-weight: bold;
}
65 changes: 65 additions & 0 deletions example/src/main/resources/static/js/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright (c) 2020-2025 Estonian Information System Authority
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

"use strict";

const languageUi = {
selectedLang: document.querySelector("#selected-lang"),
languageButton: document.querySelector("#language-button"),
languageMenu: document.querySelector("#language-menu"),
languageOptions: document.querySelectorAll(".language-option")
};

export function setupLanguageSelection(currentLang, onLangChange) {
const selectedOption = Array.from(languageUi.languageOptions)
.find(option => option.dataset.lang === currentLang);

languageUi.selectedLang.textContent = selectedOption ? selectedOption.dataset.display : "EN";

languageUi.languageOptions.forEach(option =>
option.classList.toggle('selected', option.dataset.lang === currentLang)
);

languageUi.languageButton.onclick = e => {
e.stopPropagation();
languageUi.languageMenu.classList.toggle('show');
e.target.classList.toggle('active');
};

document.onclick = () => {
languageUi.languageMenu.classList.remove('show');
languageUi.languageButton.classList.remove('active');
};

languageUi.languageMenu.onclick = e => e.stopPropagation();

languageUi.languageOptions.forEach(option => {
option.onclick = () => {
onLangChange(option.dataset.lang);
languageUi.selectedLang.textContent = option.dataset.display;
languageUi.languageOptions.forEach(o => o.classList.remove('selected'));
option.classList.add('selected');
languageUi.languageMenu.classList.remove('show');
languageUi.languageButton.classList.remove('active');
};
});
}
36 changes: 32 additions & 4 deletions example/src/main/resources/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,41 @@ <h3><a id="usage"></a>Usage</h3>
Attach a smart card reader to the computer and insert the eID card into the reader.
</li>
<li>Click <i>Authenticate</i> below.</li>
<li>
Select the Web eID application language from the dropdown menu.
If you have previously configured a language preference within the Web eID application dialog, that setting will take precedence over the language selection made here.
Please note that this language setting does not affect the website interface.
</li>
</ol>

<div id="error-message" class="alert alert-danger" style="display: none;" role="alert">
<div class="message"></div>
<pre class="details"></pre>
</div>
<p class="text-center p-4">

<div class="d-flex justify-content-center align-items-center p-4">
<button id="webeid-auth-button" class="btn btn-info">Authenticate</button>
</p>
<div class="language-dropdown ml-1">
<button id="language-button" class="language-btn" type="button">
<span id="selected-lang">EN</span>
<span class="dropdown-arrow">▼</span>
</button>
<div id="language-menu" class="language-menu">
<div class="language-grid">
<button class="language-option" data-lang="et" data-display="ET">Eesti</button>
<button class="language-option" data-lang="en" data-display="EN">English</button>
<button class="language-option" data-lang="ru" data-display="RU">Русский</button>
<button class="language-option" data-lang="fi" data-display="FI">Suomi</button>
<button class="language-option" data-lang="hr" data-display="HR">Hrvatska</button>
<button class="language-option" data-lang="de" data-display="DE">Deutsch</button>
<button class="language-option" data-lang="fr" data-display="FR">Française</button>
<button class="language-option" data-lang="nl" data-display="NL">Nederlands</button>
<button class="language-option" data-lang="cs" data-display="CS">Čeština</button>
<button class="language-option" data-lang="sk" data-display="SK">Slovenština</button>
</div>
</div>
</div>
</div>

<p>The privacy policy of the test service is available <a href="/files/Web eID privacy policy.pdf">here</a>.
</p>
Expand Down Expand Up @@ -250,6 +276,7 @@ <h3><a id="for-developers"></a>For developers</h3>
"use strict";
import * as webeid from "/js/web-eid.js";
import {hideErrorMessage, showErrorMessage, checkHttpError} from "/js/errors.js";
import {setupLanguageSelection} from "/js/index.js";

hideErrorMessage();

Expand All @@ -258,7 +285,8 @@ <h3><a id="for-developers"></a>For developers</h3>
const csrfToken = document.querySelector('#csrftoken').content;
const csrfHeaderName = document.querySelector('#csrfheadername').content;

const lang = new URLSearchParams(window.location.search).get("lang") || "en";
let lang = new URLSearchParams(window.location.search).get("lang") || "en";
setupLanguageSelection(lang, changedLang => lang = changedLang);

authButton.addEventListener("click", async () => {
hideErrorMessage();
Expand Down Expand Up @@ -289,7 +317,7 @@ <h3><a id="for-developers"></a>For developers</h3>

console.log("Authentication successful! Result:", authTokenResult);

window.location.href = "/welcome";
window.location.href = "/welcome?lang=" + lang;

} catch (error) {
showErrorMessage(error);
Expand Down