Permalink
Fetching contributors…
Cannot retrieve contributors at this time
338 lines (307 sloc) 12.4 KB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Course Launch Page</title>
<script src="scripts/TinCanJS/build/tincan-min.js" type="text/javascript"></script>
<script src="scripts/common.js" type="text/javascript"></script>
<script type="text/javascript">
//TinCan.enableDebug();
//
// content definition
//
var pageArray = [
"Playing/Playing.html",
"Playing/Par.html",
"Playing/Scoring.html",
"Playing/OtherScoring.html",
"Playing/RulesOfGolf.html",
"Etiquette/Course.html",
"Etiquette/Distracting.html",
"Etiquette/Play.html",
"Handicapping/Overview.html",
"Handicapping/CalculatingHandicap.html",
"Handicapping/CalculatingScore.html",
"Handicapping/Example.html",
"HavingFun/HowToHaveFun.html",
"HavingFun/MakeFriends.html",
"HavingFun/HowToBeStylish.html",
"assessmenttemplate.html"
],
processedUnload = false,
reachedEnd = false,
maxPageReached = 0,
tincan = new TinCan (
{
url: window.location.href,
activity: GolfExample.CourseActivity
}
);
var BookmarkingTracking = function(){
this.currentPage = 0;
this.startTimeStamp = new Date();
this.startAttemptDuration = 0;
this.attemptComplete = false;
};
BookmarkingTracking.prototype = {
initFromBookmark: function(bookmark){
this.setPage(parseInt(bookmark.location, 10));
this.setStartDuration(bookmark.attemptDuration);
this.getCompletion(bookmark.attemptComplete);
},
reset: function(){
this.setPage(0);
this.setStartDuration(0);
this.setCompletion(false);
},
save: function (callback){
var bookmarking = {
location: this.currentPage,
attemptDuration: this.getAttemptDuration(),
attemptComplete: this.attemptComplete
};
tincan.setState("bookmarking-data", bookmarking, {
contentType: "application/json",
overwriteJSON: false,
callback: callback
});
},
get: function(){
var stateResult = tincan.getState("bookmarking-data");
if (stateResult.err === null && stateResult.state !== null && stateResult.state.contents !== "") {
return stateResult.state.contents;
}
return null;
},
setStartDuration: function(duration){
this.startAttemptDuration = duration;
},
setPage: function(page){
this.currentPage = page;
return true;
},
getPage: function(){
return this.currentPage;
},
incrementPage: function (){
this.currentPage++;
},
decrementPage: function (){
this.currentPage--;
},
setCompletion: function(completion){
this.attemptComplete = completion;
return true;
},
getCompletion: function(completion){
return this.attemptComplete;
},
getAttemptDuration: function (){
return this.startAttemptDuration + this.getSessionDuration();
},
getSessionDuration: function (){
return Math.abs ((new Date()) - this.startTimeStamp);
}
};
var bookmarkingData = new BookmarkingTracking();
//
// functions for sizing the iFrame
//
function setIframeHeight(id, navWidth) {
if ( document.getElementById ) {
var theIframe = document.getElementById(id);
if (theIframe) {
var height = getWindowHeight();
theIframe.style.height = Math.round( height ) - navWidth + "px";
theIframe.style.marginTop = Math.round( ((height - navWidth) - parseInt(theIframe.style.height) )/2 ) + "px";
}
}
}
function getWindowHeight() {
var height = 0;
if (window.innerHeight){
height = window.innerHeight - 18;
}
else if (document.documentElement && document.documentElement.clientHeight){
height = document.documentElement.clientHeight;
}
else if (document.body && document.body.clientHeight) {
height = document.body.clientHeight;
}
return height;
}
function SetupIFrame(){
//set our iFrame for the content to take up the full screen except for our navigation
var navWidth = 80;
setIframeHeight("contentFrame", navWidth);
window.onresize = function() { setIframeHeight("contentFrame", navWidth); };
}
//
// navigation functions
//
function doStart(){
//get the iFrame sized correctly and set up
SetupIFrame();
var statements = [];
statements.push({
verb: {
id: "http://adlnet.gov/expapi/verbs/initialized",
display: {
"en-US" : "initialized"
}
},
context: GolfExample.getContext(),
result: {
duration: "PT0S"
}
});
var attemptedStatement = {
verb: {
id: "http://adlnet.gov/expapi/verbs/attempted",
display: {
"en-US" : "attempted"
}
},
context: GolfExample.getContext(),
result: {
duration: "PT0S"
}
};
//get activity_id bookmark if it exists
var bookmark = bookmarkingData.get();
if (bookmark !== null) {
if (confirm("Would you like to resume from where you previously left off? Click cancel to start a afresh.")) {
bookmarkingData.initFromBookmark(bookmark);
if (!bookmarkingData.getCompletion()) {
var resumedStatement = {
verb: {
id: "http://adlnet.gov/expapi/verbs/resumed",
display: {
"en-US": "resumed"
}
},
context: GolfExample.getContext(),
result: {
duration: TinCan.Utils.convertMillisecondsToISO8601Duration(bookmark.attemptDuration)
}
};
statements.push(resumedStatement);
}
}
else {
bookmarkingData.reset();
//start new attempt
statements.push(attemptedStatement);
bookmarkingData.save();
}
}
else {
// if there isn't a stored bookmark, start the user at the first page
bookmarkingData.setPage(0);
statements.push(attemptedStatement);
}
tincan.sendStatements(statements);
goToPage();
}
function goToPage(){
var theIframe = document.getElementById("contentFrame"),
prevButton = document.getElementById("butPrevious"),
nextButton = document.getElementById("butNext");
//pass the TC arguments to the iframe
var tc_argStr = (pageArray[bookmarkingData.getPage()].indexOf("?") != -1) ? "&" + location.search.slice(1) : location.search;
//navigate the iFrame to the content
theIframe.src = pageArray[bookmarkingData.getPage()] + tc_argStr;
//disable the prev/next buttons if we are on the first or last page.
if (bookmarkingData.getPage() === 0){
nextButton.disabled = false;
prevButton.disabled = true;
}
else if (bookmarkingData.getPage() === (pageArray.length - 1)){
nextButton.disabled = true;
prevButton.disabled = false;
}
else{
nextButton.disabled = false;
prevButton.disabled = false;
}
bookmarkingData.save();
}
function doPrevious(){
if (bookmarkingData.getPage() > 0){
bookmarkingData.decrementPage();
}
goToPage();
}
function doNext(){
if (bookmarkingData.getPage() < (pageArray.length - 1)){
bookmarkingData.incrementPage();
}
goToPage();
}
function doExit(){
document.getElementById("exitButton").setAttribute("value","Saving...");
bookmarkingData.save(function(){
document.getElementById("exitButton").setAttribute("value","Save & Exit");
if (confirm("Are you sure you want to Exit?")) {
var statements = [];
if (!bookmarkingData.getCompletion()){
statements.push({
verb: {
id: "http://adlnet.gov/expapi/verbs/suspended",
display: {
"en-US": "suspended"
}
},
context: GolfExample.getContext(),
result: {
duration: TinCan.Utils.convertMillisecondsToISO8601Duration(bookmarkingData.getAttemptDuration())
}
});
}
statements.push({
verb: {
id: "http://adlnet.gov/expapi/verbs/terminated",
display: {
"en-US": "terminated"
}
},
context: GolfExample.getContext(),
result: {
duration: TinCan.Utils.convertMillisecondsToISO8601Duration(bookmarkingData.getSessionDuration())
}
});
tincan.sendStatements(statements, function (){
close();
document.write("Course exited and progress saved. You may now close this window.");
});
}
});
}
function FormatChoiceResponse(value){
var newValue = new String(value);
//replace all whitespace
newValue = newValue.replace(/\W/g, "_");
return newValue;
}
</script>
</head>
<body onload="doStart(false);">
<div style="text-align: center; width: 100%; margin: 10px;"><a style="" href="http://tincanapi.com/">Tin Can Home</a></div>
<iframe width="100%" id="contentFrame" src=""></iframe>
<div id="navDiv">
<input type="button" value="<- Previous" id="butPrevious" onclick="doPrevious();"/>
<input type="button" value="Next ->" id="butNext" onclick="doNext();"/>
<input id="exitButton" type="button" value="Save & Exit" id="butNext" onclick="doExit();"/>
</div>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-26545776-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</body>
</html>