Calendar widget v1
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
<div class="diary-cal">
|
||||
<div class="diary-cal-label"><a href="{{.DiaryURL}}">Chronological</a></div>
|
||||
<div class="diary-cal-nav">
|
||||
<a href="{{.MonthURL}}" class="diary-cal-heading">{{.MonthName}}</a>
|
||||
<div class="dropdown diary-cal-drop">
|
||||
<button type="button" class="btn btn-small" data-action="cal-month-drop" aria-expanded="false" title="Monat wählen">▾</button>
|
||||
<div class="dropdown-menu">
|
||||
{{range .AllMonths}}<a class="dropdown-item{{if .IsCurrent}} cal-current{{end}}" href="{{.URL}}">{{.Name}}</a>{{end}}
|
||||
</div>
|
||||
</div>
|
||||
<a href="{{.YearURL}}" class="diary-cal-heading">{{.DisplayYear}}</a>
|
||||
<div class="dropdown diary-cal-drop">
|
||||
<button type="button" class="btn btn-small" data-action="cal-year-drop" aria-expanded="false" title="Jahr wählen">▾</button>
|
||||
<div class="dropdown-menu align-right">
|
||||
{{range .Years}}<a class="dropdown-item{{if .IsCurrent}} cal-current{{end}}" href="{{.URL}}">{{.Num}}</a>{{end}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<table class="diary-cal-grid">
|
||||
<thead>
|
||||
<tr><th>Mo</th><th>Di</th><th>Mi</th><th>Do</th><th>Fr</th><th>Sa</th><th>So</th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{range .Weeks}}<tr>{{range .}}<td class="{{if .IsCurrent}}cal-current{{else if .IsToday}}cal-today{{end}}{{if and .Num (not .HasEntry)}} cal-empty{{end}}">{{if .Num}}<a href="{{.URL}}">{{.Num}}</a>{{end}}</td>{{end}}</tr>
|
||||
{{end}}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
@@ -0,0 +1,60 @@
|
||||
(function () {
|
||||
var cal = document.querySelector(".diary-cal");
|
||||
if (!cal) return;
|
||||
|
||||
var toggle = document.createElement("button");
|
||||
toggle.type = "button";
|
||||
toggle.className = "diary-cal-toggle";
|
||||
toggle.textContent = "Kalender";
|
||||
toggle.setAttribute("aria-expanded", "false");
|
||||
toggle.addEventListener("click", function () {
|
||||
var open = cal.classList.toggle("is-open");
|
||||
toggle.setAttribute("aria-expanded", open ? "true" : "false");
|
||||
});
|
||||
|
||||
var main = document.querySelector("main");
|
||||
if (main) {
|
||||
main.parentNode.insertBefore(toggle, main);
|
||||
main.parentNode.insertBefore(cal, main);
|
||||
}
|
||||
|
||||
// Wire up month/year dropdowns inside the calendar.
|
||||
var drops = cal.querySelectorAll(".diary-cal-drop");
|
||||
drops.forEach(function (drop) {
|
||||
var trigger = drop.querySelector("button");
|
||||
var menu = drop.querySelector(".dropdown-menu");
|
||||
if (!trigger || !menu) return;
|
||||
trigger.addEventListener("click", function (e) {
|
||||
e.stopPropagation();
|
||||
drops.forEach(function (other) {
|
||||
if (other !== drop) {
|
||||
other.querySelector(".dropdown-menu").classList.remove("is-open");
|
||||
}
|
||||
});
|
||||
menu.classList.toggle("is-open");
|
||||
});
|
||||
});
|
||||
document.addEventListener("click", function (e) {
|
||||
drops.forEach(function (drop) {
|
||||
if (!drop.contains(e.target)) {
|
||||
drop.querySelector(".dropdown-menu").classList.remove("is-open");
|
||||
}
|
||||
});
|
||||
});
|
||||
document.addEventListener("keydown", function (e) {
|
||||
if (e.key !== "Escape") return;
|
||||
drops.forEach(function (drop) {
|
||||
drop.querySelector(".dropdown-menu").classList.remove("is-open");
|
||||
});
|
||||
});
|
||||
|
||||
var pageHeader = document.querySelector("header");
|
||||
function updateTop() {
|
||||
if (!pageHeader || getComputedStyle(cal).position !== "fixed") return;
|
||||
var rect = pageHeader.getBoundingClientRect();
|
||||
cal.style.top = Math.max(8, rect.bottom + 8) + "px";
|
||||
}
|
||||
window.addEventListener("scroll", updateTop, { passive: true });
|
||||
window.addEventListener("resize", updateTop);
|
||||
updateTop();
|
||||
})();
|
||||
@@ -99,5 +99,9 @@
|
||||
{{end}}
|
||||
{{end}}
|
||||
</main>
|
||||
{{if .DiaryWidget}}
|
||||
{{.DiaryWidget}}
|
||||
<script src="/_/diary/diary-calendar.js"></script>
|
||||
{{end}}
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -516,6 +516,140 @@ hr {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
/* === Diary Calendar === */
|
||||
.diary-cal {
|
||||
position: fixed;
|
||||
top: 1rem;
|
||||
left: 1rem;
|
||||
width: 13rem;
|
||||
border: 1px solid var(--secondary);
|
||||
background: var(--bg);
|
||||
padding: 0.5rem 0.75rem;
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
|
||||
.diary-cal-label {
|
||||
font-size: 0.75rem;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.05em;
|
||||
color: var(--text-muted);
|
||||
border-bottom: 1px dashed var(--secondary);
|
||||
padding-bottom: 0.25rem;
|
||||
margin-bottom: 0.4rem;
|
||||
}
|
||||
|
||||
.diary-cal-nav {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 0.2rem;
|
||||
margin-bottom: 0.4rem;
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
|
||||
.diary-cal-nav .diary-cal-drop + .diary-cal-heading {
|
||||
margin-left: 0.75rem;
|
||||
}
|
||||
|
||||
.diary-cal-heading {
|
||||
color: var(--link);
|
||||
}
|
||||
|
||||
.diary-cal-heading:hover {
|
||||
color: var(--link-hover);
|
||||
}
|
||||
|
||||
.diary-cal-grid {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
font-size: 0.8rem;
|
||||
margin-bottom: 0.4rem;
|
||||
}
|
||||
|
||||
.diary-cal-grid th,
|
||||
.diary-cal-grid td {
|
||||
text-align: center;
|
||||
padding: 0.1rem 0.15rem;
|
||||
font-weight: normal;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.diary-cal-grid td a {
|
||||
color: var(--link);
|
||||
display: block;
|
||||
}
|
||||
|
||||
.diary-cal-grid td a:hover {
|
||||
color: var(--link-hover);
|
||||
}
|
||||
|
||||
.diary-cal-grid td.cal-empty a {
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.diary-cal-grid td.cal-empty a:hover {
|
||||
color: var(--link-hover);
|
||||
}
|
||||
|
||||
.diary-cal-grid td.cal-today {
|
||||
background: var(--bg-panel);
|
||||
}
|
||||
|
||||
.diary-cal-grid td.cal-current,
|
||||
.diary-cal-grid td.cal-current a {
|
||||
color: var(--primary-hover);
|
||||
}
|
||||
|
||||
.diary-cal-drop .dropdown-menu {
|
||||
max-height: 14rem;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.diary-cal-drop .dropdown-item.cal-current {
|
||||
color: var(--primary-hover);
|
||||
}
|
||||
|
||||
.diary-cal-toggle {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* === Responsive === */
|
||||
@media (max-width: 1100px) {
|
||||
.diary-cal-toggle {
|
||||
display: block;
|
||||
background: none;
|
||||
border: 1px solid var(--secondary);
|
||||
color: var(--text);
|
||||
font: inherit;
|
||||
font-size: 0.8rem;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.05em;
|
||||
cursor: pointer;
|
||||
padding: 0.4rem 0.75rem;
|
||||
margin: 1rem auto;
|
||||
width: calc(100% - 2rem);
|
||||
max-width: 860px;
|
||||
}
|
||||
.diary-cal-toggle::before {
|
||||
content: "▸ ";
|
||||
color: var(--secondary);
|
||||
}
|
||||
.diary-cal-toggle[aria-expanded="true"]::before {
|
||||
content: "▾ ";
|
||||
}
|
||||
.diary-cal {
|
||||
position: static;
|
||||
display: none;
|
||||
width: calc(100% - 2rem);
|
||||
max-width: 860px;
|
||||
margin: 0 auto 1rem;
|
||||
max-height: none;
|
||||
}
|
||||
.diary-cal.is-open {
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
|
||||
/* === Responsive === */
|
||||
@media (max-width: 1100px) {
|
||||
.toc-toggle {
|
||||
@@ -567,6 +701,10 @@ hr {
|
||||
.toc.is-open {
|
||||
width: calc(100% - 1.5rem);
|
||||
}
|
||||
.diary-cal-toggle,
|
||||
.diary-cal.is-open {
|
||||
width: calc(100% - 1.5rem);
|
||||
}
|
||||
.modal-backdrop {
|
||||
padding: 0.5rem;
|
||||
align-items: flex-start;
|
||||
|
||||
Reference in New Issue
Block a user