Skip to content

Commit

Permalink
Fixing sliders not updating properly
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas Bachschwell <[email protected]>
  • Loading branch information
s00500 committed Aug 26, 2020
1 parent eec13e4 commit 6506f6f
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 105 deletions.
154 changes: 97 additions & 57 deletions data/css/style.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion data/css/style.min.css

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions data/js/controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ function start() {
};

var handleEvent = function (evt) {
//console.log(evt);
console.log(evt);
var data = JSON.parse(evt.data);
var e = document.body;
var center = "";
Expand Down Expand Up @@ -750,7 +750,7 @@ function start() {
break;

case UPDATE_SLIDER:
slider_move($("#sl" + data.id), data.value, "100", false);
slider_move($("#id" + data.id), data.value, "100", false);
break;

case UPDATE_NUMBER:
Expand Down
4 changes: 2 additions & 2 deletions data/js/controls.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function restart(){$(document).add("*").off();$("#row").html("");websock.close()
function conStatusError(){websockConnected=false;$("#conStatus").removeClass("color-green");$("#conStatus").addClass("color-red");$("#conStatus").html("Error / No Connection &#8635;");$("#conStatus").off();$("#conStatus").on({click:restart,});}
function handleVisibilityChange(){if(!websockConnected&&!document.hidden){restart();}}
function start(){document.addEventListener("visibilitychange",handleVisibilityChange,false);if(window.location.port!=""||window.location.port!=80||window.location.port!=443){websock=new WebSocket("ws://"+window.location.hostname+":"+window.location.port+"/ws");}else{websock=new WebSocket("ws://"+window.location.hostname+"/ws");}
websock.onopen=function(evt){console.log("websock open");$("#conStatus").addClass("color-green");$("#conStatus").text("Connected");websockConnected=true;};websock.onclose=function(evt){console.log("websock close");conStatusError();};websock.onerror=function(evt){console.log(evt);conStatusError();};var handleEvent=function(evt){var data=JSON.parse(evt.data);var e=document.body;var center="";switch(data.type){case UI_INITIAL_GUI:$("#row").html("");$("#tabsnav").html("");$("#tabscontent").html("");if(data.sliderContinuous){sliderContinuous=data.sliderContinuous;}
websock.onopen=function(evt){console.log("websock open");$("#conStatus").addClass("color-green");$("#conStatus").text("Connected");websockConnected=true;};websock.onclose=function(evt){console.log("websock close");conStatusError();};websock.onerror=function(evt){console.log(evt);conStatusError();};var handleEvent=function(evt){console.log(evt);var data=JSON.parse(evt.data);var e=document.body;var center="";switch(data.type){case UI_INITIAL_GUI:$("#row").html("");$("#tabsnav").html("");$("#tabscontent").html("");if(data.sliderContinuous){sliderContinuous=data.sliderContinuous;}
data.controls.forEach(element=>{var fauxEvent={data:JSON.stringify(element),};handleEvent(fauxEvent);});break;case UI_RELOAD:window.location.reload();break;case UI_TITEL:document.title=data.label;$("#mainHeader").html(data.label);break;case UI_LABEL:var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");}
parent.append("<div id='id"+
data.id+
Expand Down Expand Up @@ -237,7 +237,7 @@ data.id+
"'></div><pre class='accelerometeroutput"+
data.id+
"'></pre>"+
"</div>");requestOrientationPermission();break;case UPDATE_LABEL:$("#l"+data.id).html(data.value);break;case UPDATE_SWITCHER:switcher(data.id,data.value=="0"?0:1);break;case UPDATE_SLIDER:slider_move($("#sl"+data.id),data.value,"100",false);break;case UPDATE_NUMBER:$("#num"+data.id).val(data.value);break;case UPDATE_TEXT_INPUT:$("#text"+data.id).val(data.value);break;case UPDATE_SELECT:$("#select"+data.id).val(data.value);break;case UPDATE_BUTTON:case UPDATE_PAD:case UPDATE_CPAD:break;case UPDATE_GAUGE:$("#gauge"+data.id).val(data.value);break;case UPDATE_ACCEL:break;default:console.error("Unknown type or event");break;}
"</div>");requestOrientationPermission();break;case UPDATE_LABEL:$("#l"+data.id).html(data.value);break;case UPDATE_SWITCHER:switcher(data.id,data.value=="0"?0:1);break;case UPDATE_SLIDER:slider_move($("#id"+data.id),data.value,"100",false);break;case UPDATE_NUMBER:$("#num"+data.id).val(data.value);break;case UPDATE_TEXT_INPUT:$("#text"+data.id).val(data.value);break;case UPDATE_SELECT:$("#select"+data.id).val(data.value);break;case UPDATE_BUTTON:case UPDATE_PAD:case UPDATE_CPAD:break;case UPDATE_GAUGE:$("#gauge"+data.id).val(data.value);break;case UPDATE_ACCEL:break;default:console.error("Unknown type or event");break;}
if(data.type>=UPDATE_OFFSET&&data.type<UI_INITIAL_GUI){var element=$("#id"+data.id);if(data.type==UPDATE_SLIDER){element.removeClass("slider-turquoise slider-emerald slider-peterriver slider-wetasphalt slider-sunflower slider-carrot slider-alizarin");element.addClass("slider-"+colorClass(data.color));}else{element.removeClass("turquoise emerald peterriver wetasphalt sunflower carrot alizarin");element.addClass(colorClass(data.color));}}};websock.onmessage=handleEvent;}
function sliderchange(number){var val=$("#sl"+number).val();websock.send("slvalue:"+val+":"+number);}
function numberchange(number){var val=$("#num"+number).val();websock.send("nvalue:"+val+":"+number);}
Expand Down
19 changes: 10 additions & 9 deletions data/js/slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function rkmd_rangeSlider(selector) {
slider_offset = self.offset().left;
sliderDiscrete = self;

sliderDiscrete.each(function(i, v) {
sliderDiscrete.each(function (i, v) {
curnt = $(this);
curnt.append(sliderDiscrete_tmplt());
range = curnt.find('input[type="range"]');
Expand All @@ -25,7 +25,7 @@ function rkmd_rangeSlider(selector) {
slider_label.find("span").text(range_val);
});

self.on("mousedown touchstart", ".slider-handle", function(e) {
self.on("mousedown touchstart", ".slider-handle", function (e) {
if (e.button === 2) {
return false;
}
Expand All @@ -37,14 +37,14 @@ function rkmd_rangeSlider(selector) {
return false;
}
$(this).addClass("is-active");
var moveFu = function(e) {
var moveFu = function (e) {
var pageX = e.pageX || e.changedTouches[0].pageX;
var slider_new_width = pageX - slider_offset;
if (slider_new_width <= slider_width && !(slider_new_width < "0")) {
slider_move(parents, slider_new_width, slider_width, true);
}
};
var upFu = function(e) {
var upFu = function (e) {
$(this).off(handlers);
parents.find(".is-active").removeClass("is-active");
};
Expand All @@ -53,12 +53,12 @@ function rkmd_rangeSlider(selector) {
mousemove: moveFu,
touchmove: moveFu,
mouseup: upFu,
touchend: upFu
touchend: upFu,
};
$(document).on(handlers);
});

self.on("mousedown touchstart", ".slider", function(e) {
self.on("mousedown touchstart", ".slider", function (e) {
if (e.button === 2) {
return false;
}
Expand All @@ -76,13 +76,13 @@ function rkmd_rangeSlider(selector) {
if (slider_new_width <= slider_width && !(slider_new_width < "0")) {
slider_move(parents, slider_new_width, slider_width, true);
}
var upFu = function(e) {
var upFu = function (e) {
$(this).off(handlers);
};

var handlers = {
mouseup: upFu,
touchend: upFu
touchend: upFu,
};
$(document).on(handlers);
});
Expand All @@ -104,13 +104,14 @@ function slider_move(parents, newW, sliderW, send) {
var slider_fill = parents.find(".slider-fill");
var slider_handle = parents.find(".slider-handle");
var range = parents.find('input[type="range"]');
range.next().html(newW); // update value

slider_fill.css("width", slider_new_val + "%");
slider_handle.css({
left: slider_new_val + "%",
transition: "none",
"-webkit-transition": "none",
"-moz-transition": "none"
"-moz-transition": "none",
});

range.val(slider_new_val);
Expand Down
22 changes: 11 additions & 11 deletions data/js/slider.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/dataControlsJS.h

Large diffs are not rendered by default.

Loading

0 comments on commit 6506f6f

Please sign in to comment.