Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
43 lines (41 sloc) 2.05 KB
<!DOCTYPE html>
<html>
<head>
<base href="https://duluth.chandlerswift.com/light/">
<meta charset='utf-8'>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<title>Switch API Implementation</title>
<style>body{margin:1em auto;max-width:40em;padding:0 .62em;font:1.2em sans-serif; line-height: 1.62em;}h1,h2,h3{line-height:1.2em;}@media print{body{max-width:none}}</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
</head>
<body>
<header>
<h1>Switch API Implementation <small>(Back to <a href="./static/client.html">Control</a> Page)</small></h1>
</header>
<div id="content">
</div>
<script>
$.getJSON("lights", function(result){
$.each(result, function(i, light){
var c = document.getElementById("content");
c.innerHTML+="<section>";
c.innerHTML+="<h2>"+light["description"] + "</h2>";
c.innerHTML+="</section>";
if (light["dimmable"] == 1) {
c.innerHTML+="<input type=\"range\" value="+light["status"]+" min=0 max=255 oninput=\"document.getElementById('slider"+i+"').innerHTML = this.value;\"" +
"onChange='$.get(\"light/set?"+i+"=\" + this.value);'>";
c.innerHTML+="<span id=\"slider"+i+"\">"+light["status"]+"</span>";
} else {
c.innerHTML+="<button onclick=\"$.get('light/set?"+i+"=1')\">On</button>"
c.innerHTML+="<button onclick=\"$.get('light/set?"+i+"=0')\">Off</button>";
c.innerHTML+="<button onclick=\"$.get('light/status?id="+i+"',function(data){alert('Status: ' + data == '1' ? 'on' : 'off');});\">Status</button>";
}
});
});
</script>
<section>
<h2 id="source">Source</h2>
<p>Improvements? <a href='https://github.com/ChandlerSwift/lightswitch-html'>Send a pull request on GitHub</a>.</p>
</section>
</body>
</html>