diff --git a/changelog/53_UNRELEASED_2019-xx-xx.md b/changelog/53_UNRELEASED_2019-xx-xx.md index 3f9a793a..67256088 100644 --- a/changelog/53_UNRELEASED_2019-xx-xx.md +++ b/changelog/53_UNRELEASED_2019-xx-xx.md @@ -1,2 +1,3 @@ - It's now possible to display a recipe directly from the meal plan (new "eye button") (thanks @kriddles) +- Improved the responsiveness of the meal plan and calendar page by automatically switching to a day calendar view on smaller screens (thanks for the idea @kriddles) - Some style/CSS detail-refinements diff --git a/public/viewjs/calendar.js b/public/viewjs/calendar.js index 6195ee31..41658afa 100644 --- a/public/viewjs/calendar.js +++ b/public/viewjs/calendar.js @@ -4,14 +4,15 @@ if (!Grocy.CalendarFirstDayOfWeek.isEmpty()) firstDay = parseInt(Grocy.CalendarFirstDayOfWeek); } -$("#calendar").fullCalendar({ +var calendar = $("#calendar").fullCalendar({ "themeSystem": "bootstrap4", "header": { - "left": "month,basicWeek,listWeek", + "left": "month,agendaWeek,agendaDay,listWeek", "center": "title", "right": "prev,next" }, "weekNumbers": Grocy.CalendarShowWeekNumbers, + "defaultView": ($(window).width() < 768) ? "agendaDay" : "month", "firstDay": firstDay, "eventLimit": true, "eventSources": fullcalendarEventSources @@ -35,3 +36,17 @@ $("#ical-button").on("click", function(e) } ); }); + +$(window).on("resize", function() +{ + // Automatically switch the calendar to "basicDay" view on small screens + // and to "month" otherwise + if ($(window).width() < 768) + { + calendar.fullCalendar("changeView", "agendaDay"); + } + else + { + calendar.fullCalendar("changeView", "month"); + } +}); diff --git a/public/viewjs/mealplan.js b/public/viewjs/mealplan.js index bc432b65..b25bb34e 100644 --- a/public/viewjs/mealplan.js +++ b/public/viewjs/mealplan.js @@ -16,7 +16,7 @@ var calendar = $("#calendar").fullCalendar({ "weekNumbers": false, "eventLimit": true, "eventSources": fullcalendarEventSources, - "defaultView": "basicWeek", + "defaultView": ($(window).width() < 768) ? "basicDay" : "basicWeek", "firstDay": firstDay, "viewRender": function(view) { @@ -94,11 +94,11 @@ var calendar = $("#calendar").fullCalendar({ } element.html(' \ -
\ -
' + recipe.name + '
\ -
' + __n(mealPlanEntry.servings, "%s serving", "%s servings") + '
\ -
' + fulfillmentIconHtml + " " + fulfillmentInfoHtml + '
\ -
' + resolvedRecipe.costs + ' ' + __t('per serving') + '
\ +
\ +
' + recipe.name + '
\ +
' + __n(mealPlanEntry.servings, "%s serving", "%s servings") + '
\ +
' + fulfillmentIconHtml + " " + fulfillmentInfoHtml + '
\ +
' + resolvedRecipe.costs + ' ' + __t('per serving') + '
\
\ \ \ @@ -109,7 +109,7 @@ var calendar = $("#calendar").fullCalendar({ if (recipe.picture_file_name && !recipe.picture_file_name.isEmpty()) { - element.html(element.html() + '') + element.html(element.html() + '
') } }, "eventAfterAllRender": function(view) @@ -321,3 +321,17 @@ $(document).on("click", ".recipe-popup-button", function(e) } }); }); + +$(window).on("resize", function() +{ + // Automatically switch the calendar to "basicDay" view on small screens + // and to "basicWeek" otherwise + if ($(window).width() < 768) + { + calendar.fullCalendar("changeView", "basicDay"); + } + else + { + calendar.fullCalendar("changeView", "basicWeek"); + } +});