Remove last dependency on hash in location, use sessionStorage

parent ed9ae402
const BIRTHDAYS_COOKIE = 'showbirthdays'; const BIRTHDAYS_COOKIE = 'showbirthdays';
const VIEW_COOKIE = 'calendarview'; const VIEW_COOKIE = 'calendarview';
const DATE_STORAGE = 'calendardate';
const SOURCES = { const SOURCES = {
events: { events: {
id: 'event', id: 'event',
...@@ -19,17 +20,17 @@ const SOURCES = { ...@@ -19,17 +20,17 @@ const SOURCES = {
}, },
}; };
function checkResponsiveState(calendar, windowWidth, view) { function checkViewState(calendar) {
var buttonText = gettext('show birthdays'); let buttonText = gettext('show birthdays');
if (calendar.getEventSourceById(SOURCES.birthdays.id)) { if (calendar.getEventSourceById(SOURCES.birthdays.id)) {
calendar.getEventSourceById(SOURCES.birthdays.id).remove(); calendar.getEventSourceById(SOURCES.birthdays.id).remove();
} }
if (windowWidth <= 768) { if (window.innerWidth <= 768) {
calendar.setOption('header', { calendar.setOption('header', {
right: '' right: ''
}); });
} else { } else {
if (view.type === 'list') { if (calendar.view.type === 'list') {
calendar.setOption('header', { calendar.setOption('header', {
right: 'list,timeGridWeek,dayGridMonth' right: 'list,timeGridWeek,dayGridMonth'
}); });
...@@ -43,7 +44,10 @@ function checkResponsiveState(calendar, windowWidth, view) { ...@@ -43,7 +44,10 @@ function checkResponsiveState(calendar, windowWidth, view) {
}); });
} }
} }
$('.fc-showBirthdays-button').html(buttonText); const showBirthdaysBtn = calendar.el.querySelector('.fc-showBirthdays-button');
if (showBirthdaysBtn) {
showBirthdaysBtn.innerHTML = buttonText;
}
} }
document.addEventListener('DOMContentLoaded', function () { document.addEventListener('DOMContentLoaded', function () {
...@@ -61,20 +65,21 @@ document.addEventListener('DOMContentLoaded', function () { ...@@ -61,20 +65,21 @@ document.addEventListener('DOMContentLoaded', function () {
if (Cookies.get(BIRTHDAYS_COOKIE)) { if (Cookies.get(BIRTHDAYS_COOKIE)) {
eventSources.push(SOURCES.birthdays); eventSources.push(SOURCES.birthdays);
} }
let tmpView = window.innerWidth < 979 ? 'list' : 'timeGridWeek';
if (Cookies.get(VIEW_COOKIE) !== undefined) { let defaultView = window.innerWidth < 979 ? 'list' : 'timeGridWeek';
tmpView = Cookies.get(VIEW_COOKIE); if (Cookies.get(VIEW_COOKIE) !== undefined && window.innerWidth >= 979) {
defaultView = Cookies.get(VIEW_COOKIE);
} }
if (window.location.hash.indexOf('date') > -1) { if (sessionStorage.getItem(DATE_STORAGE)) {
defaultDate = window.location.hash.substr(window.location.hash.indexOf('date') + 5, 24); defaultDate = sessionStorage.getItem(DATE_STORAGE);
} }
const calendar = new FullCalendar.Calendar(calendarEl, { const calendar = new FullCalendar.Calendar(calendarEl, {
plugins: ['timeGrid', 'dayGrid', 'bootstrap', listViewPlugin], plugins: ['timeGrid', 'dayGrid', 'bootstrap', listViewPlugin],
aspectRatio: 1.8, aspectRatio: 1.8,
themeSystem: 'bootstrap', themeSystem: 'bootstrap',
defaultView: tmpView, defaultView: defaultView,
defaultDate: defaultDate, defaultDate: defaultDate,
eventSources: eventSources, eventSources: eventSources,
firstDay: 1, firstDay: 1,
...@@ -112,11 +117,7 @@ document.addEventListener('DOMContentLoaded', function () { ...@@ -112,11 +117,7 @@ document.addEventListener('DOMContentLoaded', function () {
} }
} }
} : {}, } : {},
header: {
right: 'showBirthdays, list,timeGridWeek,dayGridMonth prev,next today'
},
eventClick: function ({ jsEvent, event }) { eventClick: function ({ jsEvent, event }) {
console.log(event);
if (event.url && event.extendedProps.blank) { if (event.url && event.extendedProps.blank) {
jsEvent.preventDefault(); jsEvent.preventDefault();
window.open(event.url, '_blank'); window.open(event.url, '_blank');
...@@ -129,18 +130,14 @@ document.addEventListener('DOMContentLoaded', function () { ...@@ -129,18 +130,14 @@ document.addEventListener('DOMContentLoaded', function () {
viewSkeletonRender: function ({ view }) { viewSkeletonRender: function ({ view }) {
const prevView = Cookies.get(VIEW_COOKIE); const prevView = Cookies.get(VIEW_COOKIE);
const date = calendar.getDate();
window.location.hash = 'date=' + date.toISOString() + '&view=' + view.type;
if (view.type !== prevView) { if (view.type !== prevView) {
const windowWidth = window.innerWidth;
Cookies.set(VIEW_COOKIE, view.type); Cookies.set(VIEW_COOKIE, view.type);
checkResponsiveState(calendar, windowWidth, view); checkViewState(calendar);
} }
}, },
datesRender: function ({ view }) { datesRender: function () {
const date = calendar.getDate(); const date = calendar.getDate();
window.location.hash = 'date=' + date.toISOString() + '&view=' + view.type; sessionStorage.setItem(DATE_STORAGE, date.toISOString());
}, },
windowResize: function () { windowResize: function () {
const windowWidth = window.innerWidth; const windowWidth = window.innerWidth;
...@@ -149,17 +146,11 @@ document.addEventListener('DOMContentLoaded', function () { ...@@ -149,17 +146,11 @@ document.addEventListener('DOMContentLoaded', function () {
if (view !== currentView.type) { if (view !== currentView.type) {
calendar.changeView(view); calendar.changeView(view);
} else { } else {
checkResponsiveState(calendar, windowWidth, currentView); checkViewState(calendar);
} }
} }
}); });
calendar.render(); calendar.render();
checkViewState(calendar);
if (calendar.view.type !== tmpView) {
calendar.changeView(tmpView);
} else {
var windowWidth = window.innerWidth;
checkResponsiveState(calendar, windowWidth, calendar.view);
}
}); });
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
var signaturePad = new SignaturePad(signatureCanvas); var signaturePad = new SignaturePad(signatureCanvas);
function canvasToField() { function canvasToField() {
console.log('canvas field');
if (signaturePad.toData().length) { if (signaturePad.toData().length) {
signatureField.val(signaturePad.toDataURL("image/svg+xml")); signatureField.val(signaturePad.toDataURL("image/svg+xml"));
} }
......
Markdown is supported
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