Skip to content

Commit

Permalink
fix: Jquery empty object causing fatal error on arithmetic quiz content
Browse files Browse the repository at this point in the history
  • Loading branch information
mimidotuser committed Jun 15, 2021
1 parent 94b79fb commit c3c0992
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 28 deletions.
2 changes: 1 addition & 1 deletion dist/main.bundle.js

Large diffs are not rendered by default.

55 changes: 28 additions & 27 deletions src/js/h5p-standalone.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,29 +54,29 @@ export default class H5PStandalone {
export: options.export
};

const contentOptions = {
const contentOptions = {
displayOptions
};

if(options.downloadUrl){
if (options.downloadUrl) {
contentOptions.exportUrl = urlPath(options.downloadUrl);
}

const generalIntegrationOptions ={
preventH5PInit: options.preventH5PInit?options.preventH5PInit:false,
const generalIntegrationOptions = {
preventH5PInit: options.preventH5PInit ? options.preventH5PInit : false,
};

// The following behaviour may change in future
if(options.frameJs){
if (options.frameJs) {
generalIntegrationOptions.coreScripts = [urlPath(options.frameJs)]
}else{
generalIntegrationOptions.coreScripts = ['./frame.bundle.js']
} else {
generalIntegrationOptions.coreScripts = ['./frame.bundle.js']
}
// The following behaviour may change in future
if(options.frameCss){
generalIntegrationOptions.coreStyles =[urlPath(options.frameCss)];
}else{
generalIntegrationOptions.coreStyles =[urlPath('./styles/h5p.css')];
if (options.frameCss) {
generalIntegrationOptions.coreStyles = [urlPath(options.frameCss)];
} else {
generalIntegrationOptions.coreStyles = [urlPath('./styles/h5p.css')];
}

this.initElement(el);
Expand All @@ -88,33 +88,33 @@ export default class H5PStandalone {
throw new Error('createH5P must be passed an element');
}

const parent =document.createElement('div');
const parent = document.createElement('div');
parent.classList.add('h5p-iframe-wrapper');
parent.style.backgroundColor='#DDD;';
parent.style.backgroundColor = '#DDD;';


const iframe = document.createElement('iframe');
iframe.id = `h5p-iframe-${this.id}`;
iframe.src='about:blank';
iframe.src = 'about:blank';

iframe.classList.add('h5p-iframe');
iframe.setAttribute('scrolling','no');
iframe.setAttribute('data-content-id',`${this.id}`);
iframe.setAttribute('scrolling', 'no');
iframe.setAttribute('data-content-id', `${this.id}`);

iframe.setAttribute('frameBorder',0);
iframe.style.width='100%'
iframe.style.height='100%'
iframe.style.border='none'
iframe.style.display='block'
iframe.setAttribute('frameBorder', 0);
iframe.style.width = '100%'
iframe.style.height = '100%'
iframe.style.border = 'none'
iframe.style.display = 'block'

parent.append(iframe);
el.append(parent);

// inject jQuery property to avoid fatal error if required
iframe.contentWindow['jQuery'] ={}
iframe.contentWindow['jQuery'] = null;
}

async initH5P(generalIntegrationOptions,contentOptions) {
async initH5P(generalIntegrationOptions, contentOptions) {
this.h5p = await this.getJSON(`${this.h5pJsonPath}/h5p.json`);

const content = await this.getJSON(`${this.contentUrl}/content.json`);
Expand All @@ -126,7 +126,7 @@ export default class H5PStandalone {

const { styles, scripts } = this.sortDependencies(dependencies);

H5PIntegration.urlLibraries = this.librariesPath ;
H5PIntegration.urlLibraries = this.librariesPath;
H5PIntegration.contents = H5PIntegration.contents ? H5PIntegration.contents : {};

H5PIntegration.core = {
Expand All @@ -141,14 +141,15 @@ export default class H5PStandalone {
scripts: scripts,
displayOptions: contentOptions.displayOptions,
contentUrl: this.contentUrl,
fullScreen: contentOptions.fullScreen,
};

if(contentOptions.exportUrl){
if (contentOptions.exportUrl) {
H5PIntegration.contents[`cid-${this.id}`].exportUrl = contentOptions.exportUrl;
}

if (!generalIntegrationOptions.preventH5PInit) {
H5P.init();
if (!generalIntegrationOptions.preventH5PInit) {
H5P.init();
}
}

Expand Down

0 comments on commit c3c0992

Please sign in to comment.