Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve presentation of navigation at mobile #16

Merged
merged 5 commits into from
Mar 7, 2017
Merged
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
61 changes: 45 additions & 16 deletions tsstats/templates/index.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
a:hover {
text-decoration: none;
}
.navbar-toggler {
cursor: pointer;
}
@media screen and (max-width: 767px) {
.hint--medium--xs:after {
white-space: normal;
Expand All @@ -24,23 +27,30 @@
</style>
</head>
<body>
<div class="container-fluid">
<nav class="navbar navbar-toggleable-md navbar-light bg-faded sticky-top">
<a class="navbar-brand" href="#">{{ title }}</a>
<nav class="navbar navbar-toggleable-md navbar-light bg-faded sticky-top">
<div class="d-flex justify-content-between hidden-lg-up">
<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 id="main-nav" class="collapse navbar-collapse">
<ul class="navbar-nav mr-auto">
<li class="hidden-md-down"><a href="" class="navbar-brand">{{ title }}</a></li>
{% for sid, _ in servers %}
<li class="nav-item">
<a class="nav-link" href="#sid{{ sid }}">Server {{ sid }}</a>
</li>
{% endfor %}
</ul>
{% if debug %}
<span class="navbar-text" style="color: red">debug mode</span>
{% endif %}
</div>
</nav>

<div class="collapse navbar-collapse">
<ul class="navbar-nav mr-auto">
{% for sid, _ in servers %}
<li class="nav-item">
<a class="nav-link" href="#sid{{ sid }}">Server {{ sid }}</a>
</li>
{% endfor %}
</ul>
{% if debug %}
<span class="navbar-text" style="color: red">debug mode</span>
{% endif %}
</div>
</nav>
<div class="container-fluid">
{% for server in servers %}
<h1 class="display-4" id="sid{{ server.sid }}">
<a href="#sid{{ server.sid }}">Server {{ server.sid }}</a>
Expand All @@ -49,5 +59,24 @@
{% endfor %}
<small>Generated by <a href="https://github.com/Thor77/TeamspeakStats" rel="noopener">TeamspeakStats</a> at {{ creation_time|frmttime }}</small>
</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>
</html>
3 changes: 2 additions & 1 deletion tsstats/tests/test_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ def test_debug(output):
logger.setLevel(logging.INFO)
soup = BeautifulSoup(open(output_path), 'html.parser')
# 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'):
nick = client_item.find('span').text
# check for right identifier
Expand Down