update
This commit is contained in:
@@ -0,0 +1,924 @@
|
||||
/*global define, module */
|
||||
|
||||
/* ===========================================================
|
||||
|
||||
pipwerks SCORM Wrapper for JavaScript
|
||||
v1.1.20180906
|
||||
|
||||
Created by Philip Hutchison, January 2008-2018
|
||||
https://github.com/pipwerks/scorm-api-wrapper
|
||||
|
||||
Copyright (c) Philip Hutchison
|
||||
MIT-style license: http://pipwerks.mit-license.org/
|
||||
|
||||
This wrapper works with both SCORM 1.2 and SCORM 2004.
|
||||
|
||||
Inspired by APIWrapper.js, created by the ADL and
|
||||
Concurrent Technologies Corporation, distributed by
|
||||
the ADL (http://www.adlnet.gov/scorm).
|
||||
|
||||
SCORM.API.find() and SCORM.API.get() functions based
|
||||
on ADL code, modified by Mike Rustici
|
||||
(http://www.scorm.com/resources/apifinder/SCORMAPIFinder.htm),
|
||||
further modified by Philip Hutchison
|
||||
|
||||
=============================================================== */
|
||||
|
||||
(function(root, factory) {
|
||||
|
||||
"use strict";
|
||||
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
// AMD. Register as an anonymous module.
|
||||
define([], factory);
|
||||
} else if (typeof module === 'object' && module.exports) {
|
||||
// Node. Does not work with strict CommonJS, but
|
||||
// only CommonJS-like environments that support module.exports,
|
||||
// like Node.
|
||||
module.exports = factory();
|
||||
} else {
|
||||
// Browser globals (root is window)
|
||||
root.pipwerks = factory();
|
||||
}
|
||||
}(this, function() {
|
||||
|
||||
"use strict";
|
||||
|
||||
var pipwerks = {}; //pipwerks 'namespace' helps ensure no conflicts with possible other "SCORM" variables
|
||||
pipwerks.UTILS = {}; //For holding UTILS functions
|
||||
pipwerks.debug = { isActive: true }; //Enable (true) or disable (false) for debug mode
|
||||
|
||||
pipwerks.SCORM = { //Define the SCORM object
|
||||
version: null, //Store SCORM version.
|
||||
handleCompletionStatus: true, //Whether or not the wrapper should automatically handle the initial completion status
|
||||
handleExitMode: true, //Whether or not the wrapper should automatically handle the exit mode
|
||||
API: {
|
||||
handle: null,
|
||||
isFound: false
|
||||
}, //Create API child object
|
||||
connection: { isActive: false }, //Create connection child object
|
||||
data: {
|
||||
completionStatus: null,
|
||||
exitStatus: null
|
||||
}, //Create data child object
|
||||
debug: {} //Create debug child object
|
||||
};
|
||||
|
||||
/* --------------------------------------------------------------------------------
|
||||
pipwerks.SCORM.isAvailable
|
||||
A simple function to allow Flash ExternalInterface to confirm
|
||||
presence of JS wrapper before attempting any LMS communication.
|
||||
|
||||
Parameters: none
|
||||
Returns: Boolean (true)
|
||||
----------------------------------------------------------------------------------- */
|
||||
|
||||
pipwerks.SCORM.isAvailable = function() {
|
||||
return true;
|
||||
};
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------- //
|
||||
// --- SCORM.API functions ------------------------------------------------- //
|
||||
// ------------------------------------------------------------------------- //
|
||||
|
||||
/* -------------------------------------------------------------------------
|
||||
pipwerks.SCORM.API.find(window)
|
||||
Looks for an object named API in parent and opener windows
|
||||
|
||||
Parameters: window (the browser window object).
|
||||
Returns: Object if API is found, null if no API found
|
||||
---------------------------------------------------------------------------- */
|
||||
|
||||
pipwerks.SCORM.API.find = function(win) {
|
||||
|
||||
var API = null,
|
||||
findAttempts = 0,
|
||||
findAttemptLimit = 500,
|
||||
traceMsgPrefix = "SCORM.API.find",
|
||||
trace = pipwerks.UTILS.trace,
|
||||
scorm = pipwerks.SCORM;
|
||||
|
||||
while ((!win.API && !win.API_1484_11) &&
|
||||
(win.parent) &&
|
||||
(win.parent != win) &&
|
||||
(findAttempts <= findAttemptLimit)) {
|
||||
|
||||
findAttempts++;
|
||||
win = win.parent;
|
||||
|
||||
}
|
||||
|
||||
//If SCORM version is specified by user, look for specific API
|
||||
if (scorm.version) {
|
||||
|
||||
switch (scorm.version) {
|
||||
|
||||
case "2004":
|
||||
|
||||
if (win.API_1484_11) {
|
||||
|
||||
API = win.API_1484_11;
|
||||
|
||||
} else {
|
||||
|
||||
trace(traceMsgPrefix + ": SCORM version 2004 was specified by user, but API_1484_11 cannot be found.");
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case "1.2":
|
||||
|
||||
if (win.API) {
|
||||
|
||||
API = win.API;
|
||||
|
||||
} else {
|
||||
|
||||
trace(traceMsgPrefix + ": SCORM version 1.2 was specified by user, but API cannot be found.");
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
} else { //If SCORM version not specified by user, look for APIs
|
||||
|
||||
if (win.API_1484_11) { //SCORM 2004-specific API.
|
||||
|
||||
scorm.version = "2004"; //Set version
|
||||
API = win.API_1484_11;
|
||||
|
||||
} else if (win.API) { //SCORM 1.2-specific API
|
||||
|
||||
scorm.version = "1.2"; //Set version
|
||||
API = win.API;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (API) {
|
||||
|
||||
trace(traceMsgPrefix + ": API found. Version: " + scorm.version);
|
||||
trace("API: " + API);
|
||||
|
||||
} else {
|
||||
|
||||
trace(traceMsgPrefix + ": Error finding API. \nFind attempts: " + findAttempts + ". \nFind attempt limit: " + findAttemptLimit);
|
||||
|
||||
}
|
||||
|
||||
return API;
|
||||
|
||||
};
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------------
|
||||
pipwerks.SCORM.API.get()
|
||||
Looks for an object named API, first in the current window's frame
|
||||
hierarchy and then, if necessary, in the current window's opener window
|
||||
hierarchy (if there is an opener window).
|
||||
|
||||
Parameters: None.
|
||||
Returns: Object if API found, null if no API found
|
||||
---------------------------------------------------------------------------- */
|
||||
|
||||
pipwerks.SCORM.API.get = function() {
|
||||
|
||||
var API = null,
|
||||
win = window,
|
||||
scorm = pipwerks.SCORM,
|
||||
find = scorm.API.find,
|
||||
trace = pipwerks.UTILS.trace;
|
||||
|
||||
API = find(win);
|
||||
|
||||
if (!API && win.parent && win.parent != win) {
|
||||
API = find(win.parent);
|
||||
}
|
||||
|
||||
if (!API && win.top && win.top.opener) {
|
||||
API = find(win.top.opener);
|
||||
}
|
||||
|
||||
//Special handling for Plateau
|
||||
//Thanks to Joseph Venditti for the patch
|
||||
if (!API && win.top && win.top.opener && win.top.opener.document) {
|
||||
API = find(win.top.opener.document);
|
||||
}
|
||||
|
||||
if (API) {
|
||||
scorm.API.isFound = true;
|
||||
} else {
|
||||
trace("API.get failed: Can't find the API!");
|
||||
}
|
||||
|
||||
return API;
|
||||
|
||||
};
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------------
|
||||
pipwerks.SCORM.API.getHandle()
|
||||
Returns the handle to API object if it was previously set
|
||||
|
||||
Parameters: None.
|
||||
Returns: Object (the pipwerks.SCORM.API.handle variable).
|
||||
---------------------------------------------------------------------------- */
|
||||
|
||||
pipwerks.SCORM.API.getHandle = function() {
|
||||
|
||||
var API = pipwerks.SCORM.API;
|
||||
|
||||
if (!API.handle && !API.isFound) {
|
||||
|
||||
API.handle = API.get();
|
||||
|
||||
}
|
||||
|
||||
return API.handle;
|
||||
|
||||
};
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------- //
|
||||
// --- pipwerks.SCORM.connection functions --------------------------------- //
|
||||
// ------------------------------------------------------------------------- //
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------------
|
||||
pipwerks.SCORM.connection.initialize()
|
||||
Tells the LMS to initiate the communication session.
|
||||
|
||||
Parameters: None
|
||||
Returns: Boolean
|
||||
---------------------------------------------------------------------------- */
|
||||
|
||||
pipwerks.SCORM.connection.initialize = function() {
|
||||
|
||||
var success = false,
|
||||
scorm = pipwerks.SCORM,
|
||||
completionStatus = scorm.data.completionStatus,
|
||||
trace = pipwerks.UTILS.trace,
|
||||
makeBoolean = pipwerks.UTILS.StringToBoolean,
|
||||
debug = scorm.debug,
|
||||
traceMsgPrefix = "SCORM.connection.initialize ";
|
||||
|
||||
trace("connection.initialize called.");
|
||||
|
||||
if (!scorm.connection.isActive) {
|
||||
|
||||
var API = scorm.API.getHandle(),
|
||||
errorCode = 0;
|
||||
|
||||
if (API) {
|
||||
|
||||
switch (scorm.version) {
|
||||
case "1.2":
|
||||
success = makeBoolean(API.LMSInitialize(""));
|
||||
break;
|
||||
case "2004":
|
||||
success = makeBoolean(API.Initialize(""));
|
||||
break;
|
||||
}
|
||||
|
||||
if (success) {
|
||||
|
||||
//Double-check that connection is active and working before returning 'true' boolean
|
||||
errorCode = debug.getCode();
|
||||
|
||||
if (errorCode !== null && errorCode === 0) {
|
||||
|
||||
scorm.connection.isActive = true;
|
||||
|
||||
if (scorm.handleCompletionStatus) {
|
||||
|
||||
//Automatically set new launches to incomplete
|
||||
completionStatus = scorm.status("get");
|
||||
|
||||
if (completionStatus) {
|
||||
|
||||
switch (completionStatus) {
|
||||
|
||||
//Both SCORM 1.2 and 2004
|
||||
case "not attempted":
|
||||
scorm.status("set", "incomplete");
|
||||
break;
|
||||
|
||||
//SCORM 2004 only
|
||||
case "unknown":
|
||||
scorm.status("set", "incomplete");
|
||||
break;
|
||||
|
||||
//Additional options, presented here in case you'd like to use them
|
||||
//case "completed" : break;
|
||||
//case "incomplete" : break;
|
||||
//case "passed" : break; //SCORM 1.2 only
|
||||
//case "failed" : break; //SCORM 1.2 only
|
||||
//case "browsed" : break; //SCORM 1.2 only
|
||||
|
||||
}
|
||||
|
||||
//Commit changes
|
||||
scorm.save();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
success = false;
|
||||
trace(traceMsgPrefix + "failed. \nError code: " + errorCode + " \nError info: " + debug.getInfo(errorCode));
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
errorCode = debug.getCode();
|
||||
|
||||
if (errorCode !== null && errorCode !== 0) {
|
||||
|
||||
trace(traceMsgPrefix + "failed. \nError code: " + errorCode + " \nError info: " + debug.getInfo(errorCode));
|
||||
|
||||
} else {
|
||||
|
||||
trace(traceMsgPrefix + "failed: No response from server.");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
trace(traceMsgPrefix + "failed: API is null.");
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
trace(traceMsgPrefix + "aborted: Connection already active.");
|
||||
|
||||
}
|
||||
|
||||
return success;
|
||||
|
||||
};
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------------
|
||||
pipwerks.SCORM.connection.terminate()
|
||||
Tells the LMS to terminate the communication session
|
||||
|
||||
Parameters: None
|
||||
Returns: Boolean
|
||||
---------------------------------------------------------------------------- */
|
||||
|
||||
pipwerks.SCORM.connection.terminate = function() {
|
||||
|
||||
var success = false,
|
||||
scorm = pipwerks.SCORM,
|
||||
exitStatus = scorm.data.exitStatus,
|
||||
completionStatus = scorm.data.completionStatus,
|
||||
trace = pipwerks.UTILS.trace,
|
||||
makeBoolean = pipwerks.UTILS.StringToBoolean,
|
||||
debug = scorm.debug,
|
||||
traceMsgPrefix = "SCORM.connection.terminate ";
|
||||
|
||||
|
||||
if (scorm.connection.isActive) {
|
||||
|
||||
var API = scorm.API.getHandle(),
|
||||
errorCode = 0;
|
||||
|
||||
if (API) {
|
||||
|
||||
if (scorm.handleExitMode && !exitStatus) {
|
||||
|
||||
if (completionStatus !== "completed" && completionStatus !== "passed") {
|
||||
|
||||
switch (scorm.version) {
|
||||
case "1.2":
|
||||
success = scorm.set("cmi.core.exit", "suspend");
|
||||
break;
|
||||
case "2004":
|
||||
success = scorm.set("cmi.exit", "suspend");
|
||||
break;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
switch (scorm.version) {
|
||||
case "1.2":
|
||||
success = scorm.set("cmi.core.exit", "logout");
|
||||
break;
|
||||
case "2004":
|
||||
success = scorm.set("cmi.exit", "normal");
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Ensure we persist the data for 1.2 - not required for 2004 where an implicit commit is applied during the Terminate
|
||||
success = (scorm.version === "1.2") ? scorm.save() : true;
|
||||
|
||||
if (success) {
|
||||
|
||||
switch (scorm.version) {
|
||||
case "1.2":
|
||||
success = makeBoolean(API.LMSFinish(""));
|
||||
break;
|
||||
case "2004":
|
||||
success = makeBoolean(API.Terminate(""));
|
||||
break;
|
||||
}
|
||||
|
||||
if (success) {
|
||||
|
||||
scorm.connection.isActive = false;
|
||||
|
||||
} else {
|
||||
|
||||
errorCode = debug.getCode();
|
||||
trace(traceMsgPrefix + "failed. \nError code: " + errorCode + " \nError info: " + debug.getInfo(errorCode));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
trace(traceMsgPrefix + "failed: API is null.");
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
trace(traceMsgPrefix + "aborted: Connection already terminated.");
|
||||
|
||||
}
|
||||
|
||||
return success;
|
||||
|
||||
};
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------- //
|
||||
// --- pipwerks.SCORM.data functions --------------------------------------- //
|
||||
// ------------------------------------------------------------------------- //
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------------
|
||||
pipwerks.SCORM.data.get(parameter)
|
||||
Requests information from the LMS.
|
||||
|
||||
Parameter: parameter (string, name of the SCORM data model element)
|
||||
Returns: string (the value of the specified data model element)
|
||||
---------------------------------------------------------------------------- */
|
||||
|
||||
pipwerks.SCORM.data.get = function(parameter) {
|
||||
|
||||
var value = null,
|
||||
scorm = pipwerks.SCORM,
|
||||
trace = pipwerks.UTILS.trace,
|
||||
debug = scorm.debug,
|
||||
traceMsgPrefix = "SCORM.data.get('" + parameter + "') ";
|
||||
|
||||
if (scorm.connection.isActive) {
|
||||
|
||||
var API = scorm.API.getHandle(),
|
||||
errorCode = 0;
|
||||
|
||||
if (API) {
|
||||
|
||||
switch (scorm.version) {
|
||||
case "1.2":
|
||||
value = API.LMSGetValue(parameter);
|
||||
break;
|
||||
case "2004":
|
||||
value = API.GetValue(parameter);
|
||||
break;
|
||||
}
|
||||
|
||||
errorCode = debug.getCode();
|
||||
|
||||
//GetValue returns an empty string on errors
|
||||
//If value is an empty string, check errorCode to make sure there are no errors
|
||||
if (value !== "" || errorCode === 0) {
|
||||
|
||||
//GetValue is successful.
|
||||
//If parameter is lesson_status/completion_status or exit status, let's
|
||||
//grab the value and cache it so we can check it during connection.terminate()
|
||||
switch (parameter) {
|
||||
|
||||
case "cmi.core.lesson_status":
|
||||
case "cmi.completion_status":
|
||||
scorm.data.completionStatus = value;
|
||||
break;
|
||||
|
||||
case "cmi.core.exit":
|
||||
case "cmi.exit":
|
||||
scorm.data.exitStatus = value;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
trace(traceMsgPrefix + "failed. \nError code: " + errorCode + "\nError info: " + debug.getInfo(errorCode));
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
trace(traceMsgPrefix + "failed: API is null.");
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
trace(traceMsgPrefix + "failed: API connection is inactive.");
|
||||
|
||||
}
|
||||
|
||||
trace(traceMsgPrefix + " value: " + value);
|
||||
|
||||
return String(value);
|
||||
|
||||
};
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------------
|
||||
pipwerks.SCORM.data.set()
|
||||
Tells the LMS to assign the value to the named data model element.
|
||||
Also stores the SCO's completion status in a variable named
|
||||
pipwerks.SCORM.data.completionStatus. This variable is checked whenever
|
||||
pipwerks.SCORM.connection.terminate() is invoked.
|
||||
|
||||
Parameters: parameter (string). The data model element
|
||||
value (string). The value for the data model element
|
||||
Returns: Boolean
|
||||
---------------------------------------------------------------------------- */
|
||||
|
||||
pipwerks.SCORM.data.set = function(parameter, value) {
|
||||
|
||||
var success = false,
|
||||
scorm = pipwerks.SCORM,
|
||||
trace = pipwerks.UTILS.trace,
|
||||
makeBoolean = pipwerks.UTILS.StringToBoolean,
|
||||
debug = scorm.debug,
|
||||
traceMsgPrefix = "SCORM.data.set('" + parameter + "') ";
|
||||
|
||||
|
||||
if (scorm.connection.isActive) {
|
||||
|
||||
var API = scorm.API.getHandle(),
|
||||
errorCode = 0;
|
||||
|
||||
if (API) {
|
||||
|
||||
switch (scorm.version) {
|
||||
case "1.2":
|
||||
success = makeBoolean(API.LMSSetValue(parameter, value));
|
||||
break;
|
||||
case "2004":
|
||||
success = makeBoolean(API.SetValue(parameter, value));
|
||||
break;
|
||||
}
|
||||
|
||||
if (success) {
|
||||
|
||||
if (parameter === "cmi.core.lesson_status" || parameter === "cmi.completion_status") {
|
||||
|
||||
scorm.data.completionStatus = value;
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
errorCode = debug.getCode();
|
||||
|
||||
trace(traceMsgPrefix + "failed. \nError code: " + errorCode + ". \nError info: " + debug.getInfo(errorCode));
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
trace(traceMsgPrefix + "failed: API is null.");
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
trace(traceMsgPrefix + "failed: API connection is inactive.");
|
||||
|
||||
}
|
||||
|
||||
trace(traceMsgPrefix + " value: " + value);
|
||||
|
||||
return success;
|
||||
|
||||
};
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------------
|
||||
pipwerks.SCORM.data.save()
|
||||
Instructs the LMS to persist all data to this point in the session
|
||||
|
||||
Parameters: None
|
||||
Returns: Boolean
|
||||
---------------------------------------------------------------------------- */
|
||||
|
||||
pipwerks.SCORM.data.save = function() {
|
||||
|
||||
var success = false,
|
||||
scorm = pipwerks.SCORM,
|
||||
trace = pipwerks.UTILS.trace,
|
||||
makeBoolean = pipwerks.UTILS.StringToBoolean,
|
||||
traceMsgPrefix = "SCORM.data.save failed";
|
||||
|
||||
|
||||
if (scorm.connection.isActive) {
|
||||
|
||||
var API = scorm.API.getHandle();
|
||||
|
||||
if (API) {
|
||||
|
||||
switch (scorm.version) {
|
||||
case "1.2":
|
||||
success = makeBoolean(API.LMSCommit(""));
|
||||
break;
|
||||
case "2004":
|
||||
success = makeBoolean(API.Commit(""));
|
||||
break;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
trace(traceMsgPrefix + ": API is null.");
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
trace(traceMsgPrefix + ": API connection is inactive.");
|
||||
|
||||
}
|
||||
|
||||
return success;
|
||||
|
||||
};
|
||||
|
||||
|
||||
pipwerks.SCORM.status = function(action, status) {
|
||||
|
||||
var success = false,
|
||||
scorm = pipwerks.SCORM,
|
||||
trace = pipwerks.UTILS.trace,
|
||||
traceMsgPrefix = "SCORM.getStatus failed",
|
||||
cmi = "";
|
||||
|
||||
if (action !== null) {
|
||||
|
||||
switch (scorm.version) {
|
||||
case "1.2":
|
||||
cmi = "cmi.core.lesson_status";
|
||||
break;
|
||||
case "2004":
|
||||
cmi = "cmi.completion_status";
|
||||
break;
|
||||
}
|
||||
|
||||
switch (action) {
|
||||
|
||||
case "get":
|
||||
success = scorm.data.get(cmi);
|
||||
break;
|
||||
|
||||
case "set":
|
||||
if (status !== null) {
|
||||
|
||||
success = scorm.data.set(cmi, status);
|
||||
|
||||
} else {
|
||||
|
||||
success = false;
|
||||
trace(traceMsgPrefix + ": status was not specified.");
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
success = false;
|
||||
trace(traceMsgPrefix + ": no valid action was specified.");
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
trace(traceMsgPrefix + ": action was not specified.");
|
||||
|
||||
}
|
||||
|
||||
return success;
|
||||
|
||||
};
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------- //
|
||||
// --- pipwerks.SCORM.debug functions -------------------------------------- //
|
||||
// ------------------------------------------------------------------------- //
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------------
|
||||
pipwerks.SCORM.debug.getCode
|
||||
Requests the error code for the current error state from the LMS
|
||||
|
||||
Parameters: None
|
||||
Returns: Integer (the last error code).
|
||||
---------------------------------------------------------------------------- */
|
||||
|
||||
pipwerks.SCORM.debug.getCode = function() {
|
||||
|
||||
var scorm = pipwerks.SCORM,
|
||||
API = scorm.API.getHandle(),
|
||||
trace = pipwerks.UTILS.trace,
|
||||
code = 0;
|
||||
|
||||
if (API) {
|
||||
|
||||
switch (scorm.version) {
|
||||
case "1.2":
|
||||
code = parseInt(API.LMSGetLastError(), 10);
|
||||
break;
|
||||
case "2004":
|
||||
code = parseInt(API.GetLastError(), 10);
|
||||
break;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
trace("SCORM.debug.getCode failed: API is null.");
|
||||
|
||||
}
|
||||
|
||||
return code;
|
||||
|
||||
};
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------------
|
||||
pipwerks.SCORM.debug.getInfo()
|
||||
"Used by a SCO to request the textual description for the error code
|
||||
specified by the value of [errorCode]."
|
||||
|
||||
Parameters: errorCode (integer).
|
||||
Returns: String.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
pipwerks.SCORM.debug.getInfo = function(errorCode) {
|
||||
|
||||
var scorm = pipwerks.SCORM,
|
||||
API = scorm.API.getHandle(),
|
||||
trace = pipwerks.UTILS.trace,
|
||||
result = "";
|
||||
|
||||
|
||||
if (API) {
|
||||
|
||||
switch (scorm.version) {
|
||||
case "1.2":
|
||||
result = API.LMSGetErrorString(errorCode.toString());
|
||||
break;
|
||||
case "2004":
|
||||
result = API.GetErrorString(errorCode.toString());
|
||||
break;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
trace("SCORM.debug.getInfo failed: API is null.");
|
||||
|
||||
}
|
||||
|
||||
return String(result);
|
||||
|
||||
};
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------------
|
||||
pipwerks.SCORM.debug.getDiagnosticInfo
|
||||
"Exists for LMS specific use. It allows the LMS to define additional
|
||||
diagnostic information through the API Instance."
|
||||
|
||||
Parameters: errorCode (integer).
|
||||
Returns: String (Additional diagnostic information about the given error code).
|
||||
---------------------------------------------------------------------------- */
|
||||
|
||||
pipwerks.SCORM.debug.getDiagnosticInfo = function(errorCode) {
|
||||
|
||||
var scorm = pipwerks.SCORM,
|
||||
API = scorm.API.getHandle(),
|
||||
trace = pipwerks.UTILS.trace,
|
||||
result = "";
|
||||
|
||||
if (API) {
|
||||
|
||||
switch (scorm.version) {
|
||||
case "1.2":
|
||||
result = API.LMSGetDiagnostic(errorCode);
|
||||
break;
|
||||
case "2004":
|
||||
result = API.GetDiagnostic(errorCode);
|
||||
break;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
trace("SCORM.debug.getDiagnosticInfo failed: API is null.");
|
||||
|
||||
}
|
||||
|
||||
return String(result);
|
||||
|
||||
};
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------- //
|
||||
// --- Shortcuts! ---------------------------------------------------------- //
|
||||
// ------------------------------------------------------------------------- //
|
||||
|
||||
// Because nobody likes typing verbose code.
|
||||
|
||||
pipwerks.SCORM.init = pipwerks.SCORM.connection.initialize;
|
||||
pipwerks.SCORM.get = pipwerks.SCORM.data.get;
|
||||
pipwerks.SCORM.set = pipwerks.SCORM.data.set;
|
||||
pipwerks.SCORM.save = pipwerks.SCORM.data.save;
|
||||
pipwerks.SCORM.quit = pipwerks.SCORM.connection.terminate;
|
||||
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------- //
|
||||
// --- pipwerks.UTILS functions -------------------------------------------- //
|
||||
// ------------------------------------------------------------------------- //
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------------
|
||||
pipwerks.UTILS.StringToBoolean()
|
||||
Converts 'boolean strings' into actual valid booleans.
|
||||
|
||||
(Most values returned from the API are the strings "true" and "false".)
|
||||
|
||||
Parameters: String
|
||||
Returns: Boolean
|
||||
---------------------------------------------------------------------------- */
|
||||
|
||||
pipwerks.UTILS.StringToBoolean = function(value) {
|
||||
var t = typeof value;
|
||||
switch (t) {
|
||||
//typeof new String("true") === "object", so handle objects as string via fall-through.
|
||||
//See https://github.com/pipwerks/scorm-api-wrapper/issues/3
|
||||
case "object":
|
||||
case "string":
|
||||
return (/(true|1)/i).test(value);
|
||||
case "number":
|
||||
return !!value;
|
||||
case "boolean":
|
||||
return value;
|
||||
case "undefined":
|
||||
return null;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------------
|
||||
pipwerks.UTILS.trace()
|
||||
Displays error messages when in debug mode.
|
||||
|
||||
Parameters: msg (string)
|
||||
Return: None
|
||||
---------------------------------------------------------------------------- */
|
||||
|
||||
pipwerks.UTILS.trace = function(msg) {
|
||||
|
||||
if (pipwerks.debug.isActive) {
|
||||
|
||||
if (window.console && window.console.log) {
|
||||
window.console.log(msg);
|
||||
} else {
|
||||
//alert(msg);
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
return pipwerks;
|
||||
|
||||
}));
|
||||
Vendored
+17
File diff suppressed because one or more lines are too long
Vendored
+7
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Vendored
+1
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Vendored
+4
File diff suppressed because one or more lines are too long
@@ -0,0 +1,37 @@
|
||||
var __instrucciones_array = new Array();
|
||||
__instrucciones_array.push(""); //0
|
||||
__instrucciones_array.push("Da clic en siguiente"); //1
|
||||
__instrucciones_array.push("Da clic en comenzar"); //2
|
||||
__instrucciones_array.push("Da clic en la flecha"); //3
|
||||
__instrucciones_array.push("Da clic en el icono"); //4
|
||||
__instrucciones_array.push("Da clic en el celular"); //5
|
||||
__instrucciones_array.push("Da clic en el botón"); //6
|
||||
__instrucciones_array.push("Da clic en cerrar"); //7
|
||||
__instrucciones_array.push("Da clic en la respuesta correcta"); //8
|
||||
__instrucciones_array.push("Da clic en verificar"); //9
|
||||
__instrucciones_array.push("Da clic en reproducir"); //10
|
||||
__instrucciones_array.push("Da clic en cada botón"); //11
|
||||
__instrucciones_array.push("Da clic en la flecha"); //12
|
||||
__instrucciones_array.push("Puedes cerrar esta ventana"); //13
|
||||
__instrucciones_array.push("Arrastra la opción hacia el campo correcto"); //14
|
||||
__instrucciones_array.push("Da clic en inténtalo de nuevo"); //15
|
||||
__instrucciones_array.push("Da clic en el mensaje"); //16
|
||||
__instrucciones_array.push("Da clic en el icono PDF"); //17
|
||||
__instrucciones_array.push("Da clic en play para reproducir el video"); //18
|
||||
|
||||
|
||||
function instruccion(index) {
|
||||
var element = ".instruccionsco p";
|
||||
var sco = __curso.temas[__curso.actual];
|
||||
$(element).html(__instrucciones_array[index]);
|
||||
if (__curso.modoDesarrollo || index == 1 || __curso.libre ) {
|
||||
$(".btn__siguiente").removeClass("blocknav");
|
||||
sco.visitado = true;
|
||||
} else if (sco.visitado == true) {
|
||||
$(".btn__siguiente").removeClass("blocknav");
|
||||
} else {
|
||||
$(".btn__siguiente").addClass("blocknav");
|
||||
}
|
||||
updateProgess();
|
||||
guardarAvance();
|
||||
}
|
||||
Vendored
+2
File diff suppressed because one or more lines are too long
Vendored
+13
File diff suppressed because one or more lines are too long
Vendored
+1
File diff suppressed because one or more lines are too long
Vendored
+2
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Vendored
+11
@@ -0,0 +1,11 @@
|
||||
/*!
|
||||
* jQuery UI Touch Punch 0.2.3
|
||||
*
|
||||
* Copyright 2011–2014, Dave Furfero
|
||||
* Dual licensed under the MIT or GPL Version 2 licenses.
|
||||
*
|
||||
* Depends:
|
||||
* jquery.ui.widget.js
|
||||
* jquery.ui.mouse.js
|
||||
*/
|
||||
!function(a){function f(a,b){if(!(a.originalEvent.touches.length>1)){a.preventDefault();var c=a.originalEvent.changedTouches[0],d=document.createEvent("MouseEvents");d.initMouseEvent(b,!0,!0,window,1,c.screenX,c.screenY,c.clientX,c.clientY,!1,!1,!1,!1,0,null),a.target.dispatchEvent(d)}}if(a.support.touch="ontouchend"in document,a.support.touch){var e,b=a.ui.mouse.prototype,c=b._mouseInit,d=b._mouseDestroy;b._touchStart=function(a){var b=this;!e&&b._mouseCapture(a.originalEvent.changedTouches[0])&&(e=!0,b._touchMoved=!1,f(a,"mouseover"),f(a,"mousemove"),f(a,"mousedown"))},b._touchMove=function(a){e&&(this._touchMoved=!0,f(a,"mousemove"))},b._touchEnd=function(a){e&&(f(a,"mouseup"),f(a,"mouseout"),this._touchMoved||f(a,"click"),e=!1)},b._mouseInit=function(){var b=this;b.element.bind({touchstart:a.proxy(b,"_touchStart"),touchmove:a.proxy(b,"_touchMove"),touchend:a.proxy(b,"_touchEnd")}),c.call(b)},b._mouseDestroy=function(){var b=this;b.element.unbind({touchstart:a.proxy(b,"_touchStart"),touchmove:a.proxy(b,"_touchMove"),touchend:a.proxy(b,"_touchEnd")}),d.call(b)}}}(jQuery);
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
/*! waitForImages jQuery Plugin 2018-02-13 */
|
||||
!function(a){"function"==typeof define&&define.amd?define(["jquery"],a):"object"==typeof exports?module.exports=a(require("jquery")):a(jQuery)}(function(a){var b="waitForImages",c=function(a){return a.srcset&&a.sizes}(new Image);a.waitForImages={hasImageProperties:["backgroundImage","listStyleImage","borderImage","borderCornerImage","cursor"],hasImageAttributes:["srcset"]},a.expr.pseudos["has-src"]=function(b){return a(b).is('img[src][src!=""]')},a.expr.pseudos.uncached=function(b){return!!a(b).is(":has-src")&&!b.complete},a.fn.waitForImages=function(){var d,e,f,g=0,h=0,i=a.Deferred(),j=this,k=[],l=a.waitForImages.hasImageProperties||[],m=a.waitForImages.hasImageAttributes||[],n=/url\(\s*(['"]?)(.*?)\1\s*\)/g;if(a.isPlainObject(arguments[0])?(f=arguments[0].waitForAll,e=arguments[0].each,d=arguments[0].finished):1===arguments.length&&"boolean"===a.type(arguments[0])?f=arguments[0]:(d=arguments[0],e=arguments[1],f=arguments[2]),d=d||a.noop,e=e||a.noop,f=!!f,!a.isFunction(d)||!a.isFunction(e))throw new TypeError("An invalid callback was supplied.");return this.each(function(){var b=a(this);f?b.find("*").addBack().each(function(){var b=a(this);b.is("img:has-src")&&!b.is("[srcset]")&&k.push({src:b.attr("src"),element:b[0]}),a.each(l,function(a,c){var d,e=b.css(c);if(!e)return!0;for(;d=n.exec(e);)k.push({src:d[2],element:b[0]})}),a.each(m,function(a,c){var d=b.attr(c);return!d||void k.push({src:b.attr("src"),srcset:b.attr("srcset"),element:b[0]})})}):b.find("img:has-src").each(function(){k.push({src:this.src,element:this})})}),g=k.length,h=0,0===g&&(d.call(j),i.resolveWith(j)),a.each(k,function(f,k){var l=new Image,m="load."+b+" error."+b;a(l).one(m,function b(c){var f=[h,g,"load"==c.type];if(h++,e.apply(k.element,f),i.notifyWith(k.element,f),a(this).off(m,b),h==g)return d.call(j[0]),i.resolveWith(j[0]),!1}),c&&k.srcset&&(l.srcset=k.srcset,l.sizes=k.sizes),l.src=k.src}),i.promise()}});
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n():"function"==typeof define&&define.amd?define(n):n()}(0,function(){"use strict";function e(e){var n=this.constructor;return this.then(function(t){return n.resolve(e()).then(function(){return t})},function(t){return n.resolve(e()).then(function(){return n.reject(t)})})}function n(e){return!(!e||"undefined"==typeof e.length)}function t(){}function o(e){if(!(this instanceof o))throw new TypeError("Promises must be constructed via new");if("function"!=typeof e)throw new TypeError("not a function");this._state=0,this._handled=!1,this._value=undefined,this._deferreds=[],c(e,this)}function r(e,n){for(;3===e._state;)e=e._value;0!==e._state?(e._handled=!0,o._immediateFn(function(){var t=1===e._state?n.onFulfilled:n.onRejected;if(null!==t){var o;try{o=t(e._value)}catch(r){return void f(n.promise,r)}i(n.promise,o)}else(1===e._state?i:f)(n.promise,e._value)})):e._deferreds.push(n)}function i(e,n){try{if(n===e)throw new TypeError("A promise cannot be resolved with itself.");if(n&&("object"==typeof n||"function"==typeof n)){var t=n.then;if(n instanceof o)return e._state=3,e._value=n,void u(e);if("function"==typeof t)return void c(function(e,n){return function(){e.apply(n,arguments)}}(t,n),e)}e._state=1,e._value=n,u(e)}catch(r){f(e,r)}}function f(e,n){e._state=2,e._value=n,u(e)}function u(e){2===e._state&&0===e._deferreds.length&&o._immediateFn(function(){e._handled||o._unhandledRejectionFn(e._value)});for(var n=0,t=e._deferreds.length;t>n;n++)r(e,e._deferreds[n]);e._deferreds=null}function c(e,n){var t=!1;try{e(function(e){t||(t=!0,i(n,e))},function(e){t||(t=!0,f(n,e))})}catch(o){if(t)return;t=!0,f(n,o)}}var a=setTimeout;o.prototype["catch"]=function(e){return this.then(null,e)},o.prototype.then=function(e,n){var o=new this.constructor(t);return r(this,new function(e,n,t){this.onFulfilled="function"==typeof e?e:null,this.onRejected="function"==typeof n?n:null,this.promise=t}(e,n,o)),o},o.prototype["finally"]=e,o.all=function(e){return new o(function(t,o){function r(e,n){try{if(n&&("object"==typeof n||"function"==typeof n)){var u=n.then;if("function"==typeof u)return void u.call(n,function(n){r(e,n)},o)}i[e]=n,0==--f&&t(i)}catch(c){o(c)}}if(!n(e))return o(new TypeError("Promise.all accepts an array"));var i=Array.prototype.slice.call(e);if(0===i.length)return t([]);for(var f=i.length,u=0;i.length>u;u++)r(u,i[u])})},o.resolve=function(e){return e&&"object"==typeof e&&e.constructor===o?e:new o(function(n){n(e)})},o.reject=function(e){return new o(function(n,t){t(e)})},o.race=function(e){return new o(function(t,r){if(!n(e))return r(new TypeError("Promise.race accepts an array"));for(var i=0,f=e.length;f>i;i++)o.resolve(e[i]).then(t,r)})},o._immediateFn="function"==typeof setImmediate&&function(e){setImmediate(e)}||function(e){a(e,0)},o._unhandledRejectionFn=function(e){void 0!==console&&console&&console.warn("Possible Unhandled Promise Rejection:",e)};var l=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if("undefined"!=typeof global)return global;throw Error("unable to locate global object")}();"Promise"in l?l.Promise.prototype["finally"]||(l.Promise.prototype["finally"]=e):l.Promise=o});
|
||||
Vendored
+6
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1,241 @@
|
||||
// JavaScript Document
|
||||
var startDate = 0;
|
||||
var debug = false;
|
||||
pipwerks.debug.isActive = debug;
|
||||
pipwerks.SCORM.handleExitMode = false; // super importante para el LMS de succesFactor
|
||||
/*
|
||||
Se especifica la version de scorm a usar, se esta usando el warpper de pipwerks
|
||||
*/
|
||||
pipwerks.SCORM.version = "1.2";
|
||||
var unloaded = false;
|
||||
/**
|
||||
* Descripción funcion que se encargar de enviar los datos al lms
|
||||
* @method unloadHandler
|
||||
* @return
|
||||
*/
|
||||
function unloadHandler() {
|
||||
if (pipwerks.SCORM.connection.isActive) {
|
||||
if (!unloaded) {
|
||||
var tiempo = computeTime();
|
||||
pipwerks.SCORM.set("cmi.core.session_time", tiempo);
|
||||
pipwerks.SCORM.save(); //save all data that has already been sent
|
||||
pipwerks.SCORM.quit(); //close the SCORM API connection properly
|
||||
unloaded = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Descripción: Obtiene la ultima pantalla visitada
|
||||
* @method getLocation
|
||||
* @return visitada
|
||||
*/
|
||||
function getLocation() {
|
||||
if (pipwerks.SCORM.connection.isActive) {
|
||||
var visitada = eval(pipwerks.SCORM.get("cmi.core.lesson_location")) || 0;
|
||||
return visitada;
|
||||
} else {
|
||||
if (sessionStorage.getItem("offlinemp.intentos")) {
|
||||
return Number(sessionStorage.getItem("offlinemp.intentos"));
|
||||
}else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Descripción: Envia al LMS la pantlla actual o visitada
|
||||
* @return
|
||||
* @method setLocation
|
||||
* @param loc es un string con el valor de la pantalla a guardar
|
||||
* @return
|
||||
*/
|
||||
function setLocation(loc) {
|
||||
if (pipwerks.SCORM.connection.isActive) {
|
||||
scorm = pipwerks.SCORM;
|
||||
if (scorm.connection.isActive) {
|
||||
var current = getLocation() || 0;
|
||||
if (Number(current) < Number(loc)) {
|
||||
var success = pipwerks.SCORM.set("cmi.core.lesson_location", loc);
|
||||
pipwerks.SCORM.save(); //save all data that has already been sent
|
||||
}
|
||||
}
|
||||
} else {
|
||||
sessionStorage.setItem("offlinemp.intentos", loc);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Descripción: Envia al LMS la calificación reportada por el sco
|
||||
* @return
|
||||
* @method setScore
|
||||
* @param score es un string con el valor calificacion en porcentaje
|
||||
* @return
|
||||
*/
|
||||
function setScore(score) {
|
||||
if (pipwerks.SCORM.connection.isActive) {
|
||||
if( score >= getScore() ){
|
||||
pipwerks.SCORM.set("cmi.core.score.raw", score);
|
||||
pipwerks.SCORM.save();
|
||||
}
|
||||
}else{
|
||||
if( score >= getScore() ){
|
||||
sessionStorage.setItem("offlinemp.score", score);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getScore() {
|
||||
if (pipwerks.SCORM.connection.isActive) {
|
||||
var currentScore = pipwerks.SCORM.get("cmi.core.score.raw") || 0;
|
||||
if (currentScore == "") {
|
||||
currentScore = 0;
|
||||
}
|
||||
return Number(currentScore);
|
||||
} else {
|
||||
if (sessionStorage.getItem("offlinemp.score")) {
|
||||
return Number(sessionStorage.getItem("offlinemp.score"));
|
||||
}else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* Descripción: Inica el conteo del tiempo en el sco
|
||||
* @return
|
||||
* @method startTimer
|
||||
* @return
|
||||
*/
|
||||
function startTimer() {
|
||||
startDate = new Date().getTime();
|
||||
}
|
||||
/**
|
||||
* Descripción: calucla el tiempo que el usuario permance en el sco
|
||||
* @method computeTime
|
||||
* @return formattedTime
|
||||
*/
|
||||
function computeTime() {
|
||||
var formattedTime = "00:00:00.0";
|
||||
if (startDate != 0) {
|
||||
var currentDate = new Date().getTime();
|
||||
var elapsedSeconds = ((currentDate - startDate) / 1000);
|
||||
formattedTime = convertTotalSeconds(elapsedSeconds);
|
||||
}
|
||||
return formattedTime;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Descripción: convierte el tiempo en segundos
|
||||
* @method convertTotalSeconds
|
||||
* @param ts de tipo time
|
||||
* @return rtnVal
|
||||
*/
|
||||
function convertTotalSeconds(ts) {
|
||||
var Sec = (ts % 60);
|
||||
ts -= Sec;
|
||||
var tmp = (ts % 3600);
|
||||
ts -= tmp;
|
||||
if ((ts % 3600) != 0) var Hour = "00";
|
||||
else var Hour = "" + (ts / 3600);
|
||||
if ((tmp % 60) != 0) var Min = "00";
|
||||
else var Min = "" + (tmp / 60);
|
||||
Sec = "" + Sec
|
||||
Sec = Sec.substring(0, Sec.indexOf("."))
|
||||
if (Hour.length < 2) Hour = "0" + Hour;
|
||||
if (Min.length < 2) Min = "0" + Min;
|
||||
if (Sec.length < 2) Sec = "0" + Sec;
|
||||
var rtnVal = Hour + ":" + Min + ":" + Sec;
|
||||
return rtnVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Descripción: envia al lms valores para guardar en suspend_data
|
||||
* @return
|
||||
* @method setSuspendData
|
||||
* @param data de tipo string
|
||||
* @return
|
||||
*/
|
||||
function setSuspendData(data) {
|
||||
if (pipwerks.SCORM.connection.isActive) {
|
||||
var success = pipwerks.SCORM.set("cmi.suspend_data", data);
|
||||
pipwerks.SCORM.save();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Descripción: obtiene el valores del lms para suspend_data
|
||||
* @method getSuspendData
|
||||
* @return CallExpression
|
||||
*/
|
||||
function getSuspendData() {
|
||||
if (pipwerks.SCORM.connection.isActive) {
|
||||
var _data = pipwerks.SCORM.get("cmi.suspend_data");
|
||||
if (_data == "") {
|
||||
return null;
|
||||
} else {
|
||||
return _data;
|
||||
}
|
||||
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
* @method getStudentName
|
||||
* @return CallExpression
|
||||
*/
|
||||
function getStudentName() {
|
||||
if (pipwerks.SCORM.connection.isActive) {
|
||||
var student_name = pipwerks.SCORM.get("cmi.core.student_name");
|
||||
if (!student_name) {
|
||||
student_name = "";
|
||||
}
|
||||
return student_name;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
cmi.core.lesson_status - indicates SCO completion -
|
||||
returns one of the following: "passed", "completed", "failed", "incomplete",
|
||||
"browsed", or "not attempted"
|
||||
*/
|
||||
function getLessonStatus() {
|
||||
if (pipwerks.SCORM.connection.isActive) {
|
||||
return pipwerks.SCORM.get("cmi.core.lesson_status");
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
function setLessonStatus(status) {
|
||||
if (pipwerks.SCORM.connection.isActive) {
|
||||
pipwerks.SCORM.set("cmi.core.lesson_status", status);
|
||||
pipwerks.SCORM.save(); //save all data that has already been sent
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function iniciarScorm() {
|
||||
var success = pipwerks.SCORM.init();
|
||||
var status = "";
|
||||
startTimer();
|
||||
if (success) {
|
||||
status = pipwerks.SCORM.get("cmi.core.lesson_status");
|
||||
if (!(status.localeCompare("completed") == 0 || status.localeCompare("passed") == 0)) {
|
||||
success = pipwerks.SCORM.set("cmi.core.lesson_status", "incomplete");
|
||||
if (success) {
|
||||
pipwerks.SCORM.save();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//window.addEventListener("load", iniciarScorm);
|
||||
window.addEventListener("beforeunload", unloadHandler);
|
||||
window.addEventListener("unload", unloadHandler);
|
||||
+800
@@ -0,0 +1,800 @@
|
||||
var __jsonObject, __spresponse;
|
||||
var __temas = new Array();
|
||||
var __rootxml = 'xml/main.xml';
|
||||
var __curso = new Object();
|
||||
__curso.databasename = "Mapfre_PLD.V10";
|
||||
__curso.modoDesarrollo = false;
|
||||
if(__curso.modoDesarrollo ) { __curso.databasename = __curso.databasename +"."+Math.random(); }
|
||||
__curso.maxAvance = 0;
|
||||
__curso.libre = false;
|
||||
__curso.actual = 0;
|
||||
var __htmlmenu = "";
|
||||
var __auxi = 0;
|
||||
var __currentSound = null;
|
||||
var circleProgressBar;
|
||||
var ___scala = 1;
|
||||
var __click = newSound("audio/click.mp3");
|
||||
|
||||
|
||||
jQuery(document).ready(function($) {
|
||||
$(".wloader").show();
|
||||
var success = pipwerks.SCORM.init();
|
||||
var status = "";
|
||||
startTimer();
|
||||
if (success) {
|
||||
status = pipwerks.SCORM.get("cmi.core.lesson_status");
|
||||
if (!(status.localeCompare("completed") == 0 || status.localeCompare("passed") == 0)) {
|
||||
success = pipwerks.SCORM.set("cmi.core.lesson_status", "incomplete");
|
||||
}
|
||||
}
|
||||
ready();
|
||||
});
|
||||
|
||||
|
||||
function ready() {
|
||||
resizeRutine();
|
||||
window.addEventListener("resize", resizeRutine);
|
||||
$.ajax({
|
||||
url: __rootxml,
|
||||
data: {
|
||||
nochache: 'cache-' + new Date().getTime()
|
||||
},
|
||||
dataType: "xml"
|
||||
})
|
||||
.done(function(response) {
|
||||
__spresponse = response;
|
||||
indexes();
|
||||
__jsonObject = $.xml2json(__spresponse);
|
||||
crearMenu();
|
||||
recuperarSesion();
|
||||
eliminarDuplicadosDelMenu();
|
||||
})
|
||||
.fail(function() {
|
||||
alert("error al leer configuración.");
|
||||
});
|
||||
// eventos de botones de menu
|
||||
$(".btn-close-menu").click(__closemenu);
|
||||
$(".btn__menu").click(__openmenu);
|
||||
$(".btn__siguiente").click(__siguiente);
|
||||
$(".btn__atras").click(__atras);
|
||||
$(".btn__home").click(__home);
|
||||
$(".btn__reload").click(__reload);
|
||||
$(".btn-show-subs").click(__togglesubs);
|
||||
$(".wcontainer").on('click', '.btn_menu_padre', function(event) {
|
||||
$(this).toggleClass("close_menu_items");
|
||||
$(this).parent().find(".btn_menu_tema").toggle("fast");
|
||||
});
|
||||
$(".wcontainer").on('click', '[data-indexmenubtn]', function(event) {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if (!$(this).hasClass('disabled')) {
|
||||
__goto(Number($(this).data('indexmenubtn')));
|
||||
__closemenu();
|
||||
} else {
|
||||
Swal.fire({
|
||||
title: '<b>Tema bloqueado</b>',
|
||||
icon: 'info',
|
||||
showCloseButton: false,
|
||||
showCancelButton: false,
|
||||
cancelButtonText: 'No',
|
||||
confirmButtonText: 'Aceptar',
|
||||
height: '100%',
|
||||
showConfirmButton: true,
|
||||
allowOutsideClick: false,
|
||||
allowEscapeKey: false,
|
||||
allowEnterKey: false,
|
||||
target: '.wcontainer',
|
||||
customClass: 'popscoinit',
|
||||
onBeforeOpen: function() {},
|
||||
onOpen: function() {},
|
||||
onRender: function() {},
|
||||
onClose: function() {},
|
||||
onAfterClose: function() {}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
$(".btn-sound-control-sco").click(function(event) {
|
||||
if ($(this).hasClass('mute')) {
|
||||
Howler.volume(1);
|
||||
if ($(".sco").find('video').length > 0) {
|
||||
$(".sco").find('video').each(function(index, el) {
|
||||
el.volume = 1;
|
||||
});
|
||||
}
|
||||
$(this).removeClass('mute');
|
||||
} else {
|
||||
$(this).addClass('mute');
|
||||
Howler.volume(0);
|
||||
if ($(".sco").find('video').length > 0) {
|
||||
$(".sco").find('video').each(function(index, el) {
|
||||
el.volume = 0;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
function eliminarDuplicadosDelMenu() {
|
||||
var cmp = "---";
|
||||
$(".btn_menu_tema").each(function(index, el) {
|
||||
var sco = __curso.temas[index];
|
||||
if (!sco.visitado && !__curso.modoDesarrollo && !__curso.libre) {
|
||||
$(el).addClass('disabled');
|
||||
}
|
||||
if ($(el).html() != cmp) {
|
||||
cmp = $(el).html();
|
||||
} else {
|
||||
$(el).remove();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function __togglesubs() {
|
||||
$(".subtenma").toggleClass("abierto");
|
||||
}
|
||||
|
||||
function indexes() {
|
||||
var _i = 0;
|
||||
$.each($(__spresponse).find('modulo'), function(index, modulo) {
|
||||
var moduloname = $(modulo).find('nombre').text();
|
||||
$.each($(modulo).find('tema'), function(index, val) {
|
||||
|
||||
if (val.childElementCount == 0) {
|
||||
var tema = new Object();
|
||||
tema.index = _i;
|
||||
tema.visitado = false;
|
||||
tema.modulo = moduloname;
|
||||
var element = $(val);
|
||||
$.each(element.get(0).attributes, function(i, attrib) {
|
||||
tema[attrib.name] = attrib.value;
|
||||
});
|
||||
tema.text = $(val).text();
|
||||
__temas.push(tema);
|
||||
$(val).attr("index", _i);
|
||||
$(val).attr("visitado", "false");
|
||||
_i++;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function crearMenu() {
|
||||
var nombredelcurso = __jsonObject["#document"].curso.nombre;
|
||||
$(".nombredelcurso").html(nombredelcurso);
|
||||
var menudiv = ".itemsmenu";
|
||||
$(menudiv).parent().prepend("<div class='menu_nombrecurso w-100'>" + nombredelcurso + "</div>");
|
||||
if ($.isArray(__jsonObject["#document"].curso.modulo)) {
|
||||
$.each(__jsonObject["#document"].curso.modulo, function(index, modulo) {
|
||||
$(menudiv).append("<div class='menu_modulo" + index + "'></div>");
|
||||
var modulodiv = '.menu_modulo' + index;
|
||||
$(modulodiv).append("<div class='menu_nombremodulo'>" + modulo.nombre + "</div>");
|
||||
agregaModuloAlMenu(index, modulo);
|
||||
});
|
||||
} else {
|
||||
$(menudiv).append("<div class='menu_modulo" + 0 + "'></div>");
|
||||
var modulodiv = '.menu_modulo' + 0;
|
||||
$(modulodiv).append("<div class='menu_nombremodulo'>" + __jsonObject["#document"].curso.modulo.nombre + "</div>");
|
||||
agregaModuloAlMenu(0, __jsonObject["#document"].curso.modulo);
|
||||
}
|
||||
}
|
||||
|
||||
function agregaModuloAlMenu(index, modulo) {
|
||||
var modulodiv = '.menu_modulo' + index;
|
||||
|
||||
if ($.isArray(modulo.tema)) {
|
||||
$.each(modulo.tema, function(indextema, tema) {
|
||||
agregaTemaAlModulo(indextema, tema, modulodiv, index);
|
||||
});
|
||||
} else {
|
||||
agregaTemaAlModulo(0, tema, modulodiv);
|
||||
}
|
||||
}
|
||||
|
||||
function agregaTemaAlModulo(indextema, tema, modulodiv, indexmodulo) {
|
||||
|
||||
if (tema.hasOwnProperty("tema")) {
|
||||
if (!tema.$.nombre) {
|
||||
alert("curso mal configurado");
|
||||
}
|
||||
var temadiv = '.menu_wtema' + indextema + indexmodulo;
|
||||
$(modulodiv).append('<div class="menu_wtema' + indextema + indexmodulo + '"><div class="btn_menu_padre">' + tema.$.nombre + '</div></div>');
|
||||
agregaTemaAlModulo(indextema, tema.tema, temadiv, indexmodulo);
|
||||
} else if ($.isArray(tema)) {
|
||||
$.each(tema, function(index, subs) {
|
||||
var temadiv = '.menu_wtema' + indextema + indexmodulo;
|
||||
agregaTemaAlModulo(index, subs, temadiv, indexmodulo);
|
||||
});
|
||||
} else {
|
||||
$(modulodiv).append('<div data-indexmenubtn="' + tema.$.index + '" class="btn_menu_tema">' + tema.txt + '</div>');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function cp() {
|
||||
circleProgressBar = new ProgressBar.Circle('.curso-progress', {
|
||||
strokeWidth: 8,
|
||||
color: '#FFF',
|
||||
trailWidth: 8,
|
||||
trailColor: 'rgba(0,0,0,0.125)',
|
||||
text: {
|
||||
autoStyleContainer: false
|
||||
},
|
||||
from: {
|
||||
color: '#DC4D54'
|
||||
},
|
||||
to: {
|
||||
color: '#C3360E'
|
||||
},
|
||||
step: function(state, circle) {
|
||||
circle.path.setAttribute('stroke', state.color);
|
||||
var value = Math.round(circle.value() * 100);
|
||||
if (value === 0) {
|
||||
circle.setText('0%');
|
||||
} else {
|
||||
circle.setText(value + "%");
|
||||
}
|
||||
|
||||
},
|
||||
fill: 'rgba(0,0,0,0.0)'
|
||||
});
|
||||
circleProgressBar.text.style.fontSize = '1rem';
|
||||
}
|
||||
|
||||
function recuperarSesion() {
|
||||
var tmpcur = recuperarAvance();
|
||||
cp();
|
||||
$(".wloader").hide();
|
||||
if (tmpcur == null) {
|
||||
__curso.temas = __temas;
|
||||
__curso.actual = 0;
|
||||
__curso.maxAvance = 0;
|
||||
__loadsco();
|
||||
} else {
|
||||
__curso = tmpcur;
|
||||
$.each(__curso.temas, function(index, val) {
|
||||
if (val.visitado) {
|
||||
$("[data-indexmenubtn='" + val.index + "']").removeClass("noclick");
|
||||
}
|
||||
});
|
||||
//preguntar al usuario si desea recuperar el avance
|
||||
Swal.fire({
|
||||
title: '<b>¿Recuperar el máximo avance en el curso?</b>',
|
||||
icon: 'info',
|
||||
showCloseButton: false,
|
||||
showCancelButton: true,
|
||||
cancelButtonText: 'No',
|
||||
confirmButtonText: 'Sí',
|
||||
showConfirmButton: true,
|
||||
allowOutsideClick: false,
|
||||
allowEscapeKey: false,
|
||||
allowEnterKey: false,
|
||||
target: '.wcontainer',
|
||||
customClass: 'popscoinit',
|
||||
onBeforeOpen: function() {},
|
||||
onOpen: function() {},
|
||||
onRender: function() {},
|
||||
onClose: function() {},
|
||||
onAfterClose: function() {}
|
||||
}).then(function(result) {
|
||||
if (result.value === true) {
|
||||
__curso.actual = __curso.maxAvance;
|
||||
} else {
|
||||
__curso.actual = 0;
|
||||
}
|
||||
__loadsco();
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function __reload() {
|
||||
__loadsco();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Description
|
||||
* @method __closemenu
|
||||
* @return
|
||||
*/
|
||||
function __closemenu() {
|
||||
$(".wmenu").removeClass('open');
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
* @method __openmenu
|
||||
* @return
|
||||
*/
|
||||
function __openmenu() {
|
||||
updateProgess();
|
||||
$(".wmenu").addClass('open');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
* @method __siguiente
|
||||
* @return
|
||||
*/
|
||||
function __siguiente() {
|
||||
if (!$(".btn__siguiente").hasClass('blocknav')) {
|
||||
__curso.actual++;
|
||||
__loadsco();
|
||||
}
|
||||
}
|
||||
|
||||
function __nextslide() {
|
||||
__curso.actual++;
|
||||
__loadsco();
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
* @method __atras
|
||||
* @return
|
||||
*/
|
||||
function __atras() {
|
||||
if (!$(".btn__atras").hasClass('blocknav')) {
|
||||
|
||||
__curso.actual--;
|
||||
__loadsco();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
* @method __home
|
||||
* @return
|
||||
*/
|
||||
function __home() {
|
||||
__curso.actual = 1;
|
||||
__loadsco();
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
* @method __goto
|
||||
* @param {} index
|
||||
* @return
|
||||
*/
|
||||
function __goto(index) {
|
||||
__curso.actual = index;
|
||||
__loadsco();
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
* @method resizeRutine
|
||||
* @return
|
||||
*/
|
||||
function resizeRutine() {
|
||||
var selector = ".wcontainer";
|
||||
var width = $(selector).outerWidth();
|
||||
var height = $(selector).outerHeight();
|
||||
___scala = Math.min(((window.innerWidth * 100) / width), ((window.innerHeight * 100) / height)) / 100;
|
||||
var left = window.innerWidth / 2 - ($(selector).outerWidth() * ___scala) / 2;
|
||||
console.log(left);
|
||||
TweenMax.set(selector, {
|
||||
scale: ___scala,
|
||||
transformOrigin: "0% 0%"
|
||||
});
|
||||
$(selector).css('left', left + 'px');
|
||||
}
|
||||
|
||||
function vhToPixels(vh) {
|
||||
return Math.round(window.innerHeight / (100 / vh)) + 'px';
|
||||
}
|
||||
|
||||
function vwToPixels(vw) {
|
||||
return Math.round(window.innerWidth / (100 / vw)) + 'px';
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
* @method __loadsco
|
||||
* @return
|
||||
*/
|
||||
function __loadsco() {
|
||||
var sco = __curso.temas[__curso.actual];
|
||||
//ajuste de subtema solo aplica para mapfre responsivo
|
||||
$(".subtematxt").html(sco.text);
|
||||
var toleft = ($(".subtenma").outerWidth() - $(".btn-show-subs").outerWidth()) * -1;
|
||||
$(".subtenma").css("left", toleft);
|
||||
$(".subtenma").removeClass("abierto");
|
||||
$(".sco").removeClass('hasvideo');
|
||||
if (swal.isVisible()) {
|
||||
swal.close();
|
||||
}
|
||||
//
|
||||
if (__curso.actual > __curso.maxAvance) {
|
||||
__curso.maxAvance = __curso.actual;
|
||||
}
|
||||
$(".btn__atras, .btn__home, .btn__siguiente").addClass('noclick');
|
||||
$(".wloader").show();
|
||||
stopAllSounds();
|
||||
instruccion(0);
|
||||
if (sco.fullscreen == "1") {
|
||||
$(".subtenma").removeClass('d-flex');
|
||||
$(".subtenma").hide();
|
||||
$(".subtematxt").hide();
|
||||
$(".sco").addClass('scofullscreen');
|
||||
} else {
|
||||
$(".subtematxt").show();
|
||||
$(".subtenma").addClass('d-flex');
|
||||
$(".subtenma").show();
|
||||
$(".sco").removeClass('scofullscreen');
|
||||
}
|
||||
__currentSound = null;
|
||||
preload();
|
||||
}
|
||||
|
||||
|
||||
function preload() {
|
||||
var sco = __curso.temas[__curso.actual];
|
||||
updateNav();
|
||||
instruccion(0);
|
||||
$.ajax({
|
||||
url: sco.src,
|
||||
data: {
|
||||
nochache: 'cache-' + new Date().getTime()
|
||||
}
|
||||
}).done(function(response) {
|
||||
$(".sco").hide();
|
||||
$(".sco").html(response).show();
|
||||
$(".sco").find(".animated").on($(".sco").whichAnimationEvent(), function() {
|
||||
if ((!$(this).hasClass("pulse") || $(this).hasClass("flash"))) {
|
||||
$(this).removeClass("animated");
|
||||
}
|
||||
});
|
||||
$(".wloader").hide();
|
||||
console.info('file: ' + sco.src);
|
||||
$('.__tema').html(sco.txt);
|
||||
resizeRutine();
|
||||
|
||||
}).fail(function() {
|
||||
alert("Error al leer: " + sco.src);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Description
|
||||
* @method updateNav
|
||||
* @return
|
||||
*/
|
||||
function updateNav() {
|
||||
|
||||
if (__curso.temas.length == 1) {
|
||||
$(".btn__atras").hide();
|
||||
$(".btn__siguiente").hide();
|
||||
} else if (__curso.actual == 0) {
|
||||
$(".btn__atras").hide();
|
||||
$(".btn__siguiente").show();
|
||||
} else if (__curso.actual > 0 && __curso.actual < __curso.temas.length - 1) {
|
||||
$(".btn__atras").show();
|
||||
$(".btn__siguiente").show();
|
||||
} else {
|
||||
$(".btn__atras").show();
|
||||
$(".btn__siguiente").hide();
|
||||
}
|
||||
/*if (__curso.temas[__curso.actual].fullscreen) {
|
||||
$(".btn__siguiente").hide();
|
||||
}*/
|
||||
var slideactual = "";
|
||||
if (Number(__curso.actual + 1) < 10) {
|
||||
slideactual = "0" + Number(__curso.actual + 1);
|
||||
} else {
|
||||
slideactual = Number(__curso.actual + 1);
|
||||
}
|
||||
var totalslides = "";
|
||||
if (__curso.temas.length < 10) {
|
||||
totalslides = "0" + Number(__curso.temas.length);
|
||||
} else {
|
||||
totalslides = __curso.temas.length;
|
||||
}
|
||||
|
||||
$(".__paginacion").html(slideactual + "/" + totalslides);
|
||||
$("[data-indexmenubtn='" + __curso.actual + "']").removeClass("disabled");
|
||||
if ($("[data-indexmenubtn='" + __curso.actual + "']").length > 0) {
|
||||
$(".btn_menu_tema").removeClass("actual");
|
||||
$("[data-indexmenubtn='" + __curso.actual + "']").addClass('actual');
|
||||
}
|
||||
/* Calculo de progreso*/
|
||||
updateProgess();
|
||||
guardarAvance();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Description
|
||||
* @method updateProgess
|
||||
* @return
|
||||
*/
|
||||
function updateProgess() {
|
||||
var totales = __curso.temas.length;
|
||||
var visitados = $.grep(__curso.temas, function(element, index) {
|
||||
return element.visitado == true;
|
||||
});
|
||||
var porcentajeDeAvance = round((visitados.length) / totales);
|
||||
circleProgressBar.set(porcentajeDeAvance);
|
||||
if (porcentajeDeAvance == 1) {
|
||||
setLessonStatus("completed");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Description
|
||||
* @method whichTransitionEvent
|
||||
* @return
|
||||
*/
|
||||
$.fn.whichTransitionEvent = function() {
|
||||
var t,
|
||||
el = document.createElement("fakeelement");
|
||||
|
||||
var transitions = {
|
||||
"transition": "transitionend",
|
||||
"OTransition": "oTransitionEnd",
|
||||
"MozTransition": "transitionend",
|
||||
"WebkitTransition": "webkitTransitionEnd"
|
||||
}
|
||||
|
||||
for (t in transitions) {
|
||||
if (el.style[t] !== undefined) {
|
||||
return transitions[t];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
* @method whichAnimationEvent
|
||||
* @return
|
||||
*/
|
||||
$.fn.whichAnimationEvent = function() {
|
||||
var t,
|
||||
el = document.createElement("fakeelement");
|
||||
|
||||
var animations = {
|
||||
"animation": "animationend",
|
||||
"OAnimation": "oAnimationEnd",
|
||||
"MozAnimation": "animationend",
|
||||
"WebkitAnimation": "webkitAnimationEnd"
|
||||
}
|
||||
|
||||
for (t in animations) {
|
||||
if (el.style[t] !== undefined) {
|
||||
return animations[t];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Howler.mobileAutoEnable = true;
|
||||
Howler.autoSuspend = false;
|
||||
/**
|
||||
* Description
|
||||
* @method newSoundAuto
|
||||
* @param {} src
|
||||
* @return snd
|
||||
*/
|
||||
function newSoundAuto(src) {
|
||||
var snd = new Howl({
|
||||
src: [src + "?nochache=" + new Date().getTime()],
|
||||
autoplay: true
|
||||
});
|
||||
return snd;
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
* @method newSound
|
||||
* @param {} src
|
||||
* @return snd
|
||||
*/
|
||||
function newSound(src) {
|
||||
var snd = new Howl({
|
||||
src: [src],
|
||||
autoplay: false
|
||||
});
|
||||
return snd;
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
* @method stopAllSounds
|
||||
* @return
|
||||
*/
|
||||
function stopAllSounds() {
|
||||
if (Array.isArray(Howler._howls)) {
|
||||
$.each(Howler._howls, function(index, sound) {
|
||||
sound.stop();
|
||||
sound.off("end");
|
||||
sound.off("load");
|
||||
sound.off();
|
||||
});
|
||||
}
|
||||
if (__currentSound != null) {
|
||||
__currentSound.stop();
|
||||
__currentSound.off("load");
|
||||
__currentSound.off("end");
|
||||
__currentSound = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
* @method stopAllSoundsAndPlay
|
||||
* @param {} audio
|
||||
* @return
|
||||
*/
|
||||
function stopAllSoundsAndPlay(audio) {
|
||||
if (Array.isArray(Howler._howls)) {
|
||||
$.each(Howler._howls, function(index, sound) {
|
||||
sound.stop();
|
||||
});
|
||||
}
|
||||
audio.play();
|
||||
console.info('audio src: ' + audio._src);
|
||||
if (__currentSound != null) {
|
||||
__currentSound.off("end");
|
||||
}
|
||||
__currentSound = audio;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Description
|
||||
* @method getCurrentSound
|
||||
* @return __currentSound
|
||||
*/
|
||||
function getCurrentSound() {
|
||||
return __currentSound;
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
* @method recuperarAvance
|
||||
* @return
|
||||
*/
|
||||
function recuperarAvance() {
|
||||
if (__curso.modoDesarrollo && !pipwerks.SCORM.connection.isActive) {
|
||||
sessionStorage.removeItem(__curso.databasename);
|
||||
//return JSON.parse(sessionStorage.getItem(__curso.databasename));
|
||||
return null;
|
||||
} else if (pipwerks.SCORM.connection.isActive) {
|
||||
var _recuperado = JSON.parse(getSuspendData());
|
||||
|
||||
if (_recuperado != null) {
|
||||
if (_recuperado.temas.length == __temas.length) {
|
||||
__curso.actual = _recuperado.actual;
|
||||
__curso.maxAvance = _recuperado.maxAvance;
|
||||
__curso.modoDesarrollo = _recuperado.modoDesarrollo;
|
||||
$.each(_recuperado.temas, function(index, val) {
|
||||
if (index < __temas.length) {
|
||||
__temas[index].visitado = val.visitado;
|
||||
}
|
||||
});
|
||||
__curso.temas = __temas;
|
||||
return __curso;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
} else if (sessionStorage.getItem(__curso.databasename)) {
|
||||
return JSON.parse(sessionStorage.getItem(__curso.databasename));
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
* @method guardarAvance
|
||||
* @return
|
||||
*/
|
||||
function guardarAvance() {
|
||||
if (pipwerks.SCORM.connection.isActive) {
|
||||
var _tosave = new Object();
|
||||
_tosave.actual = __curso.actual;
|
||||
_tosave.maxAvance = __curso.maxAvance;
|
||||
_tosave.modoDesarrollo = __curso.modoDesarrollo;
|
||||
_tosave.temas = new Array();
|
||||
$.each(__curso.temas, function(index, val) {
|
||||
var _tema = new Object();
|
||||
_tema.visitado = val.visitado;
|
||||
_tosave.temas.push(_tema);
|
||||
|
||||
});
|
||||
setSuspendData(JSON.stringify(_tosave));
|
||||
} else {
|
||||
sessionStorage.setItem(__curso.databasename, JSON.stringify(__curso));
|
||||
}
|
||||
}
|
||||
|
||||
function round(num) {
|
||||
var decimales = 2;
|
||||
var signo = (num >= 0 ? 1 : -1);
|
||||
num = num * signo;
|
||||
if (decimales === 0) //con 0 decimales
|
||||
return signo * Math.round(num);
|
||||
// round(x * 10 ^ decimales)
|
||||
num = num.toString().split('e');
|
||||
num = Math.round(+(num[0] + 'e' + (num[1] ? (+num[1] + decimales) : decimales)));
|
||||
// x * 10 ^ (-decimales)
|
||||
num = num.toString().split('e');
|
||||
return signo * (num[0] + 'e' + (num[1] ? (+num[1] - decimales) : -decimales));
|
||||
}
|
||||
|
||||
|
||||
|
||||
function getRandomInt(min, max) {
|
||||
min = Math.ceil(min);
|
||||
max = Math.floor(max);
|
||||
return Math.floor(Math.random() * (max - min + 1)) + min;
|
||||
}
|
||||
|
||||
$.fn.loadsvg = function(svgUrl) {
|
||||
var div = $(this);
|
||||
$.get(svgUrl, function(data) {
|
||||
var data = new XMLSerializer().serializeToString(data.documentElement)
|
||||
div.html(data);
|
||||
div.trigger("complete", [data]);
|
||||
});
|
||||
}
|
||||
|
||||
function rotateCard(btn) {
|
||||
var $card = $(btn).closest('.card-container');
|
||||
console.log($card);
|
||||
if ($card.hasClass('hover')) {
|
||||
$card.removeClass('hover');
|
||||
} else {
|
||||
$card.addClass('hover');
|
||||
}
|
||||
}
|
||||
|
||||
$.fn.addRandomClassAnimation = function() {
|
||||
var animaciones = ['bounce', 'shake', 'wobble', 'bounceInLeft', 'fadeIn', 'fadeInLeftBig', 'fadeInUpBig', 'rotateIn', 'rotateInUpRight', 'rollIn', 'zoomInLeft', 'flash', 'headShake', 'jello', 'bounceInRight', 'fadeInDown', 'fadeInRight', 'rotateInDownLeft', 'zoomInRight', 'pulse', 'swing', 'bounceIn', 'bounceInUp', 'fadeInDownBig', 'fadeInRightBig', 'flipInX', 'lightSpeedIn', 'rotateInDownRight', 'zoomIn', 'zoomInUp', 'slideInRight', 'rubberBand', 'tada', 'bounceInDown', 'fadeInLeft', 'fadeInUp', 'flipInY', 'rotateInUpLeft', 'jackInTheBox', 'zoomInDown', 'slideInUp'];
|
||||
$(this).addClass('animated');
|
||||
animaciones = animaciones.sort(function() {
|
||||
return 0.5 - Math.random()
|
||||
});
|
||||
var animation = animaciones[0];
|
||||
$(this).addClass(animation);
|
||||
var animationEnd = (function(el) {
|
||||
var animations = {
|
||||
animation: 'animationend',
|
||||
OAnimation: 'oAnimationEnd',
|
||||
MozAnimation: 'mozAnimationEnd',
|
||||
WebkitAnimation: 'webkitAnimationEnd',
|
||||
};
|
||||
|
||||
for (var t in animations) {
|
||||
if (el.style[t] !== undefined) {
|
||||
return animations[t];
|
||||
}
|
||||
}
|
||||
})(document.createElement('div'));
|
||||
$(this).one(animationEnd, resizeRutine);
|
||||
}
|
||||
$.fn.changeOrderOfElements = function() {
|
||||
var parent = $(this);
|
||||
var divs = parent.children();
|
||||
parent.html("");
|
||||
while (divs.length) {
|
||||
parent.append(divs.splice(Math.floor(Math.random() * divs.length), 1)[0]);
|
||||
}
|
||||
}
|
||||
Vendored
+1
File diff suppressed because one or more lines are too long
Vendored
+23
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+136
@@ -0,0 +1,136 @@
|
||||
/**
|
||||
* jQuery plugin to convert a given $.ajax response xml object to json.
|
||||
*
|
||||
* @example var json = $.xml2json(response);
|
||||
*/
|
||||
(function() {
|
||||
|
||||
// default options based on https://github.com/Leonidas-from-XIV/node-xml2js
|
||||
var defaultOptions = {
|
||||
attrkey: '$',
|
||||
charkey: 'txt',
|
||||
normalize: true,
|
||||
explicitArray: false
|
||||
};
|
||||
|
||||
// extracted from jquery
|
||||
function parseXML(data) {
|
||||
var xml, tmp;
|
||||
if (!data || typeof data !== "string") {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
if (window.DOMParser) { // Standard
|
||||
tmp = new DOMParser();
|
||||
xml = tmp.parseFromString(data, "text/xml");
|
||||
} else { // IE
|
||||
xml = new ActiveXObject("Microsoft.XMLDOM");
|
||||
xml.async = "false";
|
||||
xml.loadXML(data);
|
||||
}
|
||||
} catch (e) {
|
||||
xml = undefined;
|
||||
}
|
||||
if (!xml || !xml.documentElement || xml.getElementsByTagName("parsererror").length) {
|
||||
throw new Error("Invalid XML: " + data);
|
||||
}
|
||||
return xml;
|
||||
}
|
||||
|
||||
function normalize(value, options){
|
||||
if (!!options.normalize){
|
||||
return (value || '').trim();
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
function xml2jsonImpl(xml, options) {
|
||||
|
||||
var i, result = {}, attrs = {}, node, child, name;
|
||||
result[options.attrkey] = attrs;
|
||||
|
||||
if (xml.attributes && xml.attributes.length > 0) {
|
||||
for (i = 0; i < xml.attributes.length; i++){
|
||||
var item = xml.attributes.item(i);
|
||||
attrs[item.nodeName] = item.value;
|
||||
}
|
||||
}
|
||||
|
||||
// element content
|
||||
if (xml.childElementCount === 0) {
|
||||
result[options.charkey] = normalize(xml.textContent, options);
|
||||
}
|
||||
|
||||
for (i = 0; i < xml.childNodes.length; i++) {
|
||||
node = xml.childNodes[i];
|
||||
if (node.nodeType === 1) {
|
||||
|
||||
if (node.attributes.length === 0 && node.childElementCount === 0){
|
||||
child = normalize(node.textContent, options);
|
||||
} else {
|
||||
child = xml2jsonImpl(node, options);
|
||||
}
|
||||
|
||||
name = node.nodeName;
|
||||
if (result.hasOwnProperty(name)) {
|
||||
// For repeating elements, cast/promote the node to array
|
||||
var val = result[name];
|
||||
if (!Array.isArray(val)) {
|
||||
val = [val];
|
||||
result[name] = val;
|
||||
}
|
||||
val.push(child);
|
||||
} else if(options.explicitArray === true) {
|
||||
result[name] = [child];
|
||||
} else {
|
||||
result[name] = child;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**w
|
||||
* Converts an xml document or string to a JSON object.
|
||||
*
|
||||
* @param xml
|
||||
*/
|
||||
function xml2json(xml, options) {
|
||||
var n;
|
||||
|
||||
if (!xml) {
|
||||
return xml;
|
||||
}
|
||||
|
||||
options = options || {};
|
||||
|
||||
for(n in defaultOptions) {
|
||||
if(defaultOptions.hasOwnProperty(n) && options[n] === undefined) {
|
||||
options[n] = defaultOptions[n];
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof xml === 'string') {
|
||||
xml = parseXML(xml).documentElement;
|
||||
}
|
||||
|
||||
var root = {};
|
||||
|
||||
if (xml.attributes && xml.attributes.length === 0 && xml.childElementCount === 0){
|
||||
root[xml.nodeName] = normalize(xml.textContent, options);
|
||||
} else {
|
||||
root[xml.nodeName] = xml2jsonImpl(xml, options);
|
||||
}
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
if (typeof jQuery !== 'undefined') {
|
||||
jQuery.extend({xml2json: xml2json});
|
||||
} else if (typeof module !== 'undefined') {
|
||||
module.exports = xml2json;
|
||||
} else if (typeof window !== 'undefined') {
|
||||
window.xml2json = xml2json;
|
||||
}
|
||||
})();
|
||||
Reference in New Issue
Block a user