Improve navbar on mobile devices (#16)

* add button to show/hide menu items
* ensure navigation fills the width of the viewport by moving it out of the main container element
This commit is contained in:
Matthew 2017-03-08 01:55:18 +11:00 committed by Thor77
parent 3207c0070c
commit c34f2d4d8b
2 changed files with 47 additions and 17 deletions

View File

@ -14,6 +14,9 @@
a:hover { a:hover {
text-decoration: none; text-decoration: none;
} }
.navbar-toggler {
cursor: pointer;
}
@media screen and (max-width: 767px) { @media screen and (max-width: 767px) {
.hint--medium--xs:after { .hint--medium--xs:after {
white-space: normal; white-space: normal;
@ -24,12 +27,17 @@
</style> </style>
</head> </head>
<body> <body>
<div class="container-fluid"> <nav class="navbar navbar-toggleable-md navbar-light bg-faded sticky-top">
<nav class="navbar navbar-toggleable-md navbar-light bg-faded sticky-top"> <div class="d-flex justify-content-between hidden-lg-up">
<a class="navbar-brand" href="#">{{ title }}</a> <a href="" class="navbar-brand">{{ title }}</a>
<button class="navbar-toggler hidden-lg-up" type="button" data-toggle="collapse" data-target="main-nav" aria-controls="main-nav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
</div>
<div class="collapse navbar-collapse"> <div id="main-nav" class="collapse navbar-collapse">
<ul class="navbar-nav mr-auto"> <ul class="navbar-nav mr-auto">
<li class="hidden-md-down"><a href="" class="navbar-brand">{{ title }}</a></li>
{% for sid, _ in servers %} {% for sid, _ in servers %}
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="#sid{{ sid }}">Server {{ sid }}</a> <a class="nav-link" href="#sid{{ sid }}">Server {{ sid }}</a>
@ -40,7 +48,9 @@
<span class="navbar-text" style="color: red">debug mode</span> <span class="navbar-text" style="color: red">debug mode</span>
{% endif %} {% endif %}
</div> </div>
</nav> </nav>
<div class="container-fluid">
{% for server in servers %} {% for server in servers %}
<h1 class="display-4" id="sid{{ server.sid }}"> <h1 class="display-4" id="sid{{ server.sid }}">
<a href="#sid{{ server.sid }}">Server {{ server.sid }}</a> <a href="#sid{{ server.sid }}">Server {{ server.sid }}</a>
@ -49,5 +59,24 @@
{% endfor %} {% endfor %}
<small>Generated by <a href="https://github.com/Thor77/TeamspeakStats" rel="noopener">TeamspeakStats</a> at {{ creation_time|frmttime }}</small> <small>Generated by <a href="https://github.com/Thor77/TeamspeakStats" rel="noopener">TeamspeakStats</a> at {{ creation_time|frmttime }}</small>
</div> </div>
<script type="text/javascript">
(function() {
var collapseTogglers = document.querySelectorAll('[data-toggle="collapse"]');
var toggleTarget;
Array.prototype.forEach.call(collapseTogglers, function(toggler) {
toggler.addEventListener('click', function(event) {
toggleTarget = document.getElementById(toggler.dataset.target);
if (toggler.getAttribute('aria-expanded') === 'true') {
toggleTarget.classList.add('collapse');
toggler.setAttribute('aria-expanded', false);
} else {
toggleTarget.classList.remove('collapse');
toggler.setAttribute('aria-expanded', true);
}
});
});
})();
</script>
</body> </body>
</html> </html>

View File

@ -28,7 +28,8 @@ def test_debug(output):
logger.setLevel(logging.INFO) logger.setLevel(logging.INFO)
soup = BeautifulSoup(open(output), 'html.parser') soup = BeautifulSoup(open(output), 'html.parser')
# check debug-label presence # check debug-label presence
assert soup.find('nav').find('span').text == 'debug mode' assert soup.find('nav').find('div', id='main-nav').find('span').text \
== 'debug mode'
for client_item in soup.find('ul', id='1.onlinetime').find_all('li'): for client_item in soup.find('ul', id='1.onlinetime').find_all('li'):
nick = client_item.find('span').text nick = client_item.find('span').text
# check for right identifier # check for right identifier