@@ -824,3 +824,52 @@ function setupPreviewClarification($input, $previewDiv, previewInitial) {
824
824
$ ( function ( ) {
825
825
$ ( '[data-toggle="tooltip"]' ) . tooltip ( ) ;
826
826
} ) ;
827
+
828
+ // Make sure the items in the desktop scoreboard fit
829
+ document . querySelectorAll ( ".desktop-scoreboard .forceWidth:not(.toolong)" ) . forEach ( el => {
830
+ if ( el instanceof Element && el . scrollWidth > el . offsetWidth ) {
831
+ el . classList . add ( "toolong" ) ;
832
+ }
833
+ } ) ;
834
+
835
+ /**
836
+ * Helper method to resize mobile team names and problem badges
837
+ */
838
+ function resizeMobileTeamNamesAndProblemBadges ( ) {
839
+ // Make team names fit on the screen, but only when the mobile
840
+ // scoreboard is visible
841
+ const mobileScoreboard = document . querySelector ( '.mobile-scoreboard' ) ;
842
+ if ( mobileScoreboard . offsetWidth === 0 ) {
843
+ return ;
844
+ }
845
+ const windowWidth = document . body . offsetWidth ;
846
+ const teamNameMaxWidth = Math . max ( 10 , windowWidth - 150 ) ;
847
+ const problemBadgesMaxWidth = Math . max ( 10 , windowWidth - 78 ) ;
848
+ document . querySelectorAll ( ".mobile-scoreboard .forceWidth:not(.toolong)" ) . forEach ( el => {
849
+ el . classList . remove ( "toolong" ) ;
850
+ el . style . maxWidth = teamNameMaxWidth + 'px' ;
851
+ if ( el instanceof Element && el . scrollWidth > el . offsetWidth ) {
852
+ el . classList . add ( "toolong" ) ;
853
+ } else {
854
+ el . classList . remove ( "toolong" ) ;
855
+ }
856
+ } ) ;
857
+ document . querySelectorAll ( ".mobile-scoreboard .mobile-problem-badges:not(.toolong)" ) . forEach ( el => {
858
+ el . classList . remove ( "toolong" ) ;
859
+ el . style . maxWidth = problemBadgesMaxWidth + 'px' ;
860
+ if ( el instanceof Element && el . scrollWidth > el . offsetWidth ) {
861
+ el . classList . add ( "toolong" ) ;
862
+ const scale = el . offsetWidth / el . scrollWidth ;
863
+ const offset = - 1 * ( el . scrollWidth - el . offsetWidth ) / 2 ;
864
+ el . style . transform = `scale(${ scale } ) translateX(${ offset } px)` ;
865
+ } else {
866
+ el . classList . remove ( "toolong" ) ;
867
+ el . style . transform = null ;
868
+ }
869
+ } ) ;
870
+ }
871
+
872
+ if ( document . querySelector ( '.mobile-scoreboard' ) ) {
873
+ window . addEventListener ( 'resize' , resizeMobileTeamNamesAndProblemBadges ) ;
874
+ resizeMobileTeamNamesAndProblemBadges ( ) ;
875
+ }
0 commit comments