diff options
| -rw-r--r-- | app.js | 22 | ||||
| -rw-r--r-- | index.html | 10 | ||||
| -rw-r--r-- | ka.js | 18 | ||||
| -rw-r--r-- | style.css | 4 |
4 files changed, 21 insertions, 33 deletions
@@ -2,7 +2,7 @@ state = {}; isLoading = 0; - const loading = (val) => { + let loading = (val) => { isLoading = val; loader.$cls(isLoading ? "" : "hidden"); } @@ -13,15 +13,13 @@ error = String(err); app.reload(); } - function errClose() { - } - window.onerror = (message, source, lineNumber, colno, err) => { + window.onerror = (message) => { setError(message); }; - window.onunhandledrejection = (event) => { - setError(event.reason); + window.onunhandledrejection = (e) => { + setError(e.reason); }; - let parseini = (data) => Object.fromEntries(data.split("\n").map(x=>x.trim()).filter(x=>x).map(x=>x.split("="))); + let parseini = (data) => fromEntries(data.split("\n").map(x=>x.trim()).filter(x=>x).map(x=>x.split("="))); let buildini = (data, prefix="") => entries(data).map(([k,v])=>`${prefix}${k}=${v}\n`).join(); let resptext = r => { if (!r.ok){ @@ -46,7 +44,7 @@ .finally(() => loading(0)); } reboot = (data, prefix) => { - var ok = 0; + let ok = 0; loading(1); cmd("reboot\n") .then(() => { @@ -61,7 +59,7 @@ }; function CErr(text) { - var el = div( + let el = div( div("✖").$cls("close").$click(errClose), span("⚠ "), text, @@ -88,7 +86,7 @@ } function CSettingInput(f) { - var inp = input("text") + let inp = input("text") .$attr("id","form__"+f.id) .$attr("name",f.id) .$attr("required",!!f.required) @@ -110,7 +108,7 @@ function CSettings(section) { let s = config.sections[section]; let form_ = form( - table(...s.fields.map(x => CSettingInput(x))).$cls("settings"), + table(...s.fields.map(x => CSettingInput(x))), input("submit").$value("Save") ); form_.onsubmit = (e) => {e.preventDefault(); setconfig({});} @@ -137,7 +135,7 @@ button("Reboot").$click(reboot), ).$cls("center"), ), - ...Object.fromEntries(entries(config.sections).map(([id, _]) => [`/${id}`, () => CSettings(id)])), + ...fromEntries(entries(config.sections).map(([id, _]) => [`/${id}`, () => CSettings(id)])), "": () => div( h1("Not Found"), p("The requested page is not available.") @@ -11,16 +11,10 @@ <header><big>🛠️ WebIF 2.0</big></header> <div id="app"></div> </div> - <div id="loader" title="цъкни да скриеш"> + <div id="loader" title="click to hide"> <div> <div class="loadspin"></div> - <p> - Loading... - <noscript> - FAILED. JavaScript is disabled. - <p><a href="command.html">Use Command Interface</a></p> - </noscript> - </p> + <p>Loading...</p> </div> </div> <script src="ka.js"></script> @@ -1,8 +1,8 @@ -(()=>{ - doc = document; - entries = Object.entries; +doc = document; +let {entries,fromEntries} = Object; - var ep = Element.prototype; +(()=>{ + let ep = Element.prototype; ep.attr = function(name){ return this.getAttribute(name); }; @@ -25,15 +25,11 @@ this.onclick = callback; return this; } - const getvalue = x => x.value; - ep.$change2state = function(state, field, valgetter=getvalue) { + let getval = x => x.value; + ep.$change2state = function(state, field, getter=getval) { this.oninput = () => { this.setCustomValidity(''); - if (this.validity.valid) { - state[field] = valgetter(this); - } else { - this.reportValidity(); - } + this.validity.valid && (state[field] = getter(this)) || this.reportValidity(); }; return this; } @@ -88,8 +88,8 @@ input[type=submit]:active, button:active { background-color: #079290; } -.settings { - margin: 0 0 1em 0; +table { + margin: 0.5em 0 1em 0; } table td.title { min-width: 150px; |
