[IMP] web: feature detection impl. normalization
This commit normalizes the different feature/browser detection modules' implementations to avoid difference between "newer" implementation and legacy ones. Its main goal is to ease future maintainability by having only one single source of truth for feature detection and, also ensure fixes applied to one version are applied everywhere. closes odoo/odoo#79499 X-original-commit: 3b90e15983edcb79e6bd6e45685926cd4dfaae6b Signed-off-by: Adrien Dieudonné (adr) <adr@odoo.com> Signed-off-by: Pierre Paridans (app) <app@odoo.com>
This commit is contained in:
@@ -15,26 +15,35 @@ export function isBrowserChrome() {
|
||||
return browser.navigator.userAgent.includes("Chrome");
|
||||
}
|
||||
|
||||
export function isAndroid() {
|
||||
return /Android/i.test(browser.navigator.userAgent);
|
||||
}
|
||||
|
||||
export function isIOS() {
|
||||
return /(iPad|iPhone|iPod)/i.test(browser.navigator.userAgent) ||
|
||||
(browser.navigator.platform === 'MacIntel' && maxTouchPoints() > 1);
|
||||
}
|
||||
|
||||
export function isOtherMobileOS() {
|
||||
return /(webOS|BlackBerry|Windows Phone)/i.test(browser.navigator.userAgent);
|
||||
}
|
||||
|
||||
export function isMacOS() {
|
||||
return Boolean(browser.navigator.userAgent.match(/Mac/i));
|
||||
}
|
||||
|
||||
export function isMobileOS() {
|
||||
return Boolean(
|
||||
browser.navigator.userAgent.match(/Android/i) ||
|
||||
browser.navigator.userAgent.match(/webOS/i) ||
|
||||
browser.navigator.userAgent.match(/iPhone/i) ||
|
||||
browser.navigator.userAgent.match(/iPad/i) ||
|
||||
browser.navigator.userAgent.match(/iPod/i) ||
|
||||
browser.navigator.userAgent.match(/BlackBerry/i) ||
|
||||
browser.navigator.userAgent.match(/Windows Phone/i)
|
||||
);
|
||||
return isAndroid() || isIOS() || isOtherMobileOS();
|
||||
}
|
||||
|
||||
export function isIosApp() {
|
||||
return navigator.userAgent.match(/OdooMobile \(iOS\)/i);
|
||||
return /OdooMobile \(iOS\)/i.test(browser.navigator.userAgent);
|
||||
}
|
||||
|
||||
export function hasTouch() {
|
||||
return "ontouchstart" in window || "onmsgesturechange" in window;
|
||||
}
|
||||
|
||||
export function maxTouchPoints() {
|
||||
return browser.navigator.maxTouchPoints || 1;
|
||||
}
|
||||
|
||||
@@ -1,19 +1,14 @@
|
||||
odoo.define('web.BrowserDetection', function (require) {
|
||||
"use strict";
|
||||
var Class = require('web.Class');
|
||||
const { isMacOS, isBrowserChrome } = require('@web/core/browser/feature_detection');
|
||||
|
||||
var BrowserDetection = Class.extend({
|
||||
init: function () {
|
||||
|
||||
},
|
||||
isOsMac: function () {
|
||||
return navigator.platform.toLowerCase().indexOf('mac') !== -1;
|
||||
},
|
||||
isBrowserChrome: function () {
|
||||
return $.browser.chrome && // depends on jquery 1.x, removed in jquery 2 and above
|
||||
navigator.userAgent.toLocaleLowerCase().indexOf('edge') === -1; // as far as jquery is concerned, Edge is chrome
|
||||
}
|
||||
|
||||
isOsMac: isMacOS,
|
||||
isBrowserChrome,
|
||||
});
|
||||
return BrowserDetection;
|
||||
});
|
||||
|
||||
@@ -2,6 +2,7 @@ odoo.define('web.config', function (require) {
|
||||
"use strict";
|
||||
|
||||
const Bus = require('web.Bus');
|
||||
const { hasTouch, isAndroid, isIOS, isMobileOS } = require('@web/core/browser/feature_detection');
|
||||
|
||||
const bus = new Bus();
|
||||
|
||||
@@ -14,11 +15,6 @@ const bus = new Bus();
|
||||
* this file someday.
|
||||
*/
|
||||
|
||||
const maxTouchPoints = navigator.maxTouchPoints || 1;
|
||||
const isAndroid = /Android/i.test(navigator.userAgent);
|
||||
const isIOS = /(iPad|iPhone|iPod)/i.test(navigator.userAgent) || (navigator.platform === 'MacIntel' && maxTouchPoints > 1);
|
||||
const isOtherMobileDevice = /(webOS|BlackBerry|Windows Phone)/i.test(navigator.userAgent);
|
||||
|
||||
var config = {
|
||||
device: {
|
||||
/**
|
||||
@@ -33,7 +29,7 @@ var config = {
|
||||
*
|
||||
* @type Boolean
|
||||
*/
|
||||
touch: 'ontouchstart' in window || 'onmsgesturechange' in window,
|
||||
touch: hasTouch(),
|
||||
/**
|
||||
* size_class is an integer: 0, 1, 2, 3 or 4, depending on the (current)
|
||||
* size of the device. This is a dynamic property, updated whenever the
|
||||
@@ -48,14 +44,14 @@ var config = {
|
||||
*
|
||||
* @return Boolean
|
||||
*/
|
||||
isAndroid: isAndroid,
|
||||
isAndroid: isAndroid(),
|
||||
/**
|
||||
* Mobile OS (iOS) device detection using userAgent.
|
||||
* This flag doesn't depend on the size/resolution of the screen.
|
||||
*
|
||||
* @return Boolean
|
||||
*/
|
||||
isIOS: isIOS,
|
||||
isIOS: isIOS(),
|
||||
/**
|
||||
* A frequent use case is to have a different render in 'mobile' mode,
|
||||
* meaning when the screen is small. This flag (boolean) is true when
|
||||
@@ -71,7 +67,7 @@ var config = {
|
||||
*
|
||||
* @return {boolean}
|
||||
*/
|
||||
isMobileDevice: isAndroid || isIOS || isOtherMobileDevice,
|
||||
isMobileDevice: isMobileOS(),
|
||||
/**
|
||||
* Mapping between the numbers 0,1,2,3,4,5,6 and some descriptions
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user