(playerName, roundNum, button)
| 429 | |
| 430 | // Trajectory diffs loading functionality |
| 431 | function loadTrajectoryDiffs(playerName, roundNum, button) { |
| 432 | const container = button.closest(".trajectory-content"); |
| 433 | |
| 434 | // Find the specific placeholder that contains this button |
| 435 | const placeholder = button.closest( |
| 436 | ".diff-load-placeholder, .incremental-diff-load-placeholder, .modified-files-load-placeholder", |
| 437 | ); |
| 438 | |
| 439 | // Try to find trajectory header |
| 440 | let trajectoryHeader = button.closest(".trajectory-header"); |
| 441 | |
| 442 | // If not found, try looking up from container |
| 443 | if (!trajectoryHeader && container) { |
| 444 | trajectoryHeader = container.closest(".trajectory-header"); |
| 445 | } |
| 446 | |
| 447 | // If still not found, look for parent details element and then its parent |
| 448 | if (!trajectoryHeader) { |
| 449 | const detailsElement = button.closest("details"); |
| 450 | if (detailsElement) { |
| 451 | trajectoryHeader = detailsElement.parentElement; |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | // Get selected folder from page |
| 456 | const selectedFolder = |
| 457 | document.body.getAttribute("data-folder") || |
| 458 | new URLSearchParams(window.location.search).get("folder"); |
| 459 | |
| 460 | if (!selectedFolder) { |
| 461 | alert("Error: Could not determine selected folder"); |
| 462 | return; |
| 463 | } |
| 464 | |
| 465 | // Hide placeholder and show loading |
| 466 | if (placeholder) { |
| 467 | placeholder.style.display = "none"; |
| 468 | } |
| 469 | |
| 470 | if (container) { |
| 471 | container.innerHTML = |
| 472 | '<div style="padding: 2rem; text-align: center;">Loading...</div>'; |
| 473 | } |
| 474 | |
| 475 | // Store trajectoryHeader in the outer scope to use in the fetch handler |
| 476 | const finalTrajectoryHeader = trajectoryHeader; |
| 477 | |
| 478 | // Fetch diff data from server |
| 479 | fetch( |
| 480 | `/load-trajectory-diffs?folder=${encodeURIComponent(selectedFolder)}&player=${encodeURIComponent(playerName)}&round=${roundNum}`, |
| 481 | ) |
| 482 | .then((response) => response.json()) |
| 483 | .then((data) => { |
| 484 | if (data.success) { |
| 485 | if (finalTrajectoryHeader) { |
| 486 | // 1. Populate main diff section |
| 487 | const diffContainer = finalTrajectoryHeader.querySelector( |
| 488 | ".trajectory-diffs-foldout .trajectory-content", |
no test coverage detected