`;
}
function fof_updatePreview() {
if (!fof_previewContent) return;
fof_previewContent.innerHTML = fof_generatePageHTML(fof_state);
}
function fof_updateCodeOutput() {
if (!fof_codeOutput) return;
fof_codeOutput.value = fof_generatePageHTML(fof_state);
}
function fof_copyCode() {
if (!fof_codeOutput) return;
fof_codeOutput.select();
try {
navigator.clipboard.writeText(fof_codeOutput.value);
fof_copyBtn.textContent = "Copied!";
setTimeout(() => { fof_copyBtn.textContent = "Copy to Clipboard"; }, 2000);
} catch (err) {
console.error('Failed to copy code: ', err);
fof_copyBtn.textContent = "Error";
setTimeout(() => { fof_copyBtn.textContent = "Copy to Clipboard"; }, 2000);
}
}
// --- TAB NAVIGATION ---
window.fof_showTab = function (tabIndex, element) {
if (!fof_tabPanels || !fof_tabLinks) return;
fof_currentTab = tabIndex;
fof_tabPanels.forEach((panel) => panel.classList.remove("fof-active"));
fof_tabLinks.forEach((link) => link.classList.remove("fof-active"));
if (fof_tabPanels[tabIndex]) {
fof_tabPanels[tabIndex].classList.add("fof-active");
}
if (element) {
element.classList.add("fof-active");
}
fof_updateNavButtons();
};
function fof_goToNextTab() {
if (fof_currentTab < fof_tabPanels.length - 1) {
fof_currentTab++;
fof_showTab(fof_currentTab, fof_tabLinks[fof_currentTab]);
}
}
function fof_goToPrevTab() {
if (fof_currentTab > 0) {
fof_currentTab--;
fof_showTab(fof_currentTab, fof_tabLinks[fof_currentTab]);
}
}
function fof_updateNavButtons() {
if (!fof_prevBtn || !fof_nextBtn) return;
fof_prevBtn.disabled = fof_currentTab === 0;
fof_nextBtn.disabled = fof_currentTab === fof_tabPanels.length - 1;
}
// --- PDF EXPORT ---
function fof_downloadPDF() {
if (typeof jspdf === "undefined") {
console.error("jsPDF library not loaded.");
alert("Error: PDF generation library failed to load.");
return;
}
// Hide buttons from PDF
const pdfBtnOriginalDisplay = fof_pdfBtn.style.display;
fof_pdfBtn.style.display = 'none';
const { jsPDF } = jspdf;
const doc = new jsPDF({
orientation: "p",
unit: "pt",
format: "a4"
});
doc.html(fof_previewWrapper, {
callback: function(doc) {
doc.save('404-Page-Preview.pdf');
// Restore button
fof_pdfBtn.style.display = pdfBtnOriginalDisplay;
},
x: 10,
y: 10,
width: 575, // A4 width in points is ~595, minus margins
windowWidth: fof_previewWrapper.scrollWidth
});
}
})();
