Skip to content

Commit e164fbb

Browse files
Move scoreboard javascript to JS file so browser can cache it.
1 parent 81ba953 commit e164fbb

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

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)