Change how H5Ps are integrated.

d6
Frode Petterson 2015-02-27 13:59:42 +01:00
parent d1cc8bcb71
commit f2595b2bce
7 changed files with 65 additions and 29 deletions

View File

@ -13,13 +13,8 @@
<body> <body>
<div class="h5p-content" data-content-id="<?php print $content['id']; ?>"></div> <div class="h5p-content" data-content-id="<?php print $content['id']; ?>"></div>
<script> <script>
H5PIntegration = <?php print json_encode($integration); ?>;
H5P.jQuery(document).ready(function () { H5P.jQuery(document).ready(function () {
H5P.postUserStatistics = <?php print $settings['postUserStatistics'] ? 'true' : 'false'; ?>;
H5P.ajaxPath = '<?php print $settings['ajaxPath']; ?>';
H5P.url = '<?php print $settings['url']; ?>';
H5P.l10n = {H5P: <?php print json_encode($settings['i18n']); ?>};
H5P.contentDatas = {'cid-<?php print $content['id']; ?>': <?php print json_encode($contentSettings); ?>};
H5P.user = <?php print json_encode($settings['user']); ?>;
H5P.init(); H5P.init();
}); });
</script> </script>

View File

@ -7,7 +7,7 @@ var H5PUpgrades = H5PUpgrades || {};
// Initialize // Initialize
$(document).ready(function () { $(document).ready(function () {
// Get library info // Get library info
info = H5PIntegration.getLibraryInfo(); info = H5PAdminIntegration.libraryInfo;
// Get and reset container // Get and reset container
$container = $('#h5p-admin-container').html('<p>' + info.message + '</p>'); $container = $('#h5p-admin-container').html('<p>' + info.message + '</p>');

View File

@ -7,8 +7,8 @@ var H5PLibraryDetails= H5PLibraryDetails || {};
* Initializing * Initializing
*/ */
H5PLibraryDetails.init = function () { H5PLibraryDetails.init = function () {
H5PLibraryDetails.$adminContainer = H5PIntegration.getAdminContainer(); H5PLibraryDetails.$adminContainer = H5P.jQuery(H5PAdminIntegration.containerSelector);
H5PLibraryDetails.library = H5PIntegration.getLibraryInfo(); H5PLibraryDetails.library = H5PAdminIntegration.libraryInfo;
// currentContent holds the current list if data (relevant for filtering) // currentContent holds the current list if data (relevant for filtering)
H5PLibraryDetails.currentContent = H5PLibraryDetails.library.content; H5PLibraryDetails.currentContent = H5PLibraryDetails.library.content;

View File

@ -7,15 +7,15 @@ var H5PLibraryList = H5PLibraryList || {};
* Initializing * Initializing
*/ */
H5PLibraryList.init = function () { H5PLibraryList.init = function () {
var $adminContainer = H5PIntegration.getAdminContainer(); var $adminContainer = H5P.jQuery(H5PAdminIntegration.containerSelector);
var libraryList = H5PIntegration.getLibraryList(); var libraryList = H5PAdminIntegration.libraryList;
if (libraryList.notCached) { if (libraryList.notCached) {
$adminContainer.append(H5PUtils.getRebuildCache(libraryList.notCached)); $adminContainer.append(H5PUtils.getRebuildCache(libraryList.notCached));
} }
// Create library list // Create library list
$adminContainer.append(H5PLibraryList.createLibraryList(H5PIntegration.getLibraryList())); $adminContainer.append(H5PLibraryList.createLibraryList(H5PAdminIntegration.libraryList));
}; };
/** /**
@ -24,7 +24,7 @@ var H5PLibraryList = H5PLibraryList || {};
* @param {object} libraries List of libraries and headers * @param {object} libraries List of libraries and headers
*/ */
H5PLibraryList.createLibraryList = function (libraries) { H5PLibraryList.createLibraryList = function (libraries) {
var t = H5PIntegration.i18n.H5P; var t = H5PAdminIntegration.l10n;
if(libraries.listData === undefined || libraries.listData.length === 0) { if(libraries.listData === undefined || libraries.listData.length === 0) {
return $('<div>' + t.NA + '</div>'); return $('<div>' + t.NA + '</div>');
} }
@ -123,7 +123,7 @@ var H5PLibraryList = H5PLibraryList || {};
} }
} }
}; };
// Initialize me: // Initialize me:
$(document).ready(function () { $(document).ready(function () {
if (!H5PLibraryList.initialized) { if (!H5PLibraryList.initialized) {

View File

@ -7,7 +7,7 @@ var H5PUtils = H5PUtils || {};
* @param {array} headers List of headers * @param {array} headers List of headers
*/ */
H5PUtils.createTable = function (headers) { H5PUtils.createTable = function (headers) {
var $table = $('<table class="h5p-admin-table' + (H5PIntegration.extraTableClasses !== undefined ? ' ' + H5PIntegration.extraTableClasses : '') + '"></table>'); var $table = $('<table class="h5p-admin-table' + (H5PAdminIntegration.extraTableClasses !== undefined ? ' ' + H5PAdminIntegration.extraTableClasses : '') + '"></table>');
if(headers) { if(headers) {
var $thead = $('<thead></thead>'); var $thead = $('<thead></thead>');

View File

@ -99,8 +99,8 @@ H5P.XAPIEvent.prototype.setObject = function(instance) {
*/ */
H5P.XAPIEvent.prototype.setActor = function() { H5P.XAPIEvent.prototype.setActor = function() {
this.data.statement.actor = { this.data.statement.actor = {
'name': H5P.user.name, 'name': H5PIntegration.user.name,
'mbox': 'mailto:' + H5P.user.mail, 'mbox': 'mailto:' + H5PIntegration.user.mail,
'objectType': 'Agent' 'objectType': 'Agent'
}; };
}; };

View File

@ -48,7 +48,7 @@ H5P.init = function () {
var $element = H5P.jQuery(this); var $element = H5P.jQuery(this);
var $container = H5P.jQuery('<div class="h5p-container"></div>').appendTo($element); var $container = H5P.jQuery('<div class="h5p-container"></div>').appendTo($element);
var contentId = $element.data('content-id'); var contentId = $element.data('content-id');
var contentData = H5P.contentDatas['cid-' + contentId]; var contentData = H5PIntegration.contents['cid-' + contentId];
if (contentData === undefined) { if (contentData === undefined) {
return H5P.error('No data for content id ' + contentId + '. Perhaps the library is gone?'); return H5P.error('No data for content id ' + contentId + '. Perhaps the library is gone?');
} }
@ -217,6 +217,47 @@ H5P.init = function () {
}); });
}; };
/**
* Loop through assets for iframe content and create a set of tags for head.
*
* @private
* @param {number} contentId
* @returns {string} HTML
*/
H5P.getHeadTags = function (contentId) {
var basePath = window.location.protocol + '//' + window.location.host + H5PIntegration.basePath;
var createUrl = function (path) {
if (path.substring(0,7) !== 'http://' && path.substring(0,8) !== 'https://') {
// Not external, add base path.
path = basePath + path;
}
return path;
};
var createStyleTags = function (styles) {
var tags = '';
for (var i = 0; i < styles.length; i++) {
tags += '<link rel="stylesheet" href="' + createUrl(styles[i]) + '">';
}
return tags;
};
var createScriptTags = function (scripts) {
var tags = '';
for (var i = 0; i < scripts.length; i++) {
tags += '<script src="' + createUrl(scripts[i]) + '"></script>';
}
return tags;
};
return createStyleTags(H5PIntegration.core.styles) +
createStyleTags(H5PIntegration.contents['cid-' + contentId].styles) +
createScriptTags(H5PIntegration.core.scripts) +
createScriptTags(H5PIntegration.contents['cid-' + contentId].scripts) +
'<script>H5PIntegration = window.top.H5PIntegration; H5P.jQuery(document).ready(function () { H5P.init(); });</script>';
};
H5P.communicator = (function () { H5P.communicator = (function () {
/** /**
* @class * @class
@ -449,7 +490,7 @@ H5P.getPath = function (path, contentId) {
} }
if (contentId !== undefined) { if (contentId !== undefined) {
prefix = H5P.url + '/content/' + contentId; prefix = H5PIntegration.url + '/content/' + contentId;
} }
else if (window.H5PEditor !== undefined) { else if (window.H5PEditor !== undefined) {
prefix = H5PEditor.filesPath; prefix = H5PEditor.filesPath;
@ -571,15 +612,15 @@ H5P.t = function (key, vars, ns) {
ns = 'H5P'; ns = 'H5P';
} }
if (H5P.l10n[ns] === undefined) { if (H5PIntegration.l10n[ns] === undefined) {
return '[Missing translation namespace "' + ns + '"]'; return '[Missing translation namespace "' + ns + '"]';
} }
if (H5P.l10n[ns][key] === undefined) { if (H5PIntegration.l10n[ns][key] === undefined) {
return '[Missing translation "' + key + '" in "' + ns + '"]'; return '[Missing translation "' + key + '" in "' + ns + '"]';
} }
var translation = H5P.l10n[ns][key]; var translation = H5PIntegration.l10n[ns][key];
if (vars !== undefined) { if (vars !== undefined) {
// Replace placeholder with variables. // Replace placeholder with variables.
@ -1156,7 +1197,7 @@ H5P.libraryFromString = function (library) {
* @returns {String} The full path to the library. * @returns {String} The full path to the library.
*/ */
H5P.getLibraryPath = function (library) { H5P.getLibraryPath = function (library) {
return H5P.url + '/libraries/' + library; return H5PIntegration.url + '/libraries/' + library;
}; };
/** /**
@ -1204,8 +1245,8 @@ H5P.trim = function (value) {
* @returns {Boolean} * @returns {Boolean}
*/ */
H5P.jsLoaded = function (path) { H5P.jsLoaded = function (path) {
H5P.loadedJs = H5P.loadedJs || []; H5PIntegration.loadedJs = H5PIntegration.loadedJs || [];
return H5P.jQuery.inArray(path, H5P.loadedJs) !== -1; return H5P.jQuery.inArray(path, H5PIntegration.loadedJs) !== -1;
}; };
/** /**
@ -1215,8 +1256,8 @@ H5P.jsLoaded = function (path) {
* @returns {Boolean} * @returns {Boolean}
*/ */
H5P.cssLoaded = function (path) { H5P.cssLoaded = function (path) {
H5P.loadedCss = H5P.loadedCss || []; H5PIntegration.loadedCss = H5PIntegration.loadedCss || [];
return H5P.jQuery.inArray(path, H5P.loadedCss) !== -1; return H5P.jQuery.inArray(path, H5PIntegration.loadedCss) !== -1;
}; };
/** /**
@ -1255,7 +1296,7 @@ H5P.shuffleArray = function (array) {
* @param {Number} time optional reported time usage * @param {Number} time optional reported time usage
*/ */
H5P.setFinished = function (contentId, score, maxScore, time) { H5P.setFinished = function (contentId, score, maxScore, time) {
if (H5P.postUserStatistics === true) { if (H5PIntegration.postUserStatistics === true) {
/** /**
* Return unix timestamp for the given JS Date. * Return unix timestamp for the given JS Date.
* *
@ -1268,7 +1309,7 @@ H5P.setFinished = function (contentId, score, maxScore, time) {
// Post the results // Post the results
// TODO: Should we use a variable with the complete path? // TODO: Should we use a variable with the complete path?
H5P.jQuery.post(H5P.ajaxPath + 'setFinished', { H5P.jQuery.post(H5PIntegration.ajaxPath + 'setFinished', {
contentId: contentId, contentId: contentId,
score: score, score: score,
maxScore: maxScore, maxScore: maxScore,