-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
136 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |