// Shared "Text size" card (models.Widget.font_scale, // _widget_font_scale_fields.html) -- only present on the calendar/tasks // dialogs (see frame_pages.py's widget_dialog), same "one shared init // function" shape as initBorderFields, just not included on every // dialog since it isn't relevant to every widget type. function initFontScaleFields() { const select = document.getElementById('widget_font_scale'); if (!select) return; // dialog fragment didn't render the font-scale card -- shouldn't happen document.getElementById('font-scale-config-form').addEventListener('submit', async (e) => { e.preventDefault(); try { const resp = await fetch(`${window.FRAME_API}/font-scale`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ font_scale: Number(select.value) }), }); if (!resp.ok) throw new Error(await apiError(resp)); showStatus(true, 'Text size saved.'); // Whichever dialog is actually open -- both loadCalendarPreview and // loadTasksPreview are always defined (plain script tags, not // module-scoped), so checking the function's existence isn't // enough; check for the it actually targets instead (calling // the wrong one throws setting .src on a null element). if (document.getElementById('calendar-preview')) loadCalendarPreview(); if (document.getElementById('tasks-preview')) loadTasksPreview(); } catch (err) { showStatus(false, err.message); } }); }