@@ -21,15 +21,26 @@ for (const element of templateItems) {
21
21
} ) ;
22
22
}
23
23
24
- $ ( function ( ) {
25
- $ ( '#hiddenSourceFilePath' ) . text ( $ ( '#sourceFilePath' ) . val ( ) ) ;
26
- $ ( '#sourceFilePath' ) . width ( $ ( '#hiddenSourceFilePath' ) . width ( ) ) ;
27
- } ) . on ( 'input' , function ( ) {
28
- $ ( '#hiddenSourceFilePath' ) . text ( $ ( '#sourceFilePath' ) . val ( ) ) ;
29
- $ ( '#sourceFilePath' ) . width ( $ ( '#hiddenSourceFilePath' ) . width ( ) + 12 ) ;
30
- const remaining =
31
- document . querySelector ( '.topnav' ) . offsetWidth - document . querySelector ( '#template-select' ) . offsetWidth - 330 ;
32
- $ ( '#sourceFilePath' ) . css ( 'maxWidth' , remaining ) ;
24
+ window . addEventListener ( 'DOMContentLoaded' , ( ) => {
25
+ const sourceFilePath = document . getElementById ( 'sourceFilePath' ) ;
26
+ const hiddenSourceFilePath = document . getElementById ( 'hiddenSourceFilePath' ) ;
27
+ if ( ! sourceFilePath || ! hiddenSourceFilePath ) return ;
28
+
29
+ const adjustSourceWidth = ( ) => {
30
+ hiddenSourceFilePath . textContent = sourceFilePath . value ;
31
+ hiddenSourceFilePath . style . display = 'inline' ;
32
+ sourceFilePath . style . width = `${ hiddenSourceFilePath . offsetWidth + 12 } px` ;
33
+ hiddenSourceFilePath . style . display = 'none' ;
34
+
35
+ const remaining =
36
+ document . querySelector ( '.topnav' ) . offsetWidth -
37
+ document . querySelector ( '#template-select' ) . offsetWidth -
38
+ 330 ;
39
+ sourceFilePath . style . maxWidth = `${ remaining } px` ;
40
+ } ;
41
+
42
+ sourceFilePath . addEventListener ( 'input' , adjustSourceWidth ) ;
43
+ adjustSourceWidth ( ) ;
33
44
} ) ;
34
45
35
46
let loadbutton = document . getElementById ( 'load-problem' ) ;
0 commit comments