21 lines
750 B
JavaScript
21 lines
750 B
JavaScript
|
|
/**
|
||
|
|
* DEVICE DETECTION
|
||
|
|
* Detects real mobile devices vs desktop browser in mobile view
|
||
|
|
* Adds 'is-mobile-device' class to body for styling differences
|
||
|
|
*/
|
||
|
|
|
||
|
|
(function() {
|
||
|
|
// Check if user agent indicates a real mobile device
|
||
|
|
const isMobileDevice = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
|
||
|
|
|
||
|
|
// Also check for touch support (additional indicator)
|
||
|
|
const hasTouch = 'ontouchstart' in window || navigator.maxTouchPoints > 0;
|
||
|
|
|
||
|
|
// Consider it a real mobile device if both conditions are met
|
||
|
|
if (isMobileDevice && hasTouch) {
|
||
|
|
document.documentElement.classList.add('is-mobile-device');
|
||
|
|
} else {
|
||
|
|
document.documentElement.classList.add('is-desktop');
|
||
|
|
}
|
||
|
|
})();
|