No jokes in setlist yet. Go to the Joke Builder to add some!
';
return;
}
jokesData.forEach((joke, index) => {
const card = document.createElement('div');
card.className = 'scjt-joke-card';
// Logic to display tags only if they exist
const tagsHtml = joke.tags ? `
Tags / Notes
${escapeHtml(joke.tags)}
` : '';
card.innerHTML = `
Setup
${escapeHtml(joke.setup)}
Punchline
${escapeHtml(joke.punchline)}
${tagsHtml}
`;
dashboardContainer.appendChild(card);
});
}
function renderConfigTable() {
configTbody.innerHTML = '';
if (jokesData.length === 0) {
configTbody.innerHTML = '
| No data available. |
';
return;
}
jokesData.forEach(joke => {
const tr = document.createElement('tr');
tr.innerHTML = `
${escapeHtml(joke.topic)} |
${escapeHtml(truncate(joke.setup, 40))} |
${escapeHtml(truncate(joke.punchline, 40))} |
|
`;
configTbody.appendChild(tr);
});
}
// --- Helper Functions ---
function escapeHtml(text) {
if (!text) return '';
return text
.replace(/&/g, "&")
.replace(//g, ">")
.replace(/"/g, """)
.replace(/'/g, "'");
}
function truncate(str, n){
return (str.length > n) ? str.substr(0, n-1) + '…' : str;
}
// --- Event Handlers ---
addJokeBtn.addEventListener('click', function() {
if(!inputTopic.value || !inputSetup.value || !inputPunchline.value) {
alert('Please fill in the Topic, Setup, and Punchline fields.');
return;
}
const newJoke = {
id: Date.now(),
topic: inputTopic.value.trim(),
setup: inputSetup.value.trim(),
punchline: inputPunchline.value.trim(),
tags: inputTags.value.trim()
};
jokesData.push(newJoke);
// Clear inputs
inputTopic.value = '';
inputSetup.value = '';
inputPunchline.value = '';
inputTags.value = '';
renderDashboard();
renderConfigTable();
scjtSwitchTab('dashboard');
});
// Global Functions for Inline OnClick
window.scjtSwitchTab = function(tabName) {
const tabs = ['dashboard', 'builder', 'config'];
const buttons = document.querySelectorAll('.scjt-tab-btn');
// Update Buttons
buttons.forEach((btn, index) => {
if(tabs[index] === tabName) {
btn.classList.add('active');
} else {
btn.classList.remove('active');
}
});
// Update Content
tabs.forEach(t => {
const el = document.getElementById('scjt-tab-' + t);
if (t === tabName) {
el.classList.add('active');
} else {
el.classList.remove('active');
}
});
};
window.scjtDeleteJoke = function(id) {
if(confirm('Are you sure you want to delete this joke?')) {
jokesData = jokesData.filter(j => j.id !== id);
renderDashboard();
renderConfigTable();
}
};
window.scjtEditJoke = function(id) {
const joke = jokesData.find(j => j.id === id);
if(joke) {
// Delete existing first to "update" it on save
if(confirm(`Edit "${joke.topic}"? This will move it to the Joke Builder for modification.`)) {
jokesData = jokesData.filter(j => j.id !== id);
inputTopic.value = joke.topic;
inputSetup.value = joke.setup;
inputPunchline.value = joke.punchline;
inputTags.value = joke.tags;
scjtSwitchTab('builder');
renderDashboard();
renderConfigTable();
}
}
};
window.scjtResetData = function() {
if(confirm('This will delete all current jokes and reset to defaults. Are you sure?')) {
jokesData = [...defaultJokes];
renderDashboard();
renderConfigTable();
scjtSwitchTab('dashboard');
}
};
// --- PDF Generation ---
pdfBtn.addEventListener('click', function() {
const element = document.getElementById('scjt-print-area');
const pdfHeader = document.getElementById('scjt-pdf-header');
// Show header for PDF
pdfHeader.style.display = 'block';
const opt = {
margin: [0.5, 0.5, 0.5, 0.5], // inches
filename: 'My_StandUp_Setlist.pdf',
image: { type: 'jpeg', quality: 0.98 },
html2canvas: { scale: 2, useCORS: true },
jsPDF: { unit: 'in', format: 'letter', orientation: 'portrait' }
};
// Add class to body to help CSS hide elements if needed
document.body.classList.add('scjt-generating-pdf');
// Temporarily hide non-pdf elements inside the card
const noPdfElements = document.querySelectorAll('.scjt-no-pdf');
noPdfElements.forEach(el => el.style.display = 'none');
html2pdf().set(opt).from(element).save().then(() => {
// Cleanup after save
pdfHeader.style.display = 'none';
document.body.classList.remove('scjt-generating-pdf');
noPdfElements.forEach(el => el.style.display = '');
});
});
// Initialize Tool
init();
});