Select Git revision
Forked from
Janek Özbay / ProgPr22-23-api
Source project has a limited visibility.
-
Janek Özbay authoredJanek Özbay authored
h5peditor-editor.js 18.08 KiB
/* global ns */
window.ns = window.H5PEditor = window.H5PEditor || {};
/**
* Construct the editor.
*
* @class H5PEditor.Editor
* @param {string} library
* @param {string} defaultParams
* @param {Element} replace
* @param {Function} iframeLoaded
*/
ns.Editor = function (library, defaultParams, replace, iframeLoaded) {
var self = this;
// Library may return "0", make sure this doesn't return true in checks
library = library && library != 0 ? library : '';
let parsedParams = {};
try {
parsedParams = JSON.parse(defaultParams);
}
catch (e) {
// Ignore failed parses, this should be handled elsewhere
}
// Define iframe DOM Element through jQuery
var $iframe = ns.$('<iframe/>', {
'css': {
display: 'block',
width: '100%',
height: '3em',
border: 'none',
zIndex: 101,
top: 0,
left: 0
},
'class': 'h5p-editor-iframe',
'frameBorder': '0',
'allowfullscreen': 'allowfullscreen',
'allow': "fullscreen"
});
const metadata = parsedParams.metadata;
let title = ''
if (metadata) {
if (metadata.a11yTitle) {
title = metadata.a11yTitle;
}
else if (metadata.title) {
title = metadata.title;
}
}
$iframe.attr('title', title);
// The DOM element is often used directly
var iframe = $iframe.get(0);
/**
* Set the iframe content and start loading the necessary assets
*
* @private
*/
var populateIframe = function () {
if (!iframe.contentDocument) {
return; // Not possible, iframe 'load' hasn't been triggered yet
}
const language = metadata && metadata.defaultLanguage
? metadata.defaultLanguage : ns.contentLanguage;
iframe.contentDocument.open();