JSFiddle - React, Tailwind, and code Playground

by mayur dubey

JavaScript

window.edx.handleScormAndProgress = function(slidenumber,totalslides,customwindow){     
   var progressbar = new scorm(slidenumber,totalslides,customwindow);
 };

// plugin which takes three arguments current slide no, total no of slides and the widnow (the course window)
 var scorm = function(slidenumber,totalslides,customwindow){
  this.slidenumber = slidenumber || 1;
  this.totalslides = totalslides || 1;
  this.customwindow = customwindow;
  this.customwinopener = (customwindow && customwindow.parent && customwindow.parent.opener) ? customwindow.parent.opener : null;
  this.init();
};

scorm.prototype = {
  init : function() {
  var that = this;
  
  this.showOverlay("Course is in Progress..");
  this.onCloseCustomWindow();
    this.trackProgress();
	
  },
  
  // function to check if user is in session or session expired or logged out
  isInSession : function(){
    var that = this;
    var interval = setInterval(function(){
    var scormwindow = (that.customwindow && that.customwindow.parent && that.customwindow.parent.opener) ? that.customwindow.parent.opener : null;
      if (!that.getCookie("edxloggedin")){
        that.customwindow.close();
        clearInterval(interval);
        return false;
      }
    },500);
  },
  
  // to track the progress of the course
  trackProgress : function() {
    if (!this.isInSession) return false;
    var that = this;
    var player = this.customwindow.GetPlayer();
    var passingScore = 100;
    var lmsAPI = this.findLMSAPI(this.customwindow);
    var status = (this.slidenumber == this.totalslides) ? "Completed" : "Incompleted";
    var progressbar = player.GetVar('bar') ? player.GetVar('bar') : this.getSlideWeightage();
    lmsAPI.SetScore(progressbar, 100, 0);
  },
  
  // to gethte LMS api
  findLMSAPI : function(win) {
    if (win.hasOwnProperty("GetStudentID")) return win;
    else if (win.parent == win) return null;
    else return this.findLMSAPI(win.parent);
  },
  
  // get cookie method to grab any cookie,...