Add a burger manu to the navbar when used on mobiles
This commit is contained in:
parent
957c884f78
commit
2f243139bf
3 changed files with 92 additions and 58 deletions
|
@ -7,6 +7,7 @@
|
||||||
<link rel="stylesheet" href="{% static 'bulma/css/style.min.css' %}">
|
<link rel="stylesheet" href="{% static 'bulma/css/style.min.css' %}">
|
||||||
<link rel="shortcut icon" href="{% static "khaganat/images/favicon.ico" %}">
|
<link rel="shortcut icon" href="{% static "khaganat/images/favicon.ico" %}">
|
||||||
<link rel="stylesheet" href="{% static "khaganat/css/khaganat.css" %}">
|
<link rel="stylesheet" href="{% static "khaganat/css/khaganat.css" %}">
|
||||||
|
<script defer src="{% static "navbar/navbar.js" %}"></script>
|
||||||
{% block headers %}{% endblock %}
|
{% block headers %}{% endblock %}
|
||||||
<title>Khaganat - {% block title %}{% endblock %}</title>
|
<title>Khaganat - {% block title %}{% endblock %}</title>
|
||||||
</head>
|
</head>
|
||||||
|
|
28
navbar/static/navbar/navbar.js
Normal file
28
navbar/static/navbar/navbar.js
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
// See Bulma documentation
|
||||||
|
// https://bulma.io/documentation/components/navbar/
|
||||||
|
|
||||||
|
document.addEventListener('DOMContentLoaded', function () {
|
||||||
|
|
||||||
|
// Get all "navbar-burger" elements
|
||||||
|
var $navbarBurgers = Array.prototype.slice.call(document.querySelectorAll('.navbar-burger'), 0);
|
||||||
|
|
||||||
|
// Check if there are any navbar burgers
|
||||||
|
if ($navbarBurgers.length > 0) {
|
||||||
|
|
||||||
|
// Add a click event on each of them
|
||||||
|
$navbarBurgers.forEach(function ($el) {
|
||||||
|
$el.addEventListener('click', function () {
|
||||||
|
|
||||||
|
// Get the target from the "data-target" attribute
|
||||||
|
var target = $el.dataset.target;
|
||||||
|
var $target = document.getElementById(target);
|
||||||
|
|
||||||
|
// Toggle the class on both the "navbar-burger" and the "navbar-menu"
|
||||||
|
$el.classList.toggle('is-active');
|
||||||
|
$target.classList.toggle('is-active');
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
|
@ -2,63 +2,68 @@
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
|
||||||
<nav class="navbar is-light">
|
<nav class="navbar is-light">
|
||||||
<div class="navbar-brand">
|
<div class="navbar-brand">
|
||||||
<a class="navbar-item" href="{% url 'index' %}"><img src="{% static "khaganat/images/icon_khaganat.png" %}" alt="Khaganat"></a>
|
<a class="navbar-item" href="{% url 'index' %}"><img src="{% static "khaganat/images/icon_khaganat.png" %}" alt="Khaganat"></a>
|
||||||
</div>
|
<a role="button" class="navbar-burger" data-target="navMenu" aria-label="menu" aria-expanded="false">
|
||||||
<div class="navbar-menu">
|
<span aria-hidden="true"></span>
|
||||||
<div class="navbar-start">
|
<span aria-hidden="true"></span>
|
||||||
{% for e in elems %}
|
<span aria-hidden="true"></span>
|
||||||
{% if e.localized_link %}
|
</a>
|
||||||
<a class="navbar-item" href="{{ e.localized_link }}"{% if e.new_window %} target="_blank"{% endif %}>{{ e }}</a>
|
</div>
|
||||||
{% elif e.children %}
|
<div class="navbar-menu" id="navMenu">
|
||||||
<div class="navbar-item has-dropdown is-hoverable">
|
<div class="navbar-start">
|
||||||
<a class="navbar-link">{{ e.description.short_name }}</a>
|
{% for e in elems %}
|
||||||
<div class="navbar-dropdown">
|
{% if e.localized_link %}
|
||||||
{% for c in e.children %}
|
<a class="navbar-item" href="{{ e.localized_link }}"{% if e.new_window %} target="_blank"{% endif %}>{{ e }}</a>
|
||||||
{% if c.is_separator %}<hr class="navbar-divider">{% else %}
|
{% elif e.children %}
|
||||||
<a class="navbar-item" href="{% if c.add_locale %}/{{ current_lang_code }}{% endif %}{{ c.localized_link }}"{% if c.new_window %} target="_blank"{% endif %}{% if c.description.description %} title="{{ c.description.description }}"{% endif %}>
|
<div class="navbar-item has-dropdown is-hoverable">
|
||||||
<span>
|
<a class="navbar-link">{{ e.description.short_name }}</a>
|
||||||
<span><img src="{% static c.icon_path %}" alt="" /></span>
|
<div class="navbar-dropdown">
|
||||||
<span>{{ c }}</span>
|
{% for c in e.children %}
|
||||||
</span>
|
{% if c.is_separator %}<hr class="navbar-divider">{% else %}
|
||||||
</a>
|
<a class="navbar-item" href="{% if c.add_locale %}/{{ current_lang_code }}{% endif %}{{ c.localized_link }}"{% if c.new_window %} target="_blank"{% endif %}{% if c.description.description %} title="{{ c.description.description }}"{% endif %}>
|
||||||
{% endif %}
|
<span>
|
||||||
{% endfor %}
|
<span><img src="{% static c.icon_path %}" alt="" /></span>
|
||||||
</div>
|
<span>{{ c }}</span>
|
||||||
</div>
|
</span>
|
||||||
{% else %}
|
</a>
|
||||||
<span class="navbar-item">{{ e }}</span>
|
{% endif %}
|
||||||
{% endif %}
|
{% endfor %}
|
||||||
{% endfor %}
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="navbar-end">
|
{% else %}
|
||||||
{% if user.is_authenticated %}
|
<span class="navbar-item">{{ e }}</span>
|
||||||
<div class="navbar-item has-dropdown is-hoverable">
|
{% endif %}
|
||||||
<a class="navbar-link">{% trans "my_account"|capfirst %}</a>
|
{% endfor %}
|
||||||
<div class="navbar-dropdown">
|
</div>
|
||||||
{% if user.is_superuser %}
|
<div class="navbar-end">
|
||||||
<a class="navbar-item" href="{% url "admin:index" %}">{% trans "administration"|capfirst %}</a>
|
{% if user.is_authenticated %}
|
||||||
{% endif %}
|
<div class="navbar-item has-dropdown is-hoverable">
|
||||||
<a class="navbar-item" href="{% url "logout" %}">{% trans "logout"|capfirst %}</a>
|
<a class="navbar-link">{% trans "my_account"|capfirst %}</a>
|
||||||
</div>
|
<div class="navbar-dropdown">
|
||||||
</div>
|
{% if user.is_superuser %}
|
||||||
{% else %}
|
<a class="navbar-item" href="{% url "admin:index" %}">{% trans "administration"|capfirst %}</a>
|
||||||
<div class="navbar-item">
|
{% endif %}
|
||||||
<div>
|
<a class="navbar-item" href="{% url "logout" %}">{% trans "logout"|capfirst %}</a>
|
||||||
<a class="button is-link" href="{% url "login" %}?next={{ current_url }}">{% trans "login"|capfirst %}</a>
|
</div>
|
||||||
<a class="button is-white" href="{% url "register" %}">{% trans "register"|capfirst %}</a>
|
</div>
|
||||||
</div>
|
{% else %}
|
||||||
</div>
|
<div class="navbar-item">
|
||||||
{% endif %}
|
<div>
|
||||||
|
<a class="button is-link" href="{% url "login" %}?next={{ current_url }}">{% trans "login"|capfirst %}</a>
|
||||||
|
<a class="button is-white" href="{% url "register" %}">{% trans "register"|capfirst %}</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<div class="navbar-item has-dropdown is-hoverable">
|
<div class="navbar-item has-dropdown is-hoverable">
|
||||||
<a class="navbar-link">{{ current_lang_name|capfirst }}</a>
|
<a class="navbar-link">{{ current_lang_name|capfirst }}</a>
|
||||||
<div class="navbar-dropdown">
|
<div class="navbar-dropdown">
|
||||||
{% for lang_code, lang_name, lang_url in all_langs %}
|
{% for lang_code, lang_name, lang_url in all_langs %}
|
||||||
<a class="navbar-item{% if lang_code == current_lang_code %} is-active{% endif %}" href="{{ lang_url }}">{{ lang_name|capfirst }}</a>
|
<a class="navbar-item{% if lang_code == current_lang_code %} is-active{% endif %}" href="{{ lang_url }}">{{ lang_name|capfirst }}</a>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
Loading…
Reference in a new issue