snowflake/proxy/static/popup.js

51 lines
1.3 KiB
JavaScript
Raw Normal View History

2019-07-14 09:41:51 +02:00
/* exported Popup */
// Add or remove a class from elem.classList, depending on cond.
function setClass(elem, className, cond) {
if (cond) {
elem.classList.add(className);
} else {
elem.classList.remove(className);
}
}
2019-07-14 09:41:51 +02:00
class Popup {
constructor() {
this.div = document.getElementById('active');
2019-07-22 16:51:33 -06:00
this.statustext = document.getElementById('statustext');
this.statusdesc = document.getElementById('statusdesc');
this.img = document.getElementById('statusimg');
2019-07-14 09:41:51 +02:00
}
setEnabled(enabled) {
setClass(this.img, 'on', enabled);
}
setActive(active) {
setClass(this.img, 'running', active);
2019-07-14 09:41:51 +02:00
}
setStatusText(txt) {
2019-07-22 16:51:33 -06:00
this.statustext.innerText = txt;
2019-07-14 09:41:51 +02:00
}
setStatusDesc(desc, error) {
2019-07-22 16:51:33 -06:00
this.statusdesc.innerText = desc;
setClass(this.statusdesc, 'error', error);
2019-07-14 09:41:51 +02:00
}
hideButton() {
document.querySelector('.button').style.display = 'none';
}
setChecked(checked) {
document.getElementById('enabled').checked = checked;
}
2019-08-14 13:45:15 -04:00
static fill(n, func) {
switch(n.nodeType) {
case 3: { // Node.TEXT_NODE
const m = /^__MSG_([^_]*)__$/.exec(n.nodeValue);
if (m) { n.nodeValue = func(m[1]); }
break;
}
case 1: // Node.ELEMENT_NODE
n.childNodes.forEach(c => Popup.fill(c, func));
break;
}
}
2019-07-14 09:41:51 +02:00
}