filters: negation, styling

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

View file

@ -2,9 +2,10 @@ define([], function () {
return function (distributor) { return function (distributor) {
var container = document.createElement("ul") var container = document.createElement("ul")
container.classList.add("filters") container.classList.add("filters")
var div = document.createElement("div")
function render(el) { function render(el) {
el.appendChild(container) el.appendChild(div)
} }
function filtersChanged(filters) { function filtersChanged(filters) {
@ -25,6 +26,11 @@ define([], function () {
} }
li.appendChild(button) li.appendChild(button)
}) })
if (container.parentNode === div && filters.length === 0)
div.removeChild(container)
else if (filters.length > 0)
div.appendChild(container)
} }
return { render: render, return { render: render,

View file

@ -1,15 +1,26 @@
define(["filters/nodefilter"], function (nodefilter) { define(["filters/nodefilter"], function (nodefilter) {
return function (name, key, value, f) { return function (name, key, value, f) {
var negate = false
var refresh
function run(d) { function run(d) {
var o = dictGet(d, key.slice(0)) var o = dictGet(d, key.slice(0))
if (f) if (f)
o = f(o) 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) { function render(el) {
@ -19,7 +30,17 @@ define(["filters/nodefilter"], function (nodefilter) {
var strong = document.createElement("strong") var strong = document.createElement("strong")
strong.textContent = value strong.textContent = value
draw(el)
label.appendChild(strong) label.appendChild(strong)
label.onclick = function () {
negate = !negate
draw(el)
if (refresh)
refresh()
}
el.appendChild(label) el.appendChild(label)
} }

View file

@ -1,28 +1,53 @@
.filters { .filters {
margin: 0; margin: 0;
padding: 0 !important; display: flex;
flex-wrap: wrap;
font-family: Roboto;
font-size: 0.83em;
font-weight: bold;
padding: 0 6pt 6pt !important;
li { li {
border-radius: 20pt;
display: flex; display: flex;
padding: 6pt 0 6pt 12pt; padding: 0pt 0 0pt 8pt;
margin: 3pt;
align-items: center; align-items: center;
background: #009ee0;
color: rgba(255, 255, 255, 0.8);
& > div { label {
flex-grow: 1; cursor: pointer;
strong {
color: rgba(255, 255, 255, 1);
}
} }
@include shadow(1); &.not {
} background: #dc0067;
}
button { button {
box-shadow: none; box-shadow: none;
margin: 0; margin: 2pt;
padding: 0; padding: 0;
background: none; width: 18pt;
font-size: 1.41em; height: 18pt;
background: rgba(255, 255, 255, 0.0);
font-size: 12pt;
vertical-align: middle;
color: rgba(255, 255, 255, 0.8);
&:hover { &:hover {
box-shadow: none !important; box-shadow: none !important;
color: #dc0067;
background: rgba(255, 255, 255, 0.9);
}
&:active {
box-shadow: none;
}
} }
} }
} }