filters: negation, styling
This commit is contained in:
parent
09bdb7d61a
commit
caf8383b6f
3 changed files with 69 additions and 17 deletions
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue