[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
This commit is contained in:
Jeremy Kersten
2020-08-18 17:40:16 +00:00
committed by Laurent Stukkens (LTU)
parent d43d791f3e
commit 8fb2ac4e65
+13 -1
View File
@@ -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);
}
}