Skip to content

Commit

Permalink
fixed bug with input msg click emulation
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianStremel committed Sep 19, 2024
1 parent 36a5f50 commit 7648ef5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
9 changes: 8 additions & 1 deletion nodes/widgets/ui_button.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ module.exports = function (RED) {
let payload = null
let payloadType = null

switch (msg.type) {
msg._event = msg._event || {"type": "inject"}

switch (msg._event.type) {
case 'pointerup':
payload = config.pointerupPayload
payloadType = config.pointerupPayloadType
Expand All @@ -28,6 +30,10 @@ module.exports = function (RED) {
payload = config.payload
payloadType = config.payloadType
break
case 'inject':
payload = config.payload
payloadType = config.payloadType
break
default:
payload = config.payload
payloadType = config.payloadType
Expand Down Expand Up @@ -105,6 +111,7 @@ module.exports = function (RED) {
beforeSend,
onInput: async function (msg) {
if (config.emulateClick) {

msg = await beforeSend(msg)

if (config.topic || config.topicType) {
Expand Down
9 changes: 3 additions & 6 deletions ui/src/widgets/ui-button/UIButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,46 +65,43 @@ export default {
methods: {
action ($evt) {
const evt = {
type: 'click',
type: $evt.type,
clientX: $evt.clientX,
clientY: $evt.clientY,
bbox: $evt.target.getBoundingClientRect()
}
const msg = this.messages[this.id] || {}
msg._event = evt
msg.type = 'click'
this.$socket.emit('widget-action', this.id, msg)
},
pointerdown: function ($evt) {
if (!this.props.enablePointerdown) {
return
}
const evt = {
type: 'click',
type: $evt.type,
clientX: $evt.clientX,
clientY: $evt.clientY,
bbox: $evt.target.getBoundingClientRect()
}
const msg = this.messages[this.id] || {}
msg._event = evt
$evt.target.setPointerCapture($evt.pointerId)
msg.type = 'pointerdown'
this.$socket.emit('widget-action', this.id, msg)
},
pointerup: function ($evt) {
if (!this.props.enablePointerup) {
return
}
const evt = {
type: 'click',
type: $evt.type,
clientX: $evt.clientX,
clientY: $evt.clientY,
bbox: $evt.target.getBoundingClientRect()
}
const msg = this.messages[this.id] || {}
msg._event = evt
$evt.target.releasePointerCapture($evt.pointerId)
msg.type = 'pointerup'
this.$socket.emit('widget-action', this.id, msg)
},
Expand Down

0 comments on commit 7648ef5

Please sign in to comment.