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 = $("