-
Notifications
You must be signed in to change notification settings - Fork 1
/
scorm.min.js
26 lines (26 loc) · 10.6 KB
/
scorm.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
var Debug_API=function(){};Debug_API.prototype.Initialize=function(){console.log(" \u2514 Debug_api:Initialize");return!0};Debug_API.prototype.Terminate=function(){console.log(" \u2514 Debug_api:Terminate");return!0};Debug_API.prototype.GetValue=function(a){return""};Debug_API.prototype.SetValue=function(a,b){console.log(" \u250c Debug_api:SetValue: "+a+"="+b);return""};Debug_API.prototype.Commit=function(){console.log(" \u2514 Debug_api:Commit");return!0};Debug_API.prototype.GetLastError=function(){return 0};
Debug_API.prototype.GetErrorString=function(a){return""};Debug_API.prototype.GetDiagnostic=function(a){return""};Debug_API.prototype.LMSInitialize=function(){console.log(" \u2514 Debug_api:LMSInitialize");return!0};Debug_API.prototype.LMSFinish=function(){console.log(" \u2514 Debug_api:LMSFinish");return!0};Debug_API.prototype.LMSGetValue=function(a){return""};Debug_API.prototype.LMSSetValue=function(a,b){console.log(" \u250c Debug_api:LMSSetValue: "+a+"="+b);return""};
Debug_API.prototype.LMSCommit=function(){console.log(" \u2514 Debug_api:Commit");return!0};Debug_API.prototype.LMSGetLastError=function(){return 0};Debug_API.prototype.LMSGetErrorString=function(a){return""};Debug_API.prototype.LMSGetDiagnostic=function(a){return""};
var Scorm=function(a){this.options=$.extend({},{debug_mode:"2004"},a);this.mode=this.scorm_interface=null;this.active=!1;this.objectives=[];this.interactions=[];this.start_time=(new Date).getTime();this.is_debug=this.has_score=!1;this._search_for_api(window);null==this.scorm_interface?(this.mode=this.options.debug_mode,this.is_debug=!0,console.log("LMS not present - Created SCORM "+this.mode+" Debug interface."),this.scorm_interface=new Debug_API):(this.mode="LMSCommit"in this.scorm_interface?"1.2":
"2004",console.log("Found SCORM "+this.mode+" interface."))};Scorm.prototype._format_time=function(a){function b(a,b){var c="0000"+new String(Math.round(a));return c.substr(c.length-b)}a/=1E3;var c=Math.floor(a/3600);a-=3600*c;var d=Math.floor(a/60);a-=60*d;return"2004"==this.mode?"PT"+(c?c+"H":"")+(d?d+"M":"")+Math.round(a)+"S":b(c,2)+":"+b(d,2)+":"+b(a,2)};
Scorm.prototype._search_for_api=function(a){try{for(;null!=a&&null==this.scorm_interface;)a.API?this.scorm_interface=a.API:a.API_1484_11&&(this.scorm_interface=a.API_1484_11),null!=a.opener&&!a.opener.closed&&this._search_for_api(a.opener),a=a==a.parent?null:a.parent}catch(b){return null}};
Scorm.prototype.Check=function(){var a=0,b="";"2004"==this.mode?(a=parseInt(this.scorm_interface.GetLastError()))&&(b="Error ("+a+"): "+this.scorm_interface.GetErrorString(a)):"1.2"==this.mode&&(a=parseInt(this.scorm_interface.LMSGetLastError()))&&(b="Error ("+a+"): "+this.scorm_interface.LMSGetErrorString(a));return{code:a,description:b}};
Scorm.prototype.Initialize=function(){console.log("Scorm:Initialize");"2004"==this.mode?this.scorm_interface.Initialize(""):"1.2"==this.mode&&this.scorm_interface.LMSInitialize("");0==this.Check().code&&(this.active=!0);var a=this.GetCompletionStatus();if(!a||"not attempted"==a||"unknown"==a)this.SetIncomplete(),this.SetExit("suspend");return this.active};
Scorm.prototype.Terminate=function(){console.log("Scorm:Terminate");"2004"==this.mode?this.scorm_interface.Terminate(""):"1.2"==this.mode&&this.scorm_interface.LMSFinish("");0==this.Check().code&&(this.active=!1)};Scorm.prototype.Deactivate=function(){console.log("Scorm:Deactivate");this.active=!1};
Scorm.prototype.SetValue=function(a,b,c){if(this.active){var d;"2004"==this.mode?(this.scorm_interface.SetValue(a,b),c||(d=this.scorm_interface.GetValue(a))):"1.2"==this.mode&&(this.scorm_interface.LMSSetValue(a,b),c||(d=this.scorm_interface.LMSGetValue(a)));top.postMessage&&top.postMessage(a+"="+b,"*");var g=this.Check(),h="Scorm:SetValue: "+a+"="+b;c||(h+="? "+(g.code?g.description:"Echo:"+d));if(g.code&&0!==g.code)try{window.dispatchEvent(new CustomEvent("REPORT_ERROR",{detail:{error:"Scorm Error",
type:"SCORM",code:g.code,description:g.description,key:a,value:b}}))}catch(f){console.warn("Error reporting error: "+f)}console.log(h);return g.code}};Scorm.prototype.GetValue=function(a){if(this.active){var b;"2004"==this.mode?b=this.scorm_interface.GetValue(a):"1.2"==this.mode&&(b=this.scorm_interface.LMSGetValue(a));console.log("Scorm:GetValue: "+a+"="+b);return b}};
Scorm.prototype.Commit=function(){console.log("Scorm:Commit");if("2004"==this.mode)return this.scorm_interface.Commit("");if("1.2"==this.mode)return this.scorm_interface.LMSCommit("")};Scorm.prototype.GetLearnerName=function(){if("2004"==this.mode)return this.GetValue("cmi.learner_name");if("1.2"==this.mode)return this.GetValue("cmi.core.student_name")};Scorm.prototype.GetLearnerID=function(){if("2004"==this.mode)return this.GetValue("cmi.learner_id");if("1.2"==this.mode)return this.GetValue("cmi.core.student_id")};
Scorm.prototype.GetLocation=function(){if("2004"==this.mode)return this.GetValue("cmi.location");if("1.2"==this.mode)return this.GetValue("cmi.core.lesson_location")};Scorm.prototype.SetLocation=function(a){if("2004"==this.mode)return this.SetValue("cmi.location",a);if("1.2"==this.mode)return this.SetValue("cmi.core.lesson_location",a)};Scorm.prototype.GetExit=function(){if("2004"==this.mode)return this.GetValue("cmi.exit");if("1.2"==this.mode)return this.GetValue("cmi.core.exit")};
Scorm.prototype.SetExit=function(a){if("2004"==this.mode)return this.SetValue("cmi.exit",a);if("1.2"==this.mode)return this.SetValue("cmi.core.exit",a)};Scorm.prototype.GetSuspendData=function(){return this.GetValue("cmi.suspend_data")};Scorm.prototype.SetSuspendData=function(a){this.SetValue("cmi.suspend_data",a);this.Commit()};Scorm.prototype.GetProgress=function(){if("2004"==this.mode)return this.GetValue("cmi.progress_measure")};
Scorm.prototype.SetProgress=function(a){if("2004"==this.mode)return this.SetValue("cmi.progress_measure",a)};Scorm.prototype.GetCompletionThreshold=function(){return"2004"==this.mode?this.GetValue("cmi.completion_threshold"):!1};Scorm.prototype.SetCompletionThreshold=function(a){"2004"==this.mode&&this.SetValue("cmi.completion_threshold",a)};Scorm.prototype.GetScoreThreshold=function(){return"2004"==this.mode?this.GetValue("cmi.progress_measure"):!1};
Scorm.prototype.SetScoreThreshold=function(a){"2004"==this.mode&&this.SetValue("cmi.scaled_passing_score",a)};Scorm.prototype.SetSessionTime=function(a){a||(a=(new Date).getTime()-this.start_time);if("2004"==this.mode)return this.SetValue("cmi.session_time",this._format_time(a),!0);if("1.2"==this.mode)return this.SetValue("cmi.core.session_time",this._format_time(a),!0)};
Scorm.prototype.GetTotalTime=function(){return"2004"==this.mode?this.GetValue("cmi.total_time"):"1.2"==this.mode?this.GetValue("cmi.core.total_time"):!1};Scorm.prototype.GetCompletionStatus=function(){if("2004"==this.mode)return this.GetValue("cmi.completion_status");if("1.2"==this.mode){var a=this.GetValue("cmi.core.lesson_status");return"passed"==a||"failed"==a?"completed":a}};
Scorm.prototype.SetCompletionStatus=function(a){"2004"==this.mode?this.SetValue("cmi.completion_status",a):"1.2"==this.mode&&this.SetValue("cmi.core.lesson_status",a);this.Commit()};Scorm.prototype.GetResult=function(){if("2004"==this.mode)return this.GetValue("cmi.success_status");if("1.2"==this.mode){var a=this.GetValue("cmi.core.lesson_status");return"passed"==a||"failed"==a?a:"unknown"}};
Scorm.prototype.SetResult=function(a){"2004"==this.mode?"passed"==a?this.SetValue("cmi.success_status","passed"):"failed"==a&&this.SetValue("cmi.success_status","failed"):"1.2"==this.mode&&("passed"==a?this.SetCompletionStatus("passed"):"failed"==a&&this.SetCompletionStatus("failed"));this.Commit()};Scorm.prototype.SetPassed=function(){this.SetResult("passed")};Scorm.prototype.SetFailed=function(){this.SetResult("failed")};Scorm.prototype.SetCompleted=function(){this.SetCompletionStatus("completed")};
Scorm.prototype.SetIncomplete=function(){this.SetCompletionStatus("incomplete")};Scorm.prototype.SetScore=function(a,b,c){this.has_score=!0;"2004"==this.mode?(this.SetValue("cmi.score.raw",a),this.SetValue("cmi.score.scaled",1/c*a),this.SetValue("cmi.score.min",b),this.SetValue("cmi.score.max",c)):"1.2"==this.mode&&(this.SetValue("cmi.core.score.raw",a),this.SetValue("cmi.core.score.min",b),this.SetValue("cmi.core.score.max",c));this.Commit()};
Scorm.prototype.SetObjective=function(a,b,c,d,g,h){var f=this.objectives.indexOf(a);-1==f&&(f=this.objectives.length,this.SetValue("cmi.objectives."+f+".id",a),"2004"==this.mode&&this.SetValue("cmi.objectives."+f+".description",h),this.objectives.push(a),this.SetValue("cmi.objectives."+f+".score.min",d?d:0),this.SetValue("cmi.objectives."+f+".score.max",g?g:100));this.SetValue("cmi.objectives."+f+".score.raw",c?c:0);"2004"==this.mode?(this.SetValue("cmi.objectives."+f+".completion_status","completed"),
("passed"==b||"failed"==b)&&this.SetValue("cmi.objectives."+f+".success_status",b)):"passed"==b||"failed"==b?this.SetValue("cmi.objectives."+f+".status",b):this.SetValue("cmi.objectives."+f+".status","completed")};
Scorm.prototype.SetInteraction=function(a,b,c,d,g,h,f,l){var e=this.interactions.indexOf(a),k="1.2"==this.mode?!0:!1;-1==e&&(e=this.interactions.length,this.SetValue("cmi.interactions."+e+".id",a,k),this.SetValue("cmi.interactions."+e+".objectives.0.id",b,k),"2004"==this.mode&&(this.SetValue("cmi.interactions."+e+".description",g),this.SetValue("cmi.interactions."+e+".type",h)),this.interactions.push(a));d&&("2004"==this.mode?h&&f&&(this.SetValue("cmi.interactions."+e+".learner_response",d),this.GetValue("cmi.interactions."+
e+".learner_response")!=d&&(this.SetValue("cmi.interactions."+e+".learner_response","elucidaterror"),this.SetValue("cmi.interactions."+e+".learner_response",d),this.GetValue("cmi.interactions."+e+".learner_response")!=d&&(a=d.split("[,]").join("__"),this.SetValue("cmi.interactions."+e+".learner_response",a))),this.SetValue("cmi.interactions."+e+".correct_responses.0.pattern",f),this.SetValue("cmi.interactions."+e+".weighting",l)):this.SetValue("cmi.interactions."+e+".student_response",d,k));"neutral"==
c?this.SetValue("cmi.interactions."+e+".result","neutral",k):"passed"==c||"completed"==c?this.SetValue("cmi.interactions."+e+".result","correct",k):"failed"==c&&("2004"==this.mode?this.SetValue("cmi.interactions."+e+".result","incorrect"):this.SetValue("cmi.interactions."+e+".result","wrong",k))};
Scorm.prototype.GetLanguage=function(){var a=null;"2004"==this.mode?a=this.GetValue("cmi.learner_preference.language"):"1.2"==this.mode&&(a=this.GetValue("cmi.student_preference.language"));a&&(a=a.toLowerCase().trim());return a};Scorm.prototype.SetLanguage=function(a){if("2004"==this.mode)return this.SetValue("cmi.learner_preference.language",a);if("1.2"==this.mode)return this.SetValue("cmi.student_preference.language",a)};