This repository has been archived by the owner on Oct 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
239 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
node_modules | ||
dist | ||
test/index-compiled.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,42 @@ | ||
# SCORM Adapter | ||
# SCORM API Adapter | ||
|
||
## Installation | ||
|
||
Install with npm executing: | ||
|
||
```bash | ||
npm i arisjulio/scorm-api-adapter | ||
``` | ||
|
||
## Usage | ||
Import, create an instance and set the API REST URI: | ||
|
||
```javascript | ||
import SCORMAdapter from 'scorm-api-adapter'; | ||
|
||
window.API = new SCORMAdapter('http://your-api-to-comit.org'); | ||
window.API = new SCORMAdapter(); | ||
window.API.uri = 'https://your-api-to-commit.org/great-endpoit'; | ||
``` | ||
|
||
## Download | ||
|
||
You can download the minified file from [here.](https://github.com/arisjulio/scorm-api-adapter/releases/latest) | ||
|
||
If you download or clone the repository, you must execute `npm run compile` and the minified file will be generated in the `dist` folder. | ||
|
||
The minified file must be included in your website: | ||
|
||
```html | ||
<script src="scorm-api-adapter.js"></script> | ||
``` | ||
|
||
> You must return an `success` in your API for know if the commit attempt was successfully executed. | ||
After, in your JS code, You can access to the `window.API` element and must set your API REST URI: | ||
|
||
For example: | ||
|
||
```javascript | ||
window.API.uri = 'https://your-api-to-commit.org/great-endpoit'; | ||
``` | ||
|
||
Now you can load an SCORM Object in a frame or new window and it will work. | ||
|
||
> **IMPORTANT:** You must return an `success` field in your API REST response to know if the commit attempt was successfully executed. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,113 +1,3 @@ | ||
import $ from 'jquery'; | ||
import { Base64 } from 'js-base64'; | ||
import Storage from './storage'; | ||
import errorDefinition from './errors'; | ||
import SCORMAdapter from './scormAdapter'; | ||
|
||
export default class SCORMAdapter { | ||
constructor(uri = 'http://localhost') { | ||
this.uri = uri; | ||
} | ||
|
||
LMSInitialize() { | ||
Storage.setItem('Initialized', true); | ||
return true; | ||
} | ||
|
||
LMSFinish() { | ||
if (!this._isInitialized()) { | ||
this._setError(301); | ||
return false; | ||
} | ||
let _return = this.LMSCommit(); | ||
Storage.setItem('Initialized', false); | ||
Storage.clearAll(); | ||
return _return; | ||
} | ||
|
||
LMSGetValue(element) { | ||
if (!this._isInitialized()) { | ||
this._setError(301); | ||
return false; | ||
} | ||
let value = Storage.getItem(element); | ||
if (!value) { | ||
this._setError(201); | ||
return ""; | ||
} | ||
return value; | ||
} | ||
|
||
LMSSetValue(element, value) { | ||
if (!this._isInitialized()) { | ||
this._setError(301); | ||
return false; | ||
} | ||
Storage.setItem(element, value); | ||
return Storage.getItem(element); | ||
} | ||
|
||
LMSCommit() { | ||
let data = Storage.getAll(); | ||
delete data['errors']; | ||
delete data['Initialized']; | ||
data = JSON.stringify(data); | ||
data = Base64.encode(data); | ||
let response; | ||
let _return = true; | ||
$.post({ | ||
url: this.uri, | ||
async: false, | ||
data: { data, success: true }, | ||
success: res => { | ||
response = res; | ||
}, | ||
error: () => { | ||
this._setError(101); | ||
_return = false; | ||
} | ||
}); | ||
if (!response.success) { | ||
this._setError(101); | ||
return false; | ||
} | ||
return _return; | ||
} | ||
|
||
LMSGetLastError() { | ||
let errors = Storage.getItem('errors'); | ||
errors = JSON.parse(errors); | ||
if (errors && errors.length > 0) { | ||
return errors.pop(); | ||
} | ||
return ""; | ||
} | ||
|
||
LMSGetErrorString(errorCode) { | ||
errorCode = errorCode.toString(); | ||
let error = errorDefinition[errorCode]; | ||
if (!error) return ""; | ||
return error["errorString"]; | ||
} | ||
|
||
LMSGetDiagnostic(errorCode) { | ||
errorCode = errorCode.toString(); | ||
let error = errorDefinition[errorCode]; | ||
if (!error) return ""; | ||
return error["diagnostic"]; | ||
} | ||
|
||
_isInitialized() { | ||
let initialized = Storage.getItem('Initialized'); | ||
return initialized; | ||
} | ||
|
||
_setError(errorCode) { | ||
errorCode = errorCode.toString(); | ||
let errors = Storage.getItem('errors'); | ||
if (!errors) errors = '[]'; | ||
errors = JSON.parse(errors); | ||
errors.push(errorCode); | ||
errors = JSON.stringify(errors); | ||
Storage.setItem('errors', errors); | ||
} | ||
} | ||
window.API = new SCORMAdapter(); |
Oops, something went wrong.