@@ -18,45 +18,50 @@ function initializeLocalTheme() {
1818 } ) ;
1919}
2020
21- function initializeCustomSelect ( ) {
21+ function initializeCustomSelect ( { initialValue = null , addListeners = false } ) {
2222 const button = document . getElementById ( 'language-button' ) ;
2323 const select = document . getElementById ( 'language-select' ) ;
2424 if ( ! button || ! select ) return ;
2525
2626 const dropdown = button . nextElementSibling ;
2727 const selectedValue = button . querySelector ( '.selected-value' ) ;
2828
29+ if ( initialValue ) {
30+ select . value = initialValue ;
31+ }
2932 selectedValue . textContent = select . options [ select . selectedIndex ] . text ;
3033
31- button . addEventListener ( 'click' , ( e ) => {
32- e . preventDefault ( ) ; // Prevent form submission
33- dropdown . classList . toggle ( 'show' ) ;
34- } ) ;
34+ if ( addListeners ) {
35+ button . addEventListener ( 'click' , ( e ) => {
36+ e . preventDefault ( ) ; // Prevent form submission
37+ dropdown . classList . toggle ( 'show' ) ;
38+ } ) ;
3539
36- document . addEventListener ( 'click' , ( e ) => {
37- if ( ! button . contains ( e . target ) ) {
38- dropdown . classList . remove ( 'show' ) ;
39- }
40- } ) ;
40+ document . addEventListener ( 'click' , ( e ) => {
41+ if ( ! button . contains ( e . target ) ) {
42+ dropdown . classList . remove ( 'show' ) ;
43+ }
44+ } ) ;
4145
42- dropdown . querySelectorAll ( '.option' ) . forEach ( option => {
43- option . addEventListener ( 'click' , ( ) => {
44- selectedValue . textContent = option . textContent ;
45- select . value = option . dataset . value ;
46- dropdown . classList . remove ( 'show' ) ;
46+ dropdown . querySelectorAll ( '.option' ) . forEach ( option => {
47+ option . addEventListener ( 'click' , ( ) => {
48+ selectedValue . textContent = option . textContent ;
49+ select . value = option . dataset . value ;
50+ dropdown . classList . remove ( 'show' ) ;
4751
48- const event = new Event ( 'change' ) ;
49- select . dispatchEvent ( event ) ;
52+ const event = new Event ( 'change' ) ;
53+ select . dispatchEvent ( event ) ;
54+ } ) ;
5055 } ) ;
51- } ) ;
56+ }
5257}
5358
5459window . initializePlayground = async function initializePlayground ( opts ) {
5560 const { local } = opts ;
5661 if ( local ) {
5762 initializeLocalTheme ( ) ;
5863 }
59- initializeCustomSelect ( ) ;
64+ initializeCustomSelect ( { addListeners : true } ) ;
6065
6166 let tree ;
6267
@@ -565,6 +570,7 @@ window.initializePlayground = async function initializePlayground(opts) {
565570 queryInput . value = query ;
566571 codeInput . value = sourceCode ;
567572 languageSelect . value = language ;
573+ initializeCustomSelect ( { initialValue : language } ) ;
568574 anonymousNodes . checked = anonNodes === "true" ;
569575 queryCheckbox . checked = queryEnabled === "true" ;
570576 }
0 commit comments