フォントのフィルタリングボタンを改善
Browse files- index.js +52 -2
- styles.css +4 -2
index.js
CHANGED
|
@@ -275,7 +275,7 @@ document.addEventListener('DOMContentLoaded', async () => {
|
|
| 275 |
button.innerHTML = `
|
| 276 |
<input type="checkbox" class="btn-check" name="fontFilter" id="filter${tag}" value="${tag}">
|
| 277 |
<label class="btn btn-outline-primary" for="filter${tag}">
|
| 278 |
-
${displayName} <span class="tag-count">(${count})</span>
|
| 279 |
</label>
|
| 280 |
`;
|
| 281 |
langButtonGroup.appendChild(button);
|
|
@@ -301,7 +301,7 @@ document.addEventListener('DOMContentLoaded', async () => {
|
|
| 301 |
button.innerHTML = `
|
| 302 |
<input type="checkbox" class="btn-check" name="fontFilter" id="filter${tag}" value="${tag}">
|
| 303 |
<label class="btn btn-outline-primary" for="filter${tag}">
|
| 304 |
-
${displayName} <span class="tag-count">(${count})</span>
|
| 305 |
</label>
|
| 306 |
`;
|
| 307 |
otherButtonGroup.appendChild(button);
|
|
@@ -312,6 +312,53 @@ document.addEventListener('DOMContentLoaded', async () => {
|
|
| 312 |
}
|
| 313 |
}
|
| 314 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 315 |
// フォントオプションの初期化と絞り込み機能の実装
|
| 316 |
function initializeFontOptions() {
|
| 317 |
// 現在選択されているフォントを保持
|
|
@@ -353,6 +400,9 @@ document.addEventListener('DOMContentLoaded', async () => {
|
|
| 353 |
fontSelect.appendChild(option);
|
| 354 |
});
|
| 355 |
|
|
|
|
|
|
|
|
|
|
| 356 |
// 選択されたフォントを読み込む
|
| 357 |
return loadGoogleFont(fontSelect.value);
|
| 358 |
}
|
|
|
|
| 275 |
button.innerHTML = `
|
| 276 |
<input type="checkbox" class="btn-check" name="fontFilter" id="filter${tag}" value="${tag}">
|
| 277 |
<label class="btn btn-outline-primary" for="filter${tag}">
|
| 278 |
+
${displayName} <span class="tag-count" data-tag="${tag}">(${count})</span>
|
| 279 |
</label>
|
| 280 |
`;
|
| 281 |
langButtonGroup.appendChild(button);
|
|
|
|
| 301 |
button.innerHTML = `
|
| 302 |
<input type="checkbox" class="btn-check" name="fontFilter" id="filter${tag}" value="${tag}">
|
| 303 |
<label class="btn btn-outline-primary" for="filter${tag}">
|
| 304 |
+
${displayName} <span class="tag-count" data-tag="${tag}">(${count})</span>
|
| 305 |
</label>
|
| 306 |
`;
|
| 307 |
otherButtonGroup.appendChild(button);
|
|
|
|
| 312 |
}
|
| 313 |
}
|
| 314 |
|
| 315 |
+
// 選択されたフィルターに基づいてタグカウントを更新
|
| 316 |
+
function updateTagCounts() {
|
| 317 |
+
const selectedFilters = Array.from(fontTagFilter.querySelectorAll('input[type="checkbox"]:checked'))
|
| 318 |
+
.map(checkbox => checkbox.value);
|
| 319 |
+
|
| 320 |
+
// 選択されたフィルターがない場合は、全体の数を表示し、すべてのボタンを表示
|
| 321 |
+
if (selectedFilters.length === 0) {
|
| 322 |
+
const totalCounts = getTagsWithCount();
|
| 323 |
+
totalCounts.forEach((count, tag) => {
|
| 324 |
+
const wrapper = document.querySelector(`#filter${tag}`).closest('.btn-check-wrapper');
|
| 325 |
+
wrapper.style.display = 'inline-block';
|
| 326 |
+
const countElement = document.querySelector(`.tag-count[data-tag="${tag}"]`);
|
| 327 |
+
if (countElement) {
|
| 328 |
+
countElement.textContent = `(${count})`;
|
| 329 |
+
}
|
| 330 |
+
});
|
| 331 |
+
return;
|
| 332 |
+
}
|
| 333 |
+
|
| 334 |
+
// 各タグについて、現在の選択と組み合わせた場合の数を計算
|
| 335 |
+
const allTags = [...new Set(fontTags.flatMap(font => font.tags))];
|
| 336 |
+
allTags.forEach(tag => {
|
| 337 |
+
const countElement = document.querySelector(`.tag-count[data-tag="${tag}"]`);
|
| 338 |
+
const wrapper = document.querySelector(`#filter${tag}`).closest('.btn-check-wrapper');
|
| 339 |
+
|
| 340 |
+
if (countElement && wrapper) {
|
| 341 |
+
// このタグが既に選択されている場合は、他の選択されたタグとの組み合わせ数を表示
|
| 342 |
+
const filtersToCheck = selectedFilters.includes(tag)
|
| 343 |
+
? selectedFilters
|
| 344 |
+
: [...selectedFilters, tag];
|
| 345 |
+
|
| 346 |
+
const count = fontTags.filter(font =>
|
| 347 |
+
filtersToCheck.every(filter => font.tags.includes(filter))
|
| 348 |
+
).length;
|
| 349 |
+
|
| 350 |
+
countElement.textContent = `(${count})`;
|
| 351 |
+
|
| 352 |
+
// カウントが0の場合、かつ現在選択されていないタグの場合は非表示
|
| 353 |
+
if (count === 0 && !selectedFilters.includes(tag)) {
|
| 354 |
+
wrapper.style.display = 'none';
|
| 355 |
+
} else {
|
| 356 |
+
wrapper.style.display = 'inline-block';
|
| 357 |
+
}
|
| 358 |
+
}
|
| 359 |
+
});
|
| 360 |
+
}
|
| 361 |
+
|
| 362 |
// フォントオプションの初期化と絞り込み機能の実装
|
| 363 |
function initializeFontOptions() {
|
| 364 |
// 現在選択されているフォントを保持
|
|
|
|
| 400 |
fontSelect.appendChild(option);
|
| 401 |
});
|
| 402 |
|
| 403 |
+
// タグカウントを更新
|
| 404 |
+
updateTagCounts();
|
| 405 |
+
|
| 406 |
// 選択されたフォントを読み込む
|
| 407 |
return loadGoogleFont(fontSelect.value);
|
| 408 |
}
|
styles.css
CHANGED
|
@@ -128,8 +128,9 @@
|
|
| 128 |
|
| 129 |
#fontTagFilter {
|
| 130 |
display: flex;
|
| 131 |
-
flex-
|
| 132 |
-
gap:
|
|
|
|
| 133 |
}
|
| 134 |
|
| 135 |
#fontTagFilter .btn {
|
|
@@ -146,6 +147,7 @@
|
|
| 146 |
|
| 147 |
.filter-group {
|
| 148 |
margin-bottom: 1rem;
|
|
|
|
| 149 |
}
|
| 150 |
|
| 151 |
.filter-group-label {
|
|
|
|
| 128 |
|
| 129 |
#fontTagFilter {
|
| 130 |
display: flex;
|
| 131 |
+
flex-direction: column;
|
| 132 |
+
gap: 1rem;
|
| 133 |
+
width: 100%;
|
| 134 |
}
|
| 135 |
|
| 136 |
#fontTagFilter .btn {
|
|
|
|
| 147 |
|
| 148 |
.filter-group {
|
| 149 |
margin-bottom: 1rem;
|
| 150 |
+
width: 100%;
|
| 151 |
}
|
| 152 |
|
| 153 |
.filter-group-label {
|