-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscorm-local.min.js
1 lines (1 loc) · 3.85 KB
/
scorm-local.min.js
1
(function(global,factory){switch(false){case!(typeof module!="undefined"&&module.exports!=null):module.exports=factory();break;case!(typeof define=="function"&&define.amd):define([],factory);break;default:global.scormLocal=factory()}})(this,function(){var defaultOpts={persistFor:60,model:null},errorCodes={0:"No error.",101:"General Exception.",201:"Invalid argument error.",202:"Element cannot have children.",203:"Element not an array. Cannot have count.",301:"Not initialized.",401:"Not implemented error",402:"Invalid set value, element is a keyword",403:"Element is read only.",404:"Element is write only.",405:"Incorrect Data Type."},defaultModel={"cmi.core._children":["student_id","student_name","lesson_location","credit","lesson_status","entry","score","total_time","lesson_mode","exit","session_time"],"cmi.core.student_id":"770b7a652cee065cbb9759ff1a0d46a927c8ba98","cmi.core.student_name":"Appleseed, John","cmi.core.lesson_location":"","cmi.core.credit":"credit","cmi.core.lesson_status":"not attempted","cmi.core.entry":"ab-initio","cmi.core.score_children":["raw","min","max"],"cmi.core.score.raw":null,"cmi.core.score.max":null,"cmi.core.score.min":null,"cmi.core.total_time":"0000:00:00.00","cmi.core.lesson_mode":"normal","cmi.core.exit":"","cmi.core.session_time":"00:00:00","cmi.suspend_data":"","cmi.launch_data":"","cmi.comments":"","cmi.comments_from_lms":"","cmi.objectives._children":["id","score","status"],"cmi.objectives._count":0,"cmi.student_data._children":["mastery_score","max_time_allowed","time_limit_action"],"cmi.student_data.mastery_score":null,"cmi.student_data.max_time_allowed":null,"cmi.student_data.time_limit_action":"continue,no message","cmi.student_preference._children":["audio","language","speed","text"],"cmi.student_preference.audio":null,"cmi.student_preference.language":null,"cmi.student_preference.speed":null,"cmi.student_preference.text":null,"cmi.interactions._children":["id","objectives","time","type","correct_responses","weighting","student_response","result","latency"],"cmi.interactions._count":0};function time(s){return(new Date).getTime()+(s||0)*1e3}function incl(a,b){var c={};a=a||{};b=b||{};Object.keys(b).forEach(function(k){c[k]=typeof a[k]=="undefined"?b[k]:a[k]});return c}return function(sco,opts){opts=incl(opts,defaultOpts);var initialized=false,lastError=0,model=incl(opts.model,defaultModel),data=store();function store(value){var k="scorm-local-"+(sco||"default"),r=null;if(typeof value=="undefined"){try{r=JSON.parse(localStorage.getItem(k))}finally{}if(!r||{}.toString.call(r)!="[object Object]"||r._flush||r._expireTime===0)return{};if(r._expireTime!==-1&&time()>=(r._expireTime||Number.POSITIVE_INIFINITY))return{};return r}else if(value===false){return localStorage.removeItem(k)}value._expireTime=function(){switch(true){case opts.persistFor>0:return time(opts.persistFor)+1;case opts.persistFor<0:return-1;default:return 0}}();localStorage.setItem(k,JSON.stringify(value));return value}return{importTo:function(obj){for(var k in this)if(/^LMS/.test(k))obj[k]=this[k].bind(this)},flush:function(){data={_flush:true};store(false)},LMSInitialize:function(){if(initialized)return lastError=101,false;lastError=0;initialized=true;return true},LMSFinish:function(){if(!initialized)return lastError=301,false;lastError=0;initialized=false;return true},LMSGetValue:function(key){if(!initialized)return lastError=301,false;var v=data[key]||model[key];if(typeof v=="undefined")return lastError=201,null;lastError=0;return v},LMSSetValue:function(key,value){if(!initialized)return lastError=301,false;if(typeof model[key]=="undefined")return lastError=201,false;data[key]=value;lastError=0;return true},LMSCommit:function(){if(!initialized)return lastError=301,false;store(data);lastError=0;return true},LMSGetLastError:function(){return lastError},LMSGetErrorString:function(code){return errorCodes[code]},LMSGetDiagnostic:function(code){return errorCodes[code]}}}});