filters: negation, styling

This commit is contained in:
Nils Schneider 2015-07-08 17:20:56 +02:00
commit caf8383b6f
3 changed files with 69 additions and 17 deletions

View file

@ -1,15 +1,26 @@
define(["filters/nodefilter"], function (nodefilter) {
return function (name, key, value, f) {
var negate = false
var refresh
function run(d) {
var o = dictGet(d, key.slice(0))
if (f)
o = f(o)
return o === value
return o === value ? !negate : negate
}
function setRefresh() {
function setRefresh(f) {
refresh = f
}
function draw(el) {
if (negate)
el.parentNode.classList.add("not")
else
el.parentNode.classList.remove("not")
}
function render(el) {
@ -19,7 +30,17 @@ define(["filters/nodefilter"], function (nodefilter) {
var strong = document.createElement("strong")
strong.textContent = value
draw(el)
label.appendChild(strong)
label.onclick = function () {
negate = !negate
draw(el)
if (refresh)
refresh()
}
el.appendChild(label)
}