diff --git a/dist/xapiwrapper.min.js b/dist/xapiwrapper.min.js index ae9cf07..e065748 100644 --- a/dist/xapiwrapper.min.js +++ b/dist/xapiwrapper.min.js @@ -1,3 +1,3 @@ -/*! xAPIWrapper v 1.10.1 | Built on 2017-03-22 15:33:43-0700 */ -function toBase64(a){return CryptoJS&&CryptoJS.enc.Base64?CryptoJS.enc.Base64.stringify(CryptoJS.enc.Latin1.parse(a)):Base64.encode(a)}function toSHA1(a){return CryptoJS&&CryptoJS.SHA1?CryptoJS.SHA1(a).toString():Crypto.util.bytesToHex(Crypto.SHA1(a,{asBytes:!0}))}function toSHA256(a){return CryptoJS&&CryptoJS.SHA256?CryptoJS.SHA256(a).toString():void 0}function isDate(a){if("[object Date]"===Object.prototype.toString.call(a))var b=a;else var b=new Date(a);return"[object Date]"===Object.prototype.toString.call(b)?isNaN(b.valueOf())?(ADL.XAPIWrapper.log("Invalid date String passed"),null):b:(ADL.XAPIWrapper.log("Invalid date object"),null)}var CryptoJS=CryptoJS||function(a,b){var c={},d=c.lib={},e=d.Base=function(){function a(){}return{extend:function(b){a.prototype=this;var c=new a;return b&&c.mixIn(b),c.hasOwnProperty("init")||(c.init=function(){c.$super.init.apply(this,arguments)}),c.init.prototype=c,c.$super=this,c},create:function(){var a=this.extend();return a.init.apply(a,arguments),a},init:function(){},mixIn:function(a){for(var b in a)a.hasOwnProperty(b)&&(this[b]=a[b]);a.hasOwnProperty("toString")&&(this.toString=a.toString)},clone:function(){return this.init.prototype.extend(this)}}}(),f=d.WordArray=e.extend({init:function(a,c){a=this.words=a||[],c!=b?this.sigBytes=c:this.sigBytes=4*a.length},toString:function(a){return(a||h).stringify(this)},concat:function(a){var b=this.words,c=a.words,d=this.sigBytes,e=a.sigBytes;if(this.clamp(),d%4)for(var f=0;e>f;f++){var g=c[f>>>2]>>>24-f%4*8&255;b[d+f>>>2]|=g<<24-(d+f)%4*8}else if(c.length>65535)for(var f=0;e>f;f+=4)b[d+f>>>2]=c[f>>>2];else b.push.apply(b,c);return this.sigBytes+=e,this},clamp:function(){var b=this.words,c=this.sigBytes;b[c>>>2]&=4294967295<<32-c%4*8,b.length=a.ceil(c/4)},clone:function(){var a=e.clone.call(this);return a.words=this.words.slice(0),a},random:function(b){for(var c=[],d=0;b>d;d+=4)c.push(4294967296*a.random()|0);return new f.init(c,b)}}),g=c.enc={},h=g.Hex={stringify:function(a){for(var b=a.words,c=a.sigBytes,d=[],e=0;c>e;e++){var f=b[e>>>2]>>>24-e%4*8&255;d.push((f>>>4).toString(16)),d.push((15&f).toString(16))}return d.join("")},parse:function(a){for(var b=a.length,c=[],d=0;b>d;d+=2)c[d>>>3]|=parseInt(a.substr(d,2),16)<<24-d%8*4;return new f.init(c,b/2)}},i=g.Latin1={stringify:function(a){for(var b=a.words,c=a.sigBytes,d=[],e=0;c>e;e++){var f=b[e>>>2]>>>24-e%4*8&255;d.push(String.fromCharCode(f))}return d.join("")},parse:function(a){for(var b=a.length,c=[],d=0;b>d;d++)c[d>>>2]|=(255&a.charCodeAt(d))<<24-d%4*8;return new f.init(c,b)}},j=g.Utf8={stringify:function(a){try{return decodeURIComponent(escape(i.stringify(a)))}catch(b){throw new Error("Malformed UTF-8 data")}},parse:function(a){return i.parse(unescape(encodeURIComponent(a)))}},k=(g.Base64={stringify:function(a){var b=a.words,c=a.sigBytes,d=this._map;a.clamp();for(var e=[],f=0;c>f;f+=3)for(var g=b[f>>>2]>>>24-f%4*8&255,h=b[f+1>>>2]>>>24-(f+1)%4*8&255,i=b[f+2>>>2]>>>24-(f+2)%4*8&255,j=g<<16|h<<8|i,k=0;4>k&&c>f+.75*k;k++)e.push(d.charAt(j>>>6*(3-k)&63));var l=d.charAt(64);if(l)for(;e.length%4;)e.push(l);return e.join("")},parse:function(a){var b=a.length,c=this._map,d=c.charAt(64);if(d){var e=a.indexOf(d);-1!=e&&(b=e)}for(var g=[],h=0,i=0;b>i;i++)if(i%4){var j=c.indexOf(a.charAt(i-1))<>>6-i%4*2;g[h>>>2]|=(j|k)<<24-h%4*8,h++}return f.create(g,h)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},d.BufferedBlockAlgorithm=e.extend({reset:function(){this._data=new f.init,this._nDataBytes=0},_append:function(a){"string"==typeof a&&(a=j.parse(a)),this._data.concat(a),this._nDataBytes+=a.sigBytes},_process:function(b){var c=this._data,d=c.words,e=c.sigBytes,g=this.blockSize,h=4*g,i=e/h;i=b?a.ceil(i):a.max((0|i)-this._minBufferSize,0);var j=i*g,k=a.min(4*j,e);if(j){for(var l=0;j>l;l+=g)this._doProcessBlock(d,l);var m=d.splice(0,j);c.sigBytes-=k}return new f.init(m,k)},clone:function(){var a=e.clone.call(this);return a._data=this._data.clone(),a},_minBufferSize:0})),l=d.Hasher=k.extend({cfg:e.extend(),init:function(a){this.cfg=this.cfg.extend(a),this.reset()},reset:function(){k.reset.call(this),this._doReset()},update:function(a){return this._append(a),this._process(),this},finalize:function(a){a&&this._append(a);var b=this._doFinalize();return b},blockSize:16,_createHelper:function(a){return function(b,c){return new a.init(c).finalize(b)}},_createHmacHelper:function(a){return function(b,c){return new m.HMAC.init(a,c).finalize(b)}}}),m=c.algo={},n=[],o=m.SHA1=l.extend({_doReset:function(){this._hash=new f.init([1732584193,4023233417,2562383102,271733878,3285377520])},_doProcessBlock:function(a,b){for(var c=this._hash.words,d=c[0],e=c[1],f=c[2],g=c[3],h=c[4],i=0;80>i;i++){if(16>i)n[i]=0|a[b+i];else{var j=n[i-3]^n[i-8]^n[i-14]^n[i-16];n[i]=j<<1|j>>>31}var k=(d<<5|d>>>27)+h+n[i];k+=20>i?(e&f|~e&g)+1518500249:40>i?(e^f^g)+1859775393:60>i?(e&f|e&g|f&g)-1894007588:(e^f^g)-899497514,h=g,g=f,f=e<<30|e>>>2,e=d,d=k}c[0]=c[0]+d|0,c[1]=c[1]+e|0,c[2]=c[2]+f|0,c[3]=c[3]+g|0,c[4]=c[4]+h|0},_doFinalize:function(){var b=this._data,c=b.words,d=8*this._nDataBytes,e=8*b.sigBytes;return c[e>>>5]|=128<<24-e%32,c[(e+64>>>9<<4)+14]=a.floor(d/4294967296),c[(e+64>>>9<<4)+15]=d,b.sigBytes=4*c.length,this._process(),this._hash},clone:function(){var a=l.clone.call(this);return a._hash=this._hash.clone(),a}});return c.SHA1=l._createHelper(o),c.HmacSHA1=l._createHmacHelper(o),c}(Math),CryptoJS=CryptoJS||function(a,b){var c={},d=c.lib={},e=function(){},f=d.Base={extend:function(a){e.prototype=this;var b=new e;return a&&b.mixIn(a),b.hasOwnProperty("init")||(b.init=function(){b.$super.init.apply(this,arguments)}),b.init.prototype=b,b.$super=this,b},create:function(){var a=this.extend();return a.init.apply(a,arguments),a},init:function(){},mixIn:function(a){for(var b in a)a.hasOwnProperty(b)&&(this[b]=a[b]);a.hasOwnProperty("toString")&&(this.toString=a.toString)},clone:function(){return this.init.prototype.extend(this)}},g=d.WordArray=f.extend({init:function(a,c){a=this.words=a||[],this.sigBytes=c!=b?c:4*a.length},toString:function(a){return(a||i).stringify(this)},concat:function(a){var b=this.words,c=a.words,d=this.sigBytes;if(a=a.sigBytes,this.clamp(),d%4)for(var e=0;a>e;e++)b[d+e>>>2]|=(c[e>>>2]>>>24-8*(e%4)&255)<<24-8*((d+e)%4);else if(65535e;e+=4)b[d+e>>>2]=c[e>>>2];else b.push.apply(b,c);return this.sigBytes+=a,this},clamp:function(){var b=this.words,c=this.sigBytes;b[c>>>2]&=4294967295<<32-8*(c%4),b.length=a.ceil(c/4)},clone:function(){var a=f.clone.call(this);return a.words=this.words.slice(0),a},random:function(b){for(var c=[],d=0;b>d;d+=4)c.push(4294967296*a.random()|0);return new g.init(c,b)}}),h=c.enc={},i=h.Hex={stringify:function(a){var b=a.words;a=a.sigBytes;for(var c=[],d=0;a>d;d++){var e=b[d>>>2]>>>24-8*(d%4)&255;c.push((e>>>4).toString(16)),c.push((15&e).toString(16))}return c.join("")},parse:function(a){for(var b=a.length,c=[],d=0;b>d;d+=2)c[d>>>3]|=parseInt(a.substr(d,2),16)<<24-4*(d%8);return new g.init(c,b/2)}},j=h.Latin1={stringify:function(a){var b=a.words;a=a.sigBytes;for(var c=[],d=0;a>d;d++)c.push(String.fromCharCode(b[d>>>2]>>>24-8*(d%4)&255));return c.join("")},parse:function(a){for(var b=a.length,c=[],d=0;b>d;d++)c[d>>>2]|=(255&a.charCodeAt(d))<<24-8*(d%4);return new g.init(c,b)}},k=h.Utf8={stringify:function(a){try{return decodeURIComponent(escape(j.stringify(a)))}catch(b){throw Error("Malformed UTF-8 data")}},parse:function(a){return j.parse(unescape(encodeURIComponent(a)))}},l=d.BufferedBlockAlgorithm=f.extend({reset:function(){this._data=new g.init,this._nDataBytes=0},_append:function(a){"string"==typeof a&&(a=k.parse(a)),this._data.concat(a),this._nDataBytes+=a.sigBytes},_process:function(b){var c=this._data,d=c.words,e=c.sigBytes,f=this.blockSize,h=e/(4*f),h=b?a.ceil(h):a.max((0|h)-this._minBufferSize,0);if(b=h*f,e=a.min(4*b,e),b){for(var i=0;b>i;i+=f)this._doProcessBlock(d,i);i=d.splice(0,b),c.sigBytes-=e}return new g.init(i,e)},clone:function(){var a=f.clone.call(this);return a._data=this._data.clone(),a},_minBufferSize:0});d.Hasher=l.extend({cfg:f.extend(),init:function(a){this.cfg=this.cfg.extend(a),this.reset()},reset:function(){l.reset.call(this),this._doReset()},update:function(a){return this._append(a),this._process(),this},finalize:function(a){return a&&this._append(a),this._doFinalize()},blockSize:16,_createHelper:function(a){return function(b,c){return new a.init(c).finalize(b)}},_createHmacHelper:function(a){return function(b,c){return new m.HMAC.init(a,c).finalize(b)}}});var m=c.algo={};return c}(Math);!function(a){for(var b=CryptoJS,c=b.lib,d=c.WordArray,e=c.Hasher,c=b.algo,f=[],g=[],h=function(a){return 4294967296*(a-(0|a))|0},i=2,j=0;64>j;){var k;a:{k=i;for(var l=a.sqrt(k),m=2;l>=m;m++)if(!(k%m)){k=!1;break a}k=!0}k&&(8>j&&(f[j]=h(a.pow(i,.5))),g[j]=h(a.pow(i,1/3)),j++),i++}var n=[],c=c.SHA256=e.extend({_doReset:function(){this._hash=new d.init(f.slice(0))},_doProcessBlock:function(a,b){for(var c=this._hash.words,d=c[0],e=c[1],f=c[2],h=c[3],i=c[4],j=c[5],k=c[6],l=c[7],m=0;64>m;m++){if(16>m)n[m]=0|a[b+m];else{var o=n[m-15],p=n[m-2];n[m]=((o<<25|o>>>7)^(o<<14|o>>>18)^o>>>3)+n[m-7]+((p<<15|p>>>17)^(p<<13|p>>>19)^p>>>10)+n[m-16]}o=l+((i<<26|i>>>6)^(i<<21|i>>>11)^(i<<7|i>>>25))+(i&j^~i&k)+g[m]+n[m],p=((d<<30|d>>>2)^(d<<19|d>>>13)^(d<<10|d>>>22))+(d&e^d&f^e&f),l=k,k=j,j=i,i=h+o|0,h=f,f=e,e=d,d=o+p|0}c[0]=c[0]+d|0,c[1]=c[1]+e|0,c[2]=c[2]+f|0,c[3]=c[3]+h|0,c[4]=c[4]+i|0,c[5]=c[5]+j|0,c[6]=c[6]+k|0,c[7]=c[7]+l|0},_doFinalize:function(){var b=this._data,c=b.words,d=8*this._nDataBytes,e=8*b.sigBytes;return c[e>>>5]|=128<<24-e%32,c[(e+64>>>9<<4)+14]=a.floor(d/4294967296),c[(e+64>>>9<<4)+15]=d,b.sigBytes=4*c.length,this._process(),this._hash},clone:function(){var a=e.clone.call(this);return a._hash=this._hash.clone(),a}});b.SHA256=e._createHelper(c),b.HmacSHA256=e._createHmacHelper(c)}(Math),function(){var a=CryptoJS,b=a.enc.Utf8;a.algo.HMAC=a.lib.Base.extend({init:function(a,c){a=this._hasher=new a.init,"string"==typeof c&&(c=b.parse(c));var d=a.blockSize,e=4*d;c.sigBytes>e&&(c=a.finalize(c)),c.clamp();for(var f=this._oKey=c.clone(),g=this._iKey=c.clone(),h=f.words,i=g.words,j=0;d>j;j++)h[j]^=1549556828,i[j]^=909522486;f.sigBytes=g.sigBytes=e,this.reset()},reset:function(){var a=this._hasher;a.reset(),a.update(this._iKey)},update:function(a){return this._hasher.update(a),this},finalize:function(a){var b=this._hasher;return a=b.finalize(a),b.reset(),b.finalize(this._oKey.clone().concat(a))}})}(),function(a){a.verbs={abandoned:{id:"https://w3id.org/xapi/adl/verbs/abandoned",display:{"en-US":"abandoned"}},answered:{id:"http://adlnet.gov/expapi/verbs/answered",display:{"de-DE":"beantwortete","en-US":"answered","fr-FR":"a répondu","es-ES":"contestó"}},asked:{id:"http://adlnet.gov/expapi/verbs/asked",display:{"de-DE":"fragte","en-US":"asked","fr-FR":"a demandé","es-ES":"preguntó"}},attempted:{id:"http://adlnet.gov/expapi/verbs/attempted",display:{"de-DE":"versuchte","en-US":"attempted","fr-FR":"a essayé","es-ES":"intentó"}},attended:{id:"http://adlnet.gov/expapi/verbs/attended",display:{"de-DE":"nahm teil an","en-US":"attended","fr-FR":"a suivi","es-ES":"asistió"}},commented:{id:"http://adlnet.gov/expapi/verbs/commented",display:{"de-DE":"kommentierte","en-US":"commented","fr-FR":"a commenté","es-ES":"comentó"}},completed:{id:"http://adlnet.gov/expapi/verbs/completed",display:{"de-DE":"beendete","en-US":"completed","fr-FR":"a terminé","es-ES":"completó"}},exited:{id:"http://adlnet.gov/expapi/verbs/exited",display:{"de-DE":"verließ","en-US":"exited","fr-FR":"a quitté","es-ES":"salió"}},experienced:{id:"http://adlnet.gov/expapi/verbs/experienced",display:{"de-DE":"erlebte","en-US":"experienced","fr-FR":"a éprouvé","es-ES":"experimentó"}},failed:{id:"http://adlnet.gov/expapi/verbs/failed",display:{"de-DE":"verfehlte","en-US":"failed","fr-FR":"a échoué","es-ES":"fracasó"}},imported:{id:"http://adlnet.gov/expapi/verbs/imported",display:{"de-DE":"importierte","en-US":"imported","fr-FR":"a importé","es-ES":"importó"}},initialized:{id:"http://adlnet.gov/expapi/verbs/initialized",display:{"de-DE":"initialisierte","en-US":"initialized","fr-FR":"a initialisé","es-ES":"inicializó"}},interacted:{id:"http://adlnet.gov/expapi/verbs/interacted",display:{"de-DE":"interagierte","en-US":"interacted","fr-FR":"a interagi","es-ES":"interactuó"}},launched:{id:"http://adlnet.gov/expapi/verbs/launched",display:{"de-DE":"startete","en-US":"launched","fr-FR":"a lancé","es-ES":"lanzó"}},mastered:{id:"http://adlnet.gov/expapi/verbs/mastered",display:{"de-DE":"meisterte","en-US":"mastered","fr-FR":"a maîtrisé","es-ES":"dominó"}},passed:{id:"http://adlnet.gov/expapi/verbs/passed",display:{"de-DE":"bestand","en-US":"passed","fr-FR":"a réussi","es-ES":"aprobó"}},preferred:{id:"http://adlnet.gov/expapi/verbs/preferred",display:{"de-DE":"bevorzugte","en-US":"preferred","fr-FR":"a préféré","es-ES":"prefirió"}},progressed:{id:"http://adlnet.gov/expapi/verbs/progressed",display:{"de-DE":"machte Fortschritt mit","en-US":"progressed","fr-FR":"a progressé","es-ES":"progresó"}},registered:{id:"http://adlnet.gov/expapi/verbs/registered",display:{"de-DE":"registrierte","en-US":"registered","fr-FR":"a enregistré","es-ES":"registró"}},responded:{id:"http://adlnet.gov/expapi/verbs/responded",display:{"de-DE":"reagierte","en-US":"responded","fr-FR":"a répondu","es-ES":"respondió"}},resumed:{id:"http://adlnet.gov/expapi/verbs/resumed",display:{"de-DE":"setzte fort","en-US":"resumed","fr-FR":"a repris","es-ES":"continuó"}},satisfied:{id:"https://w3id.org/xapi/adl/verbs/satisfied",display:{"en-US":"satisfied"}},scored:{id:"http://adlnet.gov/expapi/verbs/scored",display:{"de-DE":"erreichte","en-US":"scored","fr-FR":"a marqué","es-ES":"anotó"}},shared:{id:"http://adlnet.gov/expapi/verbs/shared",display:{"de-DE":"teilte","en-US":"shared","fr-FR":"a partagé","es-ES":"compartió"}},suspended:{id:"http://adlnet.gov/expapi/verbs/suspended",display:{"de-DE":"pausierte","en-US":"suspended","fr-FR":"a suspendu","es-ES":"aplazó"}},terminated:{id:"http://adlnet.gov/expapi/verbs/terminated",display:{"de-DE":"beendete","en-US":"terminated","fr-FR":"a terminé","es-ES":"terminó"}},voided:{id:"http://adlnet.gov/expapi/verbs/voided",display:{"de-DE":"entwertete","en-US":"voided","fr-FR":"a annulé","es-ES":"anuló"}},waived:{id:"https://w3id.org/xapi/adl/verbs/waived",display:{"en-US":"waived"}}}}(window.ADL=window.ADL||{}),Date.prototype.toISOString||!function(){function a(a){var b=String(a);return 1===b.length&&(b="0"+b),b}Date.prototype.toISOString=function(){return this.getUTCFullYear()+"-"+a(this.getUTCMonth()+1)+"-"+a(this.getUTCDate())+"T"+a(this.getUTCHours())+":"+a(this.getUTCMinutes())+":"+a(this.getUTCSeconds())+"."+String((this.getUTCMilliseconds()/1e3).toFixed(3)).slice(2,5)+"Z"}}(),function(a){function b(){try{return void 0!=this.lrs.endpoint&&""!=this.lrs.endpoint}catch(a){return!1}}function c(a){if(!c.debug)return!1;try{return console.log(a),!0}catch(b){return!1}}function d(a,b){for(var e in b){prop=b[e],c(e+" : "+prop);try{b[e].constructor==Object?a[e]=d(a[e],b[e]):(void 0==a&&(a=new Object),a[e]=b[e])}catch(f){void 0==a&&(a=new Object),a[e]=b[e]}}return a}function e(a){var b,c,e=["endpoint","auth","actor","registration","activity_id","grouping","activity_platform"],g=new Object;if(b=f(),void 0!==b&&0!==Object.keys(b).length){for(var h=0;h0&&(f.push(e.substr(g+1)),e=e.substr(0,g)),e=e+"?method="+a,null!==c)for(var h in c)f.push(h+"="+encodeURIComponent(c[h]));return null!==d&&f.push("content="+encodeURIComponent(d)),{method:"POST",url:e,headers:{},data:f.join("&")}}c.debug=!1;var i=function(){var a={};a.endpoint="http://localhost:8000/xapi/";try{a.auth="Basic "+toBase64("tom:1234")}catch(b){c("Exception in Config trying to encode auth: "+b)}return a}();XAPIWrapper=function(c,f){function g(b){var c=document.createElement("a");return c.href=b,c.protocol&&c.host?c.protocol+"//"+c.host:void a.XAPIWrapper.log("Couldn't create base url from endpoint: "+this.lrs.endpoint)}function h(a,b,c){a.auth="Basic "+toBase64(b+":"+c)}this.lrs=e(c||{}),this.lrs.user&&this.lrs.password&&h(this.lrs,this.lrs.user,this.lrs.password),this.base=g(this.lrs.endpoint),this.withCredentials=!1,this.withCredentials=c&&c.withCredentials,this.strictCallbacks=!1,this.strictCallbacks=c&&c.strictCallbacks,f&&b.call(this)&&window.ADL.XHR_request(this.lrs,this.lrs.endpoint+"about","GET",null,null,function(b){if(200==b.status)try{var c=JSON.parse(b.response),d=!1;for(var e in c.version)if(c.version[e]==a.XAPIWrapper.xapiVersion){d=!0;break}d||a.XAPIWrapper.log("The lrs version ["+c.version+"] does not match this wrapper's XAPI version ["+a.XAPIWrapper.xapiVersion+"]")}catch(f){a.XAPIWrapper.log("The response was not an about object")}else a.XAPIWrapper.log("The request to get information about the LRS failed: "+b)},null,!1,null,this.withCredentials,!1),this.searchParams=function(){var a={format:"exact"};return a},this.hash=function(b){if(!b)return null;try{return toSHA1(b)}catch(c){return a.XAPIWrapper.log("Error trying to hash -- "+c),null}},this.changeConfig=function(b){try{a.XAPIWrapper.log("updating lrs object with new configuration"),this.lrs=d(this.lrs,b),b.user&&b.password&&this.updateAuth(this.lrs,b.user,b.password),this.base=g(this.lrs.endpoint),this.withCredentials=b.withCredentials,this.strictCallbacks=b.strictCallbacks}catch(c){a.XAPIWrapper.log("error while changing configuration -- "+c)}},this.updateAuth=h},XAPIWrapper.prototype.xapiVersion="1.0.1",XAPIWrapper.prototype.prepareStatement=function(a){void 0===a.actor?a.actor=JSON.parse(this.lrs.actor):"string"==typeof a.actor&&(a.actor=JSON.parse(a.actor)),(this.lrs.grouping||this.lrs.registration||this.lrs.activity_platform)&&(a.context||(a.context={})),this.lrs.grouping&&(a.context.contextActivities||(a.context.contextActivities={}),a.context.contextActivities.grouping=[{id:this.lrs.grouping}]),this.lrs.registration&&(a.context.registration=this.lrs.registration),this.lrs.activity_platform&&(a.context.platform=this.lrs.activity_platform)},XAPIWrapper.prototype.testConfig=b,XAPIWrapper.prototype.log=c,XAPIWrapper.prototype.sendStatement=function(b,c,d){if(this.testConfig()){this.prepareStatement(b);var e;b.id?e=b.id:(e=a.ruuid(),b.id=e);var f=JSON.stringify(b),g=null;d&&d.length>0&&(g={},f=this.buildMultipartPost(b,d,g));var h=a.XHR_request(this.lrs,this.lrs.endpoint+"statements","POST",f,this.lrs.auth,c,{id:e},null,g,this.withCredentials,this.strictCallbacks);if(!c)return{xhr:h,id:e}}},XAPIWrapper.prototype.buildMultipartPost=function(a,b,c){a.attachments=[];for(var d=0;d0&&(e=e+"?"+f.join("&"))}var h=a.XHR_request(this.lrs,e,"GET",null,this.lrs.auth,d,null,!1,null,this.withCredentials,this.strictCallbacks);if(void 0===h||404==h.status)return null;try{return JSON.parse(h.response)}catch(i){return h.response}}},XAPIWrapper.prototype.getActivities=function(b,c){if(this.testConfig()){var d=this.lrs.endpoint+"activities?activityId=";d=d.replace("",encodeURIComponent(b));var e=a.XHR_request(this.lrs,d,"GET",null,this.lrs.auth,c,null,!0,null,this.withCredentials,this.strictCallbacks);if(void 0===e||404==e.status)return null;try{return JSON.parse(e.response)}catch(f){return e.response}}},XAPIWrapper.prototype.sendState=function(b,d,e,f,g,h,i,j){if(this.testConfig()){var k=this.lrs.endpoint+"activities/state?activityId=&agent=&stateId=";k=k.replace("",encodeURIComponent(b)),k=k.replace("",encodeURIComponent(JSON.stringify(d))),k=k.replace("",encodeURIComponent(e)),f&&(k+="®istration="+encodeURIComponent(f));var l=null;h&&i?c("Can't have both If-Match and If-None-Match"):h?l={"If-Match":'"'+h+'"'}:i&&(l={"If-None-Match":'"'+i+'"'});var m="PUT";if(!g)return this.log("No activity state was included."),!1;g instanceof Array?(g=JSON.stringify(g),l=l||{},l["Content-Type"]="application/json"):g instanceof Object?(g=JSON.stringify(g),l=l||{},l["Content-Type"]="application/json",m="POST"):(l=l||{},l["Content-Type"]="application/octet-stream"),a.XHR_request(this.lrs,k,m,g,this.lrs.auth,j,null,null,l,this.withCredentials,this.strictCallbacks)}},XAPIWrapper.prototype.getState=function(b,c,d,e,f,g){if(this.testConfig()){var h=this.lrs.endpoint+"activities/state?activityId=&agent=";h=h.replace("",encodeURIComponent(b)),h=h.replace("",encodeURIComponent(JSON.stringify(c))),d&&(h+="&stateId="+encodeURIComponent(d)),e&&(h+="®istration="+encodeURIComponent(e)),f&&(f=isDate(f),null!=f&&(h+="&since="+encodeURIComponent(f.toISOString())));var i=a.XHR_request(this.lrs,h,"GET",null,this.lrs.auth,g,null,!0,null,this.withCredentials,this.strictCallbacks);if(void 0===i||404==i.status)return null;try{return JSON.parse(i.response)}catch(j){return i.response}}},XAPIWrapper.prototype.deleteState=function(b,d,e,f,g,h,i){if(this.testConfig()){var j=this.lrs.endpoint+"activities/state?activityId=&agent=&stateId=";j=j.replace("",encodeURIComponent(b)),j=j.replace("",encodeURIComponent(JSON.stringify(d))),j=j.replace("",encodeURIComponent(e)),f&&(j+="®istration="+encodeURIComponent(f));var k=null;g&&h?c("Can't have both If-Match and If-None-Match"):g?k={"If-Match":'"'+g+'"'}:h&&(k={"If-None-Match":'"'+h+'"'});var l=a.XHR_request(this.lrs,j,"DELETE",null,this.lrs.auth,i,null,!1,k,this.withCredentials,this.strictCallbacks);if(void 0===l||404==l.status)return null;try{return JSON.parse(l.response)}catch(m){return l}}},XAPIWrapper.prototype.sendActivityProfile=function(b,d,e,f,g,h){if(this.testConfig()){var i=this.lrs.endpoint+"activities/profile?activityId=&profileId=";i=i.replace("",encodeURIComponent(b)),i=i.replace("",encodeURIComponent(d));var j=null;f&&g?c("Can't have both If-Match and If-None-Match"):f?j={"If-Match":'"'+f+'"'}:g&&(j={"If-None-Match":'"'+g+'"'});var k="PUT";if(!e)return this.log("No activity profile was included."),!1;e instanceof Array?(e=JSON.stringify(e),j=j||{},j["Content-Type"]="application/json"):e instanceof Object?(e=JSON.stringify(e),j=j||{},j["Content-Type"]="application/json",k="POST"):(j=j||{},j["Content-Type"]="application/octet-stream"),a.XHR_request(this.lrs,i,k,e,this.lrs.auth,h,null,!1,j,this.withCredentials,this.strictCallbacks)}},XAPIWrapper.prototype.getActivityProfile=function(b,c,d,e){if(this.testConfig()){var f=this.lrs.endpoint+"activities/profile?activityId=";f=f.replace("",encodeURIComponent(b)),c&&(f+="&profileId="+encodeURIComponent(c)),d&&(d=isDate(d),null!=d&&(f+="&since="+encodeURIComponent(d.toISOString())));var g=a.XHR_request(this.lrs,f,"GET",null,this.lrs.auth,e,null,!0,null,this.withCredentials,this.strictCallbacks);if(void 0===g||404==g.status)return null;try{return JSON.parse(g.response)}catch(h){return g.response}}},XAPIWrapper.prototype.deleteActivityProfile=function(b,d,e,f,g){if(this.testConfig()){var h=this.lrs.endpoint+"activities/profile?activityId=&profileId=";h=h.replace("",encodeURIComponent(b)),h=h.replace("",encodeURIComponent(d));var i=null;e&&f?c("Can't have both If-Match and If-None-Match"):e?i={"If-Match":'"'+e+'"'}:f&&(i={"If-None-Match":'"'+f+'"'});var j=a.XHR_request(this.lrs,h,"DELETE",null,this.lrs.auth,g,null,!1,i,this.withCredentials,this.strictCallbacks);if(void 0===j||404==j.status)return null;try{return JSON.parse(j.response)}catch(k){return j}}},XAPIWrapper.prototype.getAgents=function(b,c){if(this.testConfig()){var d=this.lrs.endpoint+"agents?agent=";d=d.replace("",encodeURIComponent(JSON.stringify(b)));var e=a.XHR_request(this.lrs,d,"GET",null,this.lrs.auth,c,null,!0,null,this.withCredentials,this.strictCallbacks);if(void 0===e||404==e.status)return null;try{return JSON.parse(e.response)}catch(f){return e.response}}},XAPIWrapper.prototype.sendAgentProfile=function(b,d,e,f,g,h){if(this.testConfig()){var i=this.lrs.endpoint+"agents/profile?agent=&profileId=";i=i.replace("",encodeURIComponent(JSON.stringify(b))),i=i.replace("",encodeURIComponent(d));var j=null;f&&g?c("Can't have both If-Match and If-None-Match"):f?j={"If-Match":'"'+f+'"'}:g&&(j={"If-None-Match":'"'+g+'"'});var k="PUT";if(!e)return this.log("No agent profile was included."),!1;e instanceof Array?(e=JSON.stringify(e),j=j||{},j["Content-Type"]="application/json"):e instanceof Object?(e=JSON.stringify(e),j=j||{},j["Content-Type"]="application/json",k="POST"):(j=j||{},j["Content-Type"]="application/octet-stream"),a.XHR_request(this.lrs,i,k,e,this.lrs.auth,h,null,!1,j,this.withCredentials,this.strictCallbacks)}},XAPIWrapper.prototype.getAgentProfile=function(b,c,d,e){if(this.testConfig()){var f=this.lrs.endpoint+"agents/profile?agent=";f=f.replace("",encodeURIComponent(JSON.stringify(b))),f=f.replace("",encodeURIComponent(c)),c&&(f+="&profileId="+encodeURIComponent(c)),d&&(d=isDate(d),null!=d&&(f+="&since="+encodeURIComponent(d.toISOString())));var g=a.XHR_request(this.lrs,f,"GET",null,this.lrs.auth,e,null,!0,null,this.withCredentials,this.strictCallbacks);if(void 0===g||404==g.status)return null;try{return JSON.parse(g.response)}catch(h){return g.response}}},XAPIWrapper.prototype.deleteAgentProfile=function(b,d,e,f,g){if(this.testConfig()){var h=this.lrs.endpoint+"agents/profile?agent=&profileId=";h=h.replace("",encodeURIComponent(JSON.stringify(b))),h=h.replace("",encodeURIComponent(d));var i=null;e&&f?c("Can't have both If-Match and If-None-Match"):e?i={"If-Match":'"'+e+'"'}:f&&(i={"If-None-Match":'"'+f+'"'});var j=a.XHR_request(this.lrs,h,"DELETE",null,this.lrs.auth,g,null,!1,i,this.withCredentials,this.strictCallbacks);if(void 0===j||404==j.status)return null;try{return JSON.parse(j.response)}catch(k){return j}}},a.ruuid=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(a){var b=16*Math.random()|0,c="x"==a?b:3&b|8;return c.toString(16)})},a.dateFromISOString=function(a){var b="([0-9]{4})(-([0-9]{2})(-([0-9]{2})([T| ]([0-9]{2}):([0-9]{2})(:([0-9]{2})(.([0-9]+))?)?(Z|(([-+])([0-9]{2}):([0-9]{2})))?)?)?)?",c=a.match(new RegExp(b)),d=0,e=new Date(c[1],0,1);c[3]&&e.setMonth(c[3]-1),c[5]&&e.setDate(c[5]),c[7]&&e.setHours(c[7]),c[8]&&e.setMinutes(c[8]),c[10]&&e.setSeconds(c[10]),c[12]&&e.setMilliseconds(1e3*Number("0."+c[12])),c[14]&&(d=60*Number(c[16])+Number(c[17]),d*="-"==c[15]?1:-1),d-=e.getTimezoneOffset(),time=Number(e)+60*d*1e3;var f=new Date;return f.setTime(Number(time)),f},a.XHR_request=function(b,c,d,e,f,i,j,k,l,m,n){"use strict";function o(){if(u)return s;u=!0;var b=k&&404===p.status;if(!(void 0===p.status||p.status>=200&&p.status<400||b)){var e;try{e="There was a problem communicating with the Learning Record Store. ( "+p.status+" | "+p.response+" )"+c}catch(f){e=f.toString()}return a.XAPIWrapper.log(e),a.xhrRequestOnError(p,d,c,i,j,n),s=p,p}if(!i)return s=p,p;if(j)n?i(null,p,j):i(p,j);else try{var g=JSON.parse(p.responseText);n?i(null,p,g):i(p,g)}catch(h){n?i(null,p,g):i(p,p.responseText)}}var p,q,r,s,t,u=!1,v=!1,w=!1,x=c.toLowerCase().match(/^(.+):\/\/([^:\/]*):?(\d+)?(\/.*)?$/),y=window.location,z={};if(z["Content-Type"]="application/json",z.Authorization=f,z["X-Experience-API-Version"]=a.XAPIWrapper.xapiVersion,null!==l)for(var A in l)z[A]=l[A];v=y.protocol.toLowerCase()!==x[1]||y.hostname.toLowerCase()!==x[2],v||(r=null===x[3]?"http"===x[1]?"80":"443":x[3],v=r===y.port);var B=window.XDomainRequest&&window.XMLHttpRequest&&void 0===(new XMLHttpRequest).responseType;if(v&&void 0!==B&&B!==!1)w=!0,q=h(d,c,z,e),p=new XDomainRequest,p.open(q.method,q.url);else{p=new XMLHttpRequest,p.withCredentials=m,p.open(d,c,null!=i);for(var A in z)p.setRequestHeader(A,z[A])}if(p.onreadystatechange=function(){return 4===p.readyState?o():void 0},p.onload=o,p.onerror=o,p.send(w?q.data:e),!i){if(w)for(t=1e3+new Date;new Datef;f++){var g=c[f>>>2]>>>24-f%4*8&255;b[d+f>>>2]|=g<<24-(d+f)%4*8}else if(c.length>65535)for(var f=0;e>f;f+=4)b[d+f>>>2]=c[f>>>2];else b.push.apply(b,c);return this.sigBytes+=e,this},clamp:function(){var b=this.words,c=this.sigBytes;b[c>>>2]&=4294967295<<32-c%4*8,b.length=a.ceil(c/4)},clone:function(){var a=e.clone.call(this);return a.words=this.words.slice(0),a},random:function(b){for(var c=[],d=0;b>d;d+=4)c.push(4294967296*a.random()|0);return new f.init(c,b)}}),g=c.enc={},h=g.Hex={stringify:function(a){for(var b=a.words,c=a.sigBytes,d=[],e=0;c>e;e++){var f=b[e>>>2]>>>24-e%4*8&255;d.push((f>>>4).toString(16)),d.push((15&f).toString(16))}return d.join("")},parse:function(a){for(var b=a.length,c=[],d=0;b>d;d+=2)c[d>>>3]|=parseInt(a.substr(d,2),16)<<24-d%8*4;return new f.init(c,b/2)}},i=g.Latin1={stringify:function(a){for(var b=a.words,c=a.sigBytes,d=[],e=0;c>e;e++){var f=b[e>>>2]>>>24-e%4*8&255;d.push(String.fromCharCode(f))}return d.join("")},parse:function(a){for(var b=a.length,c=[],d=0;b>d;d++)c[d>>>2]|=(255&a.charCodeAt(d))<<24-d%4*8;return new f.init(c,b)}},j=g.Utf8={stringify:function(a){try{return decodeURIComponent(escape(i.stringify(a)))}catch(b){throw new Error("Malformed UTF-8 data")}},parse:function(a){return i.parse(unescape(encodeURIComponent(a)))}},k=(g.Base64={stringify:function(a){var b=a.words,c=a.sigBytes,d=this._map;a.clamp();for(var e=[],f=0;c>f;f+=3)for(var g=b[f>>>2]>>>24-f%4*8&255,h=b[f+1>>>2]>>>24-(f+1)%4*8&255,i=b[f+2>>>2]>>>24-(f+2)%4*8&255,j=g<<16|h<<8|i,k=0;4>k&&c>f+.75*k;k++)e.push(d.charAt(j>>>6*(3-k)&63));var l=d.charAt(64);if(l)for(;e.length%4;)e.push(l);return e.join("")},parse:function(a){var b=a.length,c=this._map,d=c.charAt(64);if(d){var e=a.indexOf(d);-1!=e&&(b=e)}for(var g=[],h=0,i=0;b>i;i++)if(i%4){var j=c.indexOf(a.charAt(i-1))<>>6-i%4*2;g[h>>>2]|=(j|k)<<24-h%4*8,h++}return f.create(g,h)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},d.BufferedBlockAlgorithm=e.extend({reset:function(){this._data=new f.init,this._nDataBytes=0},_append:function(a){"string"==typeof a&&(a=j.parse(a)),this._data.concat(a),this._nDataBytes+=a.sigBytes},_process:function(b){var c=this._data,d=c.words,e=c.sigBytes,g=this.blockSize,h=4*g,i=e/h;i=b?a.ceil(i):a.max((0|i)-this._minBufferSize,0);var j=i*g,k=a.min(4*j,e);if(j){for(var l=0;j>l;l+=g)this._doProcessBlock(d,l);var m=d.splice(0,j);c.sigBytes-=k}return new f.init(m,k)},clone:function(){var a=e.clone.call(this);return a._data=this._data.clone(),a},_minBufferSize:0})),l=d.Hasher=k.extend({cfg:e.extend(),init:function(a){this.cfg=this.cfg.extend(a),this.reset()},reset:function(){k.reset.call(this),this._doReset()},update:function(a){return this._append(a),this._process(),this},finalize:function(a){a&&this._append(a);var b=this._doFinalize();return b},blockSize:16,_createHelper:function(a){return function(b,c){return new a.init(c).finalize(b)}},_createHmacHelper:function(a){return function(b,c){return new m.HMAC.init(a,c).finalize(b)}}}),m=c.algo={},n=[],o=m.SHA1=l.extend({_doReset:function(){this._hash=new f.init([1732584193,4023233417,2562383102,271733878,3285377520])},_doProcessBlock:function(a,b){for(var c=this._hash.words,d=c[0],e=c[1],f=c[2],g=c[3],h=c[4],i=0;80>i;i++){if(16>i)n[i]=0|a[b+i];else{var j=n[i-3]^n[i-8]^n[i-14]^n[i-16];n[i]=j<<1|j>>>31}var k=(d<<5|d>>>27)+h+n[i];k+=20>i?(e&f|~e&g)+1518500249:40>i?(e^f^g)+1859775393:60>i?(e&f|e&g|f&g)-1894007588:(e^f^g)-899497514,h=g,g=f,f=e<<30|e>>>2,e=d,d=k}c[0]=c[0]+d|0,c[1]=c[1]+e|0,c[2]=c[2]+f|0,c[3]=c[3]+g|0,c[4]=c[4]+h|0},_doFinalize:function(){var b=this._data,c=b.words,d=8*this._nDataBytes,e=8*b.sigBytes;return c[e>>>5]|=128<<24-e%32,c[(e+64>>>9<<4)+14]=a.floor(d/4294967296),c[(e+64>>>9<<4)+15]=d,b.sigBytes=4*c.length,this._process(),this._hash},clone:function(){var a=l.clone.call(this);return a._hash=this._hash.clone(),a}});return c.SHA1=l._createHelper(o),c.HmacSHA1=l._createHmacHelper(o),c}(Math),CryptoJS=CryptoJS||function(a,b){var c={},d=c.lib={},e=function(){},f=d.Base={extend:function(a){e.prototype=this;var b=new e;return a&&b.mixIn(a),b.hasOwnProperty("init")||(b.init=function(){b.$super.init.apply(this,arguments)}),b.init.prototype=b,b.$super=this,b},create:function(){var a=this.extend();return a.init.apply(a,arguments),a},init:function(){},mixIn:function(a){for(var b in a)a.hasOwnProperty(b)&&(this[b]=a[b]);a.hasOwnProperty("toString")&&(this.toString=a.toString)},clone:function(){return this.init.prototype.extend(this)}},g=d.WordArray=f.extend({init:function(a,c){a=this.words=a||[],this.sigBytes=c!=b?c:4*a.length},toString:function(a){return(a||i).stringify(this)},concat:function(a){var b=this.words,c=a.words,d=this.sigBytes;if(a=a.sigBytes,this.clamp(),d%4)for(var e=0;a>e;e++)b[d+e>>>2]|=(c[e>>>2]>>>24-8*(e%4)&255)<<24-8*((d+e)%4);else if(65535e;e+=4)b[d+e>>>2]=c[e>>>2];else b.push.apply(b,c);return this.sigBytes+=a,this},clamp:function(){var b=this.words,c=this.sigBytes;b[c>>>2]&=4294967295<<32-8*(c%4),b.length=a.ceil(c/4)},clone:function(){var a=f.clone.call(this);return a.words=this.words.slice(0),a},random:function(b){for(var c=[],d=0;b>d;d+=4)c.push(4294967296*a.random()|0);return new g.init(c,b)}}),h=c.enc={},i=h.Hex={stringify:function(a){var b=a.words;a=a.sigBytes;for(var c=[],d=0;a>d;d++){var e=b[d>>>2]>>>24-8*(d%4)&255;c.push((e>>>4).toString(16)),c.push((15&e).toString(16))}return c.join("")},parse:function(a){for(var b=a.length,c=[],d=0;b>d;d+=2)c[d>>>3]|=parseInt(a.substr(d,2),16)<<24-4*(d%8);return new g.init(c,b/2)}},j=h.Latin1={stringify:function(a){var b=a.words;a=a.sigBytes;for(var c=[],d=0;a>d;d++)c.push(String.fromCharCode(b[d>>>2]>>>24-8*(d%4)&255));return c.join("")},parse:function(a){for(var b=a.length,c=[],d=0;b>d;d++)c[d>>>2]|=(255&a.charCodeAt(d))<<24-8*(d%4);return new g.init(c,b)}},k=h.Utf8={stringify:function(a){try{return decodeURIComponent(escape(j.stringify(a)))}catch(b){throw Error("Malformed UTF-8 data")}},parse:function(a){return j.parse(unescape(encodeURIComponent(a)))}},l=d.BufferedBlockAlgorithm=f.extend({reset:function(){this._data=new g.init,this._nDataBytes=0},_append:function(a){"string"==typeof a&&(a=k.parse(a)),this._data.concat(a),this._nDataBytes+=a.sigBytes},_process:function(b){var c=this._data,d=c.words,e=c.sigBytes,f=this.blockSize,h=e/(4*f),h=b?a.ceil(h):a.max((0|h)-this._minBufferSize,0);if(b=h*f,e=a.min(4*b,e),b){for(var i=0;b>i;i+=f)this._doProcessBlock(d,i);i=d.splice(0,b),c.sigBytes-=e}return new g.init(i,e)},clone:function(){var a=f.clone.call(this);return a._data=this._data.clone(),a},_minBufferSize:0});d.Hasher=l.extend({cfg:f.extend(),init:function(a){this.cfg=this.cfg.extend(a),this.reset()},reset:function(){l.reset.call(this),this._doReset()},update:function(a){return this._append(a),this._process(),this},finalize:function(a){return a&&this._append(a),this._doFinalize()},blockSize:16,_createHelper:function(a){return function(b,c){return new a.init(c).finalize(b)}},_createHmacHelper:function(a){return function(b,c){return new m.HMAC.init(a,c).finalize(b)}}});var m=c.algo={};return c}(Math);!function(a){for(var b=CryptoJS,c=b.lib,d=c.WordArray,e=c.Hasher,c=b.algo,f=[],g=[],h=function(a){return 4294967296*(a-(0|a))|0},i=2,j=0;64>j;){var k;a:{k=i;for(var l=a.sqrt(k),m=2;l>=m;m++)if(!(k%m)){k=!1;break a}k=!0}k&&(8>j&&(f[j]=h(a.pow(i,.5))),g[j]=h(a.pow(i,1/3)),j++),i++}var n=[],c=c.SHA256=e.extend({_doReset:function(){this._hash=new d.init(f.slice(0))},_doProcessBlock:function(a,b){for(var c=this._hash.words,d=c[0],e=c[1],f=c[2],h=c[3],i=c[4],j=c[5],k=c[6],l=c[7],m=0;64>m;m++){if(16>m)n[m]=0|a[b+m];else{var o=n[m-15],p=n[m-2];n[m]=((o<<25|o>>>7)^(o<<14|o>>>18)^o>>>3)+n[m-7]+((p<<15|p>>>17)^(p<<13|p>>>19)^p>>>10)+n[m-16]}o=l+((i<<26|i>>>6)^(i<<21|i>>>11)^(i<<7|i>>>25))+(i&j^~i&k)+g[m]+n[m],p=((d<<30|d>>>2)^(d<<19|d>>>13)^(d<<10|d>>>22))+(d&e^d&f^e&f),l=k,k=j,j=i,i=h+o|0,h=f,f=e,e=d,d=o+p|0}c[0]=c[0]+d|0,c[1]=c[1]+e|0,c[2]=c[2]+f|0,c[3]=c[3]+h|0,c[4]=c[4]+i|0,c[5]=c[5]+j|0,c[6]=c[6]+k|0,c[7]=c[7]+l|0},_doFinalize:function(){var b=this._data,c=b.words,d=8*this._nDataBytes,e=8*b.sigBytes;return c[e>>>5]|=128<<24-e%32,c[(e+64>>>9<<4)+14]=a.floor(d/4294967296),c[(e+64>>>9<<4)+15]=d,b.sigBytes=4*c.length,this._process(),this._hash},clone:function(){var a=e.clone.call(this);return a._hash=this._hash.clone(),a}});b.SHA256=e._createHelper(c),b.HmacSHA256=e._createHmacHelper(c)}(Math),function(){var a=CryptoJS,b=a.enc.Utf8;a.algo.HMAC=a.lib.Base.extend({init:function(a,c){a=this._hasher=new a.init,"string"==typeof c&&(c=b.parse(c));var d=a.blockSize,e=4*d;c.sigBytes>e&&(c=a.finalize(c)),c.clamp();for(var f=this._oKey=c.clone(),g=this._iKey=c.clone(),h=f.words,i=g.words,j=0;d>j;j++)h[j]^=1549556828,i[j]^=909522486;f.sigBytes=g.sigBytes=e,this.reset()},reset:function(){var a=this._hasher;a.reset(),a.update(this._iKey)},update:function(a){return this._hasher.update(a),this},finalize:function(a){var b=this._hasher;return a=b.finalize(a),b.reset(),b.finalize(this._oKey.clone().concat(a))}})}(),function(a){a.verbs={abandoned:{id:"https://w3id.org/xapi/adl/verbs/abandoned",display:{"en-US":"abandoned"}},answered:{id:"http://adlnet.gov/expapi/verbs/answered",display:{"de-DE":"beantwortete","en-US":"answered","fr-FR":"a répondu","es-ES":"contestó"}},asked:{id:"http://adlnet.gov/expapi/verbs/asked",display:{"de-DE":"fragte","en-US":"asked","fr-FR":"a demandé","es-ES":"preguntó"}},attempted:{id:"http://adlnet.gov/expapi/verbs/attempted",display:{"de-DE":"versuchte","en-US":"attempted","fr-FR":"a essayé","es-ES":"intentó"}},attended:{id:"http://adlnet.gov/expapi/verbs/attended",display:{"de-DE":"nahm teil an","en-US":"attended","fr-FR":"a suivi","es-ES":"asistió"}},commented:{id:"http://adlnet.gov/expapi/verbs/commented",display:{"de-DE":"kommentierte","en-US":"commented","fr-FR":"a commenté","es-ES":"comentó"}},completed:{id:"http://adlnet.gov/expapi/verbs/completed",display:{"de-DE":"beendete","en-US":"completed","fr-FR":"a terminé","es-ES":"completó"}},exited:{id:"http://adlnet.gov/expapi/verbs/exited",display:{"de-DE":"verließ","en-US":"exited","fr-FR":"a quitté","es-ES":"salió"}},experienced:{id:"http://adlnet.gov/expapi/verbs/experienced",display:{"de-DE":"erlebte","en-US":"experienced","fr-FR":"a éprouvé","es-ES":"experimentó"}},failed:{id:"http://adlnet.gov/expapi/verbs/failed",display:{"de-DE":"verfehlte","en-US":"failed","fr-FR":"a échoué","es-ES":"fracasó"}},imported:{id:"http://adlnet.gov/expapi/verbs/imported",display:{"de-DE":"importierte","en-US":"imported","fr-FR":"a importé","es-ES":"importó"}},initialized:{id:"http://adlnet.gov/expapi/verbs/initialized",display:{"de-DE":"initialisierte","en-US":"initialized","fr-FR":"a initialisé","es-ES":"inicializó"}},interacted:{id:"http://adlnet.gov/expapi/verbs/interacted",display:{"de-DE":"interagierte","en-US":"interacted","fr-FR":"a interagi","es-ES":"interactuó"}},launched:{id:"http://adlnet.gov/expapi/verbs/launched",display:{"de-DE":"startete","en-US":"launched","fr-FR":"a lancé","es-ES":"lanzó"}},mastered:{id:"http://adlnet.gov/expapi/verbs/mastered",display:{"de-DE":"meisterte","en-US":"mastered","fr-FR":"a maîtrisé","es-ES":"dominó"}},passed:{id:"http://adlnet.gov/expapi/verbs/passed",display:{"de-DE":"bestand","en-US":"passed","fr-FR":"a réussi","es-ES":"aprobó"}},preferred:{id:"http://adlnet.gov/expapi/verbs/preferred",display:{"de-DE":"bevorzugte","en-US":"preferred","fr-FR":"a préféré","es-ES":"prefirió"}},progressed:{id:"http://adlnet.gov/expapi/verbs/progressed",display:{"de-DE":"machte Fortschritt mit","en-US":"progressed","fr-FR":"a progressé","es-ES":"progresó"}},registered:{id:"http://adlnet.gov/expapi/verbs/registered",display:{"de-DE":"registrierte","en-US":"registered","fr-FR":"a enregistré","es-ES":"registró"}},responded:{id:"http://adlnet.gov/expapi/verbs/responded",display:{"de-DE":"reagierte","en-US":"responded","fr-FR":"a répondu","es-ES":"respondió"}},resumed:{id:"http://adlnet.gov/expapi/verbs/resumed",display:{"de-DE":"setzte fort","en-US":"resumed","fr-FR":"a repris","es-ES":"continuó"}},satisfied:{id:"https://w3id.org/xapi/adl/verbs/satisfied",display:{"en-US":"satisfied"}},scored:{id:"http://adlnet.gov/expapi/verbs/scored",display:{"de-DE":"erreichte","en-US":"scored","fr-FR":"a marqué","es-ES":"anotó"}},shared:{id:"http://adlnet.gov/expapi/verbs/shared",display:{"de-DE":"teilte","en-US":"shared","fr-FR":"a partagé","es-ES":"compartió"}},suspended:{id:"http://adlnet.gov/expapi/verbs/suspended",display:{"de-DE":"pausierte","en-US":"suspended","fr-FR":"a suspendu","es-ES":"aplazó"}},terminated:{id:"http://adlnet.gov/expapi/verbs/terminated",display:{"de-DE":"beendete","en-US":"terminated","fr-FR":"a terminé","es-ES":"terminó"}},voided:{id:"http://adlnet.gov/expapi/verbs/voided",display:{"de-DE":"entwertete","en-US":"voided","fr-FR":"a annulé","es-ES":"anuló"}},waived:{id:"https://w3id.org/xapi/adl/verbs/waived",display:{"en-US":"waived"}}}}(window.ADL=window.ADL||{}),Date.prototype.toISOString||!function(){function a(a){var b=String(a);return 1===b.length&&(b="0"+b),b}Date.prototype.toISOString=function(){return this.getUTCFullYear()+"-"+a(this.getUTCMonth()+1)+"-"+a(this.getUTCDate())+"T"+a(this.getUTCHours())+":"+a(this.getUTCMinutes())+":"+a(this.getUTCSeconds())+"."+String((this.getUTCMilliseconds()/1e3).toFixed(3)).slice(2,5)+"Z"}}(),function(a){function b(){try{return void 0!=this.lrs.endpoint&&""!=this.lrs.endpoint}catch(a){return!1}}function c(a){if(!c.debug)return!1;try{return console.log(a),!0}catch(b){return!1}}function d(a,b){for(var e in b){prop=b[e],c(e+" : "+prop);try{b[e].constructor==Object?a[e]=d(a[e],b[e]):(void 0==a&&(a=new Object),a[e]=b[e])}catch(f){void 0==a&&(a=new Object),a[e]=b[e]}}return a}function e(a){var b,c,e=["endpoint","auth","actor","registration","activity_id","grouping","activity_platform"],g=new Object;if(b=f(),void 0!==b&&0!==Object.keys(b).length){for(var h=0;h0&&(f.push(e.substr(g+1)),e=e.substr(0,g)),e=e+"?method="+a,null!==c)for(var h in c)f.push(h+"="+encodeURIComponent(c[h]));return null!==d&&f.push("content="+encodeURIComponent(d)),{method:"POST",url:e,headers:{},data:f.join("&")}}c.debug=!1;var i=function(){var a={};a.endpoint="http://localhost:8000/xapi/";try{a.auth="Basic "+toBase64("tom:1234")}catch(b){c("Exception in Config trying to encode auth: "+b)}return a}();XAPIWrapper=function(c,f){function g(b){var c=document.createElement("a");return c.href=b,c.protocol&&c.host?c.protocol+"//"+c.host:void a.XAPIWrapper.log("Couldn't create base url from endpoint: "+this.lrs.endpoint)}function h(a,b,c){a.auth="Basic "+toBase64(b+":"+c)}this.lrs=e(c||{}),this.lrs.user&&this.lrs.password&&h(this.lrs,this.lrs.user,this.lrs.password),this.base=g(this.lrs.endpoint),this.withCredentials=!1,this.withCredentials=c&&c.withCredentials,this.strictCallbacks=!1,this.strictCallbacks=c&&c.strictCallbacks,f&&b.call(this)&&window.ADL.XHR_request(this.lrs,this.lrs.endpoint+"about","GET",null,null,function(b){if(200==b.status)try{var c=JSON.parse(b.response),d=!1;for(var e in c.version)if(c.version[e]==a.XAPIWrapper.xapiVersion){d=!0;break}d||a.XAPIWrapper.log("The lrs version ["+c.version+"] does not match this wrapper's XAPI version ["+a.XAPIWrapper.xapiVersion+"]")}catch(f){a.XAPIWrapper.log("The response was not an about object")}else a.XAPIWrapper.log("The request to get information about the LRS failed: "+b)},null,!1,null,this.withCredentials,!1),this.searchParams=function(){var a={format:"exact"};return a},this.hash=function(b){if(!b)return null;try{return toSHA1(b)}catch(c){return a.XAPIWrapper.log("Error trying to hash -- "+c),null}},this.changeConfig=function(b){try{a.XAPIWrapper.log("updating lrs object with new configuration"),this.lrs=d(this.lrs,b),b.user&&b.password&&this.updateAuth(this.lrs,b.user,b.password),this.base=g(this.lrs.endpoint),this.withCredentials=b.withCredentials,this.strictCallbacks=b.strictCallbacks}catch(c){a.XAPIWrapper.log("error while changing configuration -- "+c)}},this.updateAuth=h},XAPIWrapper.prototype.xapiVersion="1.0.1",XAPIWrapper.prototype.prepareStatement=function(a){void 0===a.actor?a.actor=JSON.parse(this.lrs.actor):"string"==typeof a.actor&&(a.actor=JSON.parse(a.actor)),(this.lrs.grouping||this.lrs.registration||this.lrs.activity_platform)&&(a.context||(a.context={})),this.lrs.grouping&&(a.context.contextActivities||(a.context.contextActivities={}),a.context.contextActivities.grouping=[{id:this.lrs.grouping}]),this.lrs.registration&&(a.context.registration=this.lrs.registration),this.lrs.activity_platform&&(a.context.platform=this.lrs.activity_platform)},XAPIWrapper.prototype.testConfig=b,XAPIWrapper.prototype.log=c,XAPIWrapper.prototype.sendStatement=function(b,c,d){if(this.testConfig()){this.prepareStatement(b);var e;b.id?e=b.id:(e=a.ruuid(),b.id=e);var f=JSON.stringify(b),g=null;d&&d.length>0&&(g={},f=this.buildMultipartPost(b,d,g));var h=a.XHR_request(this.lrs,this.lrs.endpoint+"statements","POST",f,this.lrs.auth,c,{id:e},null,g,this.withCredentials,this.strictCallbacks);if(!c)return{xhr:h,id:e}}},XAPIWrapper.prototype.buildMultipartPost=function(a,b,c){a.attachments=[];for(var d=0;d0&&(e=e+"?"+f.join("&"))}var h=a.XHR_request(this.lrs,e,"GET",null,this.lrs.auth,d,null,!1,null,this.withCredentials,this.strictCallbacks);if(void 0===h||404==h.status)return null;try{return JSON.parse(h.response)}catch(i){return h.response}}},XAPIWrapper.prototype.getActivities=function(b,c){if(this.testConfig()){var d=this.lrs.endpoint+"activities?activityId=";d=d.replace("",encodeURIComponent(b));var e=a.XHR_request(this.lrs,d,"GET",null,this.lrs.auth,c,null,!0,null,this.withCredentials,this.strictCallbacks);if(void 0===e||404==e.status)return null;try{return JSON.parse(e.response)}catch(f){return e.response}}},XAPIWrapper.prototype.sendState=function(b,d,e,f,g,h,i,j){if(this.testConfig()){var k=this.lrs.endpoint+"activities/state?activityId=&agent=&stateId=";k=k.replace("",encodeURIComponent(b)),k=k.replace("",encodeURIComponent(JSON.stringify(d))),k=k.replace("",encodeURIComponent(e)),f&&(k+="®istration="+encodeURIComponent(f));var l=null;h&&i?c("Can't have both If-Match and If-None-Match"):h?l={"If-Match":'"'+h+'"'}:i&&(l={"If-None-Match":'"'+i+'"'});var m="PUT";if(!g)return this.log("No activity state was included."),!1;g instanceof Array?(g=JSON.stringify(g),l=l||{},l["Content-Type"]="application/json"):g instanceof Object?(g=JSON.stringify(g),l=l||{},l["Content-Type"]="application/json",m="POST"):(l=l||{},l["Content-Type"]="application/octet-stream"),a.XHR_request(this.lrs,k,m,g,this.lrs.auth,j,null,null,l,this.withCredentials,this.strictCallbacks)}},XAPIWrapper.prototype.getState=function(b,c,d,e,f,g){if(this.testConfig()){var h=this.lrs.endpoint+"activities/state?activityId=&agent=";h=h.replace("",encodeURIComponent(b)),h=h.replace("",encodeURIComponent(JSON.stringify(c))),d&&(h+="&stateId="+encodeURIComponent(d)),e&&(h+="®istration="+encodeURIComponent(e)),f&&(f=isDate(f),null!=f&&(h+="&since="+encodeURIComponent(f.toISOString())));var i=a.XHR_request(this.lrs,h,"GET",null,this.lrs.auth,g,null,!0,null,this.withCredentials,this.strictCallbacks);if(void 0===i||404==i.status)return null;try{return JSON.parse(i.response)}catch(j){return i.response}}},XAPIWrapper.prototype.deleteState=function(b,d,e,f,g,h,i){if(this.testConfig()){var j=this.lrs.endpoint+"activities/state?activityId=&agent=&stateId=";j=j.replace("",encodeURIComponent(b)),j=j.replace("",encodeURIComponent(JSON.stringify(d))),j=j.replace("",encodeURIComponent(e)),f&&(j+="®istration="+encodeURIComponent(f));var k=null;g&&h?c("Can't have both If-Match and If-None-Match"):g?k={"If-Match":'"'+g+'"'}:h&&(k={"If-None-Match":'"'+h+'"'});var l=a.XHR_request(this.lrs,j,"DELETE",null,this.lrs.auth,i,null,!1,k,this.withCredentials,this.strictCallbacks);if(void 0===l||404==l.status)return null;try{return JSON.parse(l.response)}catch(m){return l}}},XAPIWrapper.prototype.sendActivityProfile=function(b,d,e,f,g,h){if(this.testConfig()){var i=this.lrs.endpoint+"activities/profile?activityId=&profileId=";i=i.replace("",encodeURIComponent(b)),i=i.replace("",encodeURIComponent(d));var j=null;f&&g?c("Can't have both If-Match and If-None-Match"):f?j={"If-Match":'"'+f+'"'}:g&&(j={"If-None-Match":'"'+g+'"'});var k="PUT";if(!e)return this.log("No activity profile was included."),!1;e instanceof Array?(e=JSON.stringify(e),j=j||{},j["Content-Type"]="application/json"):e instanceof Object?(e=JSON.stringify(e),j=j||{},j["Content-Type"]="application/json",k="POST"):(j=j||{},j["Content-Type"]="application/octet-stream"),a.XHR_request(this.lrs,i,k,e,this.lrs.auth,h,null,!1,j,this.withCredentials,this.strictCallbacks)}},XAPIWrapper.prototype.getActivityProfile=function(b,c,d,e){if(this.testConfig()){var f=this.lrs.endpoint+"activities/profile?activityId=";f=f.replace("",encodeURIComponent(b)),c&&(f+="&profileId="+encodeURIComponent(c)),d&&(d=isDate(d),null!=d&&(f+="&since="+encodeURIComponent(d.toISOString())));var g=a.XHR_request(this.lrs,f,"GET",null,this.lrs.auth,e,null,!0,null,this.withCredentials,this.strictCallbacks);if(void 0===g||404==g.status)return null;try{return JSON.parse(g.response)}catch(h){return g.response}}},XAPIWrapper.prototype.deleteActivityProfile=function(b,d,e,f,g){if(this.testConfig()){var h=this.lrs.endpoint+"activities/profile?activityId=&profileId=";h=h.replace("",encodeURIComponent(b)),h=h.replace("",encodeURIComponent(d));var i=null;e&&f?c("Can't have both If-Match and If-None-Match"):e?i={"If-Match":'"'+e+'"'}:f&&(i={"If-None-Match":'"'+f+'"'});var j=a.XHR_request(this.lrs,h,"DELETE",null,this.lrs.auth,g,null,!1,i,this.withCredentials,this.strictCallbacks);if(void 0===j||404==j.status)return null;try{return JSON.parse(j.response)}catch(k){return j}}},XAPIWrapper.prototype.getAgents=function(b,c){if(this.testConfig()){var d=this.lrs.endpoint+"agents?agent=";d=d.replace("",encodeURIComponent(JSON.stringify(b)));var e=a.XHR_request(this.lrs,d,"GET",null,this.lrs.auth,c,null,!0,null,this.withCredentials,this.strictCallbacks);if(void 0===e||404==e.status)return null;try{return JSON.parse(e.response)}catch(f){return e.response}}},XAPIWrapper.prototype.sendAgentProfile=function(b,d,e,f,g,h){if(this.testConfig()){var i=this.lrs.endpoint+"agents/profile?agent=&profileId=";i=i.replace("",encodeURIComponent(JSON.stringify(b))),i=i.replace("",encodeURIComponent(d));var j=null;f&&g?c("Can't have both If-Match and If-None-Match"):f?j={"If-Match":'"'+f+'"'}:g&&(j={"If-None-Match":'"'+g+'"'});var k="PUT";if(!e)return this.log("No agent profile was included."),!1;e instanceof Array?(e=JSON.stringify(e),j=j||{},j["Content-Type"]="application/json"):e instanceof Object?(e=JSON.stringify(e),j=j||{},j["Content-Type"]="application/json",k="POST"):(j=j||{},j["Content-Type"]="application/octet-stream"),a.XHR_request(this.lrs,i,k,e,this.lrs.auth,h,null,!1,j,this.withCredentials,this.strictCallbacks)}},XAPIWrapper.prototype.getAgentProfile=function(b,c,d,e){if(this.testConfig()){var f=this.lrs.endpoint+"agents/profile?agent=";f=f.replace("",encodeURIComponent(JSON.stringify(b))),f=f.replace("",encodeURIComponent(c)),c&&(f+="&profileId="+encodeURIComponent(c)),d&&(d=isDate(d),null!=d&&(f+="&since="+encodeURIComponent(d.toISOString())));var g=a.XHR_request(this.lrs,f,"GET",null,this.lrs.auth,e,null,!0,null,this.withCredentials,this.strictCallbacks);if(void 0===g||404==g.status)return null;try{return JSON.parse(g.response)}catch(h){return g.response}}},XAPIWrapper.prototype.deleteAgentProfile=function(b,d,e,f,g){if(this.testConfig()){var h=this.lrs.endpoint+"agents/profile?agent=&profileId=";h=h.replace("",encodeURIComponent(JSON.stringify(b))),h=h.replace("",encodeURIComponent(d));var i=null;e&&f?c("Can't have both If-Match and If-None-Match"):e?i={"If-Match":'"'+e+'"'}:f&&(i={"If-None-Match":'"'+f+'"'});var j=a.XHR_request(this.lrs,h,"DELETE",null,this.lrs.auth,g,null,!1,i,this.withCredentials,this.strictCallbacks);if(void 0===j||404==j.status)return null;try{return JSON.parse(j.response)}catch(k){return j}}},a.ruuid=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(a){var b=16*Math.random()|0,c="x"==a?b:3&b|8;return c.toString(16)})},a.dateFromISOString=function(a){var b="([0-9]{4})(-([0-9]{2})(-([0-9]{2})([T| ]([0-9]{2}):([0-9]{2})(:([0-9]{2})(.([0-9]+))?)?(Z|(([-+])([0-9]{2}):([0-9]{2})))?)?)?)?",c=a.match(new RegExp(b)),d=0,e=new Date(c[1],0,1);c[3]&&e.setMonth(c[3]-1),c[5]&&e.setDate(c[5]),c[7]&&e.setHours(c[7]),c[8]&&e.setMinutes(c[8]),c[10]&&e.setSeconds(c[10]),c[12]&&e.setMilliseconds(1e3*Number("0."+c[12])),c[14]&&(d=60*Number(c[16])+Number(c[17]),d*="-"==c[15]?1:-1),d-=e.getTimezoneOffset(),time=Number(e)+60*d*1e3;var f=new Date;return f.setTime(Number(time)),f},a.XHR_request=function(b,c,d,e,f,i,j,k,l,m,n){"use strict";function o(){if(u)return s;u=!0;var b=k&&404===p.status;if(!(void 0===p.status||p.status>=200&&p.status<400||b)){var e;try{e="There was a problem communicating with the Learning Record Store. ( "+p.status+" | "+p.response+" )"+c}catch(f){e=f.toString()}return a.XAPIWrapper.log(e),a.xhrRequestOnError(p,d,c,i,j,n),s=p,p}if(!i)return s=p,p;if(j)n?i(null,p,j):i(p,j);else try{var g=JSON.parse(p.responseText);n?i(null,p,g):i(p,g)}catch(h){n?i(null,p,g):i(p,p.responseText)}}var p,q,r,s,t,u=!1,v=!1,w=!1,x=c.toLowerCase().match(/^(.+):\/\/([^:\/]*):?(\d+)?(\/.*)?$/),y=window.location,z={};if(z["Content-Type"]="application/json",z.Authorization=f,z["X-Experience-API-Version"]=a.XAPIWrapper.xapiVersion,null!==l)for(var A in l)z[A]=l[A];v=y.protocol.toLowerCase()!==x[1]||y.hostname.toLowerCase()!==x[2],v||(r=null===x[3]?"http"===x[1]?"80":"443":x[3],v=r===y.port);var B=window.XDomainRequest&&window.XMLHttpRequest&&void 0===(new XMLHttpRequest).responseType;if(v&&void 0!==B&&B!==!1)w=!0,q=h(d,c,z,e),p=new XDomainRequest,p.open(q.method,q.url);else{p=new XMLHttpRequest,p.withCredentials=m,p.open(d,c,null!=i);for(var A in z)p.setRequestHeader(A,z[A])}if(p.onreadystatechange=function(){return 4===p.readyState?o():void 0},p.onload=o,p.onerror=o,p.send(w?q.data:e),!i){if(w)for(t=1e3+new Date;new Date-1?i+"&"+f:i+"?"+f,h.href=i)}}function f(a,h,i){a=c(a);try{var j=b("xAPILaunchKey"),k=b("xAPILaunchService");b("encrypted");if(f.terminate=function(a){var b=new URL(k);b.pathname+="launch/"+j+"/terminate";var c=new XMLHttpRequest;c.withCredentials=!0,c.crossDomain=!0,c.open("POST",b.toString(),!1),c.setRequestHeader("Content-type","application/json"),c.send(JSON.stringify({code:0,description:a||"User closed content"}))},!j||!k)return a("invalid launch parameters");var l=new URL(k);l.pathname+="launch/"+j;var m=new XMLHttpRequest;m.withCredentials=!0,m.crossDomain=!0,m.onerror=function(b){window.setTimeout(function(){return a(b)})},m.onload=function(b){if(200!==m.status)return m.onerror(m.responseText);var c=JSON.parse(m.responseText),j=c,k={};k.endpoint=j.endpoint,k.actor=j.actor,k.withCredentials=!0,k.strictCallbacks=i||!1,window.onunload=function(){h&&f.terminate("User closed content")};var l=new g.XAPIWrapper.constructor;return l.changeConfig(k),e(document.body.querySelectorAll("a")),d(),a(null,c,l)},m.open("POST",l.toString(),!0),m.send()}catch(n){a(n)}}var g=a;g.launch=f}(window.ADL=window.ADL||{}); \ No newline at end of file diff --git a/src/xapiwrapper.js b/src/xapiwrapper.js index b9ff25d..bf96244 100644 --- a/src/xapiwrapper.js +++ b/src/xapiwrapper.js @@ -1570,13 +1570,13 @@ function isDate(date) { } if (callbackargs) { - callback(null, xhr, callbackargs); + callback(error, xhr, callbackargs); } else { try { var body = JSON.parse(xhr.responseText); - callback(null, xhr, body); + callback(error, xhr, body); } catch(e){ - callback(null, xhr, xhr.responseText); + callback(error, xhr, xhr.responseText); } } }