mirror of
https://github.com/nikdoof/website-hugo.git
synced 2025-12-14 08:02:19 +00:00
Simplify open status JS
This commit is contained in:
@@ -14,7 +14,6 @@ company = "Leigh Hackspace CIC"
|
|||||||
company_number = "09404083"
|
company_number = "09404083"
|
||||||
copyright_years = "2023"
|
copyright_years = "2023"
|
||||||
description = "Leigh Hackspace is a hackspace located in the north-west of England."
|
description = "Leigh Hackspace is a hackspace located in the north-west of England."
|
||||||
space_api_endpoint = "https://api.leighhack.org/space.json"
|
|
||||||
|
|
||||||
[params.social]
|
[params.social]
|
||||||
twitter = 'leigh_hackspace'
|
twitter = 'leigh_hackspace'
|
||||||
|
|||||||
@@ -4,7 +4,11 @@ subtitle: Leigh Hackspace is a social enterprise created for the benefit of our
|
|||||||
layout: home
|
layout: home
|
||||||
---
|
---
|
||||||
|
|
||||||
{{< open >}}
|
{{< rawhtml >}}
|
||||||
|
<div class="notification has-text-centered" id="hackspace-open">
|
||||||
|
Leigh Hackspace is currently <span id="hackspace-status">Closed</span>
|
||||||
|
</div>
|
||||||
|
{{</ rawhtml >}}
|
||||||
|
|
||||||
| Day | Opening Times |
|
| Day | Opening Times |
|
||||||
| --------- | ------------- |
|
| --------- | ------------- |
|
||||||
|
|||||||
@@ -1,24 +1,26 @@
|
|||||||
document.addEventListener('DOMContentLoaded', () => {
|
$(document).ready(function () {
|
||||||
|
$(".navbar-burger").click(function () {
|
||||||
|
$(".navbar-burger").toggleClass("is-active");
|
||||||
|
$(".navbar-menu").toggleClass("is-active");
|
||||||
|
});
|
||||||
|
|
||||||
// Get all "navbar-burger" elements
|
if ($('span#hackspace-status').length) {
|
||||||
const $navbarBurgers = Array.prototype.slice.call(document.querySelectorAll('.navbar-burger'), 0);
|
$.getJSON("https://api.leighhack.org/space.json", function (data) {
|
||||||
|
var date = new Date(data.state.lastchange * 1000);
|
||||||
|
|
||||||
// Check if there are any navbar burgers
|
if (data.state.open) {
|
||||||
if ($navbarBurgers.length > 0) {
|
message = '<b>Open<b>'
|
||||||
|
if ('message' in data.state) {
|
||||||
// Add a click event on each of them
|
message = message + ': ' + data.state.message;
|
||||||
$navbarBurgers.forEach(el => {
|
}
|
||||||
el.addEventListener('click', () => {
|
$('span#hackspace-status').html(message);
|
||||||
|
$('div#hackspace-open').addClass('is-success');
|
||||||
// Get the target from the "data-target" attribute
|
} else {
|
||||||
const target = el.dataset.target;
|
$('span#hackspace_status').html('<b>Closed</b>');
|
||||||
const $target = document.getElementById(target);
|
}
|
||||||
|
|
||||||
// Toggle the "is-active" class on both the "navbar-burger" and the "navbar-menu"
|
|
||||||
el.classList.toggle('is-active');
|
|
||||||
$target.classList.toggle('is-active');
|
|
||||||
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,19 +0,0 @@
|
|||||||
<div class="notification has-text-centered" id="hackspace-open">
|
|
||||||
Leigh Hackspace is currently <span id="hackspace-status">Closed</span>
|
|
||||||
</div>
|
|
||||||
<script>
|
|
||||||
$.getJSON("{{ .Site.Params.space_api_endpoint }}", function (data) {
|
|
||||||
var date = new Date(data.state.lastchange * 1000);
|
|
||||||
|
|
||||||
if (data.state.open) {
|
|
||||||
message = '<b>Open<b>'
|
|
||||||
if ('message' in data.state) {
|
|
||||||
message = message + ': ' + data.state.message;
|
|
||||||
}
|
|
||||||
$('span#hackspace-status').html(message);
|
|
||||||
$('div#hackspace-open').addClass('is-success');
|
|
||||||
} else {
|
|
||||||
$('span#hackspace_status').html('<b>Closed</b>');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
Reference in New Issue
Block a user