genericnode.js 990 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. define([], function () {
  2. return function (name, key, value, f) {
  3. var negate = false
  4. var refresh
  5. var label = document.createElement("label")
  6. var strong = document.createElement("strong")
  7. label.textContent = name + " "
  8. label.appendChild(strong)
  9. function run(d) {
  10. var o = dictGet(d, key.slice(0))
  11. if (f)
  12. o = f(o)
  13. return o === value ? !negate : negate
  14. }
  15. function setRefresh(f) {
  16. refresh = f
  17. }
  18. function draw(el) {
  19. if (negate)
  20. el.parentNode.classList.add("not")
  21. else
  22. el.parentNode.classList.remove("not")
  23. strong.textContent = (negate ? "¬" : "" ) + value
  24. }
  25. function render(el) {
  26. el.appendChild(label)
  27. draw(el)
  28. label.onclick = function () {
  29. negate = !negate
  30. draw(el)
  31. if (refresh)
  32. refresh()
  33. }
  34. }
  35. return { run: run,
  36. setRefresh: setRefresh,
  37. render: render
  38. }
  39. }
  40. })