@@ -944,3 +944,52 @@ function initializeKeyboardShortcuts() {
944
944
}
945
945
} ) ;
946
946
}
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
+ }
0 commit comments