mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
Keep card-detail sub-popups open on touch when assigning a user / setting the due date (#5942); render minicards one-per-row and make the Home button a proper tap target (#5902); clamp enormous icon/text sizing (#6018); and trim excessive padding/margins (#5982). Mobile overrides are scoped under media queries in a new responsiveFixes.css; isMobileViewport helper unit tested. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
47 lines
1.8 KiB
JavaScript
47 lines
1.8 KiB
JavaScript
// Small, dependency-free helpers for responsive / mobile behaviour.
|
|
//
|
|
// Kept deliberately tiny and pure so it can be unit-tested without a DOM
|
|
// (see client/lib/tests/responsive.tests.js). UI code (e.g. the mobile popup
|
|
// fix in client/components/main/popup.js) imports these helpers instead of
|
|
// hard-coding viewport breakpoints in several places.
|
|
|
|
// Default breakpoint (px) below which we treat the viewport as "mobile".
|
|
// Matches the 768px tablet/phone boundary used across the responsive CSS.
|
|
export const MOBILE_BREAKPOINT = 768;
|
|
|
|
/**
|
|
* Decide whether a given viewport width should be treated as a mobile/narrow
|
|
* layout.
|
|
*
|
|
* @param {number} width viewport width in CSS pixels
|
|
* @param {number} breakpoint width at/below which we consider it mobile
|
|
* @returns {boolean} true when width is a valid number <= breakpoint
|
|
*/
|
|
export function isMobileViewport(width, breakpoint = MOBILE_BREAKPOINT) {
|
|
if (typeof width !== 'number' || Number.isNaN(width)) {
|
|
return false;
|
|
}
|
|
return width <= breakpoint;
|
|
}
|
|
|
|
/**
|
|
* Convenience wrapper that reads the current browser width. Falls back to a
|
|
* desktop width when there is no window object (e.g. during unit tests / SSR).
|
|
*
|
|
* @param {number} breakpoint width at/below which we consider it mobile
|
|
* @returns {boolean}
|
|
*/
|
|
export function isMobileViewportNow(breakpoint = MOBILE_BREAKPOINT) {
|
|
if (typeof window === 'undefined' || typeof window.innerWidth !== 'number') {
|
|
return false;
|
|
}
|
|
return isMobileViewport(window.innerWidth, breakpoint);
|
|
}
|
|
|
|
// Also expose on window for non-module callers / debugging, mirroring the
|
|
// pattern used by client/lib/utils.js and client/lib/popup.js.
|
|
if (typeof window !== 'undefined') {
|
|
window.isMobileViewport = isMobileViewport;
|
|
window.isMobileViewportNow = isMobileViewportNow;
|
|
}
|