mirror of
https://github.com/beestat/app.git
synced 2025-08-11 09:13:50 -04:00
Added ability to detect touch-enabled devices...because why not?
This commit is contained in:
parent
b096b4e6c5
commit
3c30398304
38
js/beestat/touch.js
Normal file
38
js/beestat/touch.js
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
/**
|
||||||
|
* Detect if the device is touch enabled.
|
||||||
|
*
|
||||||
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTTP/Browser_detection_using_the_user_agent
|
||||||
|
* @return {boolean} Whether or not the device is touch enabled.
|
||||||
|
*/
|
||||||
|
beestat.touch = function() {
|
||||||
|
return true;
|
||||||
|
if (beestat.touch_ !== undefined) {
|
||||||
|
return beestat.touch_;
|
||||||
|
}
|
||||||
|
|
||||||
|
let touch = false;
|
||||||
|
if ('maxTouchPoints' in navigator) {
|
||||||
|
touch = navigator.maxTouchPoints > 0;
|
||||||
|
} else if ('msMaxTouchPoints' in navigator) {
|
||||||
|
touch = navigator.msMaxTouchPoints > 0;
|
||||||
|
} else {
|
||||||
|
var mq = window.matchMedia && matchMedia('(pointer:coarse)');
|
||||||
|
if (mq && mq.media === '(pointer:coarse)') {
|
||||||
|
touch = Boolean(mq.matches);
|
||||||
|
} else if ('orientation' in window) {
|
||||||
|
// Deprecated, but good fallback
|
||||||
|
touch = true;
|
||||||
|
} else {
|
||||||
|
// Only as a last resort, fall back to user agent sniffing
|
||||||
|
var UA = navigator.userAgent;
|
||||||
|
touch = (
|
||||||
|
(/\b(BlackBerry|webOS|iPhone|IEMobile)\b/i).test(UA) ||
|
||||||
|
(/\b(Android|Windows Phone|iPad|iPod)\b/i).test(UA)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cache result
|
||||||
|
beestat.touch_ = touch;
|
||||||
|
return beestat.touch_;
|
||||||
|
};
|
@ -37,6 +37,7 @@ if($setting->get('environment') === 'dev' || $setting->get('environment') === 'd
|
|||||||
echo '<script src="/js/beestat/runtime_sensor.js"></script>' . PHP_EOL;
|
echo '<script src="/js/beestat/runtime_sensor.js"></script>' . PHP_EOL;
|
||||||
echo '<script src="/js/beestat/sensor.js"></script>' . PHP_EOL;
|
echo '<script src="/js/beestat/sensor.js"></script>' . PHP_EOL;
|
||||||
echo '<script src="/js/beestat/requestor.js"></script>' . PHP_EOL;
|
echo '<script src="/js/beestat/requestor.js"></script>' . PHP_EOL;
|
||||||
|
echo '<script src="/js/beestat/touch.js"></script>' . PHP_EOL;
|
||||||
|
|
||||||
// Layer
|
// Layer
|
||||||
echo '<script src="/js/layer.js"></script>' . PHP_EOL;
|
echo '<script src="/js/layer.js"></script>' . PHP_EOL;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user