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 all commits
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: 4 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ CommonsBooking is a plugin for the management and booking of common goods. This
> This might fail, if you don't have the PHP extension [uopz](https://www.php.net/manual/en/book.uopz.php) installed. Try running `composer install --no-dev && npm install && npm run dist` if you just quickly want to test a specific branch without installing the extension.
5. Activate the plugin in the plugins dashboard

## Usage

Apart from the documentation mentioned above, we document the WordPress action and filter hooks in the following file: [docs/examples/filters.md](https://github.com/wielebenwir/commonsbooking/blob/master/docs/examples/filters.md)

## Contribute

Either through translating WordPress into your native tongue ([see the already existing WordPress Plugin Translations](https://translate.wordpress.org/projects/wp-plugins/commonsbooking/)) or through developing and testing new versions of the application.
Expand Down
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
23 changes: 23 additions & 0 deletions docs/examples/filters.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Hooks and Filters

WordPress and WordPress plugins can be customized via so-called [action hooks and filters](https://developer.wordpress.org/plugins/hooks/).
The customizations are defined in PHP code, so for example you need to place them as PHP code in the themes `functions.php` of your website.

## Actions

These are the [action hooks](https://developer.wordpress.org/plugins/hooks/actions/) exposed by the plugin.

## Filters

These are the [filter hooks](https://developer.wordpress.org/plugins/hooks/filters/) exposed by the plugin.

### Filter `commonsbooking_mobile_calendar_month_count`

Lets you define the number of months that are displayed in the mobile layout of the calendar view using a filter.

Example usage:

```php
// Sets the mobile calendar view to display 2 month
add_filter('commonsbooking_mobile_calendar_month_count', fn(): int => 2);
```
22 changes: 22 additions & 0 deletions src/View/Calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,27 @@ 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 {
$month = 1;
/**
* Default amount of months shown in the Litepicker mobile view portrait mode.
*
* @since 2.10.3
*
* @param int $month defaults is 1
*/
return apply_filters( 'commonsbooking_mobile_calendar_month_count', $month );
}

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

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