|
<!DOCTYPE html> |
|
<html lang="en"> |
|
<head> |
|
<meta charset="UTF-8"> |
|
<title>Solarized Sprite Filter</title> |
|
<style> |
|
body { font-family: sans-serif; max-width: 700px; margin: auto; padding: 1em; } |
|
label { margin-right: 1em; } |
|
select { margin-right: 1em; } |
|
ul { list-style-type: none; padding-left: 0; } |
|
li { margin: 0.3em 0; } |
|
</style> |
|
</head> |
|
<body> |
|
|
|
<h1>Solarized Sprite Filter</h1> |
|
|
|
<div id="filterControls"> |
|
<label> |
|
Shape: |
|
<select id="shapeFilter"></select> |
|
</label> |
|
<label> |
|
Color: |
|
<select id="colorFilter"></select> |
|
</label> |
|
<label> |
|
Size: |
|
<select id="sizeFilter"></select> |
|
</label> |
|
</div> |
|
|
|
<div id="results" style="margin-top:2em;"></div> |
|
|
|
<!-- 🔽 Paste full JSON into this script tag --> |
|
<script id="spriteData" type="application/json"> |
|
{ |
|
"metadata": { |
|
"colors": ["blue", "red"], |
|
"shapes": ["bar", "circle"], |
|
"sizes": [ |
|
{ "width": 720, "height": 16 }, |
|
{ "width": 8, "height": 8 } |
|
] |
|
}, |
|
"files": [ |
|
{ "filename": "bar-blue-720x16.svg", "shape": "bar", "color": "blue", "width": 720, "height": 16 }, |
|
{ "filename": "circle-red-8x8.svg", "shape": "circle", "color": "red", "width": 8, "height": 8 } |
|
] |
|
} |
|
</script> |
|
|
|
<script> |
|
const data = JSON.parse(document.getElementById('spriteData').textContent); |
|
|
|
const shapeFilter = document.getElementById('shapeFilter'); |
|
const colorFilter = document.getElementById('colorFilter'); |
|
const sizeFilter = document.getElementById('sizeFilter'); |
|
const results = document.getElementById('results'); |
|
|
|
// Init filters |
|
function populateFilters() { |
|
fillSelect(shapeFilter, data.metadata.shapes); |
|
fillSelect(colorFilter, data.metadata.colors); |
|
const sizeLabels = data.metadata.sizes.map(s => `${s.width}x${s.height}`); |
|
fillSelect(sizeFilter, sizeLabels); |
|
} |
|
|
|
function fillSelect(select, items) { |
|
select.innerHTML = '<option value="">All</option>'; |
|
items.forEach(value => { |
|
const opt = document.createElement('option'); |
|
opt.value = value; |
|
opt.textContent = value; |
|
select.appendChild(opt); |
|
}); |
|
} |
|
|
|
// Filtering logic |
|
function applyFilters() { |
|
const shape = shapeFilter.value; |
|
const color = colorFilter.value; |
|
const size = sizeFilter.value; |
|
|
|
const filtered = data.files.filter(f => { |
|
const matchShape = !shape || f.shape === shape; |
|
const matchColor = !color || f.color === color; |
|
const matchSize = !size || `${f.width}x${f.height}` === size; |
|
return matchShape && matchColor && matchSize; |
|
}); |
|
|
|
results.innerHTML = `<h2>${filtered.length} Result(s)</h2><ul>` + |
|
filtered.map(f => `<li><a href="${f.filename}">${f.filename}</a></li>`).join('') + |
|
`</ul>`; |
|
} |
|
|
|
// Bind events |
|
[shapeFilter, colorFilter, sizeFilter].forEach(el => el.addEventListener('change', applyFilters)); |
|
|
|
// Init |
|
populateFilters(); |
|
applyFilters(); |
|
</script> |
|
|
|
</body> |
|
</html> |