@@ -4,21 +4,34 @@ document.addEventListener("DOMContentLoaded", function () {
44 document . getElementById ( "judge0-year" ) . innerText = new Date ( ) . getFullYear ( ) ;
55} ) ;
66
7+ /**
8+ * Dropdown component consists of the following elements:
9+ * 1. A wrapper div with class "judge0-dropdown".
10+ * 2. A button with class "judge0-dropdown-btn".
11+ * 3. A span with class "judge0-dropdown-value".
12+ * 4. A div with class "judge0-dropdown-menu" that contains the dropdown options.
13+ * 5. A list of options with class "judge0-dropdown-option".
14+ *
15+ * If the dropdown is not select dropdown then classes (3) and (5) are not required.
16+ */
717document . body . addEventListener ( "click" , function ( event ) {
818 const dropdown = event . target . closest ( ".judge0-dropdown" ) ;
919 const dropdownBtn = event . target . closest ( ".judge0-dropdown-btn" ) ;
1020
1121 if ( event . target && dropdownBtn && dropdownBtn . contains ( event . target ) ) {
1222 dropdown . querySelector ( ".judge0-dropdown-menu" ) . classList . toggle ( "hidden" ) ;
1323 } else if ( event . target && event . target . classList . contains ( "judge0-dropdown-option" ) ) {
14- const span = dropdown . querySelector ( "span" ) ;
24+ const span = dropdown . querySelector ( "span.judge0-dropdown-value " ) ;
1525 span . innerText = event . target . innerText ;
1626 dropdown . querySelector ( ".judge0-dropdown-menu" ) . classList . toggle ( "hidden" ) ;
1727 }
1828
19- // For each dropdown menu check if it needs to be hidden.
20- // If the click is outside of the dropdown menu and if that dropdown menu is not
21- // the dropdown menu of the just clicked dropdown button, hide it.
29+ /**
30+ * For each dropdown menu check if it needs to be hidden.
31+ * Hide the dropdown menu if all applies:
32+ * 1. The click is outside of the dropdown menu.
33+ * 2. The dropdown menu is not the dropdown menu of the just clicked dropdown button.
34+ */
2235 document . querySelectorAll ( ".judge0-dropdown-menu" ) . forEach ( function ( dropdownMenu ) {
2336 if ( ! dropdownMenu . contains ( event . target ) && dropdown !== dropdownMenu . closest ( ".judge0-dropdown" ) ) {
2437 dropdownMenu . classList . add ( "hidden" ) ;
0 commit comments