/!\ events: groundwork for containers onTouch scripts:

Drag events are now reverse-bubbling (from parents to child) to allow containers to monitor/control interaction inside them
This commit is contained in:
jean-emmanuel 2025-03-21 09:23:44 +01:00
parent e001d3be10
commit 4d30880d0f
6 changed files with 79 additions and 9 deletions

View file

@ -45,6 +45,9 @@ class Panel extends Container() {
children: {
widgets: {type: 'array', value: [], help: 'Each element of the array must be a widget object. A panel cannot contain widgets and tabs simultaneously.'},
tabs: {type: 'array', value: [], help: 'Each element of the array must be a tab object. A panel cannot contain widgets and tabs simultaneously'},
},
scripting: {
onTouch: {type: 'script', value: '', editor:'javascript', help: ['Script executed when the session is touched and released, and when the pointer moves when the widget is touched. See <a href="https://openstagecontrol.ammd.net/docs/widgets/canvas/">documentation</a>.',]},
}
})
@ -267,6 +270,12 @@ class Panel extends Container() {
if (this.getProp('traversing')) this.setTraversing()
if (this.getProp('onTouch')) {
this.on('draginit',(e)=>this.onTouch(e, 'start'), {element: this.container, multitouch: true})
this.on('drag',(e)=>this.onTouch(e, 'move'), {element: this.container, multitouch: true})
this.on('dragend',(e)=>this.onTouch(e, 'stop'), {element: this.container, multitouch: true})
}
}
createNavigation() {
@ -348,6 +357,30 @@ class Panel extends Container() {
}
onTouch(e, name) {
var event = {...e}
delete event.firstTarget
event.targetName = event.target.getAttribute('name')
event.targetTagName = event.target.tagName
var w = widgetManager.getWidgetByElement(event.target)
if (w) event.target = w === this ? 'this' : w.getProp('id')
else event.target = null
event.type = name
this.scripts.onTouch.run({
value: this.value,
event: event
}, {sync: true, send: true})
if (name != 'stop' && event.preventDefault) e.preventDefault = true
if (event.allowScroll) e.allowScroll = true
}
onPropChanged(propName, options, oldPropValue) {
if (super.onPropChanged(...arguments)) return true

View file

@ -47,6 +47,7 @@ class Root extends StaticProperties(Panel, {visible: true, label: false, id: 'ro
super(options)
this.widget.classList.add('root')
this.root = true
this.checkMenuVisibility()
@ -61,7 +62,7 @@ class Root extends StaticProperties(Panel, {visible: true, label: false, id: 'ro
if (READ_ONLY) return
mainMenu = mainMenu || require('../../ui/main-menu')
if (this.getProp('hideMenu')) {
mainMenu.container.style.display = 'none'
} else {

View file

@ -119,8 +119,6 @@ class MultiXy extends Pad {
if (!i) return
e.stopPropagation = true
this.pads[i].touched = 0
this.pads[i].trigger('dragend', e)
@ -146,8 +144,6 @@ class MultiXy extends Pad {
if (!id) return
e.stopPropagation = true
this.trigger('touch', {stopPropagation: true, touch: [parseInt(id), 1]})
this.pads[id].trigger('draginit', e)