Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions static/site/js/touch-interface-dropdown.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
document.addEventListener('DOMContentLoaded', function () {
// check if touch device, return if not
const isTouchDevice = matchMedia('(hover: none)').matches;

if (!isTouchDevice) return;

// Find all hoverable dropdowns and disable hover for them
const dropdowns = document.querySelectorAll('.navbar-item.has-dropdown.is-hoverable');

dropdowns.forEach(dropdown => {
dropdown.classList.remove('is-hoverable');

const link = dropdown.querySelector('.navbar-link');

// Toggle dropdown on touch and close all other dropdowns
link.addEventListener('click', function (event) {
event.preventDefault();

dropdowns.forEach(d => {
if (d !== dropdown) d.classList.remove('is-active');
});

dropdown.classList.toggle('is-active');
});
});

// If touched anywhere else, close all dropdowns
document.addEventListener('click', function (event) {
if (!event.target.closest('.navbar-item.has-dropdown')) {
dropdowns.forEach(d => d.classList.remove('is-active'));
}
});
});
4 changes: 3 additions & 1 deletion templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
<link rel="stylesheet" href="{% static 'site/css/base.css' %}">
{% block headcss %}{% endblock %}
{# Head Scripts #}
{% block headscripts %}{% endblock %}
{% block headscripts %}
<script src="{% static 'site/js/touch-interface-dropdown.js' %}"></script>
{% endblock %}
</head>
<body class="has-navbar-fixed-top">
{# Navigation #}
Expand Down