mirror of
https://github.com/lumapu/ahoy.git
synced 2025-05-12 16:36:38 +02:00
* improved api (now webApi)
* converted index to static page
This commit is contained in:
parent
08d8658737
commit
440d386ec0
11 changed files with 266 additions and 240 deletions
65
tools/esp8266/html/api.js
Normal file
65
tools/esp8266/html/api.js
Normal file
|
@ -0,0 +1,65 @@
|
|||
function toggle(name, hide) {
|
||||
var elm = document.getElementsByName(name)[0];
|
||||
if(hide) {
|
||||
if(!elm.classList.contains("hide"))
|
||||
elm.classList.add("hide");
|
||||
}
|
||||
else
|
||||
elm.classList.remove('hide');
|
||||
}
|
||||
|
||||
function getAjax(url, ptr) {
|
||||
var http = new XMLHttpRequest();
|
||||
if(http != null) {
|
||||
http.open("GET", url, true);
|
||||
http.onreadystatechange = p;
|
||||
http.send(null);
|
||||
}
|
||||
function p() {
|
||||
if(http.readyState == 4)
|
||||
ptr(JSON.parse(http.responseText));
|
||||
}
|
||||
}
|
||||
|
||||
function des(val) {
|
||||
e = document.createElement('p');
|
||||
e.classList.add("subdes");
|
||||
e.innerHTML = val;
|
||||
return e;
|
||||
}
|
||||
|
||||
function lbl(id, val) {
|
||||
e = document.createElement('label');
|
||||
e.htmlFor = id;
|
||||
e.innerHTML = val;
|
||||
return e;
|
||||
}
|
||||
|
||||
function inp(name, val, max=32, cl=["text"]) {
|
||||
e = document.createElement('input');
|
||||
e.classList.add(...cl);
|
||||
e.name = name;
|
||||
e.value = val;
|
||||
e.maxLength = max;
|
||||
return e;
|
||||
}
|
||||
|
||||
function sel(name, opt, selId) {
|
||||
e = document.createElement('select');
|
||||
e.name = name;
|
||||
for(it of opt) {
|
||||
o = document.createElement('option');
|
||||
o.value = it[0];
|
||||
o.innerHTML = it[1];
|
||||
if(it[0] == selId)
|
||||
o.selected = true;
|
||||
e.appendChild(o);
|
||||
}
|
||||
return e;
|
||||
}
|
||||
|
||||
function div(cl) {
|
||||
e = document.createElement('div');
|
||||
e.classList.add(cl);
|
||||
return e;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue