Add capability to send payload on mouse down or mouse up

This commit is contained in:
2023-08-31 19:14:13 +02:00
parent fbfb09a545
commit 3f95905578
+17 -3
View File
@@ -15,7 +15,7 @@ module.exports = function (RED) {
var heightPx = config.buttonheight * sizes.sy - sizes.gy;
var html = `<div style="width=100%; height=100%">
<md-button id="{{$index}}" style="width:${widthPx}px; height:${heightPx}px; margin: ${sizes.gx}px ${sizes.gy}px; background-color: {{button.color}}; white-space: pre-wrap; word-break: break-word;" ng-click="buttonClick($event)" ng-repeat="button in msg.buttons">{{button.label}}</md-button>
<md-button id="{{$index}}" style="width:${widthPx}px; height:${heightPx}px; margin: ${sizes.gx}px ${sizes.gy}px; background-color: {{button.color}}; white-space: pre-wrap; word-break: break-word;" ng-click="buttonClick($event)" ng-mousedown="buttonDown($event)" ng-mouseup="buttonUp($event)" ng-repeat="button in msg.buttons">{{button.label}}</md-button>
</div>`;
var done = ui.addWidget({
@@ -45,8 +45,22 @@ module.exports = function (RED) {
$scope.buttonClick = function (e) {
e.preventDefault();
var buttonId = e.target.id;
if ($scope.msg.buttons[buttonId].payload) {
$scope.send({ "payload": $scope.msg.buttons[buttonId].payload });
if ($scope.msg.buttons[buttonId].click) {
$scope.send($scope.msg.buttons[buttonId].click);
}
};
$scope.buttonDown = function (e) {
e.preventDefault();
var buttonId = e.target.id;
if ($scope.msg.buttons[buttonId].down) {
$scope.send($scope.msg.buttons[buttonId].down);
}
};
$scope.buttonUp = function (e) {
e.preventDefault();
var buttonId = e.target.id;
if ($scope.msg.buttons[buttonId].up) {
$scope.send($scope.msg.buttons[buttonId].up);
}
};
}