Science Resource List Generator
Catalog educational materials, tools, and links by scientific discipline.
Enter resource details including the subject topic, the type of resource, and its access link.
Review the final resource catalog. Use the filter to display resources by specific topic.
${resource.type} — ${resource.url}
`; resourceList.appendChild(cardDiv); }); } // --- Tab Switching --- function srlg_showTab(targetId, element) { tabButtons.forEach(btn => btn.classList.remove('srlg-active')); document.querySelectorAll('.srlg-tab-content').forEach(content => content.classList.remove('active')); if (element) { element.classList.add('srlg-active'); } document.getElementById(targetId).classList.add('active'); if (targetId === 'review') { srlg_renderReview(dom.topicFilter.value); } } window.srlg_showTab = srlg_showTab; // --- PDF Export --- function srlg_downloadPDF() { srlg_collectResourceData(); const filterTopic = dom.topicFilter.value; if (typeof jspdf === 'undefined' || typeof jspdf.plugin.autotable === 'undefined') { alert('Error: PDF library not fully loaded for export.'); return; } const filteredResources = filterTopic === 'all' ? SRLG_STATE.resources : SRLG_STATE.resources.filter(c => c.topic === filterTopic); if (filteredResources.length === 0) { alert('No resources match the current filter selection for export.'); return; } const { jsPDF } = jspdf; const doc = new jsPDF({ orientation: 'l', unit: 'pt', format: 'a4' }); doc.setFont('sans-serif', 'normal'); const margin = 40; const pageWidth = doc.internal.pageSize.getWidth(); let yPos = margin; // --- Header --- doc.setFontSize(18); doc.setFont('sans-serif', 'bold'); doc.setTextColor('#0891b2'); // Cyan-600 doc.text(`Science Resource Catalog: ${filterTopic === 'all' ? 'All Topics' : filterTopic}`, pageWidth / 2, yPos, { align: 'center' }); yPos += 30; // --- Resource Table --- doc.setFontSize(10); const tableHeaders = ['#', 'Topic', 'Resource Name', 'Type', 'URL / Link']; const tableBody = filteredResources.map((resource, index) => [ (index + 1).toString(), resource.topic, resource.name, resource.type, resource.url ]); doc.autoTable({ head: [tableHeaders], body: tableBody, startY: yPos, theme: 'grid', styles: { fontSize: 9, cellPadding: 6, overflow: 'linebreak' }, headStyles: { fillColor: [8, 145, 178], textColor: 255, fontStyle: 'bold' }, // Cyan-600 alternateRowStyles: { fillColor: [245, 255, 255] }, columnStyles: { 0: { cellWidth: 20, halign: 'center' }, 2: { cellWidth: 150 }, // Name gets space 4: { cellWidth: 150 } // URL gets space }, didDrawPage: function(data) { yPos = data.cursor.y; } }); doc.save(`Science_Resource_List_${filterTopic.replace(/\s/g, '_')}.pdf`); } // --- Initialization --- document.addEventListener('DOMContentLoaded', () => { // 1. Assign DOM elements dom.topicFilter = document.getElementById('topic-filter'); // 2. Attach listeners document.getElementById('srlg-add-resource-btn').addEventListener('click', srlg_addResource); document.getElementById('matrix-next-btn').addEventListener('click', () => srlg_showTab('review', document.querySelector('.srlg-tab-btn[data-tab="review"]'))); document.getElementById('srlg-download-pdf').addEventListener('click', srlg_downloadPDF); tabButtons.forEach(btn => { btn.addEventListener('click', (e) => srlg_showTab(e.target.dataset.tab, e.target)); }); // Filter listener dom.topicFilter.addEventListener('change', () => srlg_renderReview(dom.topicFilter.value)); // 3. Initial population srlg_renderMatrixTable(); });