Commit bfcfe345 authored by Jim Driessen's avatar Jim Driessen
Browse files

Fix going back to the calendar from an event jumping to the wrong view or date.

parent e3a14e0c
......@@ -50,7 +50,23 @@
eventSources.push(sources.birthdays);
}
$('#calendar').fullCalendar({
// History idea and code parts from
// https://github.com/fullcalendar/fullcalendar/issues/659#issuecomment-132535804
// and https://github.com/fullcalendar/fullcalendar/issues/659#issuecomment-245544401
var startDate = new Date('{{ upcoming_activity.start|date:'Y-m-d' }}');
var tmpYear = startDate.getFullYear();
var tmpMonth = startDate.getMonth();
var tmpDay = startDate.getDate();
var tmpView = ($(window).width() < 979) ? 'list' : 'agendaWeek';
var vars = window.location.hash.split("&");
for (var i = 0; i < vars.length; i++) {
if (vars[i].match("^#year")) tmpYear = vars[i].substring(6);
if (vars[i].match("^month")) tmpMonth = vars[i].substring(6) - 1;
if (vars[i].match("^day")) tmpDay = vars[i].substring(4);
if (vars[i].match("^view")) tmpView = vars[i].substring(5);
}
var calendarDiv = $('#calendar');
calendarDiv.fullCalendar({
defaultDate:
{% spaceless %}
{% if upcoming_activity %}
......@@ -88,7 +104,7 @@
},
firstDay: 1,
scrollTime: '14:00:00',
defaultView: ($(window).width() < 979) ? 'list' : 'agendaWeek',
defaultView: tmpView,
editable: false,
lang: '{{ LANGUAGE_CODE }}',
titleRangeSeparator: ' - ',
......@@ -106,8 +122,27 @@
},
eventRender: function(event, element) {
element.attr('title', event.description);
},
viewRender: function(view) {
var moment = calendarDiv.fullCalendar('getDate');
if (moment) {
window.location.hash = 'year=' + moment.format('YYYY') + '&month=' + (moment.format('M')) + '&day=' + moment.format('DD') + '&view=' + view.name;
}
}
});
var date = new Date(tmpYear, tmpMonth, tmpDay, 0, 0, 0);
var d = calendarDiv.fullCalendar('getDate');
var moment = calendarDiv.fullCalendar('getDate');
var view = calendarDiv.fullCalendar('getView');
if (date.getFullYear() != moment.format('YYYY') ||
date.getMonth() != moment.format('M') ||
date.getDate() != moment.format('DD')) {
calendarDiv.fullCalendar('gotoDate', date);
}
if (view.name != tmpView) {
calendarDiv.fullCalendar('changeView', tmpView);
}
});
</script>
{% endblock body %}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment