@@ -170,27 +170,78 @@ function initializeExportSelection() {
170170 const presetRadios = document . querySelectorAll ( 'input[name="preset"]' )
171171 const formatRadios = document . querySelectorAll ( 'input[name="format"]' )
172172
173- // When preset is selected, deselect formats
173+ // When preset is selected, deselect formats and update settings
174174 presetRadios . forEach ( ( radio ) => {
175175 radio . addEventListener ( 'change' , ( ) => {
176176 if ( radio . checked ) {
177177 formatRadios . forEach ( ( formatRadio ) => {
178178 formatRadio . checked = false
179179 } )
180+ updateAdvancedSettings ( radio . value )
180181 }
181182 } )
182183 } )
183184
184- // When format is selected, deselect presets
185+ // When format is selected, deselect presets and update settings
185186 formatRadios . forEach ( ( radio ) => {
186187 radio . addEventListener ( 'change' , ( ) => {
187188 if ( radio . checked ) {
188189 presetRadios . forEach ( ( presetRadio ) => {
189190 presetRadio . checked = false
190191 } )
192+ updateAdvancedSettings ( radio . value )
191193 }
192194 } )
193195 } )
196+
197+ // Initialize with default selection (Moodle)
198+ updateAdvancedSettings ( 'moodle' )
199+
200+ // PDF-specific: Toggle header/footer template fields
201+ initializePdfHeaderFooter ( )
202+ }
203+
204+ // Initialize PDF header/footer toggle
205+ function initializePdfHeaderFooter ( ) {
206+ const displayHeaderFooter = document . getElementById ( 'pdfDisplayHeaderFooter' )
207+ const headerGroup = document . getElementById ( 'pdfHeaderGroup' )
208+ const footerGroup = document . getElementById ( 'pdfFooterGroup' )
209+
210+ if ( displayHeaderFooter && headerGroup && footerGroup ) {
211+ displayHeaderFooter . addEventListener ( 'change' , ( ) => {
212+ if ( displayHeaderFooter . checked ) {
213+ headerGroup . style . display = 'block'
214+ footerGroup . style . display = 'block'
215+ } else {
216+ headerGroup . style . display = 'none'
217+ footerGroup . style . display = 'none'
218+ }
219+ } )
220+ }
221+ }
222+
223+ // Update advanced settings based on selected format
224+ function updateAdvancedSettings ( selectedValue ) {
225+ const settingsGroups = document . querySelectorAll ( '.settings-group' )
226+ const noSettings = document . querySelector ( '.settings-group.no-settings' )
227+ let hasVisibleSettings = false
228+
229+ settingsGroups . forEach ( ( group ) => {
230+ if ( group . classList . contains ( 'no-settings' ) ) return
231+
232+ const formats = group . dataset . formats
233+ if ( formats && formats . split ( ',' ) . includes ( selectedValue ) ) {
234+ group . style . display = 'block'
235+ hasVisibleSettings = true
236+ } else {
237+ group . style . display = 'none'
238+ }
239+ } )
240+
241+ // Show "no settings" message if no specific settings available
242+ if ( noSettings ) {
243+ noSettings . style . display = hasVisibleSettings ? 'none' : 'block'
244+ }
194245}
195246
196247// Advanced settings
0 commit comments