♻️ Move home switcher JS to external file

pull/100/head
James Panther 2022-01-27 12:28:32 +11:00
parent cc3960cf2a
commit 15e67f5903
No known key found for this signature in database
GPG Key ID: D36F789E45745D17
6 changed files with 31 additions and 23 deletions

View File

Before

Width:  |  Height:  |  Size: 53 KiB

After

Width:  |  Height:  |  Size: 53 KiB

View File

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 25 KiB

View File

@ -0,0 +1,27 @@
function switchHomeLayout() {
const pageDiv = document.getElementById("page");
const profileDiv = document.getElementById("profile");
const layoutCode = document.querySelectorAll("code[id=layout]");
if (pageDiv.style.display === "none") {
pageDiv.style.display = "block";
profileDiv.style.display = "none";
layoutCode.forEach(function (el) {
el.innerText = "page";
});
} else {
pageDiv.style.display = "none";
profileDiv.style.display = "block";
layoutCode.forEach(function (el) {
el.innerText = "profile";
});
}
}
window.addEventListener("DOMContentLoaded", (event) => {
document.querySelectorAll("#switch-layout-button").forEach((button) =>
button.addEventListener("click", function (e) {
e.preventDefault();
switchHomeLayout();
})
);
});

View File

@ -13,7 +13,7 @@ dateFormat = "2 January 2006"
[author]
name = "Congo"
image = "author.jpg"
image = "img/author.jpg"
# headline = ""
bio = "This is an example author bio, and although there's a stock photo of a dog here, this article was actually created by a human. :dog:"
links = [

View File

@ -16,8 +16,8 @@ This is a demo site built entirely using Congo. It also contains a complete set
<span class="flex items-center justify-between grow dark:text-neutral-300">
<span class="prose dark:prose-invert">This is a demo of the <code id="layout">page</code> layout.</span>
<button
id="switch-layout-button"
class="px-4 !text-neutral !no-underline rounded-md bg-primary-600 hover:!bg-primary-500 dark:bg-primary-800 dark:hover:!bg-primary-700"
onclick="switchLayout()"
>
Switch layout &orarr;
</button>

View File

@ -1,27 +1,8 @@
{{ $jsHome := resources.Get "js/home.js" | resources.Minify | resources.Fingerprint "sha512" }}
<div id="page">
{{ partial "partials/home/page.html" . }}
</div>
<div id="profile" class="hidden h-full">
{{ partial "partials/home/profile.html" . }}
</div>
<script type="text/javascript">
function switchLayout() {
const pageDiv = document.getElementById("page");
const profileDiv = document.getElementById("profile");
const layoutCode = document.querySelectorAll("code[id=layout]");
if (pageDiv.style.display === "none") {
pageDiv.style.display = "block";
profileDiv.style.display = "none";
layoutCode.forEach(function (el) {
el.innerText = "page";
});
} else {
pageDiv.style.display = "none";
profileDiv.style.display = "block";
layoutCode.forEach(function (el) {
el.innerText = "profile";
});
}
}
</script>
<script defer type="text/javascript" src="{{ $jsHome.RelPermalink }}" integrity="{{ $jsHome.Data.Integrity }}"></script>