A web TODO list application
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

143 lines
4.7 KiB

{{ define "base" }}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>dela</title>
<link rel="shortcut icon" href="/static/images/favicon.ico" type="image/x-icon">
<link rel="stylesheet" href="/static/bootstrap/css/bootstrap.min.css">
<script src="/static/bootstrap/js/bootstrap.min.js"></script>
<style>
html * {
font-family: "Roboto" !important;
src: url("/static/fonts/Roboto-Regular.ttf");
}
</style>
</head>
<body class="w-100 h-100">
<header class="p-3 text-bg-primary">
<div class="container">
<div class="d-flex flex-wrap align-items-center justify-content-center justify-content-lg-start">
<a href="/" class="d-flex align-items-center mb-2 mb-lg-0 text-white text-decoration-none">
<a href="/" class="d-inline-flex link-body-emphasis text-decoration-none">
<img width="64" height="64" src="/static/images/android-chrome-192x192.png" alt="Dela">
</a>
</a>
<ul class="nav col-12 col-lg-auto me-lg-auto mb-2 justify-content-center mb-md-0">
<li><a href="/" class="nav-link px-2 text-white">{{index .Translation "base link main"}}</a></li>
<li><a href="/about" class="nav-link px-2 text-white">{{index .Translation "base link about"}}</a></li>
</ul>
<div class="text-end p-3">
<button id="theme-switch-btn" class="btn btn-secondary" onclick="toggleTheme();">
<img id="theme-svg" src="/static/images/brightness-high.svg" alt="Change theme">
</button>
<button id="locale-switch-btn" onclick="switchLocale();" class="btn btn-secondary">
<img src="/static/images/globe.svg" alt="Change Locale">
<small id="locale">ENG</small>
</button>
</div>
<div class="text-end">
<a class="btn btn-secondary" href="/profile"><img src="/static/images/person-vcard.svg"></a>
</div>
<div class="text-end" id="bar-auth">
<a href="/login" class="btn btn-outline-light me-2">{{index .Translation "base link log in"}}</a>
<a href="/register" class="btn btn-warning">{{index .Translation "base link sign up"}}</a>
</div>
</div>
</div>
</div>
</header>
<!-- Content -->
{{ template "content" . }}
</body>
</html>
<script src="/scripts/auth.js"></script>
<script src="/scripts/api.js"></script>
<script>
const locales = ["ENG", "RU"];
function switchLocale() {
let currentLocale = localStorage.getItem("locale");
if (!currentLocale) {
currentLocale = locales[0];
}
// Switch to the next locale
let index = locales.indexOf(currentLocale);
let newLocale;
if (index + 1 >= locales.length) {
newLocale = locales[0];
} else {
newLocale = locales[index+1];
}
// Set locale cookie
document.cookie = "locale="+newLocale+";path=/";
localStorage.setItem("locale", newLocale);
// Refresh page
window.location.reload();
}
function toggleTheme() {
if (document.documentElement.getAttribute('data-bs-theme') == 'dark') {
document.documentElement.setAttribute('data-bs-theme','light');
localStorage.setItem("theme", "light");
document.getElementById("theme-svg").src = "/static/images/brightness-high.svg";
} else {
document.documentElement.setAttribute('data-bs-theme','dark');
localStorage.setItem("theme", "dark");
document.getElementById("theme-svg").src = "/static/images/moon-stars.svg";
}
}
document.addEventListener('DOMContentLoaded', async function() {
// Locale
let currentLocale = localStorage.getItem("locale");
document.getElementById("locale").innerText = currentLocale;
// Theme
let theme = localStorage.getItem("theme");
if (theme) {
document.documentElement.setAttribute('data-bs-theme', theme);
if (theme == "dark") {
document.getElementById("theme-svg").src = "/static/images/moon-stars.svg";
} else {
document.getElementById("theme-svg").src = "/static/images/brightness-high.svg";
}
}
// Check if auth info is valid
try {
let response = await getUser();
if (response.ok) {
let barAuth = document.getElementById("bar-auth");
barAuth.innerHTML = '<button id="log-out-btn" class="btn btn-outline-light me-2"><img src="/static/images/person-dash-fill.svg"></button>';
document.getElementById("log-out-btn").addEventListener("click", (event) => {
// Log out
forgetAuthInfo();
window.location.replace("/about");
});
}
} catch(error) {
forgetAuthInfo();
return;
}
}, false)
</script>
{{ end }}