(strip, subfolders, sourceId = '')
| 402 | } |
| 403 | |
| 404 | function renderFolderStripPaged(strip, subfolders, sourceId = '') { |
| 405 | if (!strip) return; |
| 406 | |
| 407 | if (!window.showFoldersInList || !subfolders.length) { |
| 408 | strip.style.display = "none"; |
| 409 | strip.innerHTML = ""; |
| 410 | return; |
| 411 | } |
| 412 | |
| 413 | const total = subfolders.length; |
| 414 | const pageSize = FOLDER_STRIP_PAGE_SIZE; |
| 415 | const totalPages = Math.ceil(total / pageSize); |
| 416 | |
| 417 | function drawPage(page) { |
| 418 | const endIdx = Math.min(page * pageSize, total); |
| 419 | const visible = subfolders.slice(0, endIdx); |
| 420 | |
| 421 | const badgeText = formatSourceBadgeText(getSourceMetaById(sourceId)); |
| 422 | const badgeHtml = badgeText |
| 423 | ? `<div class="folder-strip-badge fr-source-badge" title="Source: ${escapeHTML(badgeText)}">${escapeHTML(badgeText)}</div>` |
| 424 | : ''; |
| 425 | |
| 426 | let html = badgeHtml + visible.map(sf => ` |
| 427 | <div class="folder-item" |
| 428 | data-folder="${sf.full}" |
| 429 | draggable="true"> |
| 430 | <span class="folder-svg"></span> |
| 431 | <div class="folder-name"> |
| 432 | ${escapeHTML(sf.name)} |
| 433 | </div> |
| 434 | </div> |
| 435 | `).join(""); |
| 436 | |
| 437 | if (endIdx < total) { |
| 438 | html += ` |
| 439 | <button type="button" |
| 440 | class="folder-strip-load-more"> |
| 441 | ${t('load_more_folders') || t('load_more') || 'Load more folders'} |
| 442 | </button> |
| 443 | `; |
| 444 | } |
| 445 | |
| 446 | strip.innerHTML = html; |
| 447 | |
| 448 | applyFolderStripLayout(strip); |
| 449 | wireFolderStripItems(strip, sourceId); |
| 450 | |
| 451 | const loadMoreBtn = strip.querySelector(".folder-strip-load-more"); |
| 452 | if (loadMoreBtn) { |
| 453 | loadMoreBtn.addEventListener("click", e => { |
| 454 | e.preventDefault(); |
| 455 | e.stopPropagation(); |
| 456 | drawPage(page + 1); |
| 457 | }); |
| 458 | } |
| 459 | } |
| 460 | |
| 461 | drawPage(1); |
no test coverage detected