`;
} else {
for (let i = 0; i < weekInputs.length; i++) {
const weekNum = i + 1;
syllabusHTML += `
Week ${weekNum}: ${document.getElementById(`week-title-${weekNum}`)?.value || 'Topics'}
Topics: ${document.getElementById(`week-topics-${weekNum}`)?.value || 'Not specified'}
Readings: ${document.getElementById(`week-readings-${weekNum}`)?.value || 'None'}
Assignments: ${document.getElementById(`week-assignments-${weekNum}`)?.value || 'None'}
`;
}
}
// Add assessments
syllabusHTML += `
Assessments
`;
const assessmentInputs = document.getElementById('assessment-inputs').children;
if (assessmentInputs.length === 0) {
syllabusHTML += `
No assessments added yet.
`;
} else {
for (let i = 0; i < assessmentInputs.length; i++) {
const assessmentNum = i + 1;
const dueDate = document.getElementById(`assessment-date-${assessmentNum}`)?.value
? new Date(document.getElementById(`assessment-date-${assessmentNum}`).value).toLocaleDateString()
: 'Not specified';
syllabusHTML += `
${document.getElementById(`assessment-name-${assessmentNum}`)?.value || 'Assessment'}
Due Date: ${dueDate}
Description: ${document.getElementById(`assessment-desc-${assessmentNum}`)?.value || 'Not specified'}
Weight: ${document.getElementById(`assessment-weight-${assessmentNum}`)?.value || '0'}%
`;
}
}
output.innerHTML = syllabusHTML;
}
// Export as HTML
function exportHTML() {
const output = document.getElementById('syllabus-output').innerHTML;
const title = document.getElementById('course-title').value || 'syllabus';
const blob = new Blob([`
${title}${output}`], {type: 'text/html'});
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `${title.toLowerCase().replace(/\s+/g, '-')}-syllabus.html`;
a.click();
}
// Get CSS styles for HTML export
function getCSSStyles() {
return `
body {
font-family: 'Poppins', sans-serif;
background-color: white;
color: #212529;
line-height: 1.6;
padding: 2rem;
max-width: 1000px;
margin: 0 auto;
}
.output-course-title {
font-size: 2rem;
color: #4361ee;
margin-bottom: 0.5rem;
}
.output-meta {
display: flex;
gap: 2rem;
margin-bottom: 1.5rem;
color: #6c757d;
}
h2 {
font-size: 1.5rem;
color: #3f37c9;
margin: 2rem 0 1.5rem;
padding-bottom: 0.5rem;
border-bottom: 2px solid #4895ef;
}
.week-item, .assessment-item {
background: white;
border-radius: 8px;
padding: 1.5rem;
margin-bottom: 1.5rem;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
border-left: 4px solid #4895ef;
}
.week-item h3, .assessment-item h3 {
color: #3f37c9;
margin-bottom: 1rem;
font-size: 1.2rem;
}
p {
margin-bottom: 0.75rem;
}
strong {
color: #212529;
}
`;
}
// Export as PDF
function exportPDF() {
const element = document.getElementById('syllabus-output');
const title = document.getElementById('course-title').value || 'syllabus';
html2canvas(element, {
scale: 2,
logging: false,
useCORS: true,
allowTaint: true
}).then(canvas => {
const imgData = canvas.toDataURL('image/png');
const pdf = new jsPDF({
orientation: 'portrait',
unit: 'mm'
});
const imgWidth = 210; // A4 width in mm
const pageHeight = 295; // A4 height in mm
const imgHeight = canvas.height * imgWidth / canvas.width;
let heightLeft = imgHeight;
let position = 0;
pdf.addImage(imgData, 'PNG', 0, position, imgWidth, imgHeight);
heightLeft -= pageHeight;
while (heightLeft >= 0) {
position = heightLeft - imgHeight;
pdf.addPage();
pdf.addImage(imgData, 'PNG', 0, position, imgWidth, imgHeight);
heightLeft -= pageHeight;
}
pdf.save(`${title.toLowerCase().replace(/\s+/g, '-')}-syllabus.pdf`);
});
}
// Print syllabus
function printSyllabus() {
const printContent = document.getElementById('syllabus-output').innerHTML;
const originalContent = document.body.innerHTML;
document.body.innerHTML = printContent;
window.print();
document.body.innerHTML = originalContent;
generateSyllabus(); // Restore the preview
}
// Reset form
function resetForm() {
if (confirm('Are you sure you want to reset all inputs?')) {
document.getElementById('course-title').value = '';
document.getElementById('course-code').value = '';
document.getElementById('instructor').value = '';
document.getElementById('duration').value = '';
document.getElementById('week-inputs').innerHTML = '';
document.getElementById('assessment-inputs').innerHTML = '';
document.getElementById('syllabus-output').innerHTML = `
Your syllabus will appear here
Fill in the details on the left and click "Generate Syllabus"
`;
}
}
// Add initial week and assessment for better UX
document.addEventListener('DOMContentLoaded', function() {
addWeek();
addAssessment();
});