This repository has been archived on 2024-05-11. You can view files and clone it, but cannot push or open issues or pull requests.
meshviewer/lib/filters/genericnode.js

53 lines
1012 B
JavaScript

define([], function () {
return function (name, key, value, f) {
var negate = false;
var refresh;
var label = document.createElement("label");
var strong = document.createElement("strong");
label.textContent = name + " ";
label.appendChild(strong);
function run(d) {
var o = dictGet(d, key.slice(0));
if (f)
o = f(o);
return o === value ? !negate : negate;
}
function setRefresh(f) {
refresh = f;
}
function draw(el) {
if (negate)
el.parentNode.classList.add("not");
else
el.parentNode.classList.remove("not");
strong.textContent = (negate ? "¬" : "" ) + value;
}
function render(el) {
el.appendChild(label);
draw(el);
label.onclick = function () {
negate = !negate;
draw(el);
if (refresh)
refresh();
};
}
return { run: run,
setRefresh: setRefresh,
render: render
};
};
});