Hide translation by default, add toggle button

rust
Elnu 2 years ago
parent c5e2b01da6
commit 00541ccfff

@ -14,19 +14,22 @@
<button id="direction" title="Text direction"></button> <button id="direction" title="Text direction"></button>
<button lang="ja" id="highlight" title="Vocab/kanji links">漢字</button> <button lang="ja" id="highlight" title="Vocab/kanji links">漢字</button>
<button lang="ja" id="kyujitai" title="Shinjitai/kyujitai">旧字体</button> <button lang="ja" id="kyujitai" title="Shinjitai/kyujitai">旧字体</button>
{{ if .Params.english }}
<button id="english" title="Show/hide translation">Show translation</button>
{{ end }}
<a id="kyujitai-info" target="_blank" class="clickable-icon" href="https://en.wikipedia.org/wiki/Ky%C5%ABjitai"><i class="fa-solid fa-circle-question"></i></a> <a id="kyujitai-info" target="_blank" class="clickable-icon" href="https://en.wikipedia.org/wiki/Ky%C5%ABjitai"><i class="fa-solid fa-circle-question"></i></a>
<header> <header>
<h3>Tegaki Tuesday #{{- $current -}}</h3> <h3>Tegaki Tuesday #{{- $current -}}</h3>
<small><ruby><rp>(</rp><rt></rt><rp>)</rp></ruby><ruby><rp>(</rp><rt></rt><rp>)</rp></ruby>きの<ruby><rp>(</rp><rt></rt><rp>)</rp></ruby><ruby><rp>(</rp><rt>よう</rt><rp>)</rp></ruby><ruby><rp>(</rp><rt></rt><rp>)</rp></ruby>{{- $current -}}・<time datetime="{{- .Date.Format " 2006-01-02T15:04:05Z07:00" -}}">{{- .Date.Format "2006年01月02日" -}}</time></small> <small><ruby><rp>(</rp><rt></rt><rp>)</rp></ruby><ruby><rp>(</rp><rt></rt><rp>)</rp></ruby>きの<ruby><rp>(</rp><rt></rt><rp>)</rp></ruby><ruby><rp>(</rp><rt>よう</rt><rp>)</rp></ruby><ruby><rp>(</rp><rt></rt><rp>)</rp></ruby>{{- $current -}}・<time datetime="{{- .Date.Format " 2006-01-02T15:04:05Z07:00" -}}">{{- .Date.Format "2006年01月02日" -}}</time></small>
</header> </header>
{{ if .Params.english }} {{ if .Params.english }}
<div id="challenge-english"> <div id="challenge-english" style="display: none">
<!-- English view --> <!-- English view -->
{{- range.Params.english -}} {{- range.Params.english -}}
<p>{{- $.RenderString . -}}</p> <p>{{- $.RenderString . -}}</p>
{{- end -}} {{- end -}}
</div>
<br> <br>
</div>
{{ end }} {{ end }}
<div id="challenge-vocab" lang="ja"> <div id="challenge-vocab" lang="ja">
<!-- Vocab view --> <!-- Vocab view -->

@ -4,6 +4,7 @@ const kyujitai = [["万","萬"],["与","與"],["両","兩"],["並","竝"],["乗"
const challenge = document.getElementById("challenge"); const challenge = document.getElementById("challenge");
const defaultHeight = challenge.scrollHeight + "px"; const defaultHeight = challenge.scrollHeight + "px";
let verticalHeight;
challenge.style.height = defaultHeight; challenge.style.height = defaultHeight;
const vocab = document.getElementById("challenge-vocab"); const vocab = document.getElementById("challenge-vocab");
@ -58,6 +59,7 @@ directionButton.addEventListener("click", function() {
texts.forEach(text => text.classList.add("vertical")); texts.forEach(text => text.classList.add("vertical"));
this.innerHTML = "↔"; this.innerHTML = "↔";
challenge.style.height = challenge.scrollHeight + "px"; challenge.style.height = challenge.scrollHeight + "px";
verticalHeight = challenge.style.height;
} else { } else {
texts.forEach(text => text.classList.remove("vertical")); texts.forEach(text => text.classList.remove("vertical"));
this.innerHTML = "↕"; this.innerHTML = "↕";
@ -66,6 +68,22 @@ directionButton.addEventListener("click", function() {
}); });
directionButton.click(); directionButton.click();
const englishButton = document.getElementById("english");
const challengeEnglish = document.getElementById("challenge-english");
if (englishButton) {
englishButton.addEventListener("click", function() {
if (this.innerHTML == "Show translation") {
challengeEnglish.style.removeProperty("display");
this.innerHTML = "Hide translation";
challenge.style.height = challenge.scrollHeight + "px";
} else {
challengeEnglish.style.display = "none";
this.innerHTML = "Show translation";
challenge.style.height = directionButton.innerHTML == "↕" ? defaultHeight : verticalHeight;
}
});
}
document.getElementById("highlight").addEventListener("click", function() { document.getElementById("highlight").addEventListener("click", function() {
if (this.innerHTML === "漢字") { if (this.innerHTML === "漢字") {
vocab.style.display = "none"; vocab.style.display = "none";

Loading…
Cancel
Save