Compare commits

...

2 Commits

Author SHA1 Message Date
jjaeger b91c3be0b4 Center button group 2023-09-04 19:38:17 +02:00
jjaeger 3f95905578 Add capability to send payload on mouse down or mouse up 2023-08-31 19:14:13 +02:00
+18 -4
View File
@@ -14,8 +14,8 @@ module.exports = function (RED) {
var heightPx = config.buttonheight * sizes.sy - sizes.gy; var heightPx = config.buttonheight * sizes.sy - sizes.gy;
var html = `<div style="width=100%; height=100%"> var html = `<div style="width=100%; height=100%; display: flex; flex-wrap: wrap; justify-content: center;">
<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>`; </div>`;
var done = ui.addWidget({ var done = ui.addWidget({
@@ -45,8 +45,22 @@ module.exports = function (RED) {
$scope.buttonClick = function (e) { $scope.buttonClick = function (e) {
e.preventDefault(); e.preventDefault();
var buttonId = e.target.id; var buttonId = e.target.id;
if ($scope.msg.buttons[buttonId].payload) { if ($scope.msg.buttons[buttonId].click) {
$scope.send({ "payload": $scope.msg.buttons[buttonId].payload }); $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);
} }
}; };
} }