Hi all,
I am struggling to make my slider work. And the reason for sure is my lack of knowledge (which requires here CSS / AngularJS / JavaScript / HTML). Learned a lot of Javascript since starting with NodeRed, but the rest is not easy to handle all at once.
So, however, I'll proceed. Too be more precise at the moment I need some help replacing the part 'findRgbFromMousePosition' as from the hotNipi code to something like 'findRgbFromSliderPosition'. The translation part from one 'domain' to the other i.e. from the available slider range to the respective rgb range is aleady implemented. But I have no clue how to make this work for the slider range. Your help woule be much appreciated. BTW: This is where I am at the moment:
[{"id":"b891c72.ebed338","type":"inject","z":"51235c6b.bd5bb4","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":"1","topic":"","payload":"","payloadType":"date","x":405,"y":170,"wires":[["24bd9c6a.bdba34"]],"l":false},{"id":"24bd9c6a.bdba34","type":"function","z":"51235c6b.bd5bb4","name":"inject","func":"// create a random rgb colour\n\nmsg.payload = { \"title\":\"Demo\",\n \"red\": Math.floor(Math.random() * (255) ),\n \"green\": Math.floor(Math.random() * (255) ),\n \"blue\": Math.floor(Math.random() * (255) )\n}\n\nreturn msg;\n\n\n/*\n// Random Hex color\nmsg.payload = { \"title\":\"Demo\",\n \"hexcolor\": \"#\" + Math.floor(Math.random()*16777215).toString(16)\n}\n*/\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":530,"y":170,"wires":[["2255061b.a0ce1a","21b8504f.7fda3"]]},{"id":"2255061b.a0ce1a","type":"ui_template","z":"51235c6b.bd5bb4","group":"20ae1040.3cf58","name":"RGB slider","order":2,"width":"0","height":"0","format":"<style>\n.slidecontainer {\n\t/* font-size: 80%; */\n\twidth: 100%;\n}\n\n.slidecontainer input {\n\tmargin-bottom:9px;\n}\n/* slider bar */\n\n.slider {\n -webkit-appearance: none;\n width: 98%;\n height: 18px;\n border-radius: 18px;\n outline: none;\n padding: 0px 2px;\n}\n\n.spectrum {\n border-radius:10px;\n background: linear-gradient(\n to right,\n rgb(255 0 0),\n rgb(255 255 0),\n rgb(0 255 0),\n rgb(0 255 255),\n rgb(0 0 255),\n rgb(255 0 255),\n rgb(255 0 0)\n );\n}\n\n\n\n/* slider knopf */\n.slider::-webkit-slider-thumb {\n -webkit-appearance: none;\n appearance: none;\n width: 24px;\n height: 24px;\n border-radius: 50%;\n background: rgba({{msg.payload.red}},{{msg.payload.green}},{{msg.payload.blue}},1);\n border: 2px solid white;\n cursor: pointer;\n box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);\n}\n\n</style>\n\n<div class=\"slidecontainer\">\n\tRGB ({{msg.payload.red}},{{msg.payload.green}},{{msg.payload.blue}})\n\t<input type=\"range\" min=\"0\" max=\"255\" value=\"{{msg.payload.red}}\" class=\"slider spectrum\" ng-model=\"msg.payload.red\" ng-mouseup=\"send(msg)\">\n</div>\n\n<script>\n \n \n(function($scope) {\n \n\nconst spectrumRanges = [\n { from: [255, 0, 0], to: [255, 255, 0] },\n { from: [255, 255, 0], to: [0, 255, 0] },\n { from: [0, 255, 0], to: [0, 255, 255] },\n { from: [0, 255, 255], to: [0, 0, 255] },\n { from: [0, 0, 255], to: [255, 0, 255] },\n { from: [255, 0, 255], to: [255, 0, 0] }\n];\n\nconst findColorValue = (from, to, leftRatio) => {\n return Math.round(from + (to - from) * leftRatio);\n};\n\nconst findRgbFromMousePosition = (event) => {\n const wrapper = document.querySelector(\".wrapper\");\n const { clientX } = event;\n const { left, width } = wrapper.getBoundingClientRect();\n const leftDistance = Math.min(Math.max(clientX - left, 0), width - 1);\n const totalRanges = spectrumRanges.length;\n const rangeWidth = width / totalRanges;\n const includedRange = Math.floor(leftDistance / rangeWidth);\n const leftRatio = ((leftDistance % rangeWidth) / rangeWidth).toFixed(2);\n const { from, to } = spectrumRanges[includedRange];\n return {\n r: findColorValue(from[0], to[0], leftRatio),\n g: findColorValue(from[1], to[1], leftRatio),\n b: findColorValue(from[2], to[2], leftRatio)\n };\n};\n\nconst rgbToHex = (r, g, b) => {\n const toHex = (rgb) => {\n let hex = Number(rgb).toString(16);\n if (hex.length < 2) {\n hex = `0${hex}`;\n }\n return hex;\n };\n const red = toHex(r);\n const green = toHex(g);\n const blue = toHex(b);\n return `#${red}${green}${blue}`;\n};\n\n\n$('.wrapper').on('click', function(e) {\n e.preventDefault(); //prevent default behavior\n var { r, g, b } = findRgbFromMousePosition(e);\n var hexValue = rgbToHex(r, g, b);\n $scope.send({\"topic\":\"color\",\"payload\": hexValue});\n});\n \n})(scope);\n\n</script>\n\n","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":true,"templateScope":"local","x":690,"y":170,"wires":[[]]},{"id":"21b8504f.7fda3","type":"debug","z":"51235c6b.bd5bb4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":690,"y":210,"wires":[]},{"id":"20ae1040.3cf58","type":"ui_group","name":"Group 1","tab":"6b520bda.e997a4","order":1,"disp":true,"width":"6","collapse":false},{"id":"6b520bda.e997a4","type":"ui_tab","name":"Experimentieren","icon":"dashboard","disabled":false,"hidden":false}]