Skip to content

Commit

Permalink
[fix] try to fix indentation
Browse files Browse the repository at this point in the history
  • Loading branch information
mpkliewer committed Mar 22, 2022
1 parent 26974d2 commit f7c3ea0
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 136 deletions.
56 changes: 28 additions & 28 deletions lumi-standalone-xapi-wrapper/src/index.html
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>H5P</title>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>H5P</title>

<style>
body {
padding: 0;
margin: 0;
overflow: hidden;
}
<style>
body {
padding: 0;
margin: 0;
overflow: hidden;
}

#h5p-frame-wrapper {
padding: 2em;
position: relative;
}
#h5p-frame-wrapper {
padding: 2em;
position: relative;
}

iframe {
border: none;
width: 100%;
height: calc(100vh - 4em);
}
</style>
iframe {
border: none;
width: 100%;
height: calc(100vh - 4em);
}
</style>

<script src="tincan-min.js"></script>
<script src="index.js"></script>
<script src="tincan-min.js"></script>
<script src="index.js"></script>

</head>
</head>

<body>
<body>

<main id="h5p-frame-wrapper">
<iframe id="h5p-frame" src="h5p.html"></iframe>
</main>
<main id="h5p-frame-wrapper">
<iframe id="h5p-frame" src="h5p.html"></iframe>
</main>


</body>
</body>

