From 9fbf91db06a6d4f4b5cd8bb45389a731bb86bf22 Mon Sep 17 00:00:00 2001 From: Richard Date: Sun, 13 Apr 2025 18:48:02 +0100 Subject: initial --- site/app/base/controls.js | 214 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 214 insertions(+) create mode 100644 site/app/base/controls.js (limited to 'site/app/base/controls.js') diff --git a/site/app/base/controls.js b/site/app/base/controls.js new file mode 100644 index 0000000..331f88b --- /dev/null +++ b/site/app/base/controls.js @@ -0,0 +1,214 @@ +var Control = function(definition) { + var self = this; + var state = false; + var type; + var element; + var elTextInput; + + + + if (!definition.hasOwnProperty("channel")) { + definition.channel = definition.name.toLowerCase(); + } + + if (!definition.hasOwnProperty("min")) { + definition.min = 0; + } + + if (!definition.hasOwnProperty("max")) { + definition.max = 1; + } + + if (!definition.hasOwnProperty("step")) { + definition.step = 0.000001; + } + + if (!definition.hasOwnProperty("dfault")) { + definition.dfault = 0; + } + + Object.defineProperty(this, "element", { + get: function() {return element;}, + set: function(v) {} + }); + + Object.defineProperty(this, "textInputElement", { + get: function() {return elTextInput;}, + set: function(v) {} + }); + + Object.defineProperty(this, "elementRow", { + get: function() { + var tr = $(""); + $("").text(definition.name).appendTo(tr); + $("").append(element).appendTo(tr); + var tinput = $("").appendTo(tr); + if (elTextInput) { + tinput.append(elTextInput); + } + return tr; + }, + set: function(v) {} + }); + + Object.defineProperty(this, "value", { + get: function() { + var val; + if (type == "select") { + val = element.val(); + if (definition.asValue) { + val = definition.options[val]; + } + } else if (type == "range") { + val = element.val(); + } else if (type == "checkbox") { + val = (element.is(":checked")) ? definition.max : definition.min; + } else if (type == "button") { + val = 0; + } else if (type == "toggle") { + val = (state) ? definition.max : definition.min; + } + + return val; + }, + set: function(v) { + if (type == "checkbox") { + element.prop("checked", v); + } else { + element.val(v); + } + } + }); + + async function createControl() { + if (definition.options) { + type = "select"; + element = $("").attr("type", "range").addClass("input-knob").attr("data-diameter", json.cellh).attr("data-src", baseurl + json.fn).attr("data-sprites", json.frames - 1).attr("data-height", height).attr("data-width", width); + type = "range"; + } else if (json.ctltype == 1 || json.ctltype == 3) { + element = $("").attr("type", "range").addClass("input-slider").attr("data-height", height).attr("data-src", baseurl + json.fn).attr("data-width", width).attr("data-sprites", json.frames - 1); //.css({width: width, height: height}); + type = "range"; + } else if (json.ctltype == 2) { + element = $("").attr("type", "checkbox").addClass("input-switch").attr("data-height", height).attr("data-width", width).attr("data-src", baseurl + json.fn); + type = "checkbox"; + } + } else { + if (!definition.type || definition.type == "range") { + type = "range"; + element = $("").attr("type", "range"); + } else if (definition.type == "toggle") { + type = "toggle"; + element = $("