[REF] web: touch detection
- use 'browser' as abstraction, allowing to mock touch detection in
QUnit tests
- remove deprecated IE 10 touch detection (using non-standard
MSGestureChange event)
- some linting
Note: touch detection using "ontouchstart" is a quite common practice.
It's useful to note that, when in touch mode, browser's have different
values for it ("null" in Chrome, "Function" in Firefox...) but all
agrees to have "window.ontouchstart" being "undefined" when in non-touch
mode.
Part-of: odoo/odoo#95924
This commit is contained in:
@@ -40,6 +40,7 @@ export const browser = {
|
||||
fetch: window.fetch.bind(window),
|
||||
innerHeight: window.innerHeight,
|
||||
innerWidth: window.innerWidth,
|
||||
ontouchstart: window.ontouchstart,
|
||||
};
|
||||
|
||||
Object.defineProperty(browser, "location", {
|
||||
@@ -73,9 +74,7 @@ export function makeRAMLocalStorage() {
|
||||
return {
|
||||
setItem(key, value) {
|
||||
store[key] = value;
|
||||
window.dispatchEvent(
|
||||
new StorageEvent('storage', { key, newValue: value })
|
||||
);
|
||||
window.dispatchEvent(new StorageEvent("storage", { key, newValue: value }));
|
||||
},
|
||||
getItem(key) {
|
||||
return store[key];
|
||||
@@ -85,9 +84,7 @@ export function makeRAMLocalStorage() {
|
||||
},
|
||||
removeItem(key) {
|
||||
delete store[key];
|
||||
window.dispatchEvent(
|
||||
new StorageEvent('storage', { key, newValue: null })
|
||||
);
|
||||
window.dispatchEvent(new StorageEvent("storage", { key, newValue: null }));
|
||||
},
|
||||
get length() {
|
||||
return Object.keys(store).length;
|
||||
|
||||
@@ -20,8 +20,10 @@ export function isAndroid() {
|
||||
}
|
||||
|
||||
export function isIOS() {
|
||||
return /(iPad|iPhone|iPod)/i.test(browser.navigator.userAgent) ||
|
||||
(browser.navigator.platform === 'MacIntel' && maxTouchPoints() > 1);
|
||||
return (
|
||||
/(iPad|iPhone|iPod)/i.test(browser.navigator.userAgent) ||
|
||||
(browser.navigator.platform === "MacIntel" && maxTouchPoints() > 1)
|
||||
);
|
||||
}
|
||||
|
||||
export function isOtherMobileOS() {
|
||||
@@ -41,7 +43,7 @@ export function isIosApp() {
|
||||
}
|
||||
|
||||
export function hasTouch() {
|
||||
return "ontouchstart" in window || "onmsgesturechange" in window;
|
||||
return browser.ontouchstart !== undefined;
|
||||
}
|
||||
|
||||
export function maxTouchPoints() {
|
||||
|
||||
Reference in New Issue
Block a user