@@ -205,7 +205,10 @@ export async function exporter(
205205 }
206206
207207 options =
208- `<select class="form-select" aria-label="Default select example" onchange="window.blur(this.value)">
208+ `<select id="categorySelect"
209+ class="form-select"
210+ aria-label="Default select example"
211+ onchange="addCategoryChip(this.value)">
209212 <option value="" selected>All categories</option>` +
210213 options +
211214 '</select>'
@@ -246,25 +249,85 @@ export async function exporter(
246249 <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
247250
248251 <script>
249- window.blur = function(category) {
250- const cards = document.querySelectorAll('div[data-category]')
251-
252- for (card of cards) {
253- if(card.dataset.category.includes(category)) {
254- ${
255- argument [ 'project-category-blur' ]
256- ? 'card.style.filter = ""'
257- : 'card.parentNode.style.display = "block"'
258- }
259- } else {
260- ${
261- argument [ 'project-category-blur' ]
262- ? 'card.style.filter = "blur(1px) opacity(35%)"'
263- : 'card.parentNode.style.display = "none"'
264- }
265- }
266- }
252+ // Globale Variable zum Speichern der ausgewählten Kategorien
253+ window.selectedCategories = []
254+
255+ // Fügt einen Chip hinzu, wenn eine Kategorie gewählt wurde
256+ function addCategoryChip(category) {
257+ if (!category) return // falls "All categories" gewählt wurde, nichts tun
258+ if (window.selectedCategories.indexOf(category) === -1) {
259+ window.selectedCategories.push(category)
260+ // Option im Select-Menü deaktivieren
261+ document.querySelector('#categorySelect option[value="' + category + '"]').disabled = true
262+ updateChipsDisplay()
263+ filterCards()
264+ }
265+ // Setze das Select-Element zurück
266+ document.getElementById('categorySelect').value = ''
267+ }
268+
269+ // Entfernt einen Chip
270+ function removeCategoryChip(category) {
271+ const index = window.selectedCategories.indexOf(category)
272+ if (index > -1) {
273+ window.selectedCategories.splice(index, 1)
274+ // Option im Select-Menü wieder aktivieren
275+ document.querySelector('#categorySelect option[value="' + category + '"]').disabled = false
276+ updateChipsDisplay()
277+ filterCards()
267278 }
279+ }
280+
281+ // Aktualisiert die Anzeige der Chips
282+ function updateChipsDisplay() {
283+ const chipsContainer = document.getElementById('chipsContainer')
284+ chipsContainer.innerHTML = ''
285+ window.selectedCategories.forEach(function (cat) {
286+ const chip = document.createElement('span')
287+ chip.className = 'badge rounded-pill bg-primary me-2'
288+ chip.style.cursor = 'pointer'
289+ chip.style.fontSize = '1rem'
290+ chip.textContent = cat + ' ×'
291+ chip.onclick = function () {
292+ removeCategoryChip(cat)
293+ }
294+ chipsContainer.appendChild(chip)
295+ })
296+ }
297+
298+ function filterCards() {
299+ const cards = document.querySelectorAll('div[data-category]')
300+ cards.forEach(function (card) {
301+ // Falls keine Filterkategorien ausgewählt wurden, zeige alle Karten
302+ if (window.selectedCategories.length === 0) {
303+ ${
304+ argument [ 'project-category-blur' ]
305+ ? 'card.style.filter = "";'
306+ : 'card.parentNode.style.display = "block";'
307+ }
308+ return
309+ }
310+ // Zerlege die im data-Attribut hinterlegten Kategorien
311+ const cardCategories = card.dataset.category.split('|')
312+ // Prüfe, ob alle ausgewählten Kategorien in der Karte vorhanden sind
313+ const show = window.selectedCategories.every(function (cat) {
314+ return cardCategories.indexOf(cat) !== -1
315+ })
316+ if (show) {
317+ ${
318+ argument [ 'project-category-blur' ]
319+ ? 'card.style.filter = "";'
320+ : 'card.parentNode.style.display = "block";'
321+ }
322+ } else {
323+ ${
324+ argument [ 'project-category-blur' ]
325+ ? 'card.style.filter = "blur(1px) opacity(35%)";'
326+ : 'card.parentNode.style.display = "none";'
327+ }
328+ }
329+ })
330+ }
268331 </script>
269332</head>
270333<body>
@@ -280,6 +343,7 @@ export async function exporter(
280343 <p class="lead text-muted">${ json . comment || '' } </p>
281344
282345 ${ options }
346+ <div id="chipsContainer" class="mt-3"></div>
283347 </div>
284348 </div>
285349 </section>
0 commit comments