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

This commit is contained in:
jean-emmanuel 2018-01-24 13:52:15 +01:00
parent be0e506e2a
commit 9119cb43f5
2 changed files with 4 additions and 2 deletions

View file

@ -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

View file

@ -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)=>{