Clutch152 / scripts

Collection of scripts for the lazy ... >.>
162 stars 78 forks source link

A Possible Solution: #82

Open Enigmacoder23 opened 5 months ago

Enigmacoder23 commented 5 months ago

To use the provided JavaScript script for SCORM API interactions in a Learning Management System (LMS) like JKO, follow these instructions and understand the code's functionality:

Instructions for Executing the Code

  1. Integration with LMS: This script is designed to be integrated into an e-learning course content that is compliant with SCORM standards. It should be included in the HTML or JavaScript files that are part of the courseware.

  2. Adding the Script: Embed the script in the HTML file of your e-learning module, typically where other JavaScript files are included. Ensure that the script is loaded before any interactions that require SCORM API calls.

  3. No Additional Setup Required: Once embedded, the script runs automatically when the e-learning module is loaded in the LMS. There's no need for manual initiation of the script.

Explanation of the Script's Functionality

Limitations and Feedback Request

As the author of this script, I no longer have the ability to test it on JKO or similar platforms directly. Therefore, for any improvements or adaptations, I am reliant on feedback from users who can test it in a live environment. If you encounter any issues or have suggestions for enhancements, please share your feedback, which will be invaluable for refining the script further. This collaborative approach will help in ensuring the script remains functional and effective for its intended purpose.


// SCORM API Abstraction Layer var SCORM_API = { initialize: function() { var API = this.findAPI(window); if (API && API.Initialize("")) { this.API = API; return true; } else { console.error("SCORM API initialization failed."); return false; } }, setValue: function(param, value) { if (this.API) { return this.API.SetValue(param, value) === "true"; } return false; }, terminate: function() { if (this.API && this.API.Terminate("")) { return true; } else { console.error("SCORM API termination failed."); return false; } }, findAPI: function(win) { try { if (win.API_1484_11) { return win.API_1484_11; } else if (win.parent && win.parent !== win) { return this.findAPI(win.parent); } } catch (e) { console.error("Access denied finding API in windows", e); } return null; }, API: null };

// Feature detection for addEventListener function addEvent(el, type, handler) { if (el.addEventListener) { el.addEventListener(type, handler); } else if (el.attachEvent) { el.attachEvent('on' + type, handler); } else { el['on' + type] = handler; } }

// Main execution addEvent(window, 'load', function() { if (SCORM_API.initialize()) { if (document.getElementsByName("courseheader").length > 0) { var courseHeader = document.getElementsByName("courseheader")[0].contentDocument; var elementC = courseHeader.getElementById("c"); if (elementC) { elementC.submit(); setTimeout(function() { SCORM_API.terminate(); }, 1000); } else { console.error("Element with id 'c' was not found."); } } else { console.error("'courseheader' element is not available."); } } });