Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion routes/create/controllers/h5pPreviewController.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ body { margin:0; padding:40px; font-family:-apple-system,BlinkMacSystemFont,"Seg

const basePath = `/h5p-preview-files/${previewId}`;
const cssTags = cssFiles.map(f => ` <link rel="stylesheet" href="${basePath}/${f}">`).join('\n');
const jsTags = jsFiles.map(f => ` <script src="${basePath}/${f}"></script>`).join('\n');
const jsTags = jsFiles.map(f => ` <script src="${basePath}/${f}" onerror="window.__h5pLoadErrors=(window.__h5pLoadErrors||[]);window.__h5pLoadErrors.push('${f.replace(/'/g, "\\'")}')"></script>`).join('\n');

// Build per-question HTML blocks and H5P.newRunnable() calls
const questionBlocks = [];
Expand Down Expand Up @@ -281,6 +281,15 @@ ${cssTags}
${questionBlocks.join('\n')}
</div>

<script>
// Track JS errors during library loading (must be before library scripts)
window.__h5pErrors = [];
window.__h5pLoadErrors = [];
window.onerror = function(msg, src, line, col, err) {
window.__h5pErrors.push({msg: msg, src: src, line: line});
console.error('H5P Script Error:', msg, 'in', src, 'line', line);
};
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<script src="/api/create/h5p-preview/core/h5p-core.js"></script>
${jsTags}
Expand All @@ -291,6 +300,14 @@ ${jsTags}
H5P.$window = jQuery(window);

jQuery(document).ready(function() {
// Log load failures and available constructors for debugging
if (window.__h5pLoadErrors.length > 0) {
console.error('H5P: Failed to load scripts:', window.__h5pLoadErrors);
}
if (window.__h5pErrors.length > 0) {
console.error('H5P: JS errors during loading:', window.__h5pErrors);
}

${runnableCalls.join('\n')}
});
</script>
Expand Down
66 changes: 66 additions & 0 deletions routes/create/services/h5pExportService.js
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,72 @@ export function convertQuestionToH5P(question, quiz) {
"title": "Cloze question"
}
};
} else if (question.type === 'flashcard') {
const front = question.content?.front || question.questionText || "Front of card";
const back = question.content?.back || question.correctAnswer || "Back of card";
const escapedFront = front.replace(/</g, '&lt;').replace(/>/g, '&gt;');
const escapedBack = back.replace(/</g, '&lt;').replace(/>/g, '&gt;');

return {
"params": {
"mode": "normal",
"dialogs": [
{
"text": `<p style="text-align:center;">${escapedFront}</p>`,
"answer": `<p style="text-align:center;">${escapedBack}</p>`,
"tips": {},
"imageAltText": ""
}
],
"behaviour": {
"enableRetry": true,
"disableBackwardsNavigation": false,
"scaleTextNotCard": false,
"randomCards": false,
"maxProficiency": 5,
"quickProgression": false
},
"answer": "Turn",
"next": "Next",
"prev": "Previous",
"retry": "Retry",
"correctAnswer": "I got it right!",
"incorrectAnswer": "I got it wrong",
"round": "Round @round",
"cardsLeft": "Cards left: @number",
"nextRound": "Proceed to round @round",
"startOver": "Start over",
"showSummary": "Next",
"summary": "Summary",
"summaryCardsRight": "Cards you got right:",
"summaryCardsWrong": "Cards you got wrong:",
"summaryCardsNotShown": "Cards in pool not shown:",
"summaryOverallScore": "Overall Score",
"summaryCardsCompleted": "Cards you have completed learning:",
"summaryCompletedRounds": "Completed rounds:",
"summaryAllDone": "Well done! You have mastered all @cards cards!",
"progressText": "Card @card of @total",
"cardFrontLabel": "Card front",
"cardBackLabel": "Card back",
"tipButtonLabel": "Show tip",
"audioNotSupported": "Your browser does not support this audio",
"confirmStartingOver": {
"header": "Start over?",
"body": "All progress will be lost. Are you sure you want to start over?",
"cancelLabel": "Cancel",
"confirmLabel": "Start over"
},
"title": "",
"description": ""
},
"library": "H5P.Dialogcards 1.9",
"subContentId": crypto.randomBytes(16).toString('hex'),
"metadata": {
"contentType": "Dialog Cards",
"license": "U",
"title": "Flashcard"
}
};
} else if (question.type === 'discussion') {
return {
"params": {
Expand Down
Loading