Node-Red configuration
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

ui_colour_picker.js 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. module.exports = function(RED) {
  2. var ui = require('../ui')(RED);
  3. var tc = require('../dist/js/tinycolor-min');
  4. function ColourPickerNode(config) {
  5. RED.nodes.createNode(this, config);
  6. this.format = config.format;
  7. this.outformat = config.outformat;
  8. var node = this;
  9. var group = RED.nodes.getNode(config.group);
  10. if (!group) { return; }
  11. var tab = RED.nodes.getNode(group.config.tab);
  12. if (!tab) { return; }
  13. node.on("input", function(msg) {
  14. node.topi = msg.topic;
  15. });
  16. var done = ui.add({
  17. node: node,
  18. tab: tab,
  19. group: group,
  20. forwardInputMessages: config.passthru,
  21. control: {
  22. type: 'colour-picker',
  23. label: config.label,
  24. format: config.format,
  25. showPicker: config.showPicker,
  26. showSwatch: config.showSwatch,
  27. showValue: config.showValue,
  28. showHue: config.showHue,
  29. showAlpha: config.showAlpha,
  30. showLightness: config.showLightness,
  31. square: (config.square == 'true') || false,
  32. dynOutput: config.dynOutput,
  33. allowEmpty: true,
  34. order: config.order,
  35. value: '',
  36. width: config.width || group.config.width || 6,
  37. height: config.height || 1,
  38. className: config.className || '',
  39. },
  40. beforeSend: function (msg) {
  41. if (node.outformat === 'object') {
  42. var pay = tc(msg.payload);
  43. if (node.format === 'rgb') { msg.payload = pay.toRgb(); }
  44. if (node.format === 'hsl') { msg.payload = pay.toHsl(); }
  45. if (node.format === 'hsv') { msg.payload = pay.toHsv(); }
  46. }
  47. var t = RED.util.evaluateNodeProperty(config.topic,config.topicType || "str",node,msg) || node.topi;
  48. if (t) { msg.topic = t; }
  49. },
  50. convert: function(p,o,m) {
  51. if (m.payload === undefined || m.payload === null) { return; }
  52. var colour = tc(m.payload);
  53. return colour.toString(config.format);
  54. }
  55. });
  56. node.on("close", done);
  57. }
  58. RED.nodes.registerType("ui_colour_picker", ColourPickerNode);
  59. };