From 8fb2ac4e6518842ac2a9f85b7710953c0089b8e3 Mon Sep 17 00:00:00 2001 From: Jeremy Kersten Date: Tue, 18 Aug 2020 14:15:46 +0000 Subject: [IMP] web: add a size_changed bus event This commit will add a bus in the web.config config that allows to trigger events. The first use case is the trigger of the size_changed event that is triggered each time the size of the screen changed of bootstrap breakpoint. task-2276740 PR #53175 --- addons/web/static/src/js/services/config.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'addons/web/static/src/js') diff --git a/addons/web/static/src/js/services/config.js b/addons/web/static/src/js/services/config.js index 7ded43e291c..6c576c351bb 100644 --- a/addons/web/static/src/js/services/config.js +++ b/addons/web/static/src/js/services/config.js @@ -1,6 +1,10 @@ -odoo.define('web.config', function () { +odoo.define('web.config', function (require) { "use strict"; +const Bus = require('web.Bus'); + +const bus = new Bus(); + /** * This module contains all the (mostly) static 'environmental' information. * This is often necessary to allow the rest of the web client to properly @@ -12,6 +16,13 @@ odoo.define('web.config', function () { var config = { device: { + /** + * bus to use in order to be able to handle device config related events + * - 'size_changed' : triggered when window size is + * corresponding to a new bootstrap breakpoint. The new size_class + * is provided. + */ + bus: bus, /** * touch is a boolean, true if the device supports touch interaction * @@ -99,6 +110,7 @@ function _updateSizeProps() { if (sc !== config.device.size_class) { config.device.size_class = sc; config.device.isMobile = config.device.size_class <= config.device.SIZES.SM; + config.device.bus.trigger('size_changed', config.device.size_class); } } -- cgit v1.2.3