Making day menu responsive.

This commit is contained in:
Víðir Valberg Guðmundsson 2017-04-29 14:58:21 +02:00
parent 521d3c9c71
commit 5ef3e79b38
3 changed files with 26 additions and 15 deletions

View file

@ -120,6 +120,9 @@ function render_day_menu(active_iso) {
var container = document.getElementById('schedule-days'); var container = document.getElementById('schedule-days');
container.innerHTML = ''; container.innerHTML = '';
var mobile_container = document.getElementById('schedule-days-mobile');
mobile_container.innerHTML = '';
function set_btn_type(classList, primary) { function set_btn_type(classList, primary) {
if(primary == true) { if(primary == true) {
classList.add('btn-primary'); classList.add('btn-primary');
@ -128,16 +131,25 @@ function render_day_menu(active_iso) {
} }
} }
function dayEvent(e) {
setHistoryState({
'day': this.dataset.iso
});
render();
}
var all_days = document.createElement('a'); var all_days = document.createElement('a');
all_days.classList.add('btn'); all_days.classList.add('btn');
set_btn_type(all_days.classList, active_iso == null); set_btn_type(all_days.classList, active_iso == null);
all_days.innerHTML = 'All days'; all_days.innerHTML = 'All days';
all_days.addEventListener('click', function(e) { all_days.dataset.iso = 'all-days';
setHistoryState({'day': 'all-days'}); all_days.addEventListener('click', dayEvent);
render();
});
container.appendChild(all_days); container.appendChild(all_days);
all_days_mobile = all_days.cloneNode(true);
all_days_mobile.addEventListener('click', dayEvent);
mobile_container.appendChild(all_days_mobile);
for(var day_id in DAYS) { for(var day_id in DAYS) {
var day_link = document.createElement('a'); var day_link = document.createElement('a');
day_link.classList.add('btn'); day_link.classList.add('btn');
@ -145,14 +157,12 @@ function render_day_menu(active_iso) {
day_link.dataset.iso = DAYS[day_id]['iso']; day_link.dataset.iso = DAYS[day_id]['iso'];
day_link.innerHTML = DAYS[day_id]['day_name']; day_link.innerHTML = DAYS[day_id]['day_name'];
day_link.addEventListener('click', function(e) { day_link.addEventListener('click', dayEvent);
setHistoryState({
'day': this.dataset.iso
});
render();
});
container.appendChild(day_link); container.appendChild(day_link);
day_link_mobile = day_link.cloneNode(true);
day_link_mobile.addEventListener('click', dayEvent);
mobile_container.appendChild(day_link_mobile);
} }
} }
@ -463,7 +473,6 @@ function setHistoryState(parts) {
} }
history.replaceState({}, '', query); history.replaceState({}, '', query);
} }
function toggleFilterBoxes(types, locations) { function toggleFilterBoxes(types, locations) {

View file

@ -4,7 +4,9 @@
{% block program_content %} {% block program_content %}
<div class="row"> <div class="row">
<div id="schedule-days" class="btn-group schedule-days"> <div id="schedule-days" class="btn-group hidden-xs">
</div>
<div id="schedule-days-mobile" class="btn-group-vertical visible-xs">
</div> </div>
</div> </div>

View file

@ -219,13 +219,13 @@ footer {
} }
} }
.schedule-days { #schedule-days {
list-style: none; list-style: none;
padding: 0; padding: 0;
display: flex; display: flex;
} }
.schedule-days a { #schedule-days a {
display: inline; display: inline;
flex-grow: 1; flex-grow: 1;
} }