From 78b9dad560aec804bf67eb7e656443bac9caefbf Mon Sep 17 00:00:00 2001 From: Romeo Fragomeli Date: Thu, 17 Oct 2019 13:54:53 +0000 Subject: [PATCH] [REF] web,barcodes: simplify mobile device detection In this commit, we introduce "isMobileDevice". Do not confuse with isMobile. isMobile: 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 the size is XS/VSM/SM. It is also updated dynamically. isMobileDevice: Mobile device detection using userAgent. This flag doesn't depend on the size/resolution of the screen. It targets mobile devices which suggests that there is a virtual keyboard. Task ID: 2090202 --- addons/barcodes/static/src/js/barcode_events.js | 10 ++-------- addons/web/static/src/js/services/config.js | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/addons/barcodes/static/src/js/barcode_events.js b/addons/barcodes/static/src/js/barcode_events.js index 5fcd68ac680..b07cf7bd19b 100644 --- a/addons/barcodes/static/src/js/barcode_events.js +++ b/addons/barcodes/static/src/js/barcode_events.js @@ -1,6 +1,7 @@ odoo.define('barcodes.BarcodeEvents', function(require) { "use strict"; +var config = require('web.config'); var core = require('web.core'); var mixins = require('web.mixins'); var session = require('web.session'); @@ -46,14 +47,7 @@ var BarcodeEvents = core.Class.extend(mixins.PropertiesMixin, { $(_.bind(this.start, this, false)); // Mobile device detection - var isMobile = navigator.userAgent.match(/Android/i) || - navigator.userAgent.match(/webOS/i) || - navigator.userAgent.match(/iPhone/i) || - navigator.userAgent.match(/iPad/i) || - navigator.userAgent.match(/iPod/i) || - navigator.userAgent.match(/BlackBerry/i) || - navigator.userAgent.match(/Windows Phone/i); - this.isChromeMobile = isMobile && navigator.userAgent.match(/Chrome/i); + this.isChromeMobile = config.device.isMobileDevice && navigator.userAgent.match(/Chrome/i); // Creates an input who will receive the barcode scanner value. this.$barcodeInput = $('', { diff --git a/addons/web/static/src/js/services/config.js b/addons/web/static/src/js/services/config.js index 8412c1319a8..91c3f1c764c 100644 --- a/addons/web/static/src/js/services/config.js +++ b/addons/web/static/src/js/services/config.js @@ -34,6 +34,20 @@ var config = { * @type Boolean */ isMobile: null, + /** + * Mobile device detection using userAgent. + * This flag doesn't depend on the size/resolution of the screen. + * It targets mobile devices which suggests that there is a virtual keyboard. + * + * @return {boolean} + */ + isMobileDevice: navigator.userAgent.match(/Android/i) || + navigator.userAgent.match(/webOS/i) || + navigator.userAgent.match(/iPhone/i) || + navigator.userAgent.match(/iPad/i) || + navigator.userAgent.match(/iPod/i) || + navigator.userAgent.match(/BlackBerry/i) || + navigator.userAgent.match(/Windows Phone/i), /** * Mapping between the numbers 0,1,2,3,4,5,6 and some descriptions */