1
0
mirror of https://github.com/hrfee/jfa-go.git synced 2025-01-03 15:00:12 +00:00

use selected language for time format, add manual selector

You can now choose between 12h and 24h time in the top left language
menu. Your preference is stored by the browser for future visits.
This commit is contained in:
Harvey Tindall 2021-04-07 15:09:44 +01:00
parent bc76770ca4
commit 66b7df7cde
Signed by: hrfee
GPG Key ID: BBC65952848FB1A2
5 changed files with 67 additions and 20 deletions

View File

@ -276,7 +276,16 @@
<span class="ml-1 chev"></span> <span class="ml-1 chev"></span>
</span> </span>
<div class="dropdown-display"> <div class="dropdown-display">
<div class="card ~neutral !low" id="lang-list"> <div class="card ~neutral !low">
<label class="switch pb-1">
<input type="radio" name="lang-time" id="lang-12h">
<span>{{ .strings.time12h }}</span>
</label>
<label class="switch pb-1">
<input type="radio" name="lang-time" id="lang-24h">
<span>{{ .strings.time24h }}</span>
</label>
<div id="lang-list"></div>
</div> </div>
</div> </div>
</span> </span>

View File

@ -142,6 +142,11 @@ class user implements User {
}; };
this.update(user); this.update(user);
document.addEventListener("timefmt-change", () => {
this.expiry = this.expiry;
this.last_active = this.last_active;
});
} }
private _updateEmail = () => { private _updateEmail = () => {

View File

@ -7,11 +7,22 @@ export function createEl(html: string): HTMLElement {
} }
export function toDateString(date: Date): string { export function toDateString(date: Date): string {
const locale = (window as any).navigator.userLanguage || window.navigator.language; const locale = window.language || (window as any).navigator.userLanguage || window.navigator.language;
return date.toLocaleDateString(locale) + " " + date.toLocaleString(locale, { const t12 = document.getElementById("lang-12h") as HTMLInputElement;
const t24 = document.getElementById("lang-24h") as HTMLInputElement;
let args1 = {};
let args2 = {
hour: "2-digit", hour: "2-digit",
minute: "2-digit" minute: "2-digit"
}) };
if (t12.checked) {
args1["hour12"] = true;
args2["hour12"] = true;
} else if (t24.checked) {
args1["hour12"] = false;
args2["hour12"] = false;
}
return date.toLocaleDateString(locale, args1) + " " + date.toLocaleString(locale, args2);
} }
export function serializeForm(id: string): Object { export function serializeForm(id: string): Object {

View File

@ -363,6 +363,10 @@ export class DOMInvite implements Invite {
this.update(invite); this.update(invite);
document.addEventListener("profileLoadEvent", () => { this.loadProfiles(); }, false); document.addEventListener("profileLoadEvent", () => { this.loadProfiles(); }, false);
document.addEventListener("timefmt-change", () => {
this.created = this.created;
this.usedBy = this.usedBy;
});
} }
update = (invite: Invite) => { update = (invite: Invite) => {

View File

@ -47,7 +47,28 @@ export class lang implements Lang {
} }
} }
export const loadLangSelector = (page: string) => _get("/lang/" + page, null, (req: XMLHttpRequest) => { export const loadLangSelector = (page: string) => {
if (page == "admin") {
const ev = new CustomEvent("timefmt-change");
const setTimefmt = (fmt: string) => {
document.dispatchEvent(ev);
localStorage.setItem("timefmt", fmt);
};
const t12 = document.getElementById("lang-12h") as HTMLInputElement;
t12.onchange = () => setTimefmt("12h");
const t24 = document.getElementById("lang-24h") as HTMLInputElement;
t24.onchange = () => setTimefmt("24h");
const preference = localStorage.getItem("timefmt");
if (preference == "12h") {
t12.checked = true;
t24.checked = false;
} else if (preference == "24h") {
t24.checked = true;
t12.checked = false;
}
}
_get("/lang/" + page, null, (req: XMLHttpRequest) => {
if (req.readyState == 4) { if (req.readyState == 4) {
if (req.status != 200) { if (req.status != 200) {
document.getElementById("lang-dropdown").remove(); document.getElementById("lang-dropdown").remove();
@ -60,8 +81,5 @@ export const loadLangSelector = (page: string) => _get("/lang/" + page, null, (r
} }
list.innerHTML = innerHTML; list.innerHTML = innerHTML;
} }
}); });
};