2015-07-08 21:17:00 +02:00
|
|
|
define([], function () {
|
2015-07-08 00:36:57 +02:00
|
|
|
return function (name, key, value, f) {
|
2015-07-08 17:20:56 +02:00
|
|
|
var negate = false
|
|
|
|
var refresh
|
|
|
|
|
2015-07-08 20:50:26 +02:00
|
|
|
var label = document.createElement("label")
|
|
|
|
var strong = document.createElement("strong")
|
|
|
|
label.textContent = name + " "
|
|
|
|
label.appendChild(strong)
|
|
|
|
|
2015-07-08 00:36:57 +02:00
|
|
|
function run(d) {
|
|
|
|
var o = dictGet(d, key.slice(0))
|
|
|
|
|
|
|
|
if (f)
|
|
|
|
o = f(o)
|
|
|
|
|
2015-07-08 17:20:56 +02:00
|
|
|
return o === value ? !negate : negate
|
|
|
|
}
|
|
|
|
|
|
|
|
function setRefresh(f) {
|
|
|
|
refresh = f
|
2015-07-08 00:36:57 +02:00
|
|
|
}
|
|
|
|
|
2015-07-08 17:20:56 +02:00
|
|
|
function draw(el) {
|
|
|
|
if (negate)
|
|
|
|
el.parentNode.classList.add("not")
|
|
|
|
else
|
|
|
|
el.parentNode.classList.remove("not")
|
2015-07-08 20:50:26 +02:00
|
|
|
|
|
|
|
strong.textContent = (negate ? "¬" : "" ) + value
|
2015-07-08 00:36:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function render(el) {
|
2015-07-08 20:50:26 +02:00
|
|
|
el.appendChild(label)
|
2015-07-08 17:20:56 +02:00
|
|
|
draw(el)
|
|
|
|
|
|
|
|
label.onclick = function () {
|
|
|
|
negate = !negate
|
|
|
|
|
|
|
|
draw(el)
|
|
|
|
|
|
|
|
if (refresh)
|
|
|
|
refresh()
|
|
|
|
}
|
2015-07-08 00:36:57 +02:00
|
|
|
}
|
|
|
|
|
2015-07-08 21:17:00 +02:00
|
|
|
return { run: run,
|
2015-07-08 00:36:57 +02:00
|
|
|
setRefresh: setRefresh,
|
|
|
|
render: render
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|