Skip to content

Litepicker: added filter hook for amount of months displayed (mobile) #1754

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 3 additions & 1 deletion assets/public/js/public.js
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,7 @@ document.addEventListener("DOMContentLoaded", () => {
lockDaysFormat: "YYYY-MM-DD",
lockDays: [],
lockDaysInclusivity: "[]",
mobileCalendarMonthCount: 1,
disallowLockDaysInRange: !0,
countLockedDays: !1,
countLockedDaysMax: 0,
Expand Down Expand Up @@ -1456,7 +1457,7 @@ document.addEventListener("DOMContentLoaded", () => {
window.addEventListener("orientationchange", function(e) {
var i = function() {
if (p.isMobile() && t.isShowning() && ("landscape" === p.getOrientation() ? (t.options.numberOfMonths = 2,
t.options.numberOfColumns = 2) : (t.options.numberOfMonths = 1,
t.options.numberOfColumns = 2) : (t.options.numberOfMonths = t.options.mobileCalendarMonthCount,
t.options.numberOfColumns = 1), t.render(), !t.options.inlineMode)) {
var e = t.picker.getBoundingClientRect();
t.picker.style.top = "calc(50% - " + e.height / 2 + "px)",
Expand Down Expand Up @@ -2042,6 +2043,7 @@ document.addEventListener("DOMContentLoaded", function(event) {
disallowLockDaysInRange: globalCalendarData["disallowLockDaysInRange"],
disallowHolidaysInRange: globalCalendarData["disallowLockDaysInRange"],
mobileFriendly: true,
mobileCalendarMonthCount: globalCalendarData["mobileCalendarMonthCount"],
selectForward: true,
useResetBtn: true,
maxDays: globalCalendarData["maxDays"],
Expand Down
2 changes: 1 addition & 1 deletion assets/public/js/src/lib/litepicker.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions assets/public/js/src/litepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ document.addEventListener("DOMContentLoaded", function (event) {
"disallowLockDaysInRange": globalCalendarData['disallowLockDaysInRange'],
"disallowHolidaysInRange": globalCalendarData['disallowLockDaysInRange'], //we treat holidays as locked days
"mobileFriendly": true,
"mobileCalendarMonthCount": globalCalendarData['mobileCalendarMonthCount'],
"selectForward": true,
"useResetBtn": true,
"maxDays": globalCalendarData['maxDays'],
Expand Down
14 changes: 14 additions & 0 deletions src/View/Calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,19 @@ private static function getDefaultCalendarEnddateTimestamp( $startDate ) {
return strtotime( 'last day of +3 months', $startDate->getDateObject()->getTimestamp() );
}

/**
* The value for the amount of months shown in the Litepicker mobile view portrait mode.
* Fixes #1103, an issue where one instance has issues with switching the months on mobile.
* This value is configurable through a filter hook only.
*
* Default value is 1.
*
* @return int
*/
private static function getMobileCalendarMonthCount(): int {
return apply_filters( 'commonsbooking_mobile_calendar_month_count', 1 );
}

/**
* Returns JSON-Data for Litepicker calendar.
*
Expand Down Expand Up @@ -546,6 +559,7 @@ public static function prepareJsonResponse(
'disallowLockDaysInRange' => true,
'countLockDaysInRange' => true,
'advanceBookingDays' => $advanceBookingDays,
'mobileCalendarMonthCount' => self::getMobileCalendarMonthCount(),
];

if ( count( $locations ) === 1 ) {
Expand Down