@@ -938,3 +938,52 @@ function initializeKeyboardShortcuts() {
938
938
}
939
939
} ) ;
940
940
}
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
+ }
0 commit comments