From 9119cb43f5abff631df58932d5e6bc002834d1c0 Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Wed, 24 Jan 2018 13:52:15 +0100 Subject: [PATCH] widgets: set root's parent (aka manager) in base class constructor to allow all events from its children to bubble up to the manager while they are parsed --- src/browser/js/app/widgets/common/_widgets_base.js | 4 +++- src/browser/js/app/widgets/containers/root.js | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/browser/js/app/widgets/common/_widgets_base.js b/src/browser/js/app/widgets/common/_widgets_base.js index 0ffb28c9..1852aa2e 100644 --- a/src/browser/js/app/widgets/common/_widgets_base.js +++ b/src/browser/js/app/widgets/common/_widgets_base.js @@ -31,7 +31,7 @@ module.exports = class _widgets_base extends EventEmitter { this.container = options.container || fallbackContainer this.widget = DOM.create(options.html) this.props = options.props - this.parent = options.parent + this.parent = options.root ? widgetManager : options.parent this.parentNode = options.parentNode this.hash = _widgets_base.createHash() this.childrenHashes = [] @@ -101,6 +101,8 @@ module.exports = class _widgets_base extends EventEmitter { this.precision = Math.min(20,Math.max(this.getProp('precision', undefined, false),0)) } + if (this.getProp('id') == 'root' && !options.root) throw new Error('There can only be one root') + this.on('widget-created', (e)=>{ if (e.widget == this) return diff --git a/src/browser/js/app/widgets/containers/root.js b/src/browser/js/app/widgets/containers/root.js index b4616f59..cf7531c0 100644 --- a/src/browser/js/app/widgets/containers/root.js +++ b/src/browser/js/app/widgets/containers/root.js @@ -40,13 +40,13 @@ module.exports = class Root extends Panel { constructor(options) { + options.root = true options.props.id = 'root' options.props.scroll = true options.props.label = false super(options) - this.parent = widgetManager this.widget.classList.add('root') DOM.each(this.widget, '> .navigation', (el)=>{