</html>
202 changes: 101 additions & 101 deletions lumi-standalone-xapi-wrapper/src/index.js
Original file line number Diff line number Diff line change
@@ -1,146 +1,146 @@
const app = {
H5P: null,
H5PIntegration: null,
H5P: null,
H5PIntegration: null,

tincan: null,
rootActivityId: null,
tincan: null,
rootActivityId: null,

init() {
this.bindEvents();
},
init() {
this.bindEvents();
},

bindEvents() {
const frameEl = document.getElementById('h5p-frame');
bindEvents() {
const frameEl = document.getElementById('h5p-frame');

frameEl.onload = this.onFrameLoaded;
},
frameEl.onload = this.onFrameLoaded;
},

onFrameLoaded() {
console.log('frameloaded');
onFrameLoaded() {
console.log('frameloaded');

if (!this.contentWindow) {
console.error('Cannot find iFrame window.');
return;
}
if (!this.contentWindow) {
console.error('Cannot find iFrame window.');
return;
}

const { H5P, H5PIntegration } = this.contentWindow;
const { H5P, H5PIntegration } = this.contentWindow;

if (!H5P || !H5PIntegration) {
console.error('Cannot find H5P in iFrame.');
return;
}
if (!H5P || !H5PIntegration) {
console.error('Cannot find H5P in iFrame.');
return;
}

app.H5P = H5P;
app.H5PIntegration = H5PIntegration;
app.H5P = H5P;
app.H5PIntegration = H5PIntegration;

app.setupXapi();
},
app.setupXapi();
},

normalizeVars() {
for (let item in app.H5PIntegration.contents) {
const contentId = item.replace('cid-', '');
normalizeVars() {
for (let item in app.H5PIntegration.contents) {
const contentId = item.replace('cid-', '');

// TODO: check if H5P activity ID is a valid URL already
const contentActivityId = [app.rootActivityId, contentId].join('/');
// TODO: check if H5P activity ID is a valid URL already
const contentActivityId = [app.rootActivityId, contentId].join('/');

console.log('contentId:', contentId);
console.log('contentActivityId:', contentActivityId);
console.log('contentId:', contentId);
console.log('contentActivityId:', contentActivityId);

app.H5PIntegration.contents[item].url = contentActivityId;
}
},
app.H5PIntegration.contents[item].url = contentActivityId;
}
},

setupXapi() {
this.tincan = new TinCan({ url: location.href });
setupXapi() {
this.tincan = new TinCan({ url: location.href });

const { activity = {} } = this.tincan;
const { activity = {} } = this.tincan;

this.rootActivityId = activity.id || 'http://h5p.org/xapi/activities';
this.rootActivityId = activity.id || 'http://h5p.org/xapi/activities';

this.normalizeVars();
this.normalizeVars();

this.sendCourseStmt('launched');
this.sendCourseStmt('launched');

this.H5P.externalDispatcher.on('xAPI', this.onXapiEvent);
},
this.H5P.externalDispatcher.on('xAPI', this.onXapiEvent);
},

sendStatement(statement) {
const { actor } = this.tincan;
statement.actor = actor;
sendStatement(statement) {
const { actor } = this.tincan;
statement.actor = actor;

statement = JSON.parse(JSON.stringify(statement).replace(/\\n/ig, ''));
statement = JSON.parse(JSON.stringify(statement).replace(/\\n/ig, ''));

this.tincan.sendStatement(statement, ({ err, xhr }) => {
if (err) {
console.error('statement error:', err, statement);
return;
}
this.tincan.sendStatement(statement, ({ err, xhr }) => {
if (err) {
console.error('statement error:', err, statement);
return;
}

console.log('statement saved:', statement);
});
},
console.log('statement saved:', statement);
});
},

sendLaunched() {
const statement = {
verb: {
id: 'http://adlnet.gov/expapi/verbs/launched',
display: {
'en-US': 'launched',
}
},
object: this.tincan.activity
}
sendLaunched() {
const statement = {
verb: {
id: 'http://adlnet.gov/expapi/verbs/launched',
display: {
'en-US': 'launched',
}
},
object: this.tincan.activity
}

app.sendStatement(statement);
},
app.sendStatement(statement);
},

courseVerbs: {
launched: 'http://adlnet.gov/expapi/verbs/launched',
completed: 'http://adlnet.gov/expapi/verbs/completed',
},
courseVerbs: {
launched: 'http://adlnet.gov/expapi/verbs/launched',
completed: 'http://adlnet.gov/expapi/verbs/completed',
},

sendCourseStmt(verbDisplay, result) {
const { activity } = this.tincan;
activity.definition = activity.definition || {};
sendCourseStmt(verbDisplay, result) {
const { activity } = this.tincan;
activity.definition = activity.definition || {};

activity.definition.type = 'http://adlnet.gov/expapi/activities/course';
activity.definition.type = 'http://adlnet.gov/expapi/activities/course';

const verbId = app.courseVerbs[verbDisplay];
const verbId = app.courseVerbs[verbDisplay];

const statement = {
verb: {
id: verbId,
display: {
'en-US': verbDisplay,
}
},
const statement = {
verb: {
id: verbId,
display: {
'en-US': verbDisplay,
}
},

object: activity
}
object: activity
}

if (verbDisplay === 'completed') {
// statement.result = { completion: true };
statement.result = result;
}
if (verbDisplay === 'completed') {
// statement.result = { completion: true };
statement.result = result;
}

app.sendStatement(statement);
},
app.sendStatement(statement);
},

onXapiEvent(event) {
const { statement } = event.data || {};
onXapiEvent(event) {
const { statement } = event.data || {};

statement && app.sendStatement(statement);
statement && app.sendStatement(statement);

if (statement.verb.id.includes('completed')) {
const { result } = statement;
if (statement.verb.id.includes('completed')) {
const { result } = statement;

app.sendCourseStmt('completed', result);
}
app.sendCourseStmt('completed', result);
}

},
},
};

document.addEventListener('DOMContentLoaded', function () {
app.init();
app.init();
});

14 changes: 7 additions & 7 deletions lumi-standalone-xapi-wrapper/src/tincan.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="utf-8" ?>
<tincan xmlns="http://projecttincan.com/tincan.xsd">
<activities>
<activity id="http://ENTER_ACTIVITY_ID" type="http://adlnet.gov/expapi/activities/course">
<name>ENTER ACTIVITY NAME</name>
<description lang="en-US">ENTER ACTIVITY DESCRIPTION</description>
<launch lang="en-us">index.html</launch>
</activity>
</activities>
<activities>
<activity id="http://ENTER_ACTIVITY_ID" type="http://adlnet.gov/expapi/activities/course">
<name>ENTER ACTIVITY NAME</name>
<description lang="en-US">ENTER ACTIVITY DESCRIPTION</description>
<launch lang="en-us">index.html</launch>
</activity>
</activities>
</tincan>

0 comments on commit f7c3ea0

Please sign in to comment.