Skip to content

Instantly share code, notes, and snippets.

@tlworkspace
Last active May 22, 2017 16:11
Show Gist options
  • Save tlworkspace/34b771b36b24befeb0dc362e47efa208 to your computer and use it in GitHub Desktop.
Save tlworkspace/34b771b36b24befeb0dc362e47efa208 to your computer and use it in GitHub Desktop.
Simple example of pulling xAPI results from LRS in an Articulate Storyline project
// Copyright 2016 TorranceLearning
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// from Storyline publish
// story_content/user.js
//
// (actual slide IDs will vary)
//
// assumes tincan.js library added to root of publish
// http://rusticisoftware.github.io/TinCanJS/
function ExecuteScript(strId)
{
switch (strId)
{
case "5ekmyskezcy":
Script1();
break;
case "61HLEwecsfH":
Script2();
break;
case "5WPh4snJffe":
Script3();
break;
}
}
function Script1()
{
var s = document.createElement("script");
s.type = "text/javascript";
s.src = "tincan.js";
document.body.appendChild(s);
}
function Script2()
{
window.tincan = new TinCan({"url": window.location.href});
}
function Script3()
{
var player = GetPlayer();
tincan.getStatements({
sendActor: true,
sendActivity: false,
params: {
registration: null,
limit: 10
},
callback: function (err, result) {
if (err !== null) { console.log('error:', err);return;}
var stmts = result.statements;
var storylineVar = [];
stmts.forEach(function(e){
var thisActor = "You";
var thisVerb = e.verb.display.und || e.verb.display["en-US"];
var thisObject = e.target.definition.name.und || e.target.definition.name["en-US"];
var thisLine = thisActor + " " + thisVerb + " " + thisObject;
storylineVar.push(thisLine);
});
storylineVar.reverse();
storylineVar = storylineVar.join("<br>");
player.SetVar("storylineVar", storylineVar);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment