mirror of
https://github.com/s00500/ESPUI.git
synced 2024-11-22 04:00:55 +00:00
Update controls.min.js
This commit is contained in:
parent
6a9c989766
commit
98ec85ea8b
60
data/js/controls.min.js
vendored
60
data/js/controls.min.js
vendored
@ -9,7 +9,7 @@ function handleVisibilityChange(){if(!websockConnected&&!document.hidden){restar
|
|||||||
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");}
|
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){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;}
|
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");}
|
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"+
|
if(data.visible){parent.append("<div id='id"+
|
||||||
data.id+
|
data.id+
|
||||||
"' class='two columns card tcenter "+
|
"' class='two columns card tcenter "+
|
||||||
colorClass(data.color)+
|
colorClass(data.color)+
|
||||||
@ -22,8 +22,9 @@ data.id+
|
|||||||
"' class='label label-wrap'>"+
|
"' class='label label-wrap'>"+
|
||||||
data.value+
|
data.value+
|
||||||
"</span>"+
|
"</span>"+
|
||||||
"</div>");break;case UI_BUTTON:var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");}
|
"</div>");}
|
||||||
parent.append("<div id='id"+
|
break;case UI_BUTTON:var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");}
|
||||||
|
if(data.visible){parent.append("<div id='id"+
|
||||||
data.id+
|
data.id+
|
||||||
"' class='one columns card tcenter "+
|
"' class='one columns card tcenter "+
|
||||||
colorClass(data.color)+
|
colorClass(data.color)+
|
||||||
@ -41,8 +42,9 @@ data.id+
|
|||||||
data.id+
|
data.id+
|
||||||
", false)'>"+
|
", false)'>"+
|
||||||
data.value+
|
data.value+
|
||||||
"</button></div>");$("#btn"+data.id).on({touchstart:function(e){e.preventDefault();buttonclick(data.id,true);},touchend:function(e){e.preventDefault();buttonclick(data.id,false);},});break;case UI_SWITCHER:var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");}
|
"</button></div>");$("#btn"+data.id).on({touchstart:function(e){e.preventDefault();buttonclick(data.id,true);},touchend:function(e){e.preventDefault();buttonclick(data.id,false);},});}
|
||||||
parent.append("<div id='id"+
|
break;case UI_SWITCHER:var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");}
|
||||||
|
if(data.visible){parent.append("<div id='id"+
|
||||||
data.id+
|
data.id+
|
||||||
"' class='one columns card tcenter "+
|
"' class='one columns card tcenter "+
|
||||||
colorClass(data.color)+
|
colorClass(data.color)+
|
||||||
@ -63,8 +65,9 @@ data.id+
|
|||||||
(data.value=="1"?"checked":"")+
|
(data.value=="1"?"checked":"")+
|
||||||
"/></div>"+
|
"/></div>"+
|
||||||
"</label>"+
|
"</label>"+
|
||||||
"</div>");switcher(data.id,data.value);break;case UI_CPAD:case UI_PAD:var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");}
|
"</div>");switcher(data.id,data.value);}
|
||||||
parent.append("<div id='id"+
|
break;case UI_CPAD:case UI_PAD:var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");}
|
||||||
|
if(data.visible){parent.append("<div id='id"+
|
||||||
data.id+
|
data.id+
|
||||||
"' class='two columns card tcenter "+
|
"' class='two columns card tcenter "+
|
||||||
colorClass(data.color)+
|
colorClass(data.color)+
|
||||||
@ -111,8 +114,9 @@ data.id+
|
|||||||
data.id+
|
data.id+
|
||||||
"'>OK</a>":"")+
|
"'>OK</a>":"")+
|
||||||
"</nav>"+
|
"</nav>"+
|
||||||
"</div>");$("#pf"+data.id).on({touchstart:function(e){e.preventDefault();padclick(UP,data.id,true);},touchend:function(e){e.preventDefault();padclick(UP,data.id,false);},});$("#pl"+data.id).on({touchstart:function(e){e.preventDefault();padclick(LEFT,data.id,true);},touchend:function(e){e.preventDefault();padclick(LEFT,data.id,false);},});$("#pr"+data.id).on({touchstart:function(e){e.preventDefault();padclick(RIGHT,data.id,true);},touchend:function(e){e.preventDefault();padclick(RIGHT,data.id,false);},});$("#pb"+data.id).on({touchstart:function(e){e.preventDefault();padclick(DOWN,data.id,true);},touchend:function(e){e.preventDefault();padclick(DOWN,data.id,false);},});$("#pc"+data.id).on({touchstart:function(e){e.preventDefault();padclick(CENTER,data.id,true);},touchend:function(e){e.preventDefault();padclick(CENTER,data.id,false);},});break;case UI_SLIDER:var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");}
|
"</div>");$("#pf"+data.id).on({touchstart:function(e){e.preventDefault();padclick(UP,data.id,true);},touchend:function(e){e.preventDefault();padclick(UP,data.id,false);},});$("#pl"+data.id).on({touchstart:function(e){e.preventDefault();padclick(LEFT,data.id,true);},touchend:function(e){e.preventDefault();padclick(LEFT,data.id,false);},});$("#pr"+data.id).on({touchstart:function(e){e.preventDefault();padclick(RIGHT,data.id,true);},touchend:function(e){e.preventDefault();padclick(RIGHT,data.id,false);},});$("#pb"+data.id).on({touchstart:function(e){e.preventDefault();padclick(DOWN,data.id,true);},touchend:function(e){e.preventDefault();padclick(DOWN,data.id,false);},});$("#pc"+data.id).on({touchstart:function(e){e.preventDefault();padclick(CENTER,data.id,true);},touchend:function(e){e.preventDefault();padclick(CENTER,data.id,false);},});}
|
||||||
parent.append("<div id='id"+
|
break;case UI_SLIDER:var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");}
|
||||||
|
if(data.visible){parent.append("<div id='id"+
|
||||||
data.id+
|
data.id+
|
||||||
"' class='two columns card tcenter card-slider "+
|
"' class='two columns card tcenter card-slider "+
|
||||||
colorClass(data.color)+
|
colorClass(data.color)+
|
||||||
@ -130,8 +134,9 @@ data.value+
|
|||||||
data.value+
|
data.value+
|
||||||
"</span>"+
|
"</span>"+
|
||||||
"</div>"+
|
"</div>"+
|
||||||
"</div>");rangeSlider(!sliderContinuous);break;case UI_NUMBER:var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");}
|
"</div>");rangeSlider(!sliderContinuous);}
|
||||||
parent.append("<div id='id"+
|
break;case UI_NUMBER:var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");}
|
||||||
|
if(data.visible){parent.append("<div id='id"+
|
||||||
data.id+
|
data.id+
|
||||||
"' class='two columns card tcenter "+
|
"' class='two columns card tcenter "+
|
||||||
colorClass(data.color)+
|
colorClass(data.color)+
|
||||||
@ -146,8 +151,9 @@ data.value+
|
|||||||
"' onchange='numberchange("+
|
"' onchange='numberchange("+
|
||||||
data.id+
|
data.id+
|
||||||
")' />"+
|
")' />"+
|
||||||
"</div>");break;case UI_TEXT_INPUT:var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");}
|
"</div>");}
|
||||||
parent.append("<div id='id"+
|
break;case UI_TEXT_INPUT:var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");}
|
||||||
|
if(data.visible){parent.append("<div id='id"+
|
||||||
data.id+
|
data.id+
|
||||||
"' class='two columns card tcenter "+
|
"' class='two columns card tcenter "+
|
||||||
colorClass(data.color)+
|
colorClass(data.color)+
|
||||||
@ -162,9 +168,11 @@ data.value+
|
|||||||
"' onchange='textchange("+
|
"' onchange='textchange("+
|
||||||
data.id+
|
data.id+
|
||||||
")' />"+
|
")' />"+
|
||||||
"</div>");break;case UI_TAB:$("#tabsnav").append("<li><a onmouseup='tabclick("+data.id+")' href='#tab"+data.id+"'>"+data.value+"</a></li>");$("#tabscontent").append("<div id='tab"+data.id+"'></div>");tabs=$(".tabscontent").tabbedContent({loop:true}).data("api");$("a").filter(function(){return $(this).attr("href")==="#click-to-switch";}).on("click",function(e){var tab=prompt("Tab to switch to (number or id)?");if(!tabs.switchTab(tab)){alert("That tab does not exist :\\");}
|
"</div>");}
|
||||||
e.preventDefault();});break;case UI_SELECT:var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");}
|
break;case UI_TAB:if(data.visible){$("#tabsnav").append("<li><a onmouseup='tabclick("+data.id+")' href='#tab"+data.id+"'>"+data.value+"</a></li>");$("#tabscontent").append("<div id='tab"+data.id+"'></div>");tabs=$(".tabscontent").tabbedContent({loop:true}).data("api");$("a").filter(function(){return $(this).attr("href")==="#click-to-switch";}).on("click",function(e){var tab=prompt("Tab to switch to (number or id)?");if(!tabs.switchTab(tab)){alert("That tab does not exist :\\");}
|
||||||
parent.append("<div id='id"+
|
e.preventDefault();});}
|
||||||
|
break;case UI_SELECT:var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");}
|
||||||
|
if(data.visible){parent.append("<div id='id"+
|
||||||
data.id+
|
data.id+
|
||||||
"' class='two columns card tcenter "+
|
"' class='two columns card tcenter "+
|
||||||
colorClass(data.color)+
|
colorClass(data.color)+
|
||||||
@ -177,7 +185,8 @@ data.id+
|
|||||||
"' onchange='selectchange("+
|
"' onchange='selectchange("+
|
||||||
data.id+
|
data.id+
|
||||||
")' />"+
|
")' />"+
|
||||||
"</div>");break;case UI_OPTION:if(data.parentControl){var parent=$("#select"+data.parentControl);parent.append("<option id='option"+
|
"</div>");}
|
||||||
|
break;case UI_OPTION:if(data.parentControl){var parent=$("#select"+data.parentControl);parent.append("<option id='option"+
|
||||||
data.id+
|
data.id+
|
||||||
"' value='"+
|
"' value='"+
|
||||||
data.value+
|
data.value+
|
||||||
@ -190,7 +199,7 @@ break;case UI_MIN:if(data.parentControl){var parent=$("#id"+data.parentControl+"
|
|||||||
break;case UI_MAX:if(data.parentControl){var parent=$("#id"+data.parentControl+" input");if(parent.size()){parent.attr("max",data.value);}}
|
break;case UI_MAX:if(data.parentControl){var parent=$("#id"+data.parentControl+" input");if(parent.size()){parent.attr("max",data.value);}}
|
||||||
break;case UI_STEP:if(data.parentControl){var parent=$("#id"+data.parentControl+" input");if(parent.size()){parent.attr("step",data.value);}}
|
break;case UI_STEP:if(data.parentControl){var parent=$("#id"+data.parentControl+" input");if(parent.size()){parent.attr("step",data.value);}}
|
||||||
break;case UI_GRAPH:var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");}
|
break;case UI_GRAPH:var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");}
|
||||||
parent.append("<div id='id"+
|
if(data.visible){parent.append("<div id='id"+
|
||||||
data.id+
|
data.id+
|
||||||
"' class='two columns card tcenter "+
|
"' class='two columns card tcenter "+
|
||||||
colorClass(data.color)+
|
colorClass(data.color)+
|
||||||
@ -205,8 +214,9 @@ data.id+
|
|||||||
data.label+
|
data.label+
|
||||||
"</figcaption>"+
|
"</figcaption>"+
|
||||||
"</figure>"+
|
"</figure>"+
|
||||||
"</div>");graphData[data.id]=restoreGraphData(data.id);renderGraphSvg(graphData[data.id],"graph"+data.id);break;case ADD_GRAPH_POINT:var ts=Math.round(new Date().getTime()/1000);graphData[data.id].push({x:ts,y:data.value});saveGraphData();renderGraphSvg(graphData[data.id],"graph"+data.id);break;case CLEAR_GRAPH:graphData[data.id]=[];saveGraphData();renderGraphSvg(graphData[data.id],"graph"+data.id);break;case UI_GAUGE:var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");}
|
"</div>");graphData[data.id]=restoreGraphData(data.id);renderGraphSvg(graphData[data.id],"graph"+data.id);}
|
||||||
parent.append("<div id='id"+
|
break;case ADD_GRAPH_POINT:var ts=Math.round(new Date().getTime()/1000);graphData[data.id].push({x:ts,y:data.value});saveGraphData();renderGraphSvg(graphData[data.id],"graph"+data.id);break;case CLEAR_GRAPH:graphData[data.id]=[];saveGraphData();renderGraphSvg(graphData[data.id],"graph"+data.id);break;case UI_GAUGE:var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");}
|
||||||
|
if(data.visible){parent.append("<div id='id"+
|
||||||
data.id+
|
data.id+
|
||||||
"' class='two columns card tcenter "+
|
"' class='two columns card tcenter "+
|
||||||
colorClass(data.color)+
|
colorClass(data.color)+
|
||||||
@ -221,8 +231,9 @@ data.value+
|
|||||||
"' onchange='numberchange("+
|
"' onchange='numberchange("+
|
||||||
data.id+
|
data.id+
|
||||||
")' />"+
|
")' />"+
|
||||||
"</div>");break;case UI_ACCEL:if(hasAccel)break;var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");}
|
"</div>");}
|
||||||
hasAccel=true;parent.append("<div id='id"+
|
break;case UI_ACCEL:if(hasAccel)break;var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");}
|
||||||
|
hasAccel=true;if(data.visible){parent.append("<div id='id"+
|
||||||
data.id+
|
data.id+
|
||||||
"' class='two columns card tcenter "+
|
"' class='two columns card tcenter "+
|
||||||
colorClass(data.color)+
|
colorClass(data.color)+
|
||||||
@ -237,9 +248,10 @@ data.id+
|
|||||||
"'></div><pre class='accelerometeroutput"+
|
"'></div><pre class='accelerometeroutput"+
|
||||||
data.id+
|
data.id+
|
||||||
"'></pre>"+
|
"'></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($("#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;}
|
"</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;}
|
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;}
|
||||||
var sliderCache={};function sliderchange(number){var val=$("#sl"+number).val();sliderCache[number]!==val&&websock.send("slvalue:"+val+":"+number);sliderCache[number]=val;}
|
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);}
|
function numberchange(number){var val=$("#num"+number).val();websock.send("nvalue:"+val+":"+number);}
|
||||||
function textchange(number){var val=$("#text"+number).val();websock.send("tvalue:"+val+":"+number);}
|
function textchange(number){var val=$("#text"+number).val();websock.send("tvalue:"+val+":"+number);}
|
||||||
function tabclick(number){var val=$("#tab"+number).val();websock.send("tabvalue:"+val+":"+number);}
|
function tabclick(number){var val=$("#tab"+number).val();websock.send("tabvalue:"+val+":"+number);}
|
||||||
|
Loading…
Reference in New Issue
Block a user