40 lines
1.1 KiB
JavaScript
40 lines
1.1 KiB
JavaScript
function RotarySwitch(parentElement)
|
|
{
|
|
console.log("found rotarySwitch");
|
|
console.log(parentElement);
|
|
|
|
this.ParentElement = parentElement;
|
|
this.ValueElement = this.ParentElement.children[0];
|
|
this.ListElement = this.ParentElement.children[1];
|
|
this.IndicatorElement = this.ParentElement.children[2];
|
|
this.AngleOffset = -135;
|
|
|
|
this.setValue = function(value, angle)
|
|
{
|
|
this.ValueElement.value = value;
|
|
console.log("new angle: " + (angle + this.AngleOffset));
|
|
this.IndicatorElement.style.transform = "rotate(" + (angle + this.AngleOffset) + "deg)";
|
|
};
|
|
|
|
for (var i = 0; i < this.ListElement.children.length; i++)
|
|
{
|
|
this.ListElement.children[i].children[0].NativeObject = this;
|
|
this.ListElement.children[i].children[0].addEventListener("click", function(e)
|
|
{
|
|
this.NativeObject.setValue(this.getAttribute("data-value"), parseFloat(this.getAttribute("data-angle")));
|
|
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
return false;
|
|
});
|
|
}
|
|
}
|
|
|
|
window.addEventListener("load", function()
|
|
{
|
|
var items = document.getElementsByClassName("uwt-rotaryswitch");
|
|
for (var i = 0; i < items.length; i++)
|
|
{
|
|
items[i].NativeObject = new RotarySwitch(items[i]);
|
|
}
|
|
}); |