Skip to content

Commit 0a82007

Browse files
Move scoreboard javascript to JS file so browser can cache it.
1 parent 3cd918f commit 0a82007

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

webapp/public/js/domjudge.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -944,3 +944,52 @@ function initializeKeyboardShortcuts() {
944944
}
945945
});
946946
}
947+
948+
// Make sure the items in the desktop scoreboard fit
949+
document.querySelectorAll(".desktop-scoreboard .forceWidth:not(.toolong)").forEach(el => {
950+
if (el instanceof Element && el.scrollWidth > el.offsetWidth) {
951+
el.classList.add("toolong");
952+
}
953+
});
954+
955+
/**
956+
* Helper method to resize mobile team names and problem badges
957+
*/
958+
function resizeMobileTeamNamesAndProblemBadges() {
959+
// Make team names fit on the screen, but only when the mobile
960+
// scoreboard is visible
961+
const mobileScoreboard = document.querySelector('.mobile-scoreboard');
962+
if (mobileScoreboard.offsetWidth === 0) {
963+
return;
964+
}
965+
const windowWidth = document.body.offsetWidth;
966+
const teamNameMaxWidth = Math.max(10, windowWidth - 150);
967+
const problemBadgesMaxWidth = Math.max(10, windowWidth - 78);
968+
document.querySelectorAll(".mobile-scoreboard .forceWidth:not(.toolong)").forEach(el => {
969+
el.classList.remove("toolong");
970+
el.style.maxWidth = teamNameMaxWidth + 'px';
971+
if (el instanceof Element && el.scrollWidth > el.offsetWidth) {
972+
el.classList.add("toolong");
973+
} else {
974+
el.classList.remove("toolong");
975+
}
976+
});
977+
document.querySelectorAll(".mobile-scoreboard .mobile-problem-badges:not(.toolong)").forEach(el => {
978+
el.classList.remove("toolong");
979+
el.style.maxWidth = problemBadgesMaxWidth + 'px';
980+
if (el instanceof Element && el.scrollWidth > el.offsetWidth) {
981+
el.classList.add("toolong");
982+
const scale = el.offsetWidth / el.scrollWidth;
983+
const offset = -1 * (el.scrollWidth - el.offsetWidth) / 2;
984+
el.style.transform = `scale(${scale}) translateX(${offset}px)`;
985+
} else {
986+
el.classList.remove("toolong");
987+
el.style.transform = null;
988+
}
989+
});
990+
}
991+
992+
if (document.querySelector('.mobile-scoreboard')) {
993+
window.addEventListener('resize', resizeMobileTeamNamesAndProblemBadges);
994+
resizeMobileTeamNamesAndProblemBadges();
995+
}

webapp/templates/public/scoreboard.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
{% if static and refresh is defined %}
5454
disableRefreshOnModal();
5555
{% endif %}
56-
resizeMobileTeamNames();
56+
resizeMobileTeamNamesAndProblemBadges();
5757
};
5858
5959
{% if static and refresh is defined %}

0 commit comments

Comments
 (0